Broyden–Fletcher–Goldfarb–Shanno algorithm

From HandWiki
Short description: Optimization method


In numerical optimization, the Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm is an iterative method for solving unconstrained nonlinear optimization problems.[1] Like the related Davidon–Fletcher–Powell method, BFGS determines the descent direction by preconditioning the gradient with curvature information. It does so by gradually improving an approximation to the Hessian matrix of the loss function, obtained only from gradient evaluations (or approximate gradient evaluations) via a generalized secant method.[2]

Since the updates of the BFGS curvature matrix do not require matrix inversion, its computational complexity is only [math]\displaystyle{ \mathcal{O}(n^{2}) }[/math], compared to [math]\displaystyle{ \mathcal{O}(n^{3}) }[/math] in Newton's method. Also in common use is L-BFGS, which is a limited-memory version of BFGS that is particularly suited to problems with very large numbers of variables (e.g., >1000). The BFGS-B variant handles simple box constraints.[3]

The algorithm is named after Charles George Broyden, Roger Fletcher, Donald Goldfarb and David Shanno.[4][5][6][7]

Rationale

The optimization problem is to minimize [math]\displaystyle{ f(\mathbf{x}) }[/math], where [math]\displaystyle{ \mathbf{x} }[/math] is a vector in [math]\displaystyle{ \mathbb{R}^n }[/math], and [math]\displaystyle{ f }[/math] is a differentiable scalar function. There are no constraints on the values that [math]\displaystyle{ \mathbf{x} }[/math] can take.

The algorithm begins at an initial estimate [math]\displaystyle{ \mathbf{x}_0 }[/math] for the optimal value and proceeds iteratively to get a better estimate at each stage.

The search direction pk at stage k is given by the solution of the analogue of the Newton equation:

[math]\displaystyle{ B_k \mathbf{p}_k = -\nabla f(\mathbf{x}_k), }[/math]

where [math]\displaystyle{ B_k }[/math] is an approximation to the Hessian matrix at [math]\displaystyle{ \mathbf{x}_k }[/math], which is updated iteratively at each stage, and [math]\displaystyle{ \nabla f(\mathbf{x}_k) }[/math] is the gradient of the function evaluated at xk. A line search in the direction pk is then used to find the next point xk+1 by minimizing [math]\displaystyle{ f(\mathbf{x}_k + \gamma\mathbf{p}_k) }[/math] over the scalar [math]\displaystyle{ \gamma \gt 0. }[/math]

The quasi-Newton condition imposed on the update of [math]\displaystyle{ B_k }[/math] is

[math]\displaystyle{ B_{k+1} (\mathbf{x}_{k+1} - \mathbf{x}_k) = \nabla f(\mathbf{x}_{k+1}) - \nabla f(\mathbf{x}_k). }[/math]

Let [math]\displaystyle{ \mathbf{y}_k = \nabla f(\mathbf{x}_{k+1}) - \nabla f(\mathbf{x}_k) }[/math] and [math]\displaystyle{ \mathbf{s}_k = \mathbf{x}_{k+1} - \mathbf{x}_k }[/math], then [math]\displaystyle{ B_{k+1} }[/math] satisfies

[math]\displaystyle{ B_{k+1} \mathbf{s}_k = \mathbf{y}_k }[/math],

which is the secant equation.

The curvature condition [math]\displaystyle{ \mathbf{s}_k^\top \mathbf{y}_k \gt 0 }[/math] should be satisfied for [math]\displaystyle{ B_{k+1} }[/math] to be positive definite, which can be verified by pre-multiplying the secant equation with [math]\displaystyle{ \mathbf{s}_k^T }[/math]. If the function is not strongly convex, then the condition has to be enforced explicitly e.g. by finding a point xk+1 satisfying the Wolfe conditions, which entail the curvature condition, using line search.

Instead of requiring the full Hessian matrix at the point [math]\displaystyle{ \mathbf{x}_{k+1} }[/math] to be computed as [math]\displaystyle{ B_{k+1} }[/math], the approximate Hessian at stage k is updated by the addition of two matrices:

[math]\displaystyle{ B_{k+1} = B_k + U_k + V_k. }[/math]

Both [math]\displaystyle{ U_k }[/math] and [math]\displaystyle{ V_k }[/math] are symmetric rank-one matrices, but their sum is a rank-two update matrix. BFGS and DFP updating matrix both differ from its predecessor by a rank-two matrix. Another simpler rank-one method is known as symmetric rank-one method, which does not guarantee the positive definiteness. In order to maintain the symmetry and positive definiteness of [math]\displaystyle{ B_{k+1} }[/math], the update form can be chosen as [math]\displaystyle{ B_{k+1} = B_k + \alpha\mathbf{u}\mathbf{u}^\top + \beta\mathbf{v}\mathbf{v}^\top }[/math]. Imposing the secant condition, [math]\displaystyle{ B_{k+1} \mathbf{s}_k = \mathbf{y}_k }[/math]. Choosing [math]\displaystyle{ \mathbf{u} = \mathbf{y}_k }[/math] and [math]\displaystyle{ \mathbf{v} = B_k \mathbf{s}_k }[/math], we can obtain:[8]

[math]\displaystyle{ \alpha = \frac{1}{\mathbf{y}_k^T \mathbf{s}_k}, }[/math]
[math]\displaystyle{ \beta = -\frac{1}{\mathbf{s}_k^T B_k \mathbf{s}_k}. }[/math]

Finally, we substitute [math]\displaystyle{ \alpha }[/math] and [math]\displaystyle{ \beta }[/math] into [math]\displaystyle{ B_{k+1} = B_k + \alpha\mathbf{u}\mathbf{u}^\top + \beta\mathbf{v}\mathbf{v}^\top }[/math] and get the update equation of [math]\displaystyle{ B_{k+1} }[/math]:

[math]\displaystyle{ B_{k+1} = B_k + \frac{\mathbf{y}_k \mathbf{y}_k^{\mathrm{T}}}{\mathbf{y}_k^{\mathrm{T}} \mathbf{s}_k} - \frac{B_k \mathbf{s}_k \mathbf{s}_k^{\mathrm{T}} B_k^{\mathrm{T}} }{\mathbf{s}_k^{\mathrm{T}} B_k \mathbf{s}_k}. }[/math]

Algorithm

Consider the following unconstrained optimization problem [math]\displaystyle{ \begin{aligned} \underset{\mathbf{x} \in \mathbb{R}^n}{\text{minimize}}\quad & f(\mathbf{x}), \end{aligned} }[/math] where [math]\displaystyle{ f : \mathbb{R}^n \to \mathbb{R} }[/math] is a nonlinear objective function.

From an initial guess [math]\displaystyle{ \mathbf{x}_0 \in \mathbb{R}^n }[/math] and an initial guess of the Hessian matrix [math]\displaystyle{ B_0 \in \mathbb{R}^{n\times n} }[/math] the following steps are repeated as [math]\displaystyle{ \mathbf{x}_k }[/math] converges to the solution:

  1. Obtain a direction [math]\displaystyle{ \mathbf{p}_k }[/math] by solving [math]\displaystyle{ B_k \mathbf{p}_k = -\nabla f(\mathbf{x}_k) }[/math].
  2. Perform a one-dimensional optimization (line search) to find an acceptable stepsize [math]\displaystyle{ \alpha_k }[/math] in the direction found in the first step. If an exact line search is performed, then [math]\displaystyle{ \alpha_k=\arg \min f(\mathbf{x}_k+\alpha\mathbf{p}_k) }[/math] . In practice, an inexact line search usually suffices, with an acceptable [math]\displaystyle{ \alpha_k }[/math] satisfying Wolfe conditions.
  3. Set [math]\displaystyle{ \mathbf{s}_k = \alpha_k \mathbf{p}_k }[/math] and update [math]\displaystyle{ \mathbf{x}_{k+1} = \mathbf{x}_k + \mathbf{s}_k }[/math].
  4. [math]\displaystyle{ \mathbf{y}_k = {\nabla f(\mathbf{x}_{k+1}) - \nabla f(\mathbf{x}_k)} }[/math].
  5. [math]\displaystyle{ B_{k+1} = B_k + \frac{\mathbf{y}_k \mathbf{y}_k^{\mathrm{T}}}{\mathbf{y}_k^{\mathrm{T}} \mathbf{s}_k} - \frac{B_k \mathbf{s}_k \mathbf{s}_k^{\mathrm{T}} B_k^{\mathrm{T}} }{\mathbf{s}_k^{\mathrm{T}} B_k \mathbf{s}_k} }[/math].

Convergence can be deterimined by observing the norm of the gradient; given some [math]\displaystyle{ \epsilon \gt 0 }[/math], one may stop the algothim when [math]\displaystyle{ ||\nabla f(\mathbf{x}_k)|| \leq \epsilon. }[/math] If [math]\displaystyle{ B_0 }[/math] is initialized with [math]\displaystyle{ B_0 = I }[/math], the first step will be equivalent to a gradient descent, but further steps are more and more refined by [math]\displaystyle{ B_{k} }[/math], the approximation to the Hessian.

The first step of the algorithm is carried out using the inverse of the matrix [math]\displaystyle{ B_k }[/math], which can be obtained efficiently by applying the Sherman–Morrison formula to the step 5 of the algorithm, giving

[math]\displaystyle{ B_{k+1}^{-1} = \left(I - \frac{\mathbf{s}_k \mathbf{y}_k^T}{\mathbf{y}_k^T \mathbf{s}_k} \right) B_{k}^{-1} \left(I - \frac{\mathbf{y}_k \mathbf{s}_k^T}{\mathbf{y}_k^T \mathbf{s}_k} \right) + \frac{\mathbf{s}_k \mathbf{s}_k^T}{\mathbf{y}_k^T \mathbf{s}_k}. }[/math]

This can be computed efficiently without temporary matrices, recognizing that [math]\displaystyle{ B_k^{-1} }[/math] is symmetric, and that [math]\displaystyle{ \mathbf{y}_k^{\mathrm{T}} B_k^{-1} \mathbf{y}_k }[/math] and [math]\displaystyle{ \mathbf{s}_k^{\mathrm{T}} \mathbf{y}_k }[/math] are scalars, using an expansion such as

[math]\displaystyle{ B_{k+1}^{-1} = B_k^{-1} + \frac{(\mathbf{s}_k^{\mathrm{T}}\mathbf{y}_k+\mathbf{y}_k^{\mathrm{T}} B_k^{-1} \mathbf{y}_k)(\mathbf{s}_k \mathbf{s}_k^{\mathrm{T}})}{(\mathbf{s}_k^{\mathrm{T}} \mathbf{y}_k)^2} - \frac{B_k^{-1} \mathbf{y}_k \mathbf{s}_k^{\mathrm{T}} + \mathbf{s}_k \mathbf{y}_k^{\mathrm{T}}B_k^{-1}}{\mathbf{s}_k^{\mathrm{T}} \mathbf{y}_k}. }[/math]

Therefore, in order to avoid any matrix inversion, the inverse of the Hessian can be approximated instead of the Hessian itself: [math]\displaystyle{ H_k \overset{\operatorname{def}}{=} B_k^{-1}. }[/math][9]

From an initial guess [math]\displaystyle{ \mathbf{x}_0 }[/math] and an approximate inverted Hessian matrix [math]\displaystyle{ H_0 }[/math] the following steps are repeated as [math]\displaystyle{ \mathbf{x}_k }[/math] converges to the solution:

  1. Obtain a direction [math]\displaystyle{ \mathbf{p}_k }[/math] by solving [math]\displaystyle{ \mathbf{p}_k = -H_k \nabla f(\mathbf{x}_k) }[/math].
  2. Perform a one-dimensional optimization (line search) to find an acceptable stepsize [math]\displaystyle{ \alpha_k }[/math] in the direction found in the first step. If an exact line search is performed, then [math]\displaystyle{ \alpha_k=\arg \min f(\mathbf{x}_k+\alpha\mathbf{p}_k) }[/math] . In practice, an inexact line search usually suffices, with an acceptable [math]\displaystyle{ \alpha_k }[/math] satisfying Wolfe conditions.
  3. Set [math]\displaystyle{ \mathbf{s}_k = \alpha_k \mathbf{p}_k }[/math] and update [math]\displaystyle{ \mathbf{x}_{k+1} = \mathbf{x}_k + \mathbf{s}_k }[/math].
  4. [math]\displaystyle{ \mathbf{y}_k = {\nabla f(\mathbf{x}_{k+1}) - \nabla f(\mathbf{x}_k)} }[/math].
  5. [math]\displaystyle{ H_{k+1} = H_k + \frac{(\mathbf{s}_k^{\mathrm{T}}\mathbf{y}_k+\mathbf{y}_k^{\mathrm{T}} H_k \mathbf{y}_k)(\mathbf{s}_k \mathbf{s}_k^{\mathrm{T}})}{(\mathbf{s}_k^{\mathrm{T}} \mathbf{y}_k)^2} - \frac{H_k \mathbf{y}_k \mathbf{s}_k^{\mathrm{T}} + \mathbf{s}_k \mathbf{y}_k^{\mathrm{T}}H_k}{\mathbf{s}_k^{\mathrm{T}} \mathbf{y}_k} }[/math].

In statistical estimation problems (such as maximum likelihood or Bayesian inference), credible intervals or confidence intervals for the solution can be estimated from the inverse of the final Hessian matrix[citation needed]. However, these quantities are technically defined by the true Hessian matrix, and the BFGS approximation may not converge to the true Hessian matrix.[10]

Further developments

The BFGS update formula heavily relies on the curvature [math]\displaystyle{ \mathbf{s}_k^\top \mathbf{y}_k }[/math] being strictly positive and bounded away from zero. This condition is satisfied when we perform a line search with Wolfe conditions on a convex target. However, some real-life applications (like Sequential Quadratic Programming methods) routinely produce negative or nearly-zero curvatures. This can occur when optimizing a nonconvex target or when employing a trust-region approach instead of a line search. It is also possible to produce spurious values due to noise in the target.

In such cases, one of the so-called damped BFGS updates can be used (see [11]) which modify [math]\displaystyle{ \mathbf{s}_k }[/math] and/or [math]\displaystyle{ \mathbf{y}_k }[/math] in order to obtain a more robust update.

Notable implementations

Notable open source implementations are:

  • ALGLIB implements BFGS and its limited-memory version in C++ and C#
  • GNU Octave uses a form of BFGS in its fsolve function, with trust region extensions.
  • The GSL implements BFGS as gsl_multimin_fdfminimizer_vector_bfgs2.[12]
  • In R, the BFGS algorithm (and the L-BFGS-B version that allows box constraints) is implemented as an option of the base function optim().[13]
  • In SciPy, the scipy.optimize.fmin_bfgs function implements BFGS.[14] It is also possible to run BFGS using any of the L-BFGS algorithms by setting the parameter L to a very large number.
  • In Julia, the Optim.jl package implements BFGS and L-BFGS as a solver option to the optimize() function (among other options).[15]

Notable proprietary implementations include:

  • The large scale nonlinear optimization software Artelys Knitro implements, among others, both BFGS and L-BFGS algorithms.
  • In the MATLAB Optimization Toolbox, the fminunc function uses BFGS with cubic line search when the problem size is set to "medium scale."
  • Mathematica includes BFGS.

See also


References

  1. Fletcher, Roger (1987), Practical Methods of Optimization (2nd ed.), New York: John Wiley & Sons, ISBN 978-0-471-91547-8, https://archive.org/details/practicalmethods0000flet 
  2. Dennis, J. E. Jr.; Schnabel, Robert B. (1983), "Secant Methods for Unconstrained Minimization", Numerical Methods for Unconstrained Optimization and Nonlinear Equations, Englewood Cliffs, NJ: Prentice-Hall, pp. 194–215, ISBN 0-13-627216-9, https://books.google.com/books?id=ksvJTtJCx9cC&pg=PA194 
  3. Byrd, Richard H.; Lu, Peihuang; Nocedal, Jorge; Zhu, Ciyou (1995), "A Limited Memory Algorithm for Bound Constrained Optimization", SIAM Journal on Scientific Computing 16 (5): 1190–1208, doi:10.1137/0916069, http://www.ece.northwestern.edu/~nocedal/PSfiles/limited.ps.gz 
  4. Broyden, C. G. (1970), "The convergence of a class of double-rank minimization algorithms", Journal of the Institute of Mathematics and Its Applications 6: 76–90, doi:10.1093/imamat/6.1.76 
  5. Fletcher, R. (1970), "A New Approach to Variable Metric Algorithms", Computer Journal 13 (3): 317–322, doi:10.1093/comjnl/13.3.317 
  6. Goldfarb, D. (1970), "A Family of Variable Metric Updates Derived by Variational Means", Mathematics of Computation 24 (109): 23–26, doi:10.1090/S0025-5718-1970-0258249-6 
  7. Shanno, David F. (July 1970), "Conditioning of quasi-Newton methods for function minimization", Mathematics of Computation 24 (111): 647–656, doi:10.1090/S0025-5718-1970-0274029-X 
  8. Fletcher, Roger (1987), Practical methods of optimization (2nd ed.), New York: John Wiley & Sons, ISBN 978-0-471-91547-8, https://archive.org/details/practicalmethods0000flet 
  9. Nocedal, Jorge; Wright, Stephen J. (2006), Numerical Optimization (2nd ed.), Berlin, New York: Springer-Verlag, ISBN 978-0-387-30303-1 
  10. Ge, Ren-pu; Powell, M. J. D. (1983). "The Convergence of Variable Metric Matrices in Unconstrained Optimization". Mathematical Programming 27 (2): 123. doi:10.1007/BF02591941. 
  11. Jorge Nocedal; Stephen J. Wright (2006), Numerical Optimization 
  12. "GNU Scientific Library — GSL 2.6 documentation". https://www.gnu.org/software/gsl/doc/html/index.html. 
  13. "R: General-purpose Optimization". https://stat.ethz.ch/R-manual/R-devel/library/stats/html/optim.html. 
  14. "scipy.optimize.fmin_bfgs — SciPy v1.5.4 Reference Guide". https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin_bfgs.html. 
  15. "Optim.jl Configurable options". https://julianlsolvers.github.io/Optim.jl/stable/#user/config/#solver-options. 

Further reading