# Broyden–Fletcher–Goldfarb–Shanno algorithm

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

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 can have acceptable performance even for non-smooth optimization instances.

In Quasi-Newton methods, the Hessian matrix of second derivatives is not computed. 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. 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 $f(\mathbf {x} )$ , where $\mathbf {x}$ is a vector in $\mathbb {R} ^{n}$ , and $f$ is a differentiable scalar function. There are no constraints on the values that $\mathbf {x}$ can take.

The algorithm begins at an initial estimate for the optimal value $\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:

$B_{k}\mathbf {p} _{k}=-\nabla f(\mathbf {x} _{k}),$ where $B_{k}$ is an approximation to the Hessian matrix, which is updated iteratively at each stage, and $\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 $f(\mathbf {x} _{k}+\gamma \mathbf {p} _{k})$ over the scalar $\gamma >0.$ The quasi-Newton condition imposed on the update of $B_{k}$ is

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

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

$\alpha ={\frac {1}{\mathbf {y} _{k}^{T}\mathbf {s} _{k}}},$ $\beta =-{\frac {1}{\mathbf {s} _{k}^{T}B_{k}\mathbf {s} _{k}}}.$ Finally, we substitute $\alpha$ and $\beta$ into $B_{k+1}=B_{k}+\alpha \mathbf {u} \mathbf {u} ^{\top }+\beta \mathbf {v} \mathbf {v} ^{\top }$ and get the update equation of $B_{k+1}$ :

$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 $\mathbf {x} _{0}$ and an approximate Hessian matrix $B_{0}$ the following steps are repeated as $\mathbf {x} _{k}$ converges to the solution:

1. Obtain a direction $\mathbf {p} _{k}$ by solving $B_{k}\mathbf {p} _{k}=-\nabla f(\mathbf {x} _{k})$ .
2. Perform a one-dimensional optimization (line search) to find an acceptable stepsize $\alpha _{k}$ in the direction found in the first step, so $\alpha _{k}=\arg \min f(\mathbf {x} _{k}+\alpha \mathbf {p} _{k})$ .
3. Set $\mathbf {s} _{k}=\alpha _{k}\mathbf {p} _{k}$ and update $\mathbf {x} _{k+1}=\mathbf {x} _{k}+\mathbf {s} _{k}$ .
4. $\mathbf {y} _{k}={\nabla f(\mathbf {x} _{k+1})-\nabla f(\mathbf {x} _{k})}$ .
5. $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}}}$ .

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

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

$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 $B_{k}^{-1}$ is symmetric, and that $\mathbf {y} _{k}^{\mathrm {T} }B_{k}^{-1}\mathbf {y} _{k}$ and $\mathbf {s} _{k}^{\mathrm {T} }\mathbf {y} _{k}$ are scalars, using an expansion such as

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

## Notable implementations

• The large scale nonlinear optimization software Artelys Knitro implements, among others, both BFGS and L-BFGS algorithms.
• The GSL implements BFGS as gsl_multimin_fdfminimizer_vector_bfgs2.
• In the MATLAB Optimization Toolbox, the fminunc function uses BFGS with cubic line search when the problem size is set to "medium scale."
• 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.