bundles / scipy 1.17.1 / scipy / optimize / _optimize / fmin_bfgs
function
scipy.optimize._optimize:fmin_bfgs
Signature
def fmin_bfgs ( f , x0 , fprime = None , args = () , gtol = 1e-05 , norm = inf , epsilon = 1.4901161193847656e-08 , maxiter = None , full_output = 0 , disp = 1 , retall = 0 , callback = None , xrtol = 0 , c1 = 0.0001 , c2 = 0.9 , hess_inv0 = None ) Summary
Minimize a function using the BFGS algorithm.
Parameters
f: callable ``f(x,*args)``Objective function to be minimized.
x0: ndarrayInitial guess, shape (n,)
fprime: callable ``f'(x,*args)``, optionalGradient of f.
args: tuple, optionalExtra arguments passed to f and fprime.
gtol: float, optionalTerminate successfully if gradient norm is less than
gtolnorm: float, optionalOrder of norm (Inf is max, -Inf is min)
epsilon: int or ndarray, optionalIf
fprimeis approximated, use this value for the step size.callback: callable, optionalAn optional user-supplied function to call after each iteration. Called as
callback(xk), wherexkis the current parameter vector.maxiter: int, optionalMaximum number of iterations to perform.
full_output: bool, optionalIf True, return
fopt,func_calls,grad_calls, andwarnflagin addition toxopt.disp: bool, optionalPrint convergence message if True.
retall: bool, optionalReturn a list of results at each iteration if True.
xrtol: float, default: 0Relative tolerance for
x. Terminate successfully if step size is less thanxk * xrtolwherexkis the current parameter vector.c1: float, default: 1e-4Parameter for Armijo condition rule.
c2: float, default: 0.9Parameter for curvature condition rule.
hess_inv0: None or ndarray, optional``Initial inverse hessian estimate, shape (n, n). If None (default) then the identity matrix is used.
Returns
xopt: ndarrayParameters which minimize f, i.e.,
f(xopt) == fopt.fopt: floatMinimum value.
gopt: ndarrayValue of gradient at minimum, f'(xopt), which should be near 0.
Bopt: ndarrayValue of 1/f''(xopt), i.e., the inverse Hessian matrix.
func_calls: intNumber of function_calls made.
grad_calls: intNumber of gradient calls made.
warnflag: integer1Maximum number of iterations exceeded. 2 : Gradient and/or function calls not changing. 3 : NaN result encountered.
allvecs: listThe value of xopt at each iteration. Only returned if
retallis True.
Notes
Optimize the function, f, whose gradient is given by fprime using the quasi-Newton method of Broyden, Fletcher, Goldfarb, and Shanno (BFGS).
Parameters c1 and c2 must satisfy 0 < c1 < c2 < 1.
Examples
import numpy as np from scipy.optimize import fmin_bfgs def quadratic_cost(x, Q): return x @ Q @ x x0 = np.array([-3, -4]) cost_weight = np.diag([1., 10.])✓
fmin_bfgs(quadratic_cost, x0, args=(cost_weight,))
✗def quadratic_cost_grad(x, Q): return 2 * Q @ x✓
fmin_bfgs(quadratic_cost, x0, quadratic_cost_grad, args=(cost_weight,))
✗See also
- minimize
Interface to minimization algorithms for multivariate functions. See
method='BFGS'in particular.
Aliases
-
scipy.optimize.fmin_bfgs