bundles / scipy 1.17.1 / scipy / optimize / _minimize / minimize_scalar
function
scipy.optimize._minimize:minimize_scalar
Signature
def minimize_scalar ( fun , bracket = None , bounds = None , args = () , method = None , tol = None , options = None ) Summary
Local minimization of scalar function of one variable.
Parameters
fun: callableObjective function. Scalar function, must return a scalar.
Suppose the callable has signature
f0(x, *my_args, **my_kwargs), wheremy_argsandmy_kwargsare required positional and keyword arguments. Rather than passingf0as the callable, wrap it to accept onlyx; e.g., passfun=lambda x: f0(x, *my_args, **my_kwargs)as the callable, wheremy_args(tuple) andmy_kwargs(dict) have been gathered before invoking this function.bracket: sequence, optionalFor methods 'brent' and 'golden',
bracketdefines the bracketing interval and is required. Either a triple(xa, xb, xc)satisfyingxa < xb < xcandfunc(xb) < func(xa) and func(xb) < func(xc), or a pair(xa, xb)to be used as initial points for a downhill bracket search (see scipy.optimize.bracket). The minimizerres.xwill not necessarily satisfyxa <= res.x <= xb.bounds: sequence, optionalFor method 'bounded',
boundsis mandatory and must have two finite items corresponding to the optimization bounds.args: tuple, optionalExtra arguments passed to the objective function.
method: str or callable, optionalType of solver. Should be one of:
Brent <optimize.minimize_scalar-brent>Bounded <optimize.minimize_scalar-bounded>Golden <optimize.minimize_scalar-golden>custom - a callable object (added in version 0.14.0), see below
Default is "Bounded" if bounds are provided and "Brent" otherwise. See the 'Notes' section for details of each solver.
tol: float, optionalTolerance for termination. For detailed control, use solver-specific options.
options: dict, optionalA dictionary of solver options.
maxiter
maxiter
disp
disp
See
show_options()for solver-specific options.
Returns
res: OptimizeResultThe optimization result represented as a
OptimizeResultobject. Important attributes are:xthe solution array,successa Boolean flag indicating if the optimizer exited successfully andmessagewhich describes the cause of the termination. See OptimizeResult for a description of other attributes.
Notes
This section describes the available solvers that can be selected by the 'method' parameter. The default method is the "Bounded" Brent method if bounds are passed and unbounded "Brent" otherwise.
Method Brent <optimize.minimize_scalar-brent> uses Brent's algorithm [1] to find a local minimum. The algorithm uses inverse parabolic interpolation when possible to speed up convergence of the golden section method.
Method Golden <optimize.minimize_scalar-golden> uses the golden section search technique [1]. It uses analog of the bisection method to decrease the bracketed interval. It is usually preferable to use the Brent method.
Method Bounded <optimize.minimize_scalar-bounded> can perform bounded minimization [2] [3]. It uses the Brent method to find a local minimum in the interval x1 < xopt < x2.
Note that the Brent and Golden methods do not guarantee success unless a valid bracket triple is provided. If a three-point bracket cannot be found, consider scipy.optimize.minimize. Also, all methods are intended only for local minimization. When the function of interest has more than one local minimum, consider global_optimization.
Custom minimizers
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 method parameter.
The callable is called as method(fun, args, **kwargs, **options) where kwargs corresponds to any other parameters passed to minimize (such as bracket, tol, etc.), except the options dict, which has its contents also passed as method parameters pair by pair. The method shall return an OptimizeResult object.
The provided method callable must be able to accept (and possibly ignore) arbitrary parameters; the set of parameters accepted by minimize may expand in future versions and then these parameters will be passed to the method. You can find an example in the scipy.optimize tutorial.
Examples
Consider the problem of minimizing the following function.def f(x): return (x - 2) * x * (x + 2)**2✓
from scipy.optimize import minimize_scalar res = minimize_scalar(f)✓
res.fun
✗res.x
✗res = minimize_scalar(f, bounds=(-3, -1), method='bounded')
✓res.fun # minimum res.x # minimizer✗
See also
- minimize
Interface to minimization algorithms for scalar multivariate functions
- show_options
Additional options accepted by the solvers
Aliases
-
scipy.optimize.minimize_scalar