Hướng dẫn dùng scipy.optimize.minimize python
Minimization of scalar function of one variable. Objective function. Scalar function, must return a scalar. For methods ‘brent’ and ‘golden’, For method ‘bounded’, bounds is mandatory and must have two items
corresponding to the optimization bounds. Extra arguments passed to the objective function. Type of solver. Should be one of: Brent Bounded Golden custom - a callable object (added in version 0.14.0), see below See the ‘Notes’ section for details of each solver. tolfloat, optionalTolerance for termination. For detailed control, use solver-specific options. optionsdict, optionalA dictionary of solver options.
See The optimization result represented as a See also minimize Interface to minimization algorithms for scalar multivariate functions show_options Additional options accepted by the solvers Notes 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. 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 The callable is called as The provided method callable must be able to accept (and possibly ignore) arbitrary parameters; the set of parameters accepted by New in version 0.11.0. Examples 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 |