# Broyden–Fletcher–Goldfarb–Shanno algorithm

Short description: Optimization method

In numerical optimization, the Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm is an iterative method for solving unconstrained nonlinear optimization problems. 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.

Since the updates of the BFGS curvature matrix do not require matrix inversion, its computational complexity is only $\displaystyle{ \mathcal{O}(n^{2}) }$, compared to $\displaystyle{ \mathcal{O}(n^{3}) }$ 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.

The algorithm is named after Charles George Broyden, Roger Fletcher, Donald Goldfarb and David Shanno.

## Rationale

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

The algorithm begins at an initial estimate for the optimal value $\displaystyle{ \mathbf{x}_0 }$ 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:

$\displaystyle{ B_k \mathbf{p}_k = -\nabla f(\mathbf{x}_k), }$

where $\displaystyle{ B_k }$ is an approximation to the Hessian matrix, which is updated iteratively at each stage, and $\displaystyle{ \nabla f(\mathbf{x}_k) }$ 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 $\displaystyle{ f(\mathbf{x}_k + \gamma\mathbf{p}_k) }$ over the scalar $\displaystyle{ \gamma \gt 0. }$

The quasi-Newton condition imposed on the update of $\displaystyle{ B_k }$ is

$\displaystyle{ B_{k+1} (\mathbf{x}_{k+1} - \mathbf{x}_k) = \nabla f(\mathbf{x}_{k+1}) - \nabla f(\mathbf{x}_k). }$

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

$\displaystyle{ B_{k+1} \mathbf{s}_k = \mathbf{y}_k }$,

which is the secant equation.

The curvature condition $\displaystyle{ \mathbf{s}_k^\top \mathbf{y}_k \gt 0 }$ should be satisfied for $\displaystyle{ B_{k+1} }$ to be positive definite, which can be verified by pre-multiplying the secant equation with $\displaystyle{ \mathbf{s}_k^T }$. 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 $\displaystyle{ \mathbf{x}_{k+1} }$ to be computed as $\displaystyle{ B_{k+1} }$, the approximate Hessian at stage k is updated by the addition of two matrices:

$\displaystyle{ B_{k+1} = B_k + U_k + V_k. }$

Both $\displaystyle{ U_k }$ and $\displaystyle{ V_k }$ 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 $\displaystyle{ B_{k+1} }$, the update form can be chosen as $\displaystyle{ B_{k+1} = B_k + \alpha\mathbf{u}\mathbf{u}^\top + \beta\mathbf{v}\mathbf{v}^\top }$. Imposing the secant condition, $\displaystyle{ B_{k+1} \mathbf{s}_k = \mathbf{y}_k }$. Choosing $\displaystyle{ \mathbf{u} = \mathbf{y}_k }$ and $\displaystyle{ \mathbf{v} = B_k \mathbf{s}_k }$, we can obtain:

$\displaystyle{ \alpha = \frac{1}{\mathbf{y}_k^T \mathbf{s}_k}, }$
$\displaystyle{ \beta = -\frac{1}{\mathbf{s}_k^T B_k \mathbf{s}_k}. }$

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

$\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}. }$

## Algorithm

From an initial guess $\displaystyle{ \mathbf{x}_0 }$ and an approximate Hessian matrix $\displaystyle{ B_0 }$ the following steps are repeated as $\displaystyle{ \mathbf{x}_k }$ converges to the solution:

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

$\displaystyle{ f(\mathbf{x}) }$ denotes the objective function to be minimized. Convergence can be checked by observing the norm of the gradient, $\displaystyle{ ||\nabla f(\mathbf{x}_k)|| }$. If $\displaystyle{ B_0 }$ is initialized with $\displaystyle{ B_0 = I }$, the first step will be equivalent to a gradient descent, but further steps are more and more refined by $\displaystyle{ B_{k} }$, the approximation to the Hessian.

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

$\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}. }$

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

$\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}. }$

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

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

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

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 . However, these quantities are technically defined by the true Hessian matrix, and the BFGS approximation may not converge to the true Hessian matrix.

## 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.
• 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().
• In SciPy, the scipy.optimize.fmin_bfgs function implements BFGS. 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).

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.