Limited-memory BFGS

From HandWiki
Short description: Optimization algorithm

Limited-memory BFGS (L-BFGS or LM-BFGS) is an optimization algorithm in the family of quasi-Newton methods that approximates the Broyden–Fletcher–Goldfarb–Shanno algorithm (BFGS) using a limited amount of computer memory.[1] It is a popular algorithm for parameter estimation in machine learning.[2][3] The algorithm's target problem is to minimize [math]\displaystyle{ f(\mathbf{x}) }[/math] over unconstrained values of the real-vector [math]\displaystyle{ \mathbf{x} }[/math] where [math]\displaystyle{ f }[/math] is a differentiable scalar function.

Like the original BFGS, L-BFGS uses an estimate of the inverse Hessian matrix to steer its search through variable space, but where BFGS stores a dense [math]\displaystyle{ n\times n }[/math] approximation to the inverse Hessian (n being the number of variables in the problem), L-BFGS stores only a few vectors that represent the approximation implicitly. Due to its resulting linear memory requirement, the L-BFGS method is particularly well suited for optimization problems with many variables. Instead of the inverse Hessian Hk, L-BFGS maintains a history of the past m updates of the position x and gradient ∇f(x), where generally the history size m can be small (often [math]\displaystyle{ m\lt 10 }[/math]). These updates are used to implicitly do operations requiring the Hk-vector product.

Algorithm

The algorithm starts with an initial estimate of the optimal value, [math]\displaystyle{ \mathbf{x}_0 }[/math], and proceeds iteratively to refine that estimate with a sequence of better estimates [math]\displaystyle{ \mathbf{x}_1,\mathbf{x}_2,\ldots }[/math]. The derivatives of the function [math]\displaystyle{ g_k:=\nabla f(\mathbf{x}_k) }[/math] are used as a key driver of the algorithm to identify the direction of steepest descent, and also to form an estimate of the Hessian matrix (second derivative) of [math]\displaystyle{ f(\mathbf{x}) }[/math].

L-BFGS shares many features with other quasi-Newton algorithms, but is very different in how the matrix-vector multiplication [math]\displaystyle{ d_k=-H_k g_k }[/math] is carried out, where [math]\displaystyle{ d_k }[/math] is the approximate Newton's direction, [math]\displaystyle{ g_k }[/math] is the current gradient, and [math]\displaystyle{ H_k }[/math] is the inverse of the Hessian matrix. There are multiple published approaches using a history of updates to form this direction vector. Here, we give a common approach, the so-called "two loop recursion."[4][5]

We take as given [math]\displaystyle{ x_k }[/math], the position at the k-th iteration, and [math]\displaystyle{ g_k\equiv\nabla f(x_k) }[/math] where [math]\displaystyle{ f }[/math] is the function being minimized, and all vectors are column vectors. We also assume that we have stored the last m updates of the form

[math]\displaystyle{ s_k = x_{k+1} - x_k }[/math]
[math]\displaystyle{ y_k = g_{k+1} - g_k }[/math].

We define [math]\displaystyle{ \rho_k = \frac{1}{y^{\top}_k s_k} }[/math], and [math]\displaystyle{ H^0_k }[/math] will be the 'initial' approximate of the inverse Hessian that our estimate at iteration k begins with.

The algorithm is based on the BFGS recursion for the inverse Hessian as

[math]\displaystyle{ H_{k+1} = (I-\rho_k s_k y_k^\top)H_k(I-\rho_k y_k s_k^\top) + \rho_k s_k s_k^\top. }[/math]

For a fixed k we define a sequence of vectors [math]\displaystyle{ q_{k-m},\ldots,q_k }[/math] as [math]\displaystyle{ q_k:=g_k }[/math] and [math]\displaystyle{ q_i:=(I-\rho_i y_i s_i^\top)q_{i+1} }[/math]. Then a recursive algorithm for calculating [math]\displaystyle{ q_i }[/math] from [math]\displaystyle{ q_{i+1} }[/math] is to define [math]\displaystyle{ \alpha_i := \rho_i s_i^\top q_{i+1} }[/math] and [math]\displaystyle{ q_i=q_{i+1}-\alpha_i y_i }[/math]. We also define another sequence of vectors [math]\displaystyle{ z_{k-m},\ldots,z_k }[/math] as [math]\displaystyle{ z_i:=H_iq_i }[/math]. There is another recursive algorithm for calculating these vectors which is to define [math]\displaystyle{ z_{k-m}=H_k^0 q_{k-m} }[/math] and then recursively define [math]\displaystyle{ \beta_i:=\rho_i y_i^\top z_i }[/math] and [math]\displaystyle{ z_{i+1}=z_i + (\alpha_i - \beta_i)s_i }[/math]. The value of [math]\displaystyle{ z_k }[/math] is then our ascent direction.

Thus we can compute the descent direction as follows:

[math]\displaystyle{ \begin{array}{l} q = g_k\\ \mathtt{For}\ i=k-1, k-2, \ldots, k-m\\ \qquad \alpha_i = \rho_i s^\top_i q\\ \qquad q = q - \alpha_i y_i\\ \gamma_k = \frac{s_{k - 1}^{\top} y_{k - 1}}{y_{k - 1}^{\top} y_{k - 1}} \\ H^0_k= \gamma_k I\\ z = H^0_k q\\ \mathtt{For}\ i=k-m, k-m+1, \ldots, k-1\\ \qquad \beta_i = \rho_i y^\top_i z\\ \qquad z = z + s_i (\alpha_i - \beta_i)\\ z = -z \end{array} }[/math]


This formulation gives the search direction for the minimization problem, i.e., [math]\displaystyle{ z = - H_k g_k }[/math]. For maximization problems, one should thus take -z instead. Note that the initial approximate inverse Hessian [math]\displaystyle{ H^0_k }[/math] is chosen as a diagonal matrix or even a multiple of the identity matrix since this is numerically efficient.

The scaling of the initial matrix [math]\displaystyle{ \gamma_k }[/math] ensures that the search direction is well scaled and therefore the unit step length is accepted in most iterations. A Wolfe line search is used to ensure that the curvature condition is satisfied and the BFGS updating is stable. Note that some software implementations use an Armijo backtracking line search, but cannot guarantee that the curvature condition [math]\displaystyle{ y_k^{\top} s_k \gt 0 }[/math] will be satisfied by the chosen step since a step length greater than [math]\displaystyle{ 1 }[/math] may be needed to satisfy this condition. Some implementations address this by skipping the BFGS update when [math]\displaystyle{ y_k^{\top} s_k }[/math] is negative or too close to zero, but this approach is not generally recommended since the updates may be skipped too often to allow the Hessian approximation [math]\displaystyle{ H_k }[/math] to capture important curvature information. Some solvers employ so called damped (L)BFGS update which modifies quantities [math]\displaystyle{ s_k }[/math] and [math]\displaystyle{ y_k }[/math] in order to satisfy the curvature condition.

The two-loop recursion formula is widely used by unconstrained optimizers due to its efficiency in multiplying by the inverse Hessian. However, it does not allow for the explicit formation of either the direct or inverse Hessian and is incompatible with non-box constraints. An alternative approach involves using a low-rank representation for the direct and/or inverse Hessian.[6] This represents the Hessian as a sum of a diagonal matrix and a low-rank update. Such a representation enables the use of L-BFGS in constrained settings, for example, as part of the SQP method.

Applications

L-BFGS has been called "the algorithm of choice" for fitting log-linear (MaxEnt) models and conditional random fields with [math]\displaystyle{ \ell 2 }[/math]-regularization.[2][3]

Variants

Since BFGS (and hence L-BFGS) is designed to minimize smooth functions without constraints, the L-BFGS algorithm must be modified to handle functions that include non-differentiable components or constraints. A popular class of modifications are called active-set methods, based on the concept of the active set. The idea is that when restricted to a small neighborhood of the current iterate, the function and constraints can be simplified.

L-BFGS-B

The L-BFGS-B algorithm extends L-BFGS to handle simple box constraints (aka bound constraints) on variables; that is, constraints of the form lixiui where li and ui are per-variable constant lower and upper bounds, respectively (for each xi, either or both bounds may be omitted).[7][8] The method works by identifying fixed and free variables at every step (using a simple gradient method), and then using the L-BFGS method on the free variables only to get higher accuracy, and then repeating the process.

OWL-QN

Orthant-wise limited-memory quasi-Newton (OWL-QN) is an L-BFGS variant for fitting [math]\displaystyle{ \ell 1 }[/math]-regularized models, exploiting the inherent sparsity of such models.[3] It minimizes functions of the form

[math]\displaystyle{ f(\vec x) = g(\vec x) + C \|\vec x\|_1 }[/math]

where [math]\displaystyle{ g }[/math] is a differentiable convex loss function. The method is an active-set type method: at each iterate, it estimates the sign of each component of the variable, and restricts the subsequent step to have the same sign. Once the sign is fixed, the non-differentiable [math]\displaystyle{ \|\vec x\|_1 }[/math] term becomes a smooth linear term which can be handled by L-BFGS. After an L-BFGS step, the method allows some variables to change sign, and repeats the process.

O-LBFGS

Schraudolph et al. present an online approximation to both BFGS and L-BFGS.[9] Similar to stochastic gradient descent, this can be used to reduce the computational complexity by evaluating the error function and gradient on a randomly drawn subset of the overall dataset in each iteration. It has been shown that O-LBFGS has a global almost sure convergence [10] while the online approximation of BFGS (O-BFGS) is not necessarily convergent.[11]

Implementation of variants

Notable open source implementations include:

  • ALGLIB implements L-BFGS in C++ and C# as well as a separate box/linearly constrained version, BLEIC.
  • R's optim general-purpose optimizer routine uses the L-BFGS-B method.
  • SciPy's optimization module's minimize method also includes an option to use L-BFGS-B.

Notable non open source implementations include:

  • The L-BFGS-B variant also exists as ACM TOMS algorithm 778.[8][12] In February 2011, some of the authors of the original L-BFGS-B code posted a major update (version 3.0).
  • A reference implementation in Fortran 77 (and with a Fortran 90 interface).[13][14] This version, as well as older versions, has been converted to many other languages.
  • An OWL-QN C++ implementation by its designers.[3][15]

Works cited

  1. Liu, D. C.; Nocedal, J. (1989). "On the Limited Memory Method for Large Scale Optimization". Mathematical Programming B 45 (3): 503–528. doi:10.1007/BF01589116. http://www.ece.northwestern.edu/~nocedal/PSfiles/limited-memory.ps.gz. 
  2. 2.0 2.1 Malouf, Robert (2002). "A comparison of algorithms for maximum entropy parameter estimation". pp. 49–55. doi:10.3115/1118853.1118871. https://dl.acm.org/citation.cfm?id=1118871. 
  3. 3.0 3.1 3.2 3.3 Andrew, Galen; Gao, Jianfeng (2007). "Scalable training of L₁-regularized log-linear models". Proceedings of the 24th International Conference on Machine Learning. doi:10.1145/1273496.1273501. ISBN 9781595937933. http://research.microsoft.com/apps/pubs/default.aspx?id=78900. 
  4. Matthies, H.; Strang, G. (1979). "The solution of non linear finite element equations". International Journal for Numerical Methods in Engineering 14 (11): 1613–1626. doi:10.1002/nme.1620141104. Bibcode1979IJNME..14.1613M. 
  5. Nocedal, J. (1980). "Updating Quasi-Newton Matrices with Limited Storage". Mathematics of Computation 35 (151): 773–782. doi:10.1090/S0025-5718-1980-0572855-7. 
  6. Byrd, R. H.; Nocedal, J.; Schnabel, R. B. (1994). "Representations of Quasi-Newton Matrices and their use in Limited Memory Methods". Mathematical Programming 63 (4): 129–156. doi:10.1007/BF01582063. 
  7. Byrd, R. H.; Lu, P.; Nocedal, J.; Zhu, C. (1995). "A Limited Memory Algorithm for Bound Constrained Optimization". SIAM J. Sci. Comput. 16 (5): 1190–1208. doi:10.1137/0916069. https://digital.library.unt.edu/ark:/67531/metadc666315/. 
  8. 8.0 8.1 Zhu, C.; Byrd, Richard H.; Lu, Peihuang; Nocedal, Jorge (1997). "L-BFGS-B: Algorithm 778: L-BFGS-B, FORTRAN routines for large scale bound constrained optimization". ACM Transactions on Mathematical Software 23 (4): 550–560. doi:10.1145/279232.279236. 
  9. Schraudolph, N.; Yu, J.; Günter, S. (2007). "A stochastic quasi-Newton method for online convex optimization". AISTATS. 
  10. Mokhtari, A.; Ribeiro, A. (2015). "Global convergence of online limited memory BFGS". Journal of Machine Learning Research 16: 3151–3181. http://www.jmlr.org/papers/volume16/mokhtari15a/mokhtari15a.pdf. 
  11. Mokhtari, A.; Ribeiro, A. (2014). "RES: Regularized Stochastic BFGS Algorithm". IEEE Transactions on Signal Processing 62 (23): 6089–6104. doi:10.1109/TSP.2014.2357775. Bibcode2014ITSP...62.6089M. 
  12. "TOMS Home". http://toms.acm.org/. 
  13. Morales, J. L.; Nocedal, J. (2011). "Remark on "algorithm 778: L-BFGS-B: Fortran subroutines for large-scale bound constrained optimization"". ACM Transactions on Mathematical Software 38: 1–4. doi:10.1145/2049662.2049669. 
  14. "L-BFGS-B Nonlinear Optimization Code". http://users.iems.northwestern.edu/~nocedal/lbfgsb.html. 
  15. "Orthant-Wise Limited-memory Quasi-Newton Optimizer for L1-regularized Objectives". https://www.microsoft.com/en-us/download/details.aspx?id=52452. 

Further reading