23.2 Curvature Methods: Newton, Quasi-Newton, and Trust Regions

Gradient descent never measures the curvature of the function it minimizes; it only endures it. The steepest direction caps the step size, the flattest direction then crawls, and the number of iterations grows with the condition number κ\kappa, or with κ\sqrt\kappa once momentum is added (Section 23.1.3). On our running example 12(x12+1000 x22)\tfrac12(x_1^2 + 1000\,x_2^2), that came to 6,9086{,}908 steps of gradient descent, or 315315 with momentum. Yet anyone can solve this problem by inspection: divide each coordinate of the gradient by its curvature (11 or 10001000) and a single step lands directly on the minimum. What can an optimizer achieve when it accounts for curvature instead of merely surviving it?

The classical answer is Newton's method, which predates gradient descent by a century and a half. At each iterate, it fits a quadratic approximation to the objective and jumps straight to the minimizer of that quadratic. In this section we examine how fast that step converges, what it costs, where it breaks down, and how much of its curvature information can be recovered from gradients alone when second derivatives are unavailable. Near a minimum, Newton's method is remarkably fast; for a neural network, however, forming the Hessian is far too expensive, and on nonconvex functions the method is drawn to saddle points just as readily as to minima. We then turn to two remedies: quasi-Newton methods, which rebuild curvature from successive gradient differences, and trust-region methods, which restrict each step to a neighborhood where the quadratic model actually agrees with the function.

For training deep networks, these classical methods are used much less often than first-order optimizers, and it is worth being candid about why. A full Hessian is too large to form, and minibatch noise spoils curvature estimates built from differences of gradients. Even so, the underlying ideas reappear throughout deep learning: the per-coordinate scaling of Adam acts as a diagonal stand-in for Newton's inverse Hessian (Section 23.5), and the damping added to curvature matrices plays the same stabilizing role as a trust region. The central result to keep in mind is the quadratic convergence of Newton's method (23.2.3); the subsection on quasi-Newton methods may be skipped on a first reading. From Section 23.1, we carry over two ingredients: the Armijo condition for backtracking line search and the test function 12x2+cos⁡y\tfrac12 x^2 + \cos y, whose saddle point stalled gradient descent.

23.2.1 Newton's Method#

Gradient descent builds a linear approximation to ff at the current point. Because a linear function has no minimum, the algorithm cannot choose its own step length and must rely on an external learning rate. A quadratic approximation, by contrast, has a unique minimum whenever it curves upward, giving us a step whose length is set automatically by the local geometry.

23.2.1.1 The Newton Step#

Newton's method lets the local curvature determine both the direction and the length of the step (Section 9.1.5.1). Writing gk=∇f(xk)\mathbf{g}_k = \nabla f(\mathbf{x}_k), we approximate ff near xk\mathbf{x}_k by its second-order Taylor expansion in the displacement p\mathbf{p}:

mk(p)=f(xk)+gk⊤p+12 p⊤∇2f(xk) p.(23.2.1)m_k(\mathbf{p}) = f(\mathbf{x}_k) + \mathbf{g}_k^\top \mathbf{p} + \tfrac12\, \mathbf{p}^\top \nabla^2 f(\mathbf{x}_k)\, \mathbf{p}. \tag{23.2.1}

When the Hessian ∇2f(xk)\nabla^2 f(\mathbf{x}_k) is positive definite, the model mkm_k is a strictly convex bowl with a unique minimizer, found by setting ∇mk(p)=gk+∇2f(xk) p=0\nabla m_k(\mathbf{p}) = \mathbf{g}_k + \nabla^2 f(\mathbf{x}_k)\,\mathbf{p} = \mathbf{0}. Solving for p\mathbf{p} and moving there gives Newton's method:

xk+1=xk−(∇2f(xk))−1∇f(xk).(23.2.2)\mathbf{x}_{k+1} = \mathbf{x}_k - \big(\nabla^2 f(\mathbf{x}_k)\big)^{-1} \nabla f(\mathbf{x}_k). \tag{23.2.2}
Figure 23.2.1:

One Newton step on f(x)=14x4+12x2f(x) = \tfrac14 x^4 + \tfrac12 x^2 from xk=1x_k = 1. The model mkm_k (dashed) shares the value, slope and curvature of ff at xkx_k, and the step pp moves to the minimizer of the model, xk+1=12x_{k+1} = \tfrac12. The minimizer of ff is x⋆=0x^\star = 0.

Figure 23.2.1 shows one such step in one dimension. Notice that no step size appears in (23.2.2): the inverse Hessian rescales each direction according to its curvature. More broadly, Newton's direction belongs to the family of preconditioned steps d=−P−1∇f\mathbf{d} = -\mathbf{P}^{-1}\nabla f with a positive definite matrix P\mathbf{P} (here P=∇2f\mathbf{P} = \nabla^2 f). Every such direction is a descent direction, since ∇f⊤d=−∇f⊤P−1∇f<0\nabla f^\top \mathbf{d} = -\nabla f^\top \mathbf{P}^{-1}\nabla f \lt 0. In fact, Newton's direction is simply the direction of steepest descent when step lengths are measured in the norm induced by the Hessian rather than the Euclidean norm (exercise 1).

On a positive definite quadratic 12x⊤Ax\tfrac12\mathbf{x}^\top\mathbf{A}\mathbf{x}, the Taylor model is exact, so a single Newton step lands immediately on the minimizer: x1=x0−A−1Ax0=0\mathbf{x}_1 = \mathbf{x}_0 - \mathbf{A}^{-1}\mathbf{A}\mathbf{x}_0 = \mathbf{0}, regardless of the condition number κ\kappa. The reason goes deeper than matrix cancellation. Newton's method is affine-invariant, meaning that its trajectory does not depend on the choice of coordinates. Under any invertible linear change of variables x=Ty\mathbf{x} = \mathbf{T}\mathbf{y}, running Newton's method on f(Ty)f(\mathbf{T}\mathbf{y}) produces the exact images of Newton's iterates for ff. Gradient descent, by contrast, changes its path under every non-orthogonal T\mathbf{T}, while a scalar multiple of an orthogonal matrix merely rescales the effective step size (exercise 1). Because some linear transformation turns any positive definite quadratic into a perfect sphere, the condition number cannot affect Newton's method. A long valley is, to Newton's method, a round bowl drawn on stretched paper.

23.2.1.2 Quadratic Convergence#

For a general non-quadratic objective, the Taylor model is only a local approximation, so one step is no longer enough. What survives is remarkable speed. Once the iterate enters a neighborhood of a minimizer, Newton's method converges much faster than geometrically, and the proof requires little more than the fundamental theorem of calculus. Let ek=xk−x⋆\mathbf{e}_k = \mathbf{x}_k - \mathbf{x}^\star denote the error at iteration kk.

Proposition (quadratic convergence). Let ∇f(x⋆)=0\nabla f(\mathbf{x}^\star) = \mathbf{0}, and suppose that on a ball around x⋆\mathbf{x}^\star the Hessian satisfies ∇2f(x)⪰μI\nabla^2 f(\mathbf{x}) \succeq \mu\mathbf{I} and ∥∇2f(x)−∇2f(y)∥≤L2∥x−y∥\|\nabla^2 f(\mathbf{x}) - \nabla^2 f(\mathbf{y})\| \le L_2\|\mathbf{x} - \mathbf{y}\|. If xk\mathbf{x}_k lies in the ball, then

∥ek+1∥  ≤  L22μ ∥ek∥2.(23.2.3)\|\mathbf{e}_{k+1}\| \;\le\; \frac{L_2}{2\mu}\, \|\mathbf{e}_k\|^2. \tag{23.2.3}

Proof. Abbreviate ∇2fk=∇2f(xk)\nabla^2 f_k = \nabla^2 f(\mathbf{x}_k). Because ∇f(x⋆)=0\nabla f(\mathbf{x}^\star) = \mathbf{0}, subtracting x⋆\mathbf{x}^\star from the Newton update yields ek+1=ek−(∇2fk)−1gk=(∇2fk)−1[∇2fk ek−(∇f(xk)−∇f(x⋆))]\mathbf{e}_{k+1} = \mathbf{e}_k - (\nabla^2 f_k)^{-1}\mathbf{g}_k = (\nabla^2 f_k)^{-1}\big[\nabla^2 f_k\,\mathbf{e}_k - (\nabla f(\mathbf{x}_k) - \nabla f(\mathbf{x}^\star))\big]. Applying the fundamental theorem of calculus along the line segment from x⋆\mathbf{x}^\star to xk\mathbf{x}_k expresses the gradient difference as ∫01∇2f(x⋆+tek) ek dt\int_0^1 \nabla^2 f(\mathbf{x}^\star + t\mathbf{e}_k)\,\mathbf{e}_k\,dt, so the bracketed term becomes ∫01[∇2fk−∇2f(x⋆+tek)]ek dt\int_0^1 \big[\nabla^2 f_k - \nabla^2 f(\mathbf{x}^\star + t\mathbf{e}_k)\big]\mathbf{e}_k\,dt. Since xk\mathbf{x}_k and x⋆+tek\mathbf{x}^\star + t\mathbf{e}_k are separated by (1−t)ek(1 - t)\mathbf{e}_k, the Lipschitz bound on the Hessian gives this integral norm at most ∫01L2(1−t)∥ek∥2 dt=L22∥ek∥2\int_0^1 L_2(1 - t)\|\mathbf{e}_k\|^2\,dt = \tfrac{L_2}{2}\|\mathbf{e}_k\|^2. Combining this with ∥(∇2fk)−1∥≤1/μ\|(\nabla^2 f_k)^{-1}\| \le 1/\mu completes the proof. ■\blacksquare

To read what (23.2.3) implies, multiply both sides by L2/(2μ)L_2/(2\mu): L22μ∥ek+1∥≤(L22μ∥ek∥)2\tfrac{L_2}{2\mu}\|\mathbf{e}_{k+1}\| \le \big(\tfrac{L_2}{2\mu}\|\mathbf{e}_k\|\big)^2. The scaled error squares at every step. If it starts below 11, it shrinks monotonically and every subsequent iterate remains in the ball. Once it drops below 0.10.1, it plunges to 10−210^{-2}, 10−410^{-4}, 10−810^{-8}, roughly doubling the number of accurate digits at each iteration. Compare that with gradient descent on our running example, which needs about 1,1501{,}150 steps to gain a single digit. The catch is written directly into the hypotheses: this quadratic rate is strictly local and guarantees nothing until the iterate is already close to x⋆\mathbf{x}^\star.

Far from x⋆\mathbf{x}^\star, the pure Newton step can overshoot even when the Hessian is positive definite. The standard safeguard is damping: update via xk+αkpk\mathbf{x}_k + \alpha_k\mathbf{p}_k along the Newton direction pk=−(∇2f(xk))−1gk\mathbf{p}_k = -(\nabla^2 f(\mathbf{x}_k))^{-1}\mathbf{g}_k, choosing αk≤1\alpha_k \le 1 by backtracking until the Armijo condition f(xk+αpk)≤f(xk)+c α gk⊤pkf(\mathbf{x}_k + \alpha\mathbf{p}_k) \le f(\mathbf{x}_k) + c\,\alpha\,\mathbf{g}_k^\top\mathbf{p}_k holds (the general-direction form of the Armijo rule in Section 23.1). Near a minimizer with a positive definite Hessian, the full step α=1\alpha = 1 automatically passes this test whenever c<12c \lt \tfrac12, so damping adds no overhead once quadratic convergence kicks in.

To test these predictions in code, we use ℓ2\ell_2-regularized logistic regression on n=200n = 200 synthetic examples in d=5d = 5 dimensions,

f(w)=1n∑i=1nlog⁡(1+exp⁡(−yi xi⊤w))+ν2∥w∥2,ν=0.1,f(\mathbf{w}) = \frac1n \sum_{i=1}^n \log\big(1 + \exp(-y_i\,\mathbf{x}_i^\top \mathbf{w})\big) + \frac{\nu}{2}\|\mathbf{w}\|^2, \qquad \nu = 0.1,

with binary labels yi=±1y_i = \pm 1 sampled from a logistic model (we write ν\nu for the weight-decay coefficient to reserve λ\lambda for eigenvalues). The setup cell below also computes a reference optimum w⋆\mathbf{w}^\star using 4,0004{,}000 gradient steps of size η=0.5\eta = 0.5, which is safely below 2/L2/L because L=λmax⁡(X⊤X)/(4n)+νL = \lambda_{\max}(\mathbf{X}^\top\mathbf{X})/(4n) + \nu is roughly 0.40.4 here (exercise 2).

rng = np.random.default_rng()
n, d, nu = 200, 5, 0.1
w_true = np.array([1.0, -2.0, 1.5, 0.0, 2.0])
X = rng.normal(size=(n, d))
y = np.where(rng.random(n) < 1 / (1 + np.exp(-X @ w_true)), 1.0, -1.0)

def loss(w, X, y, nu):
    return np.logaddexp(0, -y * (X @ w)).mean() + nu / 2 * (w @ w)

def grad_rows(w, X, y, nu):                   # row i: gradient of example i
    s = 1 / (1 + np.exp(y * (X @ w)))         # sigmoid(-y_i x_i^T w)
    return -(y * s)[:, None] * X + nu * w

w_star = np.zeros(d)
for _ in range(4000):                         # full-batch reference optimum
    w_star = w_star - 0.5 * grad_rows(w_star, X, y, nu).mean(axis=0)

We can now test both predictions directly. On our running quadratic diag(1,1000)\mathrm{diag}(1, 1000), a single Newton step should replace the log⁡106/log⁡(1001/999)≈6,908\log 10^6/\log(1001/999) \approx 6{,}908 steps required by gradient descent at its optimal fixed step size (Section 23.1.3). On the non-quadratic logistic loss, the exponent of the gradient norm should roughly double at every iteration once the local phase begins.

A2 = np.diag([1.0, 1000.0])                   # the running example, kappa = 1000
x = np.array([1.0, 1.0])
x_new = x - np.linalg.solve(A2, A2 @ x)       # one Newton step
rate = (1000 - 1) / (1000 + 1)
print(f'Newton on the quadratic: |x_1| = {np.linalg.norm(x_new):.1e} after one step')
print(f'GD at the optimal step contracts by {rate:.4f}; it needs '
      f'{int(np.ceil(np.log(1e-6) / np.log(rate)))} steps for |x_k| <= 1e-6 |x_0|')
w = np.zeros(d)                               # Newton on the logistic loss
for it in range(6):
    s = 1 / (1 + np.exp(y * (X @ w)))
    g = grad_rows(w, X, y, nu).mean(axis=0)
    hess = (X * (s * (1 - s))[:, None]).T @ X / n + nu * np.eye(d)
    w = w - np.linalg.solve(hess, g)
    print(f'Newton iteration {it + 1}:  |grad| = {np.linalg.norm(g):.1e}')
print(f'max |w - w_star| = {np.abs(w - w_star).max():.1e}')
Newton on the quadratic: |x_1| = 0.0e+00 after one step
GD at the optimal step contracts by 0.9980; it needs 6908 steps for |x_k| <= 1e-6 |x_0|
Newton iteration 1:  |grad| = 3.5e-01
Newton iteration 2:  |grad| = 4.1e-02
Newton iteration 3:  |grad| = 1.7e-03
Newton iteration 4:  |grad| = 3.0e-06
Newton iteration 5:  |grad| = 9.9e-12
Newton iteration 6:  |grad| = 1.6e-17
max |w - w_star| = 4.4e-16

Both predictions hold. On the quadratic, a single Newton step drives the error to zero, whereas optimal fixed-step gradient descent contracts by only 0.9980.998 per step and requires 6,9086{,}908 iterations. On the logistic loss, the gradient norm starts at a few tenths and drops below 10−810^{-8} by the fifth iteration, its exponent roughly doubling once it becomes small. After just six iterations, Newton's iterate agrees with the reference optimum to roughly 10−1510^{-15}, matching the precision of the reference itself. Six linear solves have accomplished what took 4,0004{,}000 gradient steps.

23.2.1.3 The Cost of a Step#

Unfortunately, comparing iteration counts alone flatters Newton's method. The Hessian contains d2d^2 entries, and solving the linear system in (23.2.2) generally requires O(d3)O(d^3) operations per step. For d=5d = 5 this cost is negligible, but for a neural network with even a modest 10810^8 parameters, the Hessian has 101610^{16} entries, ruling out exact Newton's method before the first step is ever taken (Section 9.1.5.1). Practical alternatives either approximate the Hessian from gradients, as in the quasi-Newton methods below, or use cheap diagonal and structured preconditioners (Section 23.5).

23.2.1.4 Saddle Points#

Computational cost is not the only drawback of Newton's method, nor is it the most instructive one. Because the Newton step solves ∇mk=0\nabla m_k = \mathbf{0}, it jumps to the stationary point of the quadratic model whether that point is a minimum, a maximum, or a saddle. Return to the function f(x,y)=12x2+cos⁡yf(x, y) = \tfrac12 x^2 + \cos y from Section 23.1, which has a saddle at the origin and a minimum of −1-1 at (0,π)(0, \pi), and start at (0.5,0.3)(0.5, 0.3). Here the gradient is (0.5,−sin⁡0.3)=(0.5,−0.296)(0.5, -\sin 0.3) = (0.5, -0.296), and the Hessian diag(1,−cos⁡0.3)=diag(1,−0.955)\mathrm{diag}(1, -\cos 0.3) = \mathrm{diag}(1, -0.955) is indefinite: the surface curves upward along xx and downward along yy. Which way does a Newton step move yy from this point, compared with a plain gradient step of size η=1\eta = 1?

def f_s(v):
    return 0.5 * v[0]**2 + np.cos(v[1])

def grad_s(v):
    return np.array([v[0], -np.sin(v[1])])

def hess_s(v):
    return np.diag([1.0, -np.cos(v[1])])

x_n = x_g = np.array([0.5, 0.3])
ys_n, ys_g = [], []
for _ in range(6):
    x_n = x_n - np.linalg.solve(hess_s(x_n), grad_s(x_n))    # Newton
    x_g = x_g - 1.0 * grad_s(x_g)                            # GD, eta = 1
    ys_n.append(x_n[1])
    ys_g.append(x_g[1])
print('Newton y:', np.array(ys_n[:3]), f'  f = {f_s(x_n):.4f}')
print('GD     y:', np.array(ys_g).round(4), f'  f = {f_s(x_g):.4f}')
Newton y: [-9.33624961e-03  2.71275924e-07 -6.61744490e-21]   f = 1.0000
GD     y: [0.5955 1.1565 2.0718 2.9489 3.1404 3.1416]   f = -1.0000

Newton's first step sends xx to 00 and yy to 0.3−tan⁡0.3=−0.00930.3 - \tan 0.3 = -0.0093; the second sends yy to 2.7×10−72.7 \times 10^{-7}. We are seeing Newton's rapid local convergence (here even cubic, since y−tan⁡y≈−y3/3y - \tan y \approx -y^3/3), driving the iterate straight into the saddle (0,0)(0, 0) with f=1f = 1. Gradient descent moves yy in the opposite direction, through 0.600.60, 1.161.16, 2.072.07, 2.952.95, 3.1403.140, and 3.14163.1416, reaching the minimum (0,π)(0, \pi) with f=−1f = -1. The richer model has led to the worse point. Because the curvature along yy is negative, the stationary point of the quadratic model is a saddle, and Newton's method is blind to the difference between a saddle and a minimum. A trust region (Section 23.2.3) fixes this flaw.

23.2.2 Quasi-Newton Methods#

Newton's method requires explicit second derivatives. Can we instead infer curvature from the gradients we are already computing? When the gradient changes rapidly along a step, the objective must have large curvature in that direction. An optimizer that records these changes can gradually assemble a model of the Hessian without ever evaluating a second derivative.

23.2.2.1 The Secant Method#

In one dimension the idea is immediate: the slope of the chord connecting the last two gradients estimates f′′f'',

hk=f′(xk)−f′(xk−1)xk−xk−1,xk+1=xk−f′(xk)hk.h_k = \frac{f'(x_k) - f'(x_{k-1})}{x_k - x_{k-1}}, \qquad x_{k+1} = x_k - \frac{f'(x_k)}{h_k}.

This is the secant method, which is simply Newton's step with f′′(xk)f''(x_k) replaced by a finite difference of gradients. Consider f(x)=ex−2xf(x) = e^x - 2x, whose minimizer is log⁡2≈0.6931\log 2 \approx 0.6931, starting from x0=0x_0 = 0 and x1=1x_1 = 1. The first secant slope is h1=(e−2)−(1−2)=e−1≈1.718h_1 = (e - 2) - (1 - 2) = e - 1 \approx 1.718, giving x2=1−(e−2)/1.718≈0.582x_2 = 1 - (e - 2)/1.718 \approx 0.582. From there the errors shrink as 1.1×10−11.1 \times 10^{-1}, 1.6×10−21.6 \times 10^{-2}, 9.3×10−49.3 \times 10^{-4}, 7.7×10−67.7 \times 10^{-6}, and 3.6×10−93.6 \times 10^{-9}. Each error is roughly half the product of the previous two (the factor of one-half comes from f′′′/(2f′′)f'''/(2f'') at the minimizer), so the number of correct digits grows by a factor approaching 1.61.6 per step. That is slightly slower than Newton's factor of 22, yet each iteration requires only a single gradient evaluation and no second derivative. On a one-dimensional quadratic λ2x2\tfrac{\lambda}{2}x^2, the secant slope equals λ\lambda exactly, and the step from x1x_1 lands directly on the minimizer.

In dd dimensions, the analogous secant condition is a single vector equation, which is far from enough to pin down a d×dd \times d matrix: one step reveals curvature along one direction only. We need a principled rule to fill in the remaining directions.

23.2.2.2 BFGS#

A quasi-Newton method maintains an approximation Mk\mathbf{M}_k to the inverse Hessian and updates it after each step using the observed change in the gradient. After moving from xk\mathbf{x}_k to xk+1\mathbf{x}_{k+1}, we record the secant pair

sk=xk+1−xk,yk=∇f(xk+1)−∇f(xk).\mathbf s_k=\mathbf x_{k+1}-\mathbf x_k, \qquad \mathbf y_k=\nabla f(\mathbf x_{k+1})-\nabla f(\mathbf x_k).

On a quadratic 12x⊤Ax\tfrac12\mathbf{x}^\top\mathbf{A}\mathbf{x}, the gradient difference satisfies yk=Ask\mathbf{y}_k = \mathbf{A}\mathbf{s}_k, so the true inverse Hessian maps yk\mathbf{y}_k back to sk\mathbf{s}_k. We require the updated approximation Mk+1\mathbf{M}_{k+1} to obey the same secant equation:

Mk+1 yk=sk.(23.2.4)\mathbf{M}_{k+1}\,\mathbf{y}_k = \mathbf{s}_k . \tag{23.2.4}

Among all symmetric matrices satisfying (23.2.4), BFGS (named after Broyden, Fletcher, Goldfarb, and Shanno) chooses the one closest to the previous estimate Mk\mathbf{M}_k in a suitably weighted Frobenius norm:

Mk+1=(I−γkskyk⊤) Mk (I−γkyksk⊤)+γksksk⊤,γk=1yk⊤sk.(23.2.5)\mathbf{M}_{k+1} =(\mathbf{I}-\gamma_k\mathbf s_k\mathbf y_k^\top)\,\mathbf{M}_k\, (\mathbf{I}-\gamma_k\mathbf y_k\mathbf s_k^\top) +\gamma_k\mathbf s_k\mathbf s_k^\top, \qquad \gamma_k=\frac{1}{\mathbf y_k^\top\mathbf s_k}. \tag{23.2.5}

Even without deriving (23.2.5), we can read off how it works (dropping the index kk on the pair for clarity). The right factor I−γys⊤\mathbf{I} - \gamma\mathbf{y}\mathbf{s}^\top sends y\mathbf{y} to zero, because γ s⊤y=1\gamma\,\mathbf{s}^\top\mathbf{y} = 1, while leaving every vector orthogonal to s\mathbf{s} untouched. Thus the first term erases what Mk\mathbf{M}_k previously predicted along y\mathbf{y}, and the second term writes in the new observation: Mk+1y=γ s (s⊤y)=s\mathbf{M}_{k+1}\mathbf{y} = \gamma\,\mathbf{s}\,(\mathbf{s}^\top\mathbf{y}) = \mathbf{s}, satisfying the secant equation.

Just as importantly, the update preserves positive definiteness, ensuring that the next search direction −Mk+1∇f(xk+1)-\mathbf{M}_{k+1}\nabla f(\mathbf{x}_{k+1}) remains a descent direction. For any nonzero vector z\mathbf{z}, set w=(I−γys⊤)z\mathbf{w} = (\mathbf{I} - \gamma\mathbf{y}\mathbf{s}^\top)\mathbf{z}, so that z⊤Mk+1z=w⊤Mkw+γ(s⊤z)2\mathbf{z}^\top\mathbf{M}_{k+1}\mathbf{z} = \mathbf{w}^\top\mathbf{M}_k\mathbf{w} + \gamma(\mathbf{s}^\top\mathbf{z})^2. When Mk≻0\mathbf{M}_k \succ 0 and γ>0\gamma > 0, both terms are nonnegative and cannot vanish simultaneously: w=0\mathbf{w} = \mathbf{0} forces z=γ(s⊤z) y\mathbf{z} = \gamma(\mathbf{s}^\top\mathbf{z})\,\mathbf{y}, which requires s⊤z≠0\mathbf{s}^\top\mathbf{z} \neq 0. The requirement γ>0\gamma > 0 is the curvature condition yk⊤sk>0\mathbf{y}_k^\top\mathbf{s}_k > 0, meaning that the directional slope increased along the step. It holds automatically on any strictly convex objective; on general objectives, the line search enforces it via a second check known as the Wolfe condition (Nocedal and Wright, 2006).

How quickly do secant pairs reconstruct the true curvature? Let us run BFGS from (1,1)(1, 1) on the two-dimensional quadratic diag(1,10)\mathrm{diag}(1, 10), starting with M0=I\mathbf{M}_0 = \mathbf{I} and using the exact line search α=−g⊤p/(p⊤Ap)\alpha = -\mathbf{g}^\top\mathbf{p}/(\mathbf{p}^\top\mathbf{A}\mathbf{p}), and inspect both x\mathbf{x} and M\mathbf{M} after each step.

def bfgs_update(M, s, y):
    gamma = 1.0 / (y @ s)
    V = np.eye(len(s)) - gamma * np.outer(s, y)
    return V @ M @ V.T + gamma * np.outer(s, s)

A = np.diag([1.0, 10.0])
x, M = np.array([1.0, 1.0]), np.eye(2)
for k in range(2):
    g = A @ x
    p = -M @ g
    alpha = -(g @ p) / (p @ A @ p)            # exact line search
    s = alpha * p
    M = bfgs_update(M, s, A @ s)              # y = A s on a quadratic
    x = x + s
    print(f'step {k + 1}: x = {x.round(4)},  M = {M.round(4).tolist()}')
print(f'A^-1 = {np.linalg.inv(A).tolist()},  '
      f'max |M_2 - A^-1| = {np.abs(M - np.linalg.inv(A)).max():.0e}')
step 1: x = [ 0.8991 -0.009 ],  M = [[1.009, -0.0001], [-0.0001, 0.1]]
step 2: x = [0. 0.],  M = [[1.0, -0.0], [-0.0, 0.1]]
A^-1 = [[1.0, 0.0], [0.0, 0.1]],  max |M_2 - A^-1| = 1e-16

After a single step, M1≈diag(1.009,0.100)\mathbf{M}_1 \approx \mathrm{diag}(1.009, 0.100) is already close to A−1\mathbf{A}^{-1} along the steep direction it has just probed. After the second step, M2=A−1\mathbf{M}_2 = \mathbf{A}^{-1} up to floating-point rounding and x2=0\mathbf{x}_2 = \mathbf{0}. This two-dimensional behavior generalizes cleanly: on any dd-dimensional positive definite quadratic with exact line searches, each secant equation remains satisfied after subsequent updates, and the steps are mutually A\mathbf{A}-conjugate (si⊤Asj=0\mathbf{s}_i^\top\mathbf{A}\mathbf{s}_j = 0 for i≠ji \neq j). After dd steps, MdA=I\mathbf{M}_d\mathbf{A} = \mathbf{I} and BFGS reaches the exact minimizer (exercise 2).

Finite termination, however, holds specifically for quadratics with exact line searches and should not be taken as a general guarantee. On non-quadratic objectives, line searches are inexact, the true Hessian varies from step to step, and stochastic gradients corrupt yk\mathbf{y}_k: the difference between two minibatch gradients is often dominated by sampling noise rather than curvature. In addition, full BFGS stores a dense d×dd \times d matrix. L-BFGS avoids that memory cost by retaining only the mm most recent secant pairs and applying the resulting inverse-Hessian approximation (a scaled identity plus a correction of rank at most 2m2m) in O(md)O(md) time and memory (Liu and Nocedal, 1989). It works very well on deterministic, medium-scale problems, though it remains awkward when fresh minibatch noise makes gradient differences unreliable.

23.2.3 Trust Regions#

Newton's method went astray at (0.5,0.3)(0.5, 0.3) because it trusted its local quadratic model across the entire space. That model was built from derivatives at a single point and accurately reflects ff only nearby. A trust-region method takes this limitation literally: it keeps the full curvature information, including directions of negative curvature, and instead bounds the step to a region where the model can be trusted.

23.2.3.1 The Subproblem#

At (0.5,0.3)(0.5, 0.3), the quadratic model of 12x2+cos⁡y\tfrac12 x^2 + \cos y has curvature −0.955-0.955 along yy. Because it curves downward without bound, asking for its unconstrained minimum makes no sense. A trust-region method instead minimizes the quadratic model inside a ball of radius Δk\Delta_k, which represents how far we believe the approximation holds:

min⁡∥p∥≤Δkmk(p)=f(xk)+∇f(xk)⊤p+12p⊤Bkp.(23.2.6)\min_{\|\mathbf p\|\le\Delta_k} m_k(\mathbf p) =f(\mathbf x_k)+\nabla f(\mathbf x_k)^\top\mathbf p +\tfrac12\mathbf p^\top \mathbf{B}_k\mathbf p. \tag{23.2.6}

Here Bk\mathbf{B}_k is either the exact Hessian or a symmetric approximation to it. Restricting p\mathbf{p} to a closed ball guarantees that a minimizer exists even when Bk\mathbf{B}_k has negative eigenvalues, because any continuous function achieves a minimum on a compact set. Better still, the exact solutions of this constrained problem have a clean characterization.

Proposition (solution of the subproblem). A step p\mathbf{p} with ∥p∥≤Δ\|\mathbf{p}\| \le \Delta solves (23.2.6) if and only if there is a τ≥0\tau \ge 0 with

(B+τI) p=−g,B+τI⪰0,τ (Δ−∥p∥)=0.(\mathbf{B} + \tau\mathbf{I})\,\mathbf{p} = -\mathbf{g}, \qquad \mathbf{B} + \tau\mathbf{I} \succeq \mathbf{0}, \qquad \tau\,(\Delta - \|\mathbf{p}\|) = 0.

This result is Theorem 4.1 of Nocedal and Wright (2006); exercise 3 proves the sufficiency of these conditions. Geometrically, the trust region adds a uniform shift τ\tau to every eigenvalue of B\mathbf{B}, just enough to make the shifted quadratic convex. Two cases arise. When B\mathbf{B} is positive definite and the unconstrained Newton step already lies inside the ball, we have τ=0\tau = 0 and simply take the Newton step. Otherwise the solution lies on the boundary ∥p∥=Δ\|\mathbf{p}\| = \Delta, and τ\tau is the root of the scalar equation ∥(B+τI)−1g∥=Δ\|(\mathbf{B} + \tau\mathbf{I})^{-1}\mathbf{g}\| = \Delta over τ>−λmin⁡(B)\tau > -\lambda_{\min}(\mathbf{B}), where the left-hand side decreases strictly as τ\tau grows.

This scalar equation fails to have a root only in the degenerate hard case, when g\mathbf{g} is orthogonal to the eigenvectors associated with the smallest eigenvalue of B\mathbf{B} (explored in part d of exercise 3). As we will see in Section 23.6, the shift τ\tau is simply the Lagrange multiplier enforcing the constraint 12∥p∥2≤12Δ2\tfrac12\|\mathbf{p}\|^2 \le \tfrac12\Delta^2.

Between iterations, the radius Δk\Delta_k adapts according to how accurately the model predicted the actual drop in ff. After solving (23.2.6), we form the ratio of actual decrease to predicted decrease:

rk=f(xk)−f(xk+pk)mk(0)−mk(pk).(23.2.7)r_k= \frac{f(\mathbf x_k)-f(\mathbf x_k+\mathbf p_k)} {m_k(\mathbf 0)-m_k(\mathbf p_k)}. \tag{23.2.7}

A ratio near 11 indicates that the quadratic model matched the objective well. In the implementation below, we accept the step whenever rk>0.1r_k > 0.1. Independently, we shrink the radius to Δ←Δ/4\Delta \leftarrow \Delta/4 whenever rk<14r_k \lt \tfrac14, and we double it when rk>34r_k > \tfrac34 and the step hit the boundary ∥pk∥=Δk\|\mathbf{p}_k\| = \Delta_k.

23.2.3.2 The Trust-Region Step at a Saddle#

Let us work out one trust-region step at (0.5,0.3)(0.5, 0.3) by hand with Δ=0.5\Delta = 0.5. At this point g=(0.5,−0.296)\mathbf{g} = (0.5, -0.296) and B=diag(1,−0.955)\mathbf{B} = \mathrm{diag}(1, -0.955). Making B+τI\mathbf{B} + \tau\mathbf{I} positive semidefinite requires τ≥0.955\tau \ge 0.955, so τ=0\tau = 0 is impossible and the step must lie on the boundary of the ball. The optimality system gives (1+τ)p1=−0.5(1 + \tau)p_1 = -0.5 and (τ−0.955)p2=0.296(\tau - 0.955)p_2 = 0.296 subject to p12+p22=0.25p_1^2 + p_2^2 = 0.25, whose solution is τ≈1.60\tau \approx 1.60 and p≈(−0.19,0.46)\mathbf{p} \approx (-0.19, 0.46). Moving to (0.31,0.76)(0.31, 0.76) lowers ff from 1.0801.080 to 0.7710.771. Because the model predicted a decrease of 0.3160.316 and the actual decrease is 0.3090.309, the ratio is r=0.98r = 0.98, so the step is accepted and the radius doubles. Crucially, the trust-region step moves away from the saddle along the negative-curvature direction where the model drops, whereas the unconstrained Newton step (−0.5,−0.31)(-0.5, -0.31) marched straight toward it.

To see where this subproblem solution leads over several iterations, we first implement tr_step(g, B, Delta), which returns the unconstrained Newton step when B≻0\mathbf{B} \succ \mathbf{0} and ∥B−1g∥≤Δ\|\mathbf{B}^{-1}\mathbf{g}\| \le \Delta, and otherwise bisects on τ\tau until ∥(B+τI)−1g∥=Δ\|(\mathbf{B} + \tau\mathbf{I})^{-1}\mathbf{g}\| = \Delta:

def tr_step(g, B, Delta):
    """Minimize g p + p B p / 2 over |p| <= Delta; return (p, tau)."""
    eig_min = np.linalg.eigvalsh(B).min()
    if eig_min > 0 and np.linalg.norm(np.linalg.solve(B, -g)) <= Delta:
        return np.linalg.solve(B, -g), 0.0     # Newton step fits: tau = 0
    lo = hi = max(0.0, -eig_min)
    hi += 1e3
    for _ in range(100):                       # bisection for |p(tau)| = Delta
        tau = (lo + hi) / 2
        p = np.linalg.solve(B + tau * np.eye(len(g)), -g)
        lo, hi = (tau, hi) if np.linalg.norm(p) > Delta else (lo, tau)
    return p, tau

Starting from x=(0.5,0.3)\mathbf{x} = (0.5, 0.3) with Δ=0.5\Delta = 0.5, we now run six trust-region iterations on fsf_s, printing the iterate, objective value, step norm ∥p∥\|\mathbf{p}\|, shift τ\tau, agreement ratio rr, and radius Δ\Delta at each step:

x, Delta = np.array([0.5, 0.3]), 0.5
print(' k        x            f      |p|    tau      r  Delta')
for k in range(6):
    g, B = grad_s(x), hess_s(x)
    p, tau = tr_step(g, B, Delta)
    r = (f_s(x) - f_s(x + p)) / -(g @ p + 0.5 * p @ B @ p)
    print(f'{k:2d} ({x[0]:6.3f},{x[1]:6.3f}) {f_s(x):7.4f} '
          f'{np.linalg.norm(p):6.3f} {tau:6.3f} {r:6.2f} {Delta:5.2f}')
    if r > 0.1:                                # accept the step
        x = x + p
    if r < 0.25:
        Delta /= 4                             # poor prediction: shrink
    elif r > 0.75 and np.linalg.norm(p) > 0.99 * Delta:
        Delta *= 2                             # good, and on the boundary
print(f'final x = ({x[0]:.4f}, {x[1]:.4f}),  f = {f_s(x):.4f}')
 k        x            f      |p|    tau      r  Delta
 0 ( 0.500, 0.300)  1.0803  0.500  1.596   0.98  0.50
 1 ( 0.307, 0.761)  0.7711  1.000  1.419   0.87  1.00
 2 ( 0.180, 1.753) -0.1652  2.000  0.311   0.41  2.00
 3 ( 0.043, 3.749) -0.8205  0.696  0.000   0.88  2.00
 4 ( 0.000, 3.054) -0.9962  0.088  0.000   1.00  2.00
 5 ( 0.000, 3.142) -1.0000  0.000  0.000   1.00  2.00
final x = (0.0000, 3.1416),  f = -1.0000

The first row matches our hand calculation. The radius doubles from 0.50.5 to 11 and then to 22, while the third step (with ratio 0.410.41) is accepted without changing the radius. By the third iterate, (0.18,1.75)(0.18, 1.75), the algorithm has entered the basin where the Hessian is positive definite. From the next iterate on, the unconstrained Newton step fits inside the trust-region ball with τ=0\tau = 0, so the method seamlessly turns into Newton's method and converges quadratically to the minimum (0,π)(0, \pi) with f=−1f = -1. Six iterations are enough; Figure 23.2.2 contrasts both trajectories.

Figure 23.2.2:

Newton's method and a trust-region method from (0.5,0.3)(0.5,0.3) on 12x2+cos⁡y\tfrac12 x^2 + \cos y, where the Hessian is diag(1,−0.96)\mathrm{diag}(1,-0.96). (a) The local quadratic model forms a saddle surface: Newton's step moves to its stationary point, whereas minimizing the model over the ball of radius Δ=0.5\Delta = 0.5 follows the negative-curvature direction away from the saddle. (b) Newton's method converges quadratically to the saddle (0,0)(0,0) with f=1f = 1, while the trust-region method (shown with its initial radius) reaches the minimum (0,π)(0,\pi) with f=−1f = -1 in six steps as its radius expands through 0.5,1,20.5, 1, 2.

Solving the trust-region subproblem exactly requires factoring Bk+τI\mathbf{B}_k + \tau\mathbf{I} for each trial value of τ\tau. Large-scale implementations instead solve it approximately using Hessian--vector products, each costing roughly the same as a single gradient evaluation (Section 22.5). Even with that speedup, neither BFGS nor trust-region methods replace stochastic gradient descent on large, noisy deep learning objectives.

The saddle of 12x2+cos⁡y\tfrac12 x^2 + \cos y has now tripped up two optimizers: gradient descent stalled at it from a start on the line y=0y = 0, and Newton's method ran straight into it from a generic one. A trust region escapes, but only by checking each local model against the true objective. Yet there is a large class of functions where none of these precautions are needed: functions with no saddles, no spurious basins, and where every stationary point is a global minimum. Identifying those functions is the subject of Section 23.3.

23.2.4 Summary#

Newton's method minimizes a local quadratic model of ff at each iterate. It solves any positive definite quadratic in a single step regardless of the condition number, and near a minimizer with a positive definite, Lipschitz-continuous Hessian it squares the error at every iteration. That speed comes with two obstacles: each step requires O(d2)O(d^2) memory and O(d3)O(d^3) operations, far beyond what a neural network can afford, and the unconstrained step is attracted to saddle points just as strongly as to minima. BFGS avoids explicit second derivatives by reconstructing the inverse Hessian from past step and gradient differences, recovering it completely in dd steps on a dd-dimensional quadratic. Trust-region methods make any quadratic model safe to use by confining each step to a ball, comparing the predicted and actual decreases in ff, and expanding or shrinking the ball accordingly.

23.2.5 Exercises#

  1. Reparametrization and preconditioning. Let T\mathbf{T} be an invertible matrix and h(y)=f(Ty)h(\mathbf{y}) = f(\mathbf{T}\mathbf{y}), so that x=Ty\mathbf{x} = \mathbf{T}\mathbf{y} is a change of coordinates.

    1. Express ∇h\nabla h and ∇2h\nabla^2 h through the derivatives of ff. Show that Newton's iterates (23.2.2) for hh, started at y0=T−1x0\mathbf{y}_0 = \mathbf{T}^{-1}\mathbf{x}_0, satisfy yk=T−1xk\mathbf{y}_k = \mathbf{T}^{-1}\mathbf{x}_k, where xk\mathbf{x}_k are Newton's iterates for ff.
    2. Run gradient descent with step η\eta on hh and map every iterate back by xk=Tyk\mathbf{x}_k = \mathbf{T}\mathbf{y}_k. Show that the mapped iterates follow xk+1=xk−η P−1∇f(xk)\mathbf{x}_{k+1} = \mathbf{x}_k - \eta\, \mathbf{P}^{-1} \nabla f(\mathbf{x}_k) for a positive definite matrix P\mathbf{P}, and find P\mathbf{P}. By problem 1b this direction is the steepest one in the norm ∥⋅∥P\|\cdot\|_{\mathbf{P}}. What is ∥x∥P\|\mathbf{x}\|_{\mathbf{P}} in the coordinates y\mathbf{y}?
    3. For f(x)=12x⊤A xf(\mathbf{x}) = \tfrac12\mathbf{x}^\top \mathbf{A}\,\mathbf{x} with A=diag(1,1000)\mathbf{A} = \mathrm{diag}(1, 1000), the κ=1000\kappa = 1000 quadratic of the Newton subsection, find a diagonal T\mathbf{T} for which gradient descent on hh with η=1\eta = 1 reaches the minimizer in one step. What does constructing such a T\mathbf{T} require for a general positive definite A\mathbf{A}?
  2. [code] BFGS on a quadratic. ● Let f(x)=12x⊤Ax−b⊤xf(\mathbf{x}) = \tfrac12\mathbf{x}^\top\mathbf{A}\mathbf{x} - \mathbf{b}^\top\mathbf{x} with A\mathbf{A} positive definite, and run BFGS (23.2.5) with exact line searches from M0=I\mathbf{M}_0 = \mathbf{I}.

    1. Show that an exact line search along pk\mathbf{p}_k gives ∇f(xk+1)⊤pk=0\nabla f(\mathbf{x}_{k+1})^\top\mathbf{p}_k = 0, and that yk=Ask\mathbf{y}_k = \mathbf{A}\mathbf{s}_k.
    2. Show the hereditary property: if Mkyj=sj\mathbf{M}_k\mathbf{y}_j = \mathbf{s}_j for all j<kj \lt k and the steps s0,…,sk−1\mathbf{s}_0, \ldots, \mathbf{s}_{k-1}, sk\mathbf{s}_k are A\mathbf{A}-conjugate, then Mk+1yj=sj\mathbf{M}_{k+1}\mathbf{y}_j = \mathbf{s}_j for all j≤kj \le k. (Hint: sj⊤yk=sj⊤Ask=0\mathbf{s}_j^\top\mathbf{y}_k = \mathbf{s}_j^\top\mathbf{A}\mathbf{s}_k = 0 for j<kj \lt k.) Conclude that after dd linearly independent steps MdA=I\mathbf{M}_d\mathbf{A} = \mathbf{I}.
    3. Run the BFGS loop of the text in d=6d = 6 dimensions, on a randomly rotated quadratic with eigenvalues from 11 to 10001000. Print max⁡j≤k∥Mk+1yj−sj∥\max_{j \le k}\|\mathbf{M}_{k+1}\mathbf{y}_j - \mathbf{s}_j\| after each step, and confirm that it stays at rounding level and that M6=A−1\mathbf{M}_6 = \mathbf{A}^{-1}. How far from the minimizer is gradient descent at its best fixed step after the same six gradients?
    4. The symmetric rank-one update Mk+1=Mk+(s−Mky)(s−Mky)⊤(s−Mky)⊤y\mathbf{M}_{k+1} = \mathbf{M}_k + \frac{(\mathbf{s} - \mathbf{M}_k\mathbf{y})(\mathbf{s} - \mathbf{M}_k\mathbf{y})^\top}{(\mathbf{s} - \mathbf{M}_k\mathbf{y})^\top\mathbf{y}} also satisfies the secant equation. Show by a 2×22 \times 2 example that it need not stay positive definite even when y⊤s>0\mathbf{y}^\top\mathbf{s} > 0, and say which of the two checks in the text fails for it.
  3. [code] Trust region at a saddle. ● Consider the model m(p)=g⊤p+12p⊤Bpm(\mathbf{p}) = \mathbf{g}^\top\mathbf{p} + \tfrac12\mathbf{p}^\top\mathbf{B}\mathbf{p} with B=diag(1,−1)\mathbf{B} = \mathrm{diag}(1, -1) and g=(12,−310)\mathbf{g} = (\tfrac12, -\tfrac{3}{10}).

    1. Show that mm is unbounded below on R2\mathbb{R}^2 and that the Newton point −B−1g=(−12,−310)-\mathbf{B}^{-1}\mathbf{g} = (-\tfrac12, -\tfrac{3}{10}) is a saddle of mm, not a minimum.
    2. Prove that the conditions of the subproblem proposition are sufficient: if (B+τI)p=−g(\mathbf{B} + \tau\mathbf{I})\mathbf{p} = -\mathbf{g} with τ≥0\tau \ge 0, B+τI⪰0\mathbf{B} + \tau\mathbf{I} \succeq \mathbf{0}, and τ(Δ−∥p∥)=0\tau(\Delta - \|\mathbf{p}\|) = 0, then every ∥q∥≤Δ\|\mathbf{q}\| \le \Delta satisfies m(q)≥m(p)+τ2(∥p∥2−∥q∥2)≥m(p)m(\mathbf{q}) \ge m(\mathbf{p}) + \tfrac{\tau}{2}(\|\mathbf{p}\|^2 - \|\mathbf{q}\|^2) \ge m(\mathbf{p}). (Hint: expand m(q)−m(p)m(\mathbf{q}) - m(\mathbf{p}) around p\mathbf{p} and use g=−(B+τI)p\mathbf{g} = -(\mathbf{B} + \tau\mathbf{I})\mathbf{p}.)
    3. For Δ=12\Delta = \tfrac12 find τ≥1\tau \ge 1 by bisection on ∥(B+τI)−1g∥=Δ\|(\mathbf{B} + \tau\mathbf{I})^{-1}\mathbf{g}\| = \Delta (the answer is τ≈1.65\tau \approx 1.65, p≈(−0.19,0.46)\mathbf{p} \approx (-0.19, 0.46)), and check that the step increases the coordinate with negative curvature while the Newton step decreases it.
    4. Replace g\mathbf{g} by (12,0)(\tfrac12, 0). Show that ∥(B+τI)−1g∥=12/(1+τ)≤14\|(\mathbf{B} + \tau\mathbf{I})^{-1}\mathbf{g}\| = \tfrac12/(1 + \tau) \le \tfrac14 for all τ>1\tau > 1, so the boundary equation has no solution with τ>1\tau > 1. Find the minimizers on the ball directly (they have τ=1\tau = 1 and p2=±Δ2−p12p_2 = \pm\sqrt{\Delta^2 - p_1^2}), and explain in one sentence what the ball does with a direction of negative curvature that the gradient does not see.

Discussions