Foundations to Frontier
Tests
A. Mathematical Foundations › A6 Optimization › Optimization for ML

Quasi-Newton Methods: BFGS and L-BFGS

Newton's method converges fast but needs second derivatives and an O(n³) solve; gradient descent is cheap but slow. Quasi-Newton methods learn an approximation of the (inverse) Hessian from successive gradients alone, satisfying the secant condition, and converge superlinearly. You will derive the BFGS update, prove it preserves positive definiteness, implement the L-BFGS two-loop recursion that scales to millions of variables with O(md) memory, and train a 200-dimensional classifier in a fraction of gradient descent's iterations.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Learning the shape of the valley as you go

Newton’s method measures the valley’s curvature directly at every step: accurate but expensive. Gradient descent ignores curvature: cheap but slow. A quasi-Newton method takes the middle road. After each step, it notes how much the slope changed and uses that to update its mental map of the curvature. After a few steps its map is good enough to take Newton-like strides, without ever measuring curvature directly.

L-BFGS keeps only the last few observations, so it works even with millions of unknowns.

Learning the curvature from gradients: BFGS on the Rosenbrock banana
■ gradient descent: > 3000 iterations■ BFGS: 35 iterations■ Newton: 21 iterations
BFGS's final H differs from the true ∇²f(1, 1)⁻¹ by 1.1%, learned from gradients alone.
Gradient descent crawls along the curved valley (thousands of steps). Newton uses exact second derivatives and converges in a few dozen. BFGS never computes a second derivative: after each step it updates a matrix H so that H·(change in gradient) = (step taken), the secant condition. It reaches the solution almost as fast as Newton, with superlinear convergence, at the cost of gradients only. L-BFGS keeps just the last m step/gradient pairs, so it scales to millions of variables.
Why engineers care

L-BFGS is the workhorse for smooth, deterministic problems: calibration, trajectory optimization, physics-informed networks, neural style transfer and many scientific-ML fits. SciPy and PyTorch both ship it. Its bound-constrained variant, L-BFGS-B, handles box constraints.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Quasi-Newton methods learn the curvature from…
  2. 2. L-BFGS remembers…
  3. 3. Compared with gradient descent, BFGS is usually…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The secant condition

Let sk=xk+1−xks_k = x_{k+1} - x_k and yk=∇f(xk+1)−∇f(xk)y_k = \nabla f(x_{k+1}) - \nabla f(x_k). Taylor gives yk≈∇2f sky_k\approx\nabla^2f\,s_k. A quasi-Newton approximation Bk+1≈∇2fB_{k+1}\approx\nabla^2f (or Hk+1≈(∇2f)−1H_{k+1}\approx(\nabla^2f)^{-1}) must satisfy

Bk+1sk=yk⟺Hk+1yk=skB_{k+1}s_k = y_k\qquad\Longleftrightarrow\qquad H_{k+1}y_k = s_k

The BFGS update (inverse form)

With ρk=1/(yk⊤sk)\rho_k = 1/(y_k^\top s_k):

Hk+1=(I−ρkskyk⊤)Hk(I−ρkyksk⊤)+ρksksk⊤H_{k+1} = (I - \rho_ks_ky_k^\top)H_k(I - \rho_ky_ks_k^\top) + \rho_ks_ks_k^\top

The direction is dk=−Hk∇f(xk)d_k = -H_k\nabla f(x_k), followed by a line search. Each step costs O(n2)O(n^2) with no linear solve, compared with Newton’s O(n3)O(n^3).

📝 Quick check (Level 1)
0/3 answered
  1. 1. The (inverse) secant condition is…
  2. 2. A BFGS update is a rank-… modification
  3. 3. The cost per BFGS iteration (dense) is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

Properties

  • Positive definiteness: if Hk≻0H_k\succ0 and yk⊤sk>0y_k^\top s_k > 0, then Hk+1≻0H_{k+1}\succ0. The Wolfe curvature condition (A6.1-5) guarantees y⊤s>0y^\top s > 0, so every direction is a descent direction.
  • Superlinear convergence: near a strong minimum, ∥xk+1−x⋆∥/∥xk−x⋆∥→0\|x_{k+1} - x^\star\|/\|x_k - x^\star\|\to0 (Dennis and Moré, 1974). That’s faster than any linear rate, though not quite quadratic.
  • Quadratics: with exact line searches, BFGS terminates in at most nn steps, and HnH_n equals the inverse Hessian.
  • Self-correction: bad early approximations are repaired as new curvature arrives.

L-BFGS

Store only the last mm pairs (si,yi)(s_i, y_i) (typically m=5m = 5–20). The two-loop recursion computes HkgH_kg in O(md)O(md) time and memory without ever forming HH. Start from H0=γIH_0 = \gamma I with γ=s⊤y/y⊤y\gamma = s^\top y/y^\top y (a curvature-scaled identity). This is how 10⁶-variable problems are solved on a laptop.

Limitations

  • Stochastic gradients break the secant information. Mini-batch noise makes yy unreliable, so L-BFGS is mostly used full-batch or with careful variance control (Byrd et al., 2016).
  • Non-convex problems: skip or damp updates when y⊤s≤0y^\top s\le0. SR1 updates allow indefinite approximations inside trust regions.
🐍 Exercise 1: BFGS on Rosenbrock
Implement the BFGS inverse update and a BFGS solver with backtracking. Solve Rosenbrock, then verify positive definiteness, the secant condition, superlinear convergence, and closeness of H to the true inverse Hessian.
📝 Quick check (Level 2)
0/3 answered
  1. 1. BFGS keeps H positive definite as long as…
  2. 2. BFGS converges…
  3. 3. L-BFGS memory scales as…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Deriving the secant condition

By the mean-value theorem, yk=∇f(xk+1)−∇f(xk)=(∫01∇2f(xk+tsk) dt)sky_k = \nabla f(x_{k+1}) - \nabla f(x_k) = \big(\int_0^1\nabla^2f(x_k + ts_k)\,dt\big)s_k, the average Hessian along the step applied to sks_k. Requiring Bk+1sk=ykB_{k+1}s_k = y_k makes the model’s gradient exact at both endpoints. ∎

BFGS satisfies the secant condition

Note (I−ρys⊤)y=y−ρy(s⊤y)=0(I - \rho ys^\top)y = y - \rho y(s^\top y) = 0. So Hk+1y=(I−ρsy⊤)H⋅0+ρs(s⊤y)=sH_{k+1}y = (I - \rho sy^\top)H\cdot0 + \rho s(s^\top y) = s. ∎

Positive definiteness

For z≠0z\ne0, let w=(I−ρys⊤)z=z−ρy(s⊤z)w = (I - \rho ys^\top)z = z - \rho y(s^\top z). Then z⊤Hk+1z=w⊤Hkw+ρ(s⊤z)2≥0z^\top H_{k+1}z = w^\top H_kw + \rho(s^\top z)^2\ge0. If s⊤z≠0s^\top z\ne0, the second term is positive (since ρ>0\rho > 0). If s⊤z=0s^\top z = 0, then w=z≠0w = z\ne0 and the first term is positive. ∎

BFGS as the closest update

BFGS solves min⁡H∥H−Hk∥W\min_H\|H - H_k\|_W s.t. H=H⊤H = H^\top, Hy=sHy = s, in a weighted Frobenius norm. It’s the least change consistent with the new information (Goldfarb, 1970).

Exercise 3.1: How many steps does BFGS (exact line search) need on a 5-D quadratic?

At most 5. The search directions are conjugate, and BFGS is equivalent to conjugate gradients on quadratics with exact line searches. That’s why it’s closely related to Krylov methods (A2.4-7).

📝 Quick check (Level 3)
0/3 answered
  1. 1. (I − ρysᵀ)y equals…
  2. 2. On an n-D quadratic with exact line search, BFGS terminates in at most…
  3. 3. BFGS is the minimal-change update in a…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

A 200-dimensional classifier in 62 iterations

Regularized logistic regression on 1000 samples with 200 features spanning a decade of scales: GD with step 1/L1/L needs 974 iterations to reach ∥∇f∥<10−6\|\nabla f\| < 10^{-6}. L-BFGS with m=10m = 10 needs 62, storing 4000 numbers instead of BFGS’s 40,000. The two-loop recursion is verified against the explicit BFGS matrix on a small case. The same algorithm scales unchanged to millions of parameters.

🐍 Exercise 2 (research): L-BFGS with the two-loop recursion
Implement the two-loop recursion and L-BFGS with backtracking. Compare with GD on 200-dimensional logistic regression, and check the recursion against the explicit BFGS matrix.

Quasi-Newton methods in AI, robotics and aerospace

  • Scientific ML: physics-informed neural networks are often fine-tuned with L-BFGS after Adam (Raissi, Perdikaris and Karniadakis, 2019).
  • Trajectory optimization and calibration: L-BFGS(-B) in SciPy and IPOPT’s quasi-Newton mode when Hessians are unavailable.
  • Computer vision: classic bundle-adjustment alternatives and image registration use L-BFGS.
  • Spacecraft trajectory design codes use quasi-Newton SQP (SNOPT) for large NLPs (Gill, Murray and Saunders, 2005).

References

  1. C. Broyden (1970); R. Fletcher (1970); D. Goldfarb (1970); D. Shanno (1970). The four BFGS papers in IMA J. Appl. Math., Computer Journal and Mathematics of Computation.
  2. J. Dennis, J. Moré (1974). “A characterization of superlinear convergence and its application to quasi-Newton methods.” Mathematics of Computation, 28(126).
  3. J. Nocedal (1980). “Updating quasi-Newton matrices with limited storage.” Mathematics of Computation, 35(151).
  4. D. Liu, J. Nocedal (1989). “On the limited memory BFGS method for large scale optimization.” Mathematical Programming, 45.
  5. R. Byrd, P. Lu, J. Nocedal, C. Zhu (1995). “A limited memory algorithm for bound constrained optimization.” SIAM Journal on Scientific Computing, 16(5) (L-BFGS-B).
  6. J. Nocedal, S. Wright (2006). Numerical Optimization, 2nd ed. Springer. Ch. 6–7.
  7. R. Byrd, S. Hansen, J. Nocedal, Y. Singer (2016). “A stochastic quasi-Newton method for large-scale optimization.” SIAM Journal on Optimization, 26(2).
  8. M. Raissi, P. Perdikaris, G. Karniadakis (2019). “Physics-informed neural networks.” Journal of Computational Physics, 378.
  9. P. Gill, W. Murray, M. Saunders (2005). “SNOPT: an SQP algorithm for large-scale constrained optimization.” SIAM Review, 47(1).
  10. D. Goldfarb (1970). “A family of variable-metric methods derived by variational means.” Mathematics of Computation, 24(109).