logo
  • Getting started
  • User Guide
  • API reference
  • Development
  • Release notes
  • Clustering package ( scipy.cluster )
  • K-means clustering and vector quantization ( scipy.cluster.vq )
  • Hierarchical clustering ( scipy.cluster.hierarchy )
  • Constants ( scipy.constants )
  • Discrete Fourier transforms ( scipy.fft )
  • Legacy discrete Fourier transforms ( scipy.fftpack )
  • Integration and ODEs ( scipy.integrate )
  • Interpolation ( scipy.interpolate )
  • Input and output ( scipy.io )
  • Linear algebra ( scipy.linalg )
  • Low-level BLAS functions ( scipy.linalg.blas )
  • Low-level LAPACK functions ( scipy.linalg.lapack )
  • BLAS Functions for Cython
  • LAPACK functions for Cython
  • Interpolative matrix decomposition ( scipy.linalg.interpolative )
  • Miscellaneous routines ( scipy.misc )
  • Multidimensional image processing ( scipy.ndimage )
  • Orthogonal distance regression ( scipy.odr )
  • Optimization and root finding ( scipy.optimize )
  • Cython optimize zeros API
  • Signal processing ( scipy.signal )
  • Sparse matrices ( scipy.sparse )
  • Sparse linear algebra ( scipy.sparse.linalg )
  • Compressed sparse graph routines ( scipy.sparse.csgraph )
  • Spatial algorithms and data structures ( scipy.spatial )
  • Distance computations ( scipy.spatial.distance )
  • Special functions ( scipy.special )
  • Statistical functions ( scipy.stats )
  • Result classes
  • Contingency table functions ( scipy.stats.contingency )
  • Statistical functions for masked arrays ( scipy.stats.mstats )
  • Quasi-Monte Carlo submodule ( scipy.stats.qmc )
  • Random Number Generators ( scipy.stats.sampling )
  • Low-level callback functions

scipy.optimize.line_search¶

scipy.optimize.line_search(f, myfprime, xk, pk, gfk=None, old_fval=None, old_old_fval=None, args=(), c1=0.0001, c2=0.9, amax=None, extra_condition=None, maxiter=10)[source]¶

Find alpha that satisfies strong Wolfe conditions.

Parameters
fcallable f(x,*args)

Objective function.

myfprimecallable f’(x,*args)

Objective function gradient.

xkndarray

Starting point.

pkndarray

Search direction.

gfkndarray, optional

Gradient value for x=xk (xk being the current parameter estimate). Will be recomputed if omitted.

old_fvalfloat, optional

Function value for x=xk. Will be recomputed if omitted.

old_old_fvalfloat, optional

Function value for the point preceding x=xk.

argstuple, optional

Additional arguments passed to objective function.

c1float, optional

Parameter for Armijo condition rule.

c2float, optional

Parameter for curvature condition rule.

amaxfloat, optional

Maximum step size

extra_conditioncallable, optional

A callable of the form extra_condition(alpha, x, f, g) returning a boolean. Arguments are the proposed step alpha and the corresponding x, f and g values. The line search accepts the value of alpha only if this callable returns True. If the callable returns False for the step length, the algorithm will continue with new iterates. The callable is only called for iterates satisfying the strong Wolfe conditions.

maxiterint, optional

Maximum number of iterations to perform.

Returns
alphafloat or None

Alpha for which x_new = x0 + alpha * pk, or None if the line search algorithm did not converge.

fcint

Number of function evaluations made.

gcint

Number of gradient evaluations made.

new_fvalfloat or None

New function value f(x_new)=f(x0+alpha*pk), or None if the line search algorithm did not converge.

old_fvalfloat

Old function value f(x0).

new_slopefloat or None

The local slope along the search direction at the new value <myfprime(x_new), pk>, or None if the line search algorithm did not converge.

Notes

Uses the line search algorithm to enforce strong Wolfe conditions. See Wright and Nocedal, ‘Numerical Optimization’, 1999, pp. 59-61.

Examples

>>> from scipy.optimize import line_search

A objective function and its gradient are defined.

>>> def obj_func(x):
...     return (x[0])**2+(x[1])**2
>>> def obj_grad(x):
...     return [2*x[0], 2*x[1]]

We can find alpha that satisfies strong Wolfe conditions.

>>> start_point = np.array([1.8, 1.7])
>>> search_gradient = np.array([-1.0, -1.0])
>>> line_search(obj_func, obj_grad, start_point, search_gradient)
(1.0, 2, 1, 1.1300000000000001, 6.13, [1.6, 1.4])
scipy.optimize.bracket scipy.optimize.LbfgsInvHessProduct

© Copyright 2008-2022, The SciPy community.

Created using Sphinx 4.0.2.