TExcelTAD
Home › Numerical Methods › Quasi-Newton Methods

Quasi-Newton Methods

Newton's method for systems needs a fresh Jacobian at every step, which costs nn function evaluations by finite differences, or much human effort by hand. Quasi-Newton methods start from one Jacobian approximation and improve it cheaply after each step using only the function values already computed. They are the multidimensional analogue of the secant method.

The secant condition

After a step sk=xk+1−xk\mathbf{s}_k = \mathbf{x}_{k+1} - \mathbf{x}_k we know the change yk=f(xk+1)−f(xk)\mathbf{y}_k = \mathbf{f}(\mathbf{x}_{k+1}) - \mathbf{f}(\mathbf{x}_k). A good Jacobian approximation should reproduce it:

Ak+1 sk=yk.A_{k+1}\,\mathbf{s}_k = \mathbf{y}_k.

In one dimension this fixes AA (the secant slope). In nn dimensions it gives only nn equations for n2n^2 entries, so we also ask that AA change as little as possible.

Broyden's update

The smallest change (in the Frobenius norm) satisfying the secant condition is the rank-one Broyden update:

Ak+1=Ak+(yk−Aksk) skTskTsk.A_{k+1} = A_k + \frac{(\mathbf{y}_k - A_k\mathbf{s}_k)\,\mathbf{s}_k^T}{\mathbf{s}_k^T\mathbf{s}_k}.

Each step costs one new evaluation of f\mathbf{f} and a linear solve; convergence is superlinear.

python · try it yourself
import numpy as np

def f(v):
    x, y = v
    return np.array([x**2 + y**2 - 4, np.exp(x) + y - 1])

def broyden(f, x, A, tol=1e-12, maxit=50):
    fx = f(x)
    evals = 1
    for k in range(maxit):
        s = np.linalg.solve(A, -fx)
        x_new = x + s
        f_new = f(x_new); evals += 1
        y = f_new - fx
        A = A + np.outer(y - A @ s, s) / (s @ s)
        x, fx = x_new, f_new
        if np.linalg.norm(fx) < tol:
            break
    return x, k + 1, evals

x0 = np.array([1.0, -1.5])
A0 = np.array([[2.0, -3.0], [np.e, 1.0]])          # exact Jacobian at x0, computed once
x, steps, evals = broyden(f, x0, A0)
print(f"root {np.round(x, 12)} in {steps} steps, {evals} evaluations of f, |f| = {np.linalg.norm(f(x)):.1e}")
root [ 1.00416874 -1.72963729] in 6 steps, 7 evaluations of f, |f| = 2.0e-13

Compare with Newton's Method for Systems, which needed fewer steps but a new Jacobian each time.

Quasi-Newton for optimization: BFGS

For minimization the "Jacobian" is the Hessian, which is symmetric and (near a minimum) positive definite. The BFGS update keeps both properties with a rank-two correction:

Bk+1=Bk−BkskskTBkskTBksk+ykykTykTsk,B_{k+1} = B_k - \frac{B_k\mathbf{s}_k\mathbf{s}_k^TB_k}{\mathbf{s}_k^TB_k\mathbf{s}_k} + \frac{\mathbf{y}_k\mathbf{y}_k^T}{\mathbf{y}_k^T\mathbf{s}_k},

with yk\mathbf{y}_k now the change of the gradient. Implementations update the inverse B−1B^{-1} directly so no system needs solving. L-BFGS stores only the last mm pairs (s,y)(\mathbf{s}, \mathbf{y}) instead of an n×nn \times n matrix, which makes it usable for millions of variables.

python · try it yourself
import numpy as np
from scipy.optimize import minimize, rosen, rosen_der

x0 = np.array([-1.2, 1.0])
for method in ("BFGS", "L-BFGS-B", "Newton-CG"):
    kw = {"jac": rosen_der}
    if method == "Newton-CG":
        from scipy.optimize import rosen_hess
        kw["hess"] = rosen_hess
    res = minimize(rosen, x0, method=method, **kw)
    print(f"{method:9s}: x = {np.round(res.x, 6)}, iterations {res.nit}, gradient evaluations {res.njev}")
BFGS     : x = [1. 1.], iterations 32, gradient evaluations 39
L-BFGS-B : x = [0.999999 0.999998], iterations 36, gradient evaluations 44
Newton-CG: x = [0.999983 0.999965], iterations 83, gradient evaluations 105

In software

  • scipy.optimize.root(f, x0, method="broyden1") (and "broyden2", "anderson", "krylov" for large systems).
  • scipy.optimize.minimize(method="BFGS") and "L-BFGS-B" (with bounds) are the default choices for smooth unconstrained optimization; L-BFGS is also used to train small neural networks and in classic ML (logistic regression in scikit-learn uses lbfgs by default).

Exercises

Exercise 1: Secant condition in 1D

Show that in one dimension the secant condition gives the secant method.

Answer

ak+1=f(xk+1)−f(xk)xk+1−xka_{k+1} = \frac{f(x_{k+1}) - f(x_k)}{x_{k+1} - x_k}.

Solution

ak+1sk=yka_{k+1}s_k = y_k with scalars gives ak+1=yk/ska_{k+1} = y_k/s_k, the slope of the secant line, and the next step xk+2=xk+1−f(xk+1)/ak+1x_{k+2} = x_{k+1} - f(x_{k+1})/a_{k+1} is the secant step.

Exercise 2: Rank of the update

What is the rank of the Broyden correction matrix, and why does that matter?

Answer

Rank one; the factorization of AA can be updated in O(n2)O(n^2) instead of recomputed in O(n3)O(n^3).

Solution

It is an outer product usT\mathbf{u}\mathbf{s}^T. The Sherman-Morrison formula updates A−1A^{-1} (or a QR factorization) in O(n2)O(n^2) operations.

Exercise 3: Broyden from the identity (code)

Run Broyden's method for the lesson's system starting from A0=IA_0 = I instead of the exact Jacobian. Does it still converge?

Answer

Yes, to the same root, but in more steps.

Solution
python · try it yourself
import numpy as np
f = lambda v: np.array([v[0]**2 + v[1]**2 - 4, np.exp(v[0]) + v[1] - 1])
x = np.array([1.0, -1.5]); A = np.eye(2); fx = f(x)
for k in range(100):
    s = np.linalg.solve(A, -fx)
    xn = x + s; fn = f(xn)
    A = A + np.outer(fn - fx - A @ s, s) / (s @ s)
    x, fx = xn, fn
    if np.linalg.norm(fx) < 1e-12:
        break
print(np.round(x, 10), "steps:", k + 1)
[ 1.00416874 -1.72963729] steps: 12

A poor initial matrix costs extra steps, and from a bad start the method may wander to a different root or fail, which is why codes add line searches.

Test yourself

The secant condition for a Jacobian approximation Ak+1A_{k+1} is…

  1. Ak+1=J(xk+1)A_{k+1} = J(\mathbf{x}_{k+1})
  2. Ak+1sk=ykA_{k+1}\mathbf{s}_k = \mathbf{y}_k
  3. Ak+1A_{k+1} symmetric
  4. Ak+1yk=skA_{k+1}\mathbf{y}_k = \mathbf{s}_k

Why is L-BFGS used for very large problems?

  1. It converges quadratically
  2. It stores only a few vector pairs instead of an n×nn \times n matrix
  3. It needs no gradient
  4. It is exact

Broyden's method needs per step…

  1. nn new function evaluations
  2. one new function evaluation
  3. the exact Jacobian
  4. the Hessian