# Broyden–Fletcher–Goldfarb–Shanno algorithm

(Redirected from BFGS)

In numerical optimization, the Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm is an iterative method for solving unconstrained nonlinear optimization problems.[1]

The BFGS method belongs to quasi-Newton methods, a class of hill-climbing optimization techniques that seek a stationary point of a (preferably twice continuously differentiable) function. For such problems, a necessary condition for optimality is that the gradient be zero. Newton's method and the BFGS methods are not guaranteed to converge unless the function has a quadratic Taylor expansion near an optimum. However, BFGS has proven to have good performance even for non-smooth optimizations.[2]

In quasi-Newton methods, the Hessian matrix of second derivatives doesn't need to be evaluated directly. Instead, the Hessian matrix is approximated using updates specified by gradient evaluations (or approximate gradient evaluations). Quasi-Newton methods are generalizations of the secant method to find the root of the first derivative for multidimensional problems. In multi-dimensional problems, the secant equation does not specify a unique solution, and quasi-Newton methods differ in how they constrain the solution. The BFGS method is one of the most popular members of this class.[3] 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[4] 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 minimise ${\displaystyle f(\mathbf {x} )}$ where ${\displaystyle \mathbf {x} }$ is a vector in ${\displaystyle 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 minimising ${\displaystyle f(\mathbf {x} _{k}+\alpha \mathbf {p} _{k})}$ over the scalar ${\displaystyle \alpha >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}>0}$ should be satisfied. If the function is not strongly convex, then the condition has to be enforced explicitly.

Instead of requiring the full Hessian matrix at the point xk+1 to be computed as Bk+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 Uk and Vk 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 definitiveness. In order to maintain the symmetry and positive definitiveness 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:[5]

${\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, so ${\displaystyle \alpha _{k}=\arg \min f(\mathbf {x} _{k}+\alpha \mathbf {p} _{k})}$.
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}}{\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 \left|\nabla f(\mathbf {x} _{k})\right|}$. Practically, ${\displaystyle B_{0}}$ can be initialized with ${\displaystyle B_{0}=I}$, so that 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 {s_{k}y_{k}^{T}}{y_{k}^{T}s_{k}}}\right)B_{k}^{-1}\left(I-{\frac {y_{k}s_{k}^{T}}{y_{k}^{T}s_{k}}}\right)+{\frac {s_{k}s_{k}^{T}}{y_{k}^{T}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 scalar, 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}}}.}$

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.

## Implementations

The GSL implements BFGS as gsl_multimin_fdfminimizer_vector_bfgs2. Ceres Solver implements both BFGS and L-BFGS.

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.

Octave uses BFGS with a double-dogleg approximation to the cubic line search.

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 the MATLAB Optimization Toolbox, the fminunc function uses BFGS with cubic line search when the problem size is set to "medium scale."

A high-precision arithmetic version of BFGS (pBFGS), implemented in C++ and integrated with the high-precision arithmetic package ARPREC is robust against numerical instability (e.g. round-off errors).

Another C++ implementation of BFGS (along with L-BFGS, L-BFGS-B, CG, and Newton's method) using Eigen (C++ library) are available on GitHub under the MIT License here.

BFGS and L-BFGS are also implemented in C as part of the open-source Gnu Regression, Econometrics and Time-series Library (gretl).