bundles / scipy 1.17.1 / scipy / optimize / _optimize / fmin_ncg
function
scipy.optimize._optimize:fmin_ncg
Signature
def fmin_ncg ( f , x0 , fprime , fhess_p = None , fhess = None , args = () , avextol = 1e-05 , epsilon = 1.4901161193847656e-08 , maxiter = None , full_output = 0 , disp = 1 , retall = 0 , callback = None , c1 = 0.0001 , c2 = 0.9 ) Summary
Unconstrained minimization of a function using the Newton-CG method.
Parameters
f: callable ``f(x, *args)``Objective function to be minimized.
x0: ndarrayInitial guess.
fprime: callable ``f'(x, *args)``Gradient of f.
fhess_p: callable ``fhess_p(x, p, *args)``, optionalFunction which computes the Hessian of f times an arbitrary vector, p.
fhess: callable ``fhess(x, *args)``, optionalFunction to compute the Hessian matrix of f.
args: tuple, optionalExtra arguments passed to f, fprime, fhess_p, and fhess (the same set of extra arguments is supplied to all of these functions).
epsilon: float or ndarray, optionalIf fhess is approximated, use this value for the step size.
callback: callable, optionalAn optional user-supplied function which is called after each iteration. Called as callback(xk), where xk is the current parameter vector.
avextol: float, optionalConvergence is assumed when the average relative error in the minimizer falls below this amount.
maxiter: int, optionalMaximum number of iterations to perform.
full_output: bool, optionalIf True, return the optional outputs.
disp: bool, optionalIf True, print convergence message.
retall: bool, optionalIf True, return a list of results at each iteration.
c1: float, default: 1e-4Parameter for Armijo condition rule.
c2: float, default: 0.9Parameter for curvature condition rule
Returns
xopt: ndarrayParameters which minimize f, i.e.,
f(xopt) == fopt.fopt: floatValue of the function at xopt, i.e.,
fopt = f(xopt).fcalls: intNumber of function calls made.
gcalls: intNumber of gradient calls made.
hcalls: intNumber of Hessian calls made.
warnflag: intWarnings generated by the algorithm. 1 : Maximum number of iterations exceeded. 2 : Line search failure (precision loss). 3 : NaN result encountered.
allvecs: listThe result at each iteration, if retall is True (see below).
Notes
Only one of fhess_p or fhess need to be given. If fhess is provided, then fhess_p will be ignored. If neither fhess nor fhess_p is provided, then the hessian product will be approximated using finite differences on fprime. fhess_p must compute the hessian times an arbitrary vector. If it is not given, finite-differences on fprime are used to compute it.
Newton-CG methods are also called truncated Newton methods. This function differs from scipy.optimize.fmin_tnc because
scipy.optimize.fmin_ncg is written purely in Python using NumPy
and scipy while scipy.optimize.fmin_tnc calls a C function.
scipy.optimize.fmin_ncg is only for unconstrained minimization
while scipy.optimize.fmin_tnc is for unconstrained minimization or box constrained minimization. (Box constraints give lower and upper bounds for each variable separately.)
Parameters c1 and c2 must satisfy 0 < c1 < c2 < 1.
See also
- minimize
Interface to minimization algorithms for multivariate functions. See the 'Newton-CG'
methodin particular.
Aliases
-
scipy.optimize.fmin_ncg