Minimization of scalar function of one or more variables.
New in version 0.11.0.
Parameters :  fun : callable
x0 : ndarray
args : tuple, optional
method : str, optional
jac : bool or callable, optional
hess, hessp : callable, optional
bounds : sequence, optional
constraints : dict or sequence of dict, optional
tol : float, optional
options : dict, optional
callback : callable, optional


Returns :  res : Result

See also
Notes
This section describes the available solvers that can be selected by the ‘method’ parameter. The default method is BFGS.
Unconstrained minimization
Method NelderMead uses the Simplex algorithm [R65], [R66]. This algorithm has been successful in many applications but other algorithms using the first and/or second derivatives information might be preferred for their better performances and robustness in general.
Method Powell is a modification of Powell’s method [R67], [R68] which is a conjugate direction method. It performs sequential onedimensional minimizations along each vector of the directions set (direc field in options and info), which is updated at each iteration of the main minimization loop. The function need not be differentiable, and no derivatives are taken.
Method CG uses a nonlinear conjugate gradient algorithm by Polak and Ribiere, a variant of the FletcherReeves method described in [R69] pp. 120122. Only the first derivatives are used.
Method BFGS uses the quasiNewton method of Broyden, Fletcher, Goldfarb, and Shanno (BFGS) [R69] pp. 136. It uses the first derivatives only. BFGS has proven good performance even for nonsmooth optimizations
Method NewtonCG uses a NewtonCG algorithm [R69] pp. 168 (also known as the truncated Newton method). It uses a CG method to the compute the search direction. See also TNC method for a boxconstrained minimization with a similar algorithm.
Method Anneal uses simulated annealing, which is a probabilistic metaheuristic algorithm for global optimization. It uses no derivative information from the function being optimized.
Constrained minimization
Method LBFGSB uses the LBFGSB algorithm [R70], [R71] for bound constrained minimization.
Method TNC uses a truncated Newton algorithm [R69], [R72] to minimize a function with variables subject to bounds. This algorithm is uses gradient information; it is also called Newton ConjugateGradient. It differs from the NewtonCG method described above as it wraps a C implementation and allows each variable to be given upper and lower bounds.
Method COBYLA uses the Constrained Optimization BY Linear Approximation (COBYLA) method [R73], [10], [11]. The algorithm is based on linear approximations to the objective function and each constraint. The method wraps a FORTRAN implementation of the algorithm.
Method SLSQP uses Sequential Least SQuares Programming to minimize a function of several variables with any combination of bounds, equality and inequality constraints. The method wraps the SLSQP Optimization subroutine originally implemented by Dieter Kraft [12].
References
[R65]  (1, 2) Nelder, J A, and R Mead. 1965. A Simplex Method for Function Minimization. The Computer Journal 7: 30813. 
[R66]  (1, 2) Wright M H. 1996. Direct search methods: Once scorned, now respectable, in Numerical Analysis 1995: Proceedings of the 1995 Dundee Biennial Conference in Numerical Analysis (Eds. D F Griffiths and G A Watson). Addison Wesley Longman, Harlow, UK. 191208. 
[R67]  (1, 2) Powell, M J D. 1964. An efficient method for finding the minimum of a function of several variables without calculating derivatives. The Computer Journal 7: 155162. 
[R68]  (1, 2) Press W, S A Teukolsky, W T Vetterling and B P Flannery. Numerical Recipes (any edition), Cambridge University Press. 
[R69]  (1, 2, 3, 4, 5, 6) Nocedal, J, and S J Wright. 2006. Numerical Optimization. Springer New York. 
[R70]  (1, 2) Byrd, R H and P Lu and J. Nocedal. 1995. A Limited Memory Algorithm for Bound Constrained Optimization. SIAM Journal on Scientific and Statistical Computing 16 (5): 11901208. 
[R71]  (1, 2) Zhu, C and R H Byrd and J Nocedal. 1997. LBFGSB: Algorithm 778: LBFGSB, FORTRAN routines for large scale bound constrained optimization. ACM Transactions on Mathematical Software 23 (4): 550560. 
[R72]  (1, 2) Nash, S G. NewtonType Minimization Via the Lanczos Method. 1984. SIAM Journal of Numerical Analysis 21: 770778. 
[R73]  (1, 2) Powell, M J D. A direct search optimization method that models the objective and constraint functions by linear interpolation. 1994. Advances in Optimization and Numerical Analysis, eds. S. Gomez and JP Hennart, Kluwer Academic (Dordrecht), 5167. 
[10]  (1, 2) Powell M J D. Direct search algorithms for optimization calculations. 1998. Acta Numerica 7: 287336. 
[11]  (1, 2) Powell M J D. A view of algorithms for optimization without derivatives. 2007.Cambridge University Technical Report DAMTP 2007/NA03 
[12]  (1, 2) Kraft, D. A software package for sequential quadratic programming. 1988. Tech. Rep. DFVLRFB 8828, DLR German Aerospace Center – Institute for Flight Mechanics, Koln, Germany. 
Examples
Let us consider the problem of minimizing the Rosenbrock function. This function (and its respective derivatives) is implemented in rosen (resp. rosen_der, rosen_hess) in the scipy.optimize.
>>> from scipy.optimize import minimize, rosen, rosen_der
A simple application of the NelderMead method is:
>>> x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
>>> res = minimize(rosen, x0, method='NelderMead')
>>> res.x
[ 1. 1. 1. 1. 1.]
Now using the BFGS algorithm, using the first derivative and a few options:
>>> res = minimize(rosen, x0, method='BFGS', jac=rosen_der,
... options={'gtol': 1e6, 'disp': True})
Optimization terminated successfully.
Current function value: 0.000000
Iterations: 52
Function evaluations: 64
Gradient evaluations: 64
>>> res.x
[ 1. 1. 1. 1. 1.]
>>> print res.message
Optimization terminated successfully.
>>> res.hess
[[ 0.00749589 0.01255155 0.02396251 0.04750988 0.09495377]
[ 0.01255155 0.02510441 0.04794055 0.09502834 0.18996269]
[ 0.02396251 0.04794055 0.09631614 0.19092151 0.38165151]
[ 0.04750988 0.09502834 0.19092151 0.38341252 0.7664427 ]
[ 0.09495377 0.18996269 0.38165151 0.7664427 1.53713523]]
Next, consider a minimization problem with several constraints (namely Example 16.4 from [R69]). The objective function is:
>>> fun = lambda x: (x[0]  1)**2 + (x[1]  2.5)**2
There are three constraints defined as:
>>> cons = ({'type': 'ineq', 'fun': lambda x: x[0]  2 * x[1] + 2},
... {'type': 'ineq', 'fun': lambda x: x[0]  2 * x[1] + 6},
... {'type': 'ineq', 'fun': lambda x: x[0] + 2 * x[1] + 2})
And variables must be positive, hence the following bounds:
>>> bnds = ((0, None), (0, None))
The optimization problem is solved using the SLSQP method as:
>>> res = minimize(fun, (2, 0), method='SLSQP', bounds=bnds,
... constraints=cons)
It should converge to the theoretical solution (1.4 ,1.7).