scipy.optimize.fmin_tnc

scipy.optimize.fmin_tnc

scipy.optimize. fmin_tnc ( func, x0, fprime=None, args=(), approx_grad=0, bounds=None, epsilon=1e-08, scale=None, offset=None, messages=15, maxCGit=-1, maxfun=None, eta=-1, stepmx=0, accuracy=0, fmin=0, ftol=-1, xtol=-1, pgtol=-1, rescale=-1, disp=None, callback=None ) [source]

Minimize a function with variables subject to bounds, usinggradient information in a truncated Newton algorithm. Thismethod wraps a C implementation of the algorithm.

Parameters:
func : callable func(x, *args)

Function to minimize. Must do one of:

  1. Return f and g, where f is the value of the function and g itsgradient (a list of floats).
  2. Return the function value but supply gradient functionseparately as fprime.
  3. Return the function value and set approx_grad=True.

If the function returns None, the minimizationis aborted.

x0 : array_like

Initial estimate of minimum.

fprime : callable fprime(x, *args), optional

Gradient of func. If None, then either func must return thefunction value and the gradient (f,g = func(x, *args))or approx_grad must be True.

args : tuple, optional

Arguments to pass to function.

approx_grad : bool, optional

If true, approximate the gradient numerically.

bounds : list, optional

(min, max) pairs for each element in x0, defining thebounds on that parameter. Use None or +/-inf for one ofmin or max when there is no bound in that direction.

epsilon : float, optional

Used if approx_grad is True. The stepsize in a finitedifference approximation for fprime.

scale : array_like, optional

Scaling factors to apply to each variable. If None, thefactors are up-low for interval bounded variables and1+|x| for the others. Defaults to None.

offset : array_like, optional

Value to subtract from each variable. If None, theoffsets are (up+low)/2 for interval bounded variablesand x for the others.

messages : int, optional

Bit mask used to select messages display duringminimization values defined in the MSGS dict. Defaults toMGS_ALL.

disp : int, optional

Integer interface to messages. 0 = no message, 5 = all messages

maxCGit : int, optional

Maximum number of hessian*vector evaluations per mainiteration. If maxCGit == 0, the direction chosen is-gradient if maxCGit < 0, maxCGit is set tomax(1,min(50,n/2)). Defaults to -1.

maxfun : int, optional

Maximum number of function evaluation. if None, maxfun isset to max(100, 10*len(x0)). Defaults to None.

eta : float, optional

Severity of the line search. if < 0 or > 1, set to 0.25.Defaults to -1.

stepmx : float, optional

Maximum step for the line search. May be increased duringcall. If too small, it will be set to 10.0. Defaults to 0.

accuracy : float, optional

Relative precision for finite difference calculations. If<= machine_precision, set to sqrt(machine_precision).Defaults to 0.

fmin : float, optional

Minimum function value estimate. Defaults to 0.

ftol : float, optional

Precision goal for the value of f in the stopping criterion.If ftol < 0.0, ftol is set to 0.0 defaults to -1.

xtol : float, optional

Precision goal for the value of x in the stoppingcriterion (after applying x scaling factors). If xtol <0.0, xtol is set to sqrt(machine_precision). Defaults to-1.

pgtol : float, optional

Precision goal for the value of the projected gradient inthe stopping criterion (after applying x scaling factors).If pgtol < 0.0, pgtol is set to 1e-2 * sqrt(accuracy).Setting it to 0.0 is not recommended. Defaults to -1.

rescale : float, optional

Scaling factor (in log10) used to trigger f valuerescaling. If 0, rescale at each iteration. If a largevalue, never rescale. If < 0, rescale is set to 1.3.

callback : callable, optional

Called after each iteration, as callback(xk), where xk is thecurrent parameter vector.

Returns:
x : ndarray

The solution.

nfeval : int

The number of function evaluations.

rc : int

Return code, see below

See also

minimize
Interface to minimization algorithms for multivariate functions. See the ‘TNC’ method in particular.

Notes

The underlying algorithm is truncated Newton, also calledNewton Conjugate-Gradient. This method differs fromscipy.optimize.fmin_ncg in that

  1. It wraps a C implementation of the algorithm
  2. It allows each variable to be given an upper and lower bound.

The algorithm incorporates the bound constraints by determiningthe descent direction as in an unconstrained truncated Newton,but never taking a step-size large enough to leave the spaceof feasible x’s. The algorithm keeps track of a set ofcurrently active constraints, and ignores them when computingthe minimum allowable step size. (The x’s associated with theactive constraint are kept fixed.) If the maximum allowablestep size is zero then a new constraint is added. At the endof each iteration one of the constraints may be deemed nolonger active and removed. A constraint is consideredno longer active is if it is currently activebut the gradient for that variable points inward from theconstraint. The specific constraint removed is the oneassociated with the variable of largest index whoseconstraint is no longer active.

Return codes are defined as follows:

-1 : Infeasible (lower bound > upper bound)
 0 : Local minimum reached (|pg| ~= 0)
 1 : Converged (|f_n-f_(n-1)| ~= 0)
 2 : Converged (|x_n-x_(n-1)| ~= 0)
 3 : Max. number of function evaluations reached
 4 : Linear search failed
 5 : All lower bounds are equal to the upper bounds
 6 : Unable to progress
 7 : User requested end of minimization

References

Wright S., Nocedal J. (2006), ‘Numerical Optimization’

Nash S.G. (1984), “Newton-Type Minimization Via the Lanczos Method”,SIAM Journal of Numerical Analysis 21, pp. 770-778

猜你喜欢

转载自blog.csdn.net/yanwucao/article/details/80427651