# `optimize.lbfgsb`¶

## Module Contents¶

### Classes¶

 `LbfgsInvHessProduct`(self,sk,yk) Linear operator for the L-BFGS approximate inverse Hessian. `Problem`()

### Functions¶

 `fmin_l_bfgs_b`(func,x0,fprime=None,args=tuple,approx_grad=0,bounds=None,m=10,factr=10000000.0,pgtol=1e-05,epsilon=1e-08,iprint=None,maxfun=15000,maxiter=15000,disp=None,callback=None,maxls=20) Minimize a function func using the L-BFGS-B algorithm. `_minimize_lbfgsb`(fun,x0,args=tuple,jac=None,bounds=None,disp=None,maxcor=10,ftol=2.220446049250313e-09,gtol=1e-05,eps=1e-08,maxfun=15000,maxiter=15000,iprint=None,callback=None,maxls=20,**unknown_options) Minimize a scalar function of one or more variables using the L-BFGS-B `func`(x) `grad`(x) `func_and_grad`(x)
`fmin_l_bfgs_b`(func, x0, fprime=None, args=tuple, approx_grad=0, bounds=None, m=10, factr=10000000.0, pgtol=1e-05, epsilon=1e-08, iprint=None, maxfun=15000, maxiter=15000, disp=None, callback=None, maxls=20)

Minimize a function func using the L-BFGS-B algorithm.

func : callable f(x,*args)
Function to minimise.
x0 : ndarray
Initial guess.
fprime : callable fprime(x,*args), optional
The gradient of func. If None, then func returns the function value and the gradient (`f, g = func(x, *args)`), unless approx_grad is True in which case func returns only `f`.
args : sequence, optional
Arguments to pass to func and fprime.
Whether to approximate the gradient numerically (in which case func returns only the function value).
bounds : list, optional
`(min, max)` pairs for each element in `x`, defining the bounds on that parameter. Use None or +-inf for one of `min` or `max` when there is no bound in that direction.
m : int, optional
The maximum number of variable metric corrections used to define the limited memory matrix. (The limited memory BFGS method does not store the full hessian but uses this many terms in an approximation to it.)
factr : float, optional
The iteration stops when `(f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= factr * eps`, where `eps` is the machine precision, which is automatically generated by the code. Typical values for factr are: 1e12 for low accuracy; 1e7 for moderate accuracy; 10.0 for extremely high accuracy. See Notes for relationship to ftol, which is exposed (instead of factr) by the scipy.optimize.minimize interface to L-BFGS-B.
pgtol : float, optional
The iteration will stop when `max{|proj g_i | i = 1, ..., n} <= pgtol` where `pg_i` is the i-th component of the projected gradient.
epsilon : float, optional
Step size used when approx_grad is True, for numerically calculating the gradient
iprint : int, optional
Controls the frequency of output. `iprint < 0` means no output; `iprint = 0` print only one line at the last iteration; `0 < iprint < 99` print also f and `|proj g|` every iprint iterations; `iprint = 99` print details of every iteration except n-vectors; `iprint = 100` print also the changes of active set and final x; `iprint > 100` print details of every iteration including x and g.
disp : int, optional
If zero, then no output. If a positive number, then this over-rides iprint (i.e., iprint gets the value of disp).
maxfun : int, optional
Maximum number of function evaluations.
maxiter : int, optional
Maximum number of iterations.
callback : callable, optional
Called after each iteration, as `callback(xk)`, where `xk` is the current parameter vector.
maxls : int, optional
Maximum number of line search steps (per iteration). Default is 20.
x : array_like
Estimated position of the minimum.
f : float
Value of func at the minimum.
d : dict

Information dictionary.

• d[‘warnflag’] is
• 0 if converged,
• 1 if too many function evaluations or too many iterations,
• 2 if stopped for another reason, given in d[‘task’]
• d[‘grad’] is the gradient at the minimum (should be 0 ish)
• d[‘funcalls’] is the number of function calls made.
• d[‘nit’] is the number of iterations.
minimize: Interface to minimization algorithms for multivariate
functions. See the ‘L-BFGS-B’ method in particular. Note that the ftol option is made available via that interface, while factr is provided via this interface, where factr is the factor multiplying the default machine floating-point precision to arrive at ftol: `ftol = factr * numpy.finfo(float).eps`.

The version included here (in fortran code) is 3.0 (released April 25, 2011). It was written by Ciyou Zhu, Richard Byrd, and Jorge Nocedal <nocedal@ece.nwu.edu>. It carries the following condition for use:

This software is freely available, but we expect that all publications describing work using this software, or all commercial products using it, quote at least one of the references given below. This software is released under the BSD License.

• R. H. Byrd, P. Lu and J. Nocedal. A Limited Memory Algorithm for Bound Constrained Optimization, (1995), SIAM Journal on Scientific and Statistical Computing, 16, 5, pp. 1190-1208.
• C. Zhu, R. H. Byrd and J. Nocedal. L-BFGS-B: Algorithm 778: L-BFGS-B, FORTRAN routines for large scale bound constrained optimization (1997), ACM Transactions on Mathematical Software, 23, 4, pp. 550 - 560.
• J.L. Morales and J. Nocedal. L-BFGS-B: Remark on Algorithm 778: L-BFGS-B, FORTRAN routines for large scale bound constrained optimization (2011), ACM Transactions on Mathematical Software, 38, 1.
`_minimize_lbfgsb`(fun, x0, args=tuple, jac=None, bounds=None, disp=None, maxcor=10, ftol=2.220446049250313e-09, gtol=1e-05, eps=1e-08, maxfun=15000, maxiter=15000, iprint=None, callback=None, maxls=20, **unknown_options)

Minimize a scalar function of one or more variables using the L-BFGS-B algorithm.

disp : bool
Set to True to print convergence messages.
maxcor : int
The maximum number of variable metric corrections used to define the limited memory matrix. (The limited memory BFGS method does not store the full hessian but uses this many terms in an approximation to it.)
ftol : float
The iteration stops when ```(f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= ftol```.
gtol : float
The iteration will stop when ```max{|proj g_i | i = 1, ..., n} <= gtol``` where `pg_i` is the i-th component of the projected gradient.
eps : float
Step size used for numerical approximation of the jacobian.
disp : int
Set to True to print convergence messages.
maxfun : int
Maximum number of function evaluations.
maxiter : int
Maximum number of iterations.
maxls : int, optional
Maximum number of line search steps (per iteration). Default is 20.

The option ftol is exposed via the scipy.optimize.minimize interface, but calling scipy.optimize.fmin_l_bfgs_b directly exposes factr. The relationship between the two is `ftol = factr * numpy.finfo(float).eps`. I.e., factr multiplies the default machine floating-point precision to arrive at ftol.

class `LbfgsInvHessProduct`(sk, yk)

Linear operator for the L-BFGS approximate inverse Hessian.

This operator computes the product of a vector with the approximate inverse of the Hessian of the objective function, using the L-BFGS limited memory approximation to the inverse Hessian, accumulated during the optimization.

Objects of this class implement the `scipy.sparse.linalg.LinearOperator` interface.

sk : array_like, shape=(n_corr, n)
Array of n_corr most recent updates to the solution vector. (See [1]).
yk : array_like, shape=(n_corr, n)
 [1] Nocedal, Jorge. “Updating quasi-Newton matrices with limited storage.” Mathematics of computation 35.151 (1980): 773-782.
`__init__`(sk, yk)

Construct the operator.

`_matvec`(x)

Efficient matrix-vector multiply with the BFGS matrices.

This calculation is described in Section (4) of [1].

x : ndarray
An array with shape (n,) or (n,1).
y : ndarray
The matrix-vector product
`todense`()

Return a dense array representation of this operator.

arr : ndarray, shape=(n, n)
An array with the same shape and containing the same data represented by this LinearOperator.
`func`(x)
`grad`(x)
`func_and_grad`(x)
class `Problem`
`fun`(x)