concept / newtons-method
Next task →
University/Optimization/Second-order methods/Newton's Method and Second-Order Optimization
Optimization · Second-order methods · Curvature-aware optimization

Newton's Method and Second-Order Optimization

Newton's method minimizes the second-order Taylor model of the objective at each step, dividing the gradient by the Hessian to correct for anisotropic curvature; it converges quadratically near a nondegenerate optimum but demands curvature information and careful globalization.

39 sectionsadvanced200 minhand-authored · structural 78/100
Take assessment →
Mastery requires: derivation reproduced, from-scratch implementation committed, failure case explained, and assessment score ≥ 80%. Current state: not_started.

1. Concept overview

Newton's method for minimizing f:Rd→Rf:\mathbb R^d\to\mathbb R applies the update

θt+1=θt−[∇2f(θt)]−1∇f(θt)\boxed{\theta_{t+1}=\theta_t-\bigl[\nabla^2 f(\theta_t)\bigr]^{-1}\nabla f(\theta_t)}

(or solves Htst=−∇f(θt)H_t s_t=-\nabla f(\theta_t) and sets θt+1=θt+st\theta_{t+1}=\theta_t+s_t). It is the root-finding Newton method applied to the stationarity condition ∇f(θ)=0\nabla f(\theta)=0, whose Jacobian is the Hessian.

Equivalently, it builds the second-order Taylor model mt(s)=f(θt)+∇f(θt)⊤s+12s⊤Htsm_t(s)=f(\theta_t)+\nabla f(\theta_t)^\top s+\tfrac12 s^\top H_ts and jumps to its minimizer. Where gradient descent sees only a slope, Newton sees the local curvature ellipsoid and rescales each direction by 1/λi1/\lambda_i: flat directions get large steps, steep directions get small ones. Near a nondegenerate optimum the error squares each iteration — quadratic convergence — but globally the raw method can diverge, stall at saddles, or be impossible to store when dd is large.

2. Why this concept exists

Gradient descent's convergence degrades with the condition number κ=L/μ\kappa=L/\mu: on a quadratic the error contracts by (1−μ/L)(1-\mu/L) per step, so κ=104\kappa=10^4 needs tens of thousands of iterations. The Hessian inverse is exactly the preconditioner that makes the local geometry spherical: in transformed coordinates s~=H1/2s\tilde s=H^{1/2}s, the quadratic model has identity curvature and Newton converges in one step for any quadratic.

Curvature also answers questions a gradient cannot: is this stationary point a minimum, maximum, or saddle (eigenvalues of HH)? How sensitive is the optimum to data (via H−1H^{-1})? How wide is the confidence region (the inverse Hessian is the asymptotic covariance in MLE)? No first-order method gives these for free.

Earlier alternatives were inadequate: coordinate descent ignores cross-derivatives; fixed diagonal preconditioners cannot handle rotated ellipses; finite-difference gradient search costs O(d)O(d) evaluations. Newton and its quasi-Newton descendants (BFGS, L-BFGS) became the default for medium-dimensional smooth optimization and remain central in scientific computing and statistics.

3. Historical background

Isaac Newton described the root-finding iteration in De Methodis Serierum et Fluxionum (written 1671, published 1736); Joseph Raphson (1690) published the cleaner form xt+1=xt−f(xt)/f′(xt)x_{t+1}=x_t-f(x_t)/f'(x_t) that bears both names. Simpson (1740) extended it to systems; Fourier (1831) gave the elimination-method viewpoint; Cauchy (1847) applied steepest descent and considered second-order corrections.

The modern optimization era began with Davidon (1959) and Fletcher & Powell (1963), who invented variable-metric (quasi-Newton) updates without Hessians; Broyden (1965) generalized the secant equation to systems; the BFGS update (Broyden–Fletcher–Goldfarb–Shanno, 1970) became the standard dense second-order method. Gill & Murray (1972) and Moré & Sorensen (1983) developed stabilized Cholesky and trust-region variants for indefinite Hessians. Nocedal (1980) introduced limited-memory L-BFGS, reducing storage from O(d2)O(d^2) to O(md)O(md). Nesterov & Polyak (2006) added cubic regularization with global complexity guarantees; Martens (2010) revived Hessian-free Newton–CG for deep networks.

4. Fundamental problem

Given a twice-differentiable objective ff, find θ⋆=arg⁡min⁡f\theta^{\star}=\arg\min f using gradient and curvature information, with three constraints:

  1. Local vs global: the quadratic model is accurate only nearby; a raw Newton step from far away can overshoot or diverge.
  2. Curvature quality: HH may be singular, indefinite (nonconvex), or wildly ill-conditioned, making the Newton direction undefined or an ascent direction.
  3. Scale: storing HH needs O(d2)O(d^2) and solving needs O(d3)O(d^3) — impossible for d=109d=10^9 parameters of a large network.

Solving these defines the design space: damping and line search (globalization), modified/cholesky-regularized Hessians (robustness), and quasi-Newton or matrix-free approximations (scale).

5. First-principles explanation

Fact 1 — local quadratic model. Taylor's theorem gives

f(θ+s)=f(θ)+∇f(θ)⊤s+12s⊤H(θ+ξs)s.f(\theta+s)=f(\theta)+\nabla f(\theta)^\top s+\tfrac12s^\top H(\theta+\xi s)s .

Replacing the intermediate Hessian by H(θ)H(\theta) gives a tractable model m(s)m(s).

Fact 2 — stationary point of a quadratic. If H≻0H\succ0, m(s)m(s) is strictly convex and its unique minimizer satisfies ∇m(s)=g+Hs=0\nabla m(s)=g+Hs=0, i.e. s=−H−1gs=-H^{-1}g. This is the Newton step.

Fact 3 — Newton as root-finding. Applying the scalar Newton iteration to g(θ)=0g(\theta)=0 gives θt+1=θt−g(θt)/g′(θt)\theta_{t+1}=\theta_t-g(\theta_t)/g'(\theta_t); in Rd\mathbb R^d, g′=∇2f=Hg'=\nabla^2f=H, so the same formula holds with a linear solve.

Fact 4 — quadratic convergence. If ∇f(θ⋆)=0\nabla f(\theta^{\star})=0, H(θ⋆)≻0H(\theta^{\star})\succ0, and HH is Lipschitz near θ⋆\theta^{\star}, then

∥θt+1−θ⋆∥≤C∥θt−θ⋆∥2,\lVert\theta_{t+1}-\theta^{\star}\rVert\le C\lVert\theta_t-\theta^{\star}\rVert^2,

because the neglected third-order Taylor term is proportional to the squared error. Doubling correct digits each step is the method's defining virtue.

6. Prerequisite concepts

You need: (1) multivariable Taylor expansion with remainder; (2) gradient and Hessian, and symmetric positive definiteness (Sylvester's criterion, eigenvalues); (3) solving linear systems by Cholesky/LU and understanding condition numbers; (4) convexity and LL-smoothness; (5) line-search (Armijo/Wolfe) and trust-region ideas; (6) gradient descent for comparison; (7) basic numerical linear algebra: why forming H−1H^{-1} is worse than solving Hs=−gHs=-g. See the linked concepts.

7. Complete mathematical formulation

Newton step. Hst=−gtHs_t=-g_t, with gt=∇f(θt)g_t=\nabla f(\theta_t), Ht=∇2f(θt)H_t=\nabla^2f(\theta_t); then θt+1=θt+st\theta_{t+1}=\theta_t+s_t.

Damped Newton. θt+1=θt+αtst\theta_{t+1}=\theta_t+\alpha_ts_t with αt∈(0,1]\alpha_t\in(0,1] chosen by Armijo backtracking: accept the smallest k≥0k\ge0 with

f(θt+2−kst)≤f(θt)+c1 2−kgt⊤st,c1∈(0,1).f(\theta_t+2^{-k}s_t)\le f(\theta_t)+c_1\,2^{-k}g_t^\top s_t,\qquad c_1\in(0,1).

Positive-definite modification. If HtH_t has eigenvalue λmin⁡<0\lambda_{\min}<0, replace Ht←Ht+γIH_t\leftarrow H_t+\gamma I with γ>−λmin⁡+ϵ\gamma>-\lambda_{\min}+\epsilon so the step is a descent direction.

BFGS update. With st=θt+1−θts_t=\theta_{t+1}-\theta_t, yt=gt+1−gty_t=g_{t+1}-g_t, and Bt≈HtB_t\approx H_t:

Bt+1=Bt−Btstst⊤Btst⊤Btst+ytyt⊤yt⊤st,B_{t+1}=B_t-\frac{B_ts_ts_t^\top B_t}{s_t^\top B_ts_t}+\frac{y_ty_t^\top}{y_t^\top s_t},

which satisfies the secant equation Bt+1st=ytB_{t+1}s_t=y_t and preserves positive definiteness when yt⊤st>0y_t^\top s_t>0.

L-BFGS stores only the last mm pairs (si,yi)(s_i,y_i) and applies Bt−1B_t^{-1} implicitly by a two-loop recursion costing O(md)O(md).

Local rate. ∥et+1∥≤M2μ∥et∥2\lVert e_{t+1}\rVert\le \frac{M}{2\mu}\lVert e_t\rVert^2 where et=θt−θ⋆e_t=\theta_t-\theta^{\star}, μ=λmin⁡(H⋆)\mu=\lambda_{\min}(H^{\star}), and MM bounds ∥∇3f∥\lVert\nabla^3f\rVert.

8. Notation dictionary

| Symbol | Meaning | Type | |---|---|---| | ff | smooth objective | function | | θt,gt,Ht\theta_t,g_t,H_t | iterate, gradient, Hessian at step tt | vector/matrix | | st=−Ht−1gts_t=-H_t^{-1}g_t | full Newton step | vector | | αt\alpha_t | damping / step length | scalar | | BtB_t | quasi-Newton approximation to HtH_t | matrix | | yt=gt+1−gty_t=g_{t+1}-g_t | gradient difference | vector | | mm | L-BFGS memory (number of stored pairs) | integer | | μ,λmin⁡\mu,\lambda_{\min} | smallest eigenvalue / strong-convexity constant | scalar | | LL | largest eigenvalue / smoothness constant | scalar | | κ=L/μ\kappa=L/\mu | condition number | scalar | | MM | bound on ∥∇3f∥\lVert\nabla^3f\rVert | scalar | | et=θt−θ⋆e_t=\theta_t-\theta^{\star} | error vector | vector | | c1c_1 | Armijo sufficient-decrease constant | scalar | | HpH_p | Gauss–Newton/GGN approximation | matrix |

9. Step-by-step derivation

Step 1 — build the local model. mt(s)=ft+gt⊤s+12s⊤Htsm_t(s)=f_t+g_t^\top s+\tfrac12s^\top H_ts.

Step 2 — stationarity. ∇smt=gt+Hts=0\nabla_s m_t=g_t+H_ts=0. If Ht≻0H_t\succ0, the unique solution st=−Ht−1gts_t=-H_t^{-1}g_t is the global minimizer of the model. If HtH_t is indefinite, the stationary point is a saddle and the direction may be an ascent direction.

Step 3 — solve, do not invert. Factor Ht=LL⊤H_t=LL^\top (Cholesky, O(d3/3)O(d^3/3)) then solve two triangular systems; forming H−1H^{-1} costs more and is less stable.

Step 4 — local convergence. Let et=θt−θ⋆e_t=\theta_t-\theta^{\star}. Taylor-expand gt=∇f(θ⋆+et)=H⋆et+O(∥et∥2)g_t=\nabla f(\theta^{\star}+e_t)=H^{\star}e_t+O(\lVert e_t\rVert^2) and Ht=H⋆+O(∥et∥)H_t=H^{\star}+O(\lVert e_t\rVert). Then

et+1=et−Ht−1gt=et−(H⋆)−1H⋆et+O(∥et∥2)=O(∥et∥2).e_{t+1}=e_t-H_t^{-1}g_t=e_t-(H^{\star})^{-1}H^{\star}e_t+O(\lVert e_t\rVert^2)=O(\lVert e_t\rVert^2).

More precisely ∥et+1∥≤M2μ∥et∥2\lVert e_{t+1}\rVert\le\frac{M}{2\mu}\lVert e_t\rVert^2.

Step 5 — globalization. Because the model can be poor far from θ⋆\theta^{\star}, apply backtracking line search: try α=1\alpha=1, halve until Armijo holds. For μ\mu-strongly convex ff with MM-Lipschitz Hessian, damped Newton reaches the quadratic-convergence region in O((f0−f⋆)/ϵ)O((f_0-f^{\star})/\epsilon) iterations.

Step 6 — secant derivation of BFGS. We want Bt+1st=ytB_{t+1}s_t=y_t with the minimal change to BtB_t in a weighted norm. Enforcing symmetry, positivity and this secant condition uniquely yields the BFGS formula above; applying the Sherman–Morrison–Woodbury identity gives the inverse update used in practice.

10. Proofs and proof intuition

Theorem (local quadratic convergence). Suppose f∈C2f\in C^2, ∇f(θ⋆)=0\nabla f(\theta^{\star})=0, H⋆⪰μIH^{\star}\succeq\mu I with μ>0\mu>0, and ∥∇2f(x)−∇2f(y)∥≤M∥x−y∥\lVert\nabla^2f(x)-\nabla^2f(y)\rVert\le M\lVert x-y\rVert near θ⋆\theta^{\star}. If θ0\theta_0 is close enough, then ∥et+1∥≤M2μ∥et∥2\lVert e_{t+1}\rVert\le\frac{M}{2\mu}\lVert e_t\rVert^2. Proof. By Taylor with integral remainder, gt=∫01H(θ⋆+τet)et dτ=H⋆et+Etetg_t=\int_0^1 H(\theta^{\star}+\tau e_t)e_t\,d\tau=H^{\star}e_t+E_t e_t with ∥Et∥≤M2∥et∥\lVert E_t\rVert\le\frac M2\lVert e_t\rVert. Then et+1=et−Ht−1gt=Ht−1(Htet−gt)=Ht−1[(Ht−H⋆)et−Etet]e_{t+1}=e_t-H_t^{-1}g_t=H_t^{-1}(H_t e_t-g_t)=H_t^{-1}[(H_t-H^{\star})e_t-E_te_t]. Bounding ∥Ht−1∥≤1/(μ−M2∥et∥)\lVert H_t^{-1}\rVert\le1/(\mu-\frac M2\lVert e_t\rVert) and ∥Ht−H⋆∥≤M∥et∥\lVert H_t-H^{\star}\rVert\le M\lVert e_t\rVert gives the bound. □\square

Proposition (affine invariance). For θ=Aϕ+b\theta=A\phi+b with AA invertible, the Newton iterate in ϕ\phi-space maps exactly to the Newton iterate in θ\theta-space. Proof. ∇ϕf=A⊤∇θf\nabla_\phi f=A^\top\nabla_\theta f and ∇ϕ2f=A⊤HθA\nabla_\phi^2f=A^\top H_\theta A; hence Δϕ=−(A⊤HθA)−1A⊤g=A−1(−Hθ−1g)\Delta\phi=-(A^\top H_\theta A)^{-1}A^\top g=A^{-1}(-H_\theta^{-1}g), and θ+AΔϕ=θ+sθ\theta+A\Delta\phi=\theta+s_\theta. □\square (Gradient descent is not affine invariant.)

Proposition (BFGS preserves positive definiteness). If Bt≻0B_t\succ0 and yt⊤st>0y_t^\top s_t>0, then Bt+1≻0B_{t+1}\succ0. Proof. For any v≠0v\neq0, v⊤Bt+1v=v⊤Btv−(st⊤Btv)2st⊤Btst+(yt⊤v)2yt⊤stv^\top B_{t+1}v=v^\top B_tv-\frac{(s_t^\top B_tv)^2}{s_t^\top B_ts_t}+\frac{(y_t^\top v)^2}{y_t^\top s_t}. The first two terms are nonnegative by Cauchy–Schwarz in the BtB_t-inner product (equality only for v∝stv\propto s_t), and the third is strictly positive in that case since yt⊤st>0y_t^\top s_t>0. □\square

Proof intuition. Newton's quadratic convergence comes from the fact that the Hessian error is first order in the position error, and after multiplying by H−1H^{-1} it becomes second order. Everything else — damping, modifications, quasi-Newton — is about preserving that local magic while surviving the real world.

11. Geometric interpretation

At each iterate, Newton fits a quadratic bowl whose curvature matrix is HtH_t. The step jumps to that bowl's bottom. For a quadratic objective the bowl is exact, so one step reaches the optimum regardless of conditioning; gradient descent instead follows the normal to elongated ellipses and zig-zags.

Preconditioning view: H−1H^{-1} rotates and rescales the gradient so that the transformed Hessian is the identity — contours become circles. The local rate for gradient descent, (κ−1)/(κ+1)(\kappa-1)/(\kappa+1), becomes zero for Newton on quadratics.

In nonconvex regions the "bowl" is a saddle: a negative eigenvalue makes H−1gH^{-1}g point toward ascent. Trust-region methods respond by constraining ∥s∥≤Δ\lVert s\rVert\le\Delta; eigenvalue modification flips negative curvature. Visualizing the Hessian's eigen-decomposition — directions of upward and downward curvature — is the right mental model for all these fixes.

12. Visual explanation

Use the interactive Newton Lab: plot contours of f(x,y)= frac12(x2+10y2)f(x,y)=\ frac12(x^2+10y^2) and overlay the trajectories of gradient descent (η=0.1\eta=0.1) and Newton. GD zig-zags for ~40 steps; Newton lands at the origin in one. Next, load the Rosenbrock function and observe that raw Newton diverges from far starts while damped Newton descends. A third panel shows a saddle point with the Hessian eigenvector corresponding to a negative eigenvalue highlighted in red; flipping its sign (adding γI\gamma I) turns the step into a descent direction. The scree of eigenvalues λi\lambda_i illustrates why a single scalar step size cannot match curvature across directions.

13. Numerical worked example

Root finding. Solve x2−4=0x^2-4=0 with xt+1=xt−(xt2−4)/(2xt)=(xt+4/xt)/2x_{t+1}=x_t-(x_t^2-4)/(2x_t)=(x_t+4/x_t)/2 from x0=4x_0=4: x1=2.5x_1=2.5, x2=2.05x_2=2.05, x3=2.0006098x_3=2.0006098, x4=2.00000000009x_4=2.00000000009. The number of correct digits roughly doubles: errors 0.5,0.05,6.1×10−4,9.3×10−110.5,0.05,6.1\times10^{-4},9.3\times10^{-11}.

Ill-conditioned quadratic. f(x,y)=12(x2+10y2)f(x,y)=\tfrac12(x^2+10y^2) from (10,10)(10,10): g=(10,100)g=(10,100), H=diag(1,10)H=\mathrm{diag}(1,10), so s=−H−1g=(−10,−10)s=-H^{-1}g=(-10,-10) and θ1=(0,0)\theta_1=(0,0) — one step to machine precision. Gradient descent with η=0.05\eta=0.05 needs about 60 steps because κ=10\kappa=10 slows the flat direction.

Logistic regression. With n=104,d=20n=10^4,d=20, H=1nX⊤WXH=\tfrac1nX^\top W X where Wii=pi(1−pi)W_{ii}=p_i(1-p_i). Damped Newton from zero typically converges in 6–10 iterations while L-BFGS takes 50–200; each iteration costs O(nd2+d3)O(nd^2+d^3) versus O(nd)O(nd) for a gradient step.

Failure. f(x)=x3−3xf(x)=x^3-3x has H(0)=0H(0)=0: starting at x0=0x_0=0, the Newton step divides by zero. Adding γ=0.1\gamma=0.1 gives a finite descent step. At x=1x=1 (a minimizer, H=6>0H=6>0) convergence is quadratic.

Saddle. f(x,y)=x2−y2f(x,y)=x^2-y^2 has H=diag(2,−2)H=\mathrm{diag}(2,-2) at the origin; the Newton step from (0,1)(0,1) is (0,−1)(0,-1) — it moves up the negative-curvature direction toward the saddle rather than down.

14. Real-world analogy

A hiker in fog with a topographical instrument that measures not just slope but the full local curvature of the terrain. Gradient descent walks downhill at a fixed pace; Newton's method uses the curvature to choose a stride per direction — small strides across sharp ridges, long strides down gentle slopes. On an elliptical valley this reaches the bottom in one perfectly aimed leap. But if the instrument reads a saddle (ground curving up one way and down another), following its advice blindly walks uphill; and if the terrain is far from the local model, the leap may overshoot into a different valley. Hence damping and curvature checks.

15. Algorithm pseudocode

algorithm Newton(f, grad, hess, theta0, T, tol):
    for t = 0 .. T-1:
        g <- grad(theta);  H <- hess(theta)
        if ||g|| < tol: break
        if lambda_min(H) <= 0: H <- H + gamma I       # curvature repair
        solve H s = -g                                 # Cholesky if SPD, else LU
        alpha <- BacktrackingLineSearch(f, g, s)       # alpha = 1 if Armijo holds
        theta <- theta + alpha * s
    return theta

algorithm BacktrackingLineSearch(f, g, s, c1=1e-4, rho=0.5):
    alpha <- 1
    while f(theta + alpha*s) > f(theta) + c1*alpha*(g . s):
        alpha <- rho * alpha
    return alpha

algorithm BFGS(f, grad, theta0, T):
    B <- I
    for t = 0 .. T-1:
        solve B s = -grad(theta)                       # or use inverse form
        theta_new <- theta + LineSearch(s)
        y <- grad(theta_new) - grad(theta)
        if y . s > 1e-12: B <- BFGSUpdate(B, s, y)     # secant update
        theta <- theta_new
    return theta

16. Implementation from scratch

import numpy as np

def newton(f, grad, hess, x0, tol=1e-12, maxiter=50, gamma=1e-6):
    x = np.asarray(x0, float).copy()
    hist = []
    for t in range(maxiter):
        g = grad(x); H = hess(x)
        if np.linalg.norm(g) < tol: break
        # curvature repair: ensure positive definiteness
        eig_min = np.linalg.eigvalsh(H)[0]
        if eig_min <= gamma:
            H = H + (gamma - eig_min + 1e-8) * np.eye(len(x))
        try:
            s = np.linalg.solve(H, -g)                 # never invert H
        except np.linalg.LinAlgError:
            s = -g / (np.linalg.norm(g) + 1e-12)
        alpha = 1.0                                     # Armijo backtracking
        while f(x + alpha*s) > f(x) + 1e-4*alpha*(g @ s) and alpha > 1e-12:
            alpha *= 0.5
        x = x + alpha*s
        hist.append((t, f(x), np.linalg.norm(g)))
    return x, hist

def bfgs(f, grad, x0, maxiter=200, tol=1e-9):
    x = np.asarray(x0, float).copy(); B = np.eye(len(x))
    for _ in range(maxiter):
        g = grad(x)
        if np.linalg.norm(g) < tol: break
        s = np.linalg.solve(B, -g)
        x_new = x + s                                    # assume unit step suffices
        y = grad(x_new) - g
        if y @ s > 1e-12:
            Bs = B @ s
            B = B - np.outer(Bs, Bs)/(s @ Bs) + np.outer(y, y)/(y @ s)
        x = x_new
    return x

f = lambda w: 0.5*(w[0]**2 + 10*w[1]**2)
g = lambda w: np.array([w[0], 10*w[1]])
H = lambda w: np.array([[1.0, 0.0], [0.0, 10.0]])
x, hist = newton(f, g, H, [10.0, 10.0])
print(x, len(hist))                                     # ~ [0,0], 1-2 iterations
print(bfgs(f, g, [10.0, 10.0]))                         # ~ [0,0]

17. Professional library implementation

import numpy as np
from scipy.optimize import minimize
import torch

fun = lambda w: 0.5*(w[0]**2 + 10*w[1]**2)
jac = lambda w: np.array([w[0], 10*w[1]])
hess = lambda w: np.array([[1.0, 0.0], [0.0, 10.0]])
res = minimize(fun, [10.0, 10.0], jac=jac, hess=hess, method="Newton-CG")
print(res.x, res.nit)

# Limited-memory BFGS for large d
res2 = minimize(fun, [10.0, 10.0], jac=jac, method="L-BFGS-B",
                options={"maxiter": 200, "ftol": 1e-12})
print(res2.x, res2.nit)

# PyTorch LBFGS for neural-network-scale problems
w = torch.tensor([10.0, 10.0], requires_grad=True)
opt = torch.optim.LBFGS([w], max_iter=20, line_search_fn="strong_wolfe")
def closure():
    opt.zero_grad(); loss = 0.5*(w[0]**2 + 10*w[1]**2); loss.backward()
    return loss
opt.step(closure)
print(w.detach())

Use method="trust-constr" or Newton-CG when the Hessian may be indefinite; L-BFGS-B for large dd; and PyTorch's LBFGS only for moderate-sized problems because it requires a closure and multiple function evaluations per step.

18. Code walkthrough

Scratch Newton. eigvalsh(H)[0] obtains the smallest eigenvalue of a symmetric matrix; adding (γ−λmin⁡+ϵ)I(\gamma-\lambda_{\min}+\epsilon)I makes the modified Hessian positive definite so the solve yields a descent direction. np.linalg.solve uses LU; for a guaranteed SPD matrix, scipy.linalg.cho_factor/cho_solve is roughly twice as fast and more stable. The Armijo loop multiplies α\alpha by 0.5 until sufficient decrease — exactly the globalization described in the derivation.

BFGS. The inverse-form update (shown) avoids an inner linear solve. The curvature condition y⊤s>0y^\top s>0 is checked before updating; skipping an update with negative curvature preserves positive definiteness. With a quadratic whose Hessian is constant, BFGS converges in at most dd steps (finite termination property).

Library. scipy.optimize.minimize with Newton-CG uses Hessian-vector products rather than a dense Hessian; L-BFGS-B stores mm correction pairs. PyTorch's LBFGS calls closure() repeatedly so it can evaluate the objective at trial points during its line search — forgetting to zero gradients inside the closure is the classic bug.

19. Tensor and memory analysis

A dense Hessian costs d2d^2 floats: d=10,000d=10{,}000 needs 400 MB in fp32, d=109d=10^9 needs 4 PB — impossible. BFGS also stores O(d2)O(d^2); L-BFGS stores 2m2m vectors of length dd, i.e. O(md)O(md) (with m=10m=10, d=109d=10^9: 80 GB, still large but tractable in sharded form). Hessian-vector products need no O(d2)O(d^2) buffer: an HVP via reverse-over-forward automatic differentiation costs roughly the price of two gradient evaluations and O(d)O(d) extra memory. Block-diagonal/K-FAC approximations store sums of Kronecker factors, e.g. O(din2+dout2)O(d_\text{in}^2+d_\text{out}^2) per layer instead of the full O((dindout)2)‘.CholeskyfactorizationneedsaworkspaceofO((d_\text{in}d_\text{out})^2)`. Cholesky factorization needs a workspace of O(d^2)`; iterative solvers (CG) need only O(d)O(d) vectors.

20. Time complexity

Per Newton iteration: O(nd2)O(nd^2) to form HH for least-squares-like losses, O(d3/3)O(d^3/3) for Cholesky, O(d2)O(d^2) for the solves — so O(nd2+d3)O(nd^2+d^3). Newton–CG replaces the solve with O(κ)O(\sqrt\kappa) CG iterations each costing one HVP O(nd)O(nd), giving O(ndκ)O(nd\sqrt\kappa) — far better when dd is huge and κ\kappa moderate. BFGS costs O(d2)O(d^2) per iteration for the rank-two update plus a line search; L-BFGS costs O(md)O(md) per step. Iteration counts: Newton needs O(log⁡log⁡(1/ϵ))O(\log\log(1/\epsilon)) locally (quadratic), damped Newton O((f0−f⋆)/ϵ)O((f_0-f^{\star})/\epsilon) globally for strongly convex ff, L-BFGS typically O(κlog⁡(1/ϵ))O(\kappa\log(1/\epsilon)) empirically. Always weigh iterations against per-iteration cost — Newton's "one step" can be far more expensive than a gradient step.

21. Space complexity

Dense Newton and BFGS: O(d2)‘forO(d^2)` for HororBplusplusO(d) for $g,s$. L-BFGS: $O(md) for mm stored (s,y)(s,y) pairs, with m≈5–20m\approx5\text{–}20. Matrix-free Newton–CG: O(d)‘forafewvectors,plusthecostofHVPs.ForO(d)` for a few vectors, plus the cost of HVPs. For d=10^7,, O(d^2)isunattainablewhileis unattainable whileO(md)` is ~800 MB — this is why large-scale practice uses L-BFGS, Hessian-free methods, or structured approximations.

22. Experimental demonstration

Compare gradient descent (η=0.1\eta=0.1), Newton, and BFGS on f=12(x2+κy2)f=\tfrac12(x^2+\kappa y^2) for κ∈{1,10,100,1000}\kappa\in\{1,10,100,1000\} from (10,10)(10,10): Newton always converges in one step, GD needs O(κ)O(\kappa), BFGS needs at most d=2d=2 steps by finite termination. Record iteration counts and wall-clock time. Then run on Rosenbrock from (−1,1)(-1,1): raw Newton diverges, damped Newton converges in ~20 iterations, BFGS in ~30. Third, fit logistic regression on a synthetic n=104,d=20‘datasetandcomparedampedNewton(6–10iterations)toL−BFGS(50–200)inbothiterationsandtotaltime.Finally,perturbtheHessianestimatewithnoiseandobservewhentheBFGScurvatureconditionn=10^4,d=20` dataset and compare damped Newton (6–10 iterations) to L-BFGS (50–200) in both iterations and total time. Finally, perturb the Hessian estimate with noise and observe when the BFGS curvature condition y^\top s>0$ fails and the update must be skipped.

23. Benchmark results

On the ill-conditioned quadratic, Newton's single iteration takes O(d3)‘butstillwinsinwall−clockforO(d^3)` but still wins in wall-clock for d\le1000;beyondthat,L−BFGSwinsbecauseeachstepis; beyond that, L-BFGS wins because each step is O(md). On logistic regression with $d=20$, damped Newton converges in fewer than 10 iterations versus L-BFGS's 50–200, but each Newton iteration forms an $O(nd^2) matrix — report both metrics. On deep networks, full Newton is infeasible; K-FAC and Hessian-free Newton–CG show speedups over SGD in some settings but require careful damping and are not universal defaults. Never quote iteration counts alone: always report per-iteration cost, damping rule, and whether curvature was exact or approximate.

24. Limitations

  • Requires twice-differentiable objectives with available (or accurate) Hessian information.
  • Dense Hessian storage O(d2)‘andfactorizationO(d^2)` and factorization O(d^3)` are prohibitive at large scale.
  • Indefinite Hessians produce ascent directions; saddle points are attractors for raw Newton.
  • Singular Hessians make the step undefined; regularization is mandatory near degenerate optima.
  • Only locally quadratically convergent — globalization (line search/trust region) is essential.
  • Noisy or stochastic gradients break the BFGS secant condition; quasi-Newton updates become unstable.
  • For nonsmooth objectives (e.g. ℓ1\ell_1 penalties) the Hessian does not exist; proximal or smoothed variants are needed.
  • Exact Hessian may be wasteful for losses with structured Gauss–Newton approximations.

25. Failure scenarios

  1. Singular Hessian: f(x)=x3−3xf(x)=x^3-3x at x=0x=0 gives H=0H=0; division by zero. Add $\gamma I`.
  2. Indefinite Hessian / saddle: f(x,y)=x2−y2f(x,y)=x^2-y^2; the Newton direction points uphill along yy. Use eigenvalue modification or trust regions.
  3. Divergence from far starts: Rosenbrock from (−1,1)(-1,1) with $\alpha=1`; backtracking or a trust region fixes it.
  4. Memory exhaustion: forming a 105×10510^5\times10^5 Hessian needs 40 GB; switch to L-BFGS or HVP-based Newton–CG.
  5. BFGS update from noisy gradients: $y^\top s\le0` makes the update non-PSD; skip the update or use damping.
  6. **Forming H−1‘explicitly∗∗:slowerandlessstablethansolvingH^{-1}` explicitly**: slower and less stable than solving Hs=-g`; use Cholesky.
  7. Stochastic Newton with minibatches: a noisy Hessian estimate can be non-PSD even when the true one is PSD; use subsampled Gauss–Newton with damping.

26. Common misconceptions

  • "Newton always converges faster than gradient descent." Locally yes (quadratic vs linear), but each iteration is much more expensive and can diverge globally without damping.
  • "The Hessian is always positive definite." Only at local minima of convex functions; saddles and nonconvex regions have negative eigenvalues.
  • "Quasi-Newton methods approximate the Hessian by finite differences." They build it from gradient differences satisfying the secant equation — no extra function evaluations.
  • "Newton minimizes ff exactly in one step." Only for an exactly quadratic $f` (or a locally quadratic model); higher-order terms require more steps.
  • "Inverting the Hessian is the natural implementation." Solving the linear system is both faster and numerically safer.
  • "Second-order methods are always better for deep learning." Curvature is expensive and noisy; adaptive first-order methods dominate large-scale training.

27. Alternative approaches

  • Gradient descent / SGD / AdamW: $O(d)` per step, robust to noise, default for deep learning.
  • BFGS / L-BFGS: secant-based curvature, O(d2)O(d^2) or $O(md)` storage; excellent for medium-dimensional smooth problems.
  • Trust-region methods: constrain step length, handle indefinite curvature rigorously.
  • Cubic regularization: adds σ3∥s∥3‘tothemodel,givingglobal\tfrac\sigma3\lVert s\rVert^3` to the model, giving global O(1/\varepsilon^{3/2})$ complexity.
  • Newton–CG / Hessian-free: matrix-free solves using Hessian-vector products.
  • Gauss–Newton / Levenberg–Marquardt: exploit least-squares structure, using $J^\top J` instead of the full Hessian.
  • Natural gradient / K-FAC: precondition with the Fisher information or a factored approximation, better matched to probability distributions.
  • Coordinate descent / derivative-free methods: when derivatives or curvature are unavailable.

29. Research applications

  • Statistical inference: the inverse Hessian gives asymptotic standard errors of maximum-likelihood estimates.
  • Scientific computing: solving nonlinear equations and PDEs with Newton–Krylov methods.
  • Machine learning: second-order optimization for logistic regression, Gaussian processes, and small-to-medium networks; K-FAC and Hessian-free training.
  • Reinforcement learning: TRPO uses a Fisher-information (natural-gradient) trust region.
  • Sharpness and generalization: Hessian eigenvalue spectra characterize flat vs sharp minima.
  • Sensitivity analysis: implicit differentiation of optimizers via $H^{-1}`.
  • Model-based control: sequential quadratic programming (SQP) uses local quadratic models with constraints.

30. Important research papers

  • Newton I. (1687), Philosophiæ Naturalis Principia Mathematica — original root-finding iteration.
  • Raphson J. (1690), Analysis Aequationum Universalis — the modern Newton–Raphson form.
  • Cauchy A.-L. (1847), Méthode générale pour la résolution des systèmes d'équations simultanées — descent and second-order context.
  • Davidon W. C. (1959), Variable Metric Method for Minimization, Argonne National Laboratory — first quasi-Newton method.
  • Fletcher R., Powell M. J. D. (1963), A Rapidly Convergent Descent Method for Minimization, Computer Journal 6:163–168.
  • Broyden C. G. (1965), A class of methods for solving nonlinear simultaneous equations, Math. Comp. 19:577–593.
  • Nocedal J. (1980), Updating quasi-Newton matrices with limited storage, Math. Comp. 35:773–782 — L-BFGS.
  • Nesterov Y., Polyak B. T. (2006), Cubic regularization of Newton's method and global complexity guarantees, Math. Program. 108:523–539.
  • Martens J. (2010), Deep learning via Hessian-free optimization, ICML.

31. Further reading

  • Nocedal & Wright, Numerical Optimization (2nd ed., 2006), chapters 3, 6, 7, 11 — the standard reference.
  • Boyd & Vandenberghe, Convex Optimization (2004), chapters 9.5, 10 — Newton and self-concordance.
  • Dennis & Schnabel, Numerical Methods for Unconstrained Optimization and Nonlinear Equations (1983).
  • Kelley, Solving Nonlinear Equations with Newton's Method (2003).
  • Conn, Gould & Toint, Trust-Region Methods (2000).
  • PyTorch docs on torch.optim.LBFGS and SciPy's optimize.minimize notes on Hessian specifications.

32. Practical exercises

  1. Implement newton from memory and verify it reaches (0,0)(0,0) from (10,10)(10,10) on f=12(x2+10y2)f=\tfrac12(x^2+10y^2) in one step.
  2. Derive and implement the Armijo backtracking line search; verify that damped Newton converges on Rosenbrock from (−1,1)(-1,1) while undamped Newton diverges.
  3. Reproduce the scalar example xt+1=(xt+4/xt)/2x_{t+1}=(x_t+4/x_t)/2 and tabulate the doubling of correct digits.
  4. Implement BFGS from memory; verify finite termination in at most dd steps on a positive-definite quadratic.
  5. Demonstrate the saddle failure on f(x,y)=x2−y2f(x,y)=x^2-y^2 and show that adding γI\gamma I produces a descent step.
  6. Compare Newton–CG (HVP-based) with dense Newton on a diagonal quadratic with $d=5000`; report memory and time.

33. Debugging challenges

  • np.linalg.solve raises a singular-matrix error. The Hessian is rank-deficient; add a Levenberg-style damping γI\gamma I.
  • Newton step increases the loss. Hessian is indefinite or the step is too large; check eigenvalues and enable line search.
  • BFGS update produces a non-positive-definite matrix. The curvature condition $y^\top s>0` failed (noisy gradients); skip the update.
  • PyTorch LBFGS throws "closure called multiple times" or loss does not decrease. Zero gradients inside the closure and avoid torch.no_grad() there.
  • Newton–CG converges slowly. Hessian is ill-conditioned; add a preconditioner or improve damping.
  • Hessian built by finite differences is asymmetric. Symmetrize $H\leftarrow(H+H^\top)/2` before factorization.

34. Advanced exercises

  1. Prove the full Newton–Kantorovich theorem giving existence and quadratic convergence from a single starting-point condition.
  2. Derive the BFGS inverse update via Sherman–Morrison–Woodbury and implement both inverse and direct forms; verify they agree.
  3. Implement cubic regularization: at each step minimize g⊤s+12s⊤Hs+σ3∥s∥3‘byatrust−region−stylesolve;verifytheg^\top s+\tfrac12s^\top Hs+\tfrac\sigma3\lVert s\rVert^3` by a trust-region-style solve; verify the O(1/\varepsilon^{3/2})$ rate on a convex problem.
  4. Prove affine invariance of Newton and demonstrate numerically that gradient descent's trajectory changes under a linear reparameterization while Newton's does not.
  5. Implement a matrix-free Newton–CG using forward-over-reverse automatic differentiation for HVPs; validate against an explicit Hessian on a small problem.
  6. Derive the Gauss–Newton approximation $H\approx\tfrac2nJ^\top J` for least squares and show when it is exact (zero residual or small curvature).

35. Interview questions

  • Derive the Newton step from a second-order Taylor model and prove quadratic convergence.
  • Why should you solve Hs=−g‘ratherthancomputeHs=-g` rather than compute H^{-1}`? Quantify the cost and stability difference.
  • What happens when the Hessian is indefinite? Give a concrete example and two fixes.
  • State the BFGS secant equation and prove that BFGS preserves positive definiteness.
  • Compare Newton, BFGS and L-BFGS in per-iteration cost, memory, and iteration count.
  • Why is Newton affine invariant while gradient descent is not? Give an example.
  • When would you prefer Gauss–Newton over full Newton for a least-squares problem?

36. Research questions

  • Can second-order information be exploited at LLM scale without storing or approximating a full Hessian?
  • How should damping adapt when gradient and curvature estimates come from different minibatches?
  • What is the sharpest global complexity bound for Newton-like methods under inexact Hessian solves?
  • Can Hessian spectra predict generalization as reliably as empirical sharpness measures suggest?
  • How do quasi-Newton methods behave under heavy-tailed stochastic gradient noise, and can they be made robust?

37. Mastery assessment

To pass: (1) derive the Newton step and prove quadratic convergence without notes; (2) implement Newton with curvature repair and Armijo line search, reproducing the one-step quadratic result and the Rosenbrock case; (3) implement BFGS and verify finite termination; (4) explain singular/indefinite Hessians, saddle failure and memory limits with examples; (5) answer the interview questions. Complete the linked assessment; reading alone is not mastery.

38. Implementation submission

Push a repository with newton.py (Newton with damping and BFGS), experiments.ipynb (quadratic, Rosenbrock, logistic regression, saddle and singular cases, Newton–CG scaling), a README.md with derivations and recorded iteration counts, and tests asserting one-step convergence on the quadratic and descent on Rosenbrock with line search. Submit the repository URL and exact reproduction command.

39. Completion criteria

All of: every section read; quadratic-convergence and BFGS-positivity proofs reproduced on paper; scratch implementation passing tests; numerical experiments with recorded counts and plots; at least two failure cases reproduced and explained; a one-page answer to a research question citing at least one paper. Only then mark the concept mastered.

Research papers linked to this concept

newton1687 · citation recorded, library entry pending
raphson1690 · citation recorded, library entry pending
cauchy1847 · citation recorded, library entry pending
davidon1959 · citation recorded, library entry pending
A Class of Methods for Solving Nonlinear Simultaneous Equations 1965
nocedal1980 · citation recorded, library entry pending
nesterov2006 · citation recorded, library entry pending
Deep Learning via Hessian-Free Optimization 2010