- scipy.optimize.minimize_scalar(fun, bracket=None, bounds=None, args=(), method='brent', tol=None, options=None)¶
Minimization of scalar function of one variable.
Objective function. Scalar function, must return a scalar.
- bracketsequence, optional
For methods ‘brent’ and ‘golden’,
bracketdefines the bracketing interval and can either have three items
(a, b, c)so that
a < b < cand
fun(b) < fun(a), fun(c)or two items
cwhich are assumed to be a starting interval for a downhill bracket search (see
bracket); it doesn’t always mean that the obtained solution will satisfy
a <= x <= c.
- boundssequence, optional
For method ‘bounded’, bounds is mandatory and must have two items corresponding to the optimization bounds.
- argstuple, optional
Extra arguments passed to the objective function.
- methodstr or callable, optional
Type of solver. Should be one of:
- tolfloat, optional
Tolerance for termination. For detailed control, use solver-specific options.
- optionsdict, optional
A dictionary of solver options.
Maximum number of iterations to perform.
Set to True to print convergence messages.
show_optionsfor solver-specific options.
The optimization result represented as a
OptimizeResultobject. Important attributes are:
xthe solution array,
successa Boolean flag indicating if the optimizer exited successfully and
messagewhich describes the cause of the termination. See
OptimizeResultfor a description of other attributes.
This section describes the available solvers that can be selected by the ‘method’ parameter. The default method is Brent.
Method Brent uses Brent’s algorithm to find a local minimum. The algorithm uses inverse parabolic interpolation when possible to speed up convergence of the golden section method.
Method Golden uses the golden section search technique. It uses analog of the bisection method to decrease the bracketed interval. It is usually preferable to use the Brent method.
Method Bounded can perform bounded minimization. It uses the Brent method to find a local minimum in the interval x1 < xopt < x2.
It may be useful to pass a custom minimization method, for example when using some library frontend to minimize_scalar. You can simply pass a callable as the
The callable is called as
method(fun, args, **kwargs, **options)where
kwargscorresponds to any other parameters passed to
bracket, tol, etc.), except the options dict, which has its contents also passed as method parameters pair by pair. The method shall return an
The provided method callable must be able to accept (and possibly ignore) arbitrary parameters; the set of parameters accepted by
minimizemay expand in future versions and then these parameters will be passed to the method. You can find an example in the scipy.optimize tutorial.
New in version 0.11.0.
Consider the problem of minimizing the following function.
>>> def f(x): ... return (x - 2) * x * (x + 2)**2
Using the Brent method, we find the local minimum as:
>>> from scipy.optimize import minimize_scalar >>> res = minimize_scalar(f) >>> res.x 1.28077640403
Using the Bounded method, we find a local minimum with specified bounds as:
>>> res = minimize_scalar(f, bounds=(-3, -1), method='bounded') >>> res.x -2.0000002026