Type at least 2 letters. Enter opens the first result, Esc closes.

    Optimization · Lesson 10 · Curvature, landscapes and modern optimizers

    Newton, quasi-Newton and Gauss–Newton methods

    Advanced 95 min 5 interactive figures 4 videos Colab notebook

    Before this lesson: lesson 02 (condition number, strong convexity), lesson 03 (rates of gradient descent, Armijo and Wolfe conditions), linear algebra 07 (positive definite matrices, Cholesky), linear algebra 12 (least squares), calculus 03 (Jacobian, Hessian, Taylor's theorem). Time: about 95 minutes, plus the notebook. This is a difficult lesson; take a break after section 3.


    Why this matters #

    Gradient descent needs about κlog⁡(1/ε)\kappa\log(1/\varepsilon) steps (lesson 03). Second-order methods remove most of this dependence on the condition number κ\kappa. They are the standard tools when the number of parameters is moderate and the gradients are exact (full batch):

    • logistic regression and other generalized linear models (scikit-learn's LogisticRegression uses L-BFGS by default; Newton's method for logistic regression is iteratively reweighted least squares);
    • fitting physical models to data (scipy.optimize.curve_fit uses Levenberg–Marquardt);
    • inverse problems with partial differential equations (PDEs), physics-informed neural networks (PINNs), and weather data assimilation, where the main method (incremental 4D-Var) is a Gauss–Newton method.

    In deep learning they come back as approximations. The Gauss–Newton and Fisher matrices of this lesson are the starting point of K-FAC and Shampoo (lesson 12). "Why don't we train neural networks with Newton's method?" is also a standard interview question.

    1. Predict first #

    2. The picture #

    Notation for this lesson: x⋆x^\star is a minimizer and ek=xk−x⋆e_k = x_k - x^\star is the error. We write the Hessian as ∇2f(x)\nabla^2 f(x). The letters BkB_k and HkH_k are reserved for quasi-Newton methods: BkB_k approximates the Hessian and HkH_k approximates its inverse (as in Nocedal and Wright).

    Newton in one dimension: fit a parabola, jump to its bottom #

    At the current point xkx_k, Taylor's theorem gives a parabola with the same value, slope and curvature as ff:

    mk(x)=f(xk)+f′(xk)(x−xk)+12f′′(xk)(x−xk)2.m_k(x) = f(x_k) + f'(x_k)(x - x_k) + \tfrac12 f''(x_k)(x - x_k)^2 .

    If f′′(xk)>0f''(x_k) > 0, the parabola opens upward. Its minimum is where mk′(x)=f′(xk)+f′′(xk)(x−xk)=0m_k'(x) = f'(x_k) + f''(x_k)(x - x_k) = 0:

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

    This is also Newton's root-finding method applied to the equation f′(x)=0f'(x) = 0: replace f′f' by its tangent line and find where the line crosses zero. If ff is itself a parabola, the model is exact and one step lands on the minimum.

    Interactive figure: loading…

    Press Step several times. The grey curve is ff; the dashed magenta parabola is the local model mkm_k at the current point, and the step goes to its stationary point. On x4/4−xx^4/4 - x from x0=2x_0 = 2, the log chart of ∣xk−1∣|x_k - 1| falls faster and faster: the exponent doubles (quadratic convergence). Then try the presets. From x0=0.1x_0 = 0.1 the curvature is tiny and the jump goes far away. On the double well from x0=0.3x_0 = 0.3 the curvature is negative: the model opens downward and pure Newton moves towards the maximum at 0. Switch to "damped" to see the fixes of section 3.

    Newton on a quadratic: the perfect preconditioner #

    Take f(x)=12x⊤Axf(x) = \tfrac12 x^\top A x with AA symmetric positive definite. Then ∇f(x)=Ax\nabla f(x) = Ax and ∇2f(x)=A\nabla^2 f(x) = A, so the Newton step from any xx is

    x+=x−A−1(Ax)=0=x⋆.x^+ = x - A^{-1}(Ax) = 0 = x^\star .

    One step, for any condition number. To see why, write the error in the eigenvectors qiq_i of AA (eigenvalues λi\lambda_i), as in lesson 03. Gradient descent multiplies the component along qiq_i by 1−ηλi1 - \eta\lambda_i: one step size η\eta must serve all directions. Newton multiplies the gradient component along qiq_i by 1/λi1/\lambda_i: a large step in a flat direction and a small step in a steep one. Every component becomes exactly 0.

    A second way to see it: change variables to z=A1/2xz = A^{1/2}x. Then f=12∥z∥2f = \tfrac12\|z\|^2, whose level sets are circles, and gradient descent with η=1\eta = 1 jumps to the centre. Mapped back to xx, this is exactly the Newton step. Newton's method is gradient descent in the coordinates where the function is round.

    Interactive figure: loading…

    Drag the point xx in the left plot. On the left are the elliptic level sets of f=12x⊤Axf = \tfrac12 x^\top A x. The blue arrow is a gradient step −1L∇f-\tfrac1L\nabla f: it is perpendicular to the level set, so it does not point at the minimum. The magenta arrow is the Newton step: it points straight at the minimum. On the right the same point is drawn in the coordinates z=A1/2xz = A^{1/2}x; the grey grid is the left grid after the change of variables. The level sets are circles, and the gradient step −z-z is the magenta arrow again. Set κ=1\kappa = 1: both arrows on the left point the same way.

    Quick check

    f(x)=12x⊤Ax−b⊤xf(x) = \tfrac12 x^\top A x - b^\top x with AA symmetric positive definite and κ(A)=106\kappa(A) = 10^6. From any start, how many pure Newton steps reach the minimizer (in exact arithmetic)?

    The race on 2D surfaces #

    On a non-quadratic function the model is only correct near xkx_k, so Newton needs several steps. But near a minimizer the model gets better and better, and the error shrinks very fast. The figure compares four methods. Damped Newton shortens the step with a line search when the full step does not decrease ff enough. BFGS (section 3) does not use the Hessian at all; it learns it from gradients.

    Interactive figure: loading…

    Pick a surface, then drag the large start dot. Blue: gradient descent (best fixed step on the quadratic, backtracking elsewhere). Magenta: pure Newton. Violet: damped Newton. Dashed magenta: BFGS. On the rotated quadratic, Newton needs one step for every κ\kappa, while gradient descent needs more steps as κ\kappa grows. On Rosenbrock, pure Newton needs 6 steps and gradient descent about 19,000. On the double well from the default start, pure Newton stops at the saddle point (0,0)(0, 0): the Hessian there is not positive definite. Damped Newton (which also fixes negative curvature) and BFGS reach a minimum.

    Quick check

    Near x⋆x^\star, Newton's errors satisfy ∣ek+1∣≈C∣ek∣2|e_{k+1}| \approx C|e_k|^2 with C≈1C \approx 1. Now ∣ek∣=10−2|e_k| = 10^{-2}. What is ∣ek+1∣|e_{k+1}|, approximately?

    3. Definitions and main results #

    The Newton step #

    The quadratic model of ff at xx is

    m(Δx)=f(x)+∇f(x)⊤Δx+12 Δx⊤∇2f(x) Δx.m(\Delta x) = f(x) + \nabla f(x)^\top \Delta x + \tfrac12\, \Delta x^\top \nabla^2 f(x)\, \Delta x .

    If ∇2f(x)≻0\nabla^2 f(x) \succ 0, the model is strictly convex and its minimizer solves the linear system

    ∇2f(x) Δxnt=−∇f(x).\nabla^2 f(x)\, \Delta x_{\rm nt} = -\nabla f(x) .

    Δxnt\Delta x_{\rm nt} is the Newton step, and pure Newton sets xk+1=xk+Δxntx_{k+1} = x_k + \Delta x_{\rm nt}. Solve the system with a Cholesky factorization ∇2f=LL⊤\nabla^2 f = LL^\top (about d3/3d^3/3 operations; see linear algebra 07). Never form the inverse matrix. If Cholesky fails, the Hessian is not positive definite, and that is useful information.

    The number δ(x)=∇f(x)⊤[∇2f(x)]−1∇f(x)\delta(x) = \sqrt{\nabla f(x)^\top [\nabla^2 f(x)]^{-1} \nabla f(x)} is the Newton decrement (Boyd and Vandenberghe write λ(x)\lambda(x)). The model predicts the decrease f(x)−min⁡m=δ(x)2/2f(x) - \min m = \delta(x)^2/2. Stopping when δ(x)2/2<ε\delta(x)^2/2 < \varepsilon is the standard rule.

    Local quadratic convergence #

    Why this is true (intuition). The Newton step is exact for a quadratic. A smooth function differs from its quadratic model by a term of order ∥e∥3\|e\|^3 (Taylor), so after division by the Hessian the new error is of order ∥e∥2\|e\|^2. Squaring a small number makes it much smaller.

    Theorem 1 (local quadratic convergence). Let ff be twice differentiable with an MM-Lipschitz Hessian, ∥∇2f(x)−∇2f(y)∥≤M∥x−y∥\|\nabla^2 f(x) - \nabla^2 f(y)\| \le M\|x - y\| (spectral norm). Let ∇f(x⋆)=0\nabla f(x^\star) = 0 and ∇2f(x⋆)⪰μI\nabla^2 f(x^\star) \succeq \mu I with μ>0\mu > 0. If ∥e0∥≤μ/(2M)\|e_0\| \le \mu/(2M), then pure Newton satisfies, for every kk,

    ∥ek+1∥≤Mμ ∥ek∥2≤12∥ek∥.\|e_{k+1}\| \le \frac{M}{\mu}\,\|e_k\|^2 \le \tfrac12\|e_k\| .

    So qk=(M/μ)∥ek∥q_k = (M/\mu)\|e_k\| satisfies qk+1≤qk2q_{k+1} \le q_k^2 and q0≤12q_0 \le \tfrac12: qk≤(1/2)2kq_k \le (1/2)^{2^k}.

    Proof of Theorem 1 (6 steps)
    1. Since ∇f(x⋆)=0\nabla f(x^\star) = 0, the Newton step gives ek+1=ek−[∇2f(xk)]−1(∇f(xk)−∇f(x⋆))e_{k+1} = e_k - [\nabla^2 f(x_k)]^{-1}\big(\nabla f(x_k) - \nabla f(x^\star)\big).
    2. Along the segment from x⋆x^\star to xk=x⋆+ekx_k = x^\star + e_k (fundamental theorem of calculus): ∇f(xk)−∇f(x⋆)=∫01∇2f(x⋆+tek) ek dt\nabla f(x_k) - \nabla f(x^\star) = \int_0^1 \nabla^2 f(x^\star + t e_k)\, e_k\, dt.
    3. Put 2 into 1 and write ek=∫01ek dte_k = \int_0^1 e_k\,dt: ek+1=[∇2f(xk)]−1∫01[∇2f(xk)−∇2f(x⋆+tek)] ek dte_{k+1} = [\nabla^2 f(x_k)]^{-1} \int_0^1 \big[\nabla^2 f(x_k) - \nabla^2 f(x^\star + t e_k)\big]\, e_k\, dt.
    4. The two points xkx_k and x⋆+tekx^\star + te_k are (1−t)∥ek∥(1 - t)\|e_k\| apart. By the Lipschitz condition, the bracket has norm at most M(1−t)∥ek∥M(1 - t)\|e_k\|.
    5. So ∥ek+1∥≤∥[∇2f(xk)]−1∥  M∥ek∥2∫01(1−t) dt=M2 λmin⁡(∇2f(xk)) ∥ek∥2\|e_{k+1}\| \le \|[\nabla^2 f(x_k)]^{-1}\|\; M\|e_k\|^2 \int_0^1 (1 - t)\,dt = \dfrac{M}{2\,\lambda_{\min}(\nabla^2 f(x_k))}\,\|e_k\|^2.
    6. If ∥ek∥≤μ/(2M)\|e_k\| \le \mu/(2M), Weyl's inequality (linear algebra 17) gives λmin⁡(∇2f(xk))≥μ−∥∇2f(xk)−∇2f(x⋆)∥≥μ−M∥ek∥≥μ/2\lambda_{\min}(\nabla^2 f(x_k)) \ge \mu - \|\nabla^2 f(x_k) - \nabla^2 f(x^\star)\| \ge \mu - M\|e_k\| \ge \mu/2. Then step 5 gives ∥ek+1∥≤(M/μ)∥ek∥2\|e_{k+1}\| \le (M/\mu)\|e_k\|^2, and (M/μ)∥ek∥≤12(M/\mu)\|e_k\| \le \tfrac12 gives ∥ek+1∥≤12∥ek∥\|e_{k+1}\| \le \tfrac12\|e_k\|. So xk+1x_{k+1} is again in the ball, and induction finishes the proof. ■\blacksquare

    In words: the number of correct digits roughly doubles at every step, once you are close enough. The theorem is local. It says nothing about a start far away (worked example (b) shows a bad one).

    Damped Newton, and what goes wrong without positive curvature #

    Damped Newton sets xk+1=xk+tk Δxntx_{k+1} = x_k + t_k\,\Delta x_{\rm nt}, where tkt_k comes from backtracking from t=1t = 1 with the Armijo condition (lesson 03). For strongly convex ff with a Lipschitz Hessian, Boyd and Vandenberghe (§9.5.3) prove two phases:

    1. Damped phase. Far from x⋆x^\star, each step decreases ff by at least a fixed amount γ>0\gamma > 0.
    2. Quadratic phase. Once ∥∇f∥\|\nabla f\| is small enough, the line search always accepts t=1t = 1, and Theorem 1 applies.

    The total number of steps is at most (f(x0)−f⋆)/γ+log⁡2log⁡2(ε0/ε)(f(x_0) - f^\star)/\gamma + \log_2\log_2(\varepsilon_0/\varepsilon). The second term is about 6 for any accuracy you can reach in double precision.

    If ∇2f(x)\nabla^2 f(x) is not positive definite (a nonconvex ff), the model has no minimum. Its stationary point can be a maximum or a saddle, so Δxnt\Delta x_{\rm nt} can point uphill or towards a saddle point. In the 1D figure, f′′(0.3)<0f''(0.3) < 0 and Newton moves towards the maximum. In 2D, Newton is attracted to saddle points (lesson 11 studies saddles in neural networks). Common fixes:

    • use −∇f-\nabla f when the Newton step is not a descent direction;
    • add a multiple of the identity, ∇2f+τI≻0\nabla^2 f + \tau I \succ 0 (Nocedal and Wright §3.4);
    • replace each eigenvalue λi\lambda_i of the Hessian by ∣λi∣|\lambda_i| (the "saddle-free Newton" idea, used for the damped Newton path in the 2D figure);
    • use a trust region: minimize the model only inside a ball where you trust it (Levenberg–Marquardt below is an example).

    Affine invariance #

    Let x=Tyx = Ty with an invertible matrix TT, and g(y)=f(Ty)g(y) = f(Ty). The chain rule gives ∇g(y)=T⊤∇f(x)\nabla g(y) = T^\top\nabla f(x) and ∇2g(y)=T⊤∇2f(x) T\nabla^2 g(y) = T^\top\nabla^2 f(x)\,T. So the Newton step in yy is

    Δynt=−(T⊤∇2f T)−1 T⊤∇f=−T−1(∇2f)−1∇f=T−1Δxnt.\Delta y_{\rm nt} = -(T^\top \nabla^2 f\, T)^{-1}\, T^\top \nabla f = -T^{-1}(\nabla^2 f)^{-1}\nabla f = T^{-1}\Delta x_{\rm nt} .

    The step in yy is the step in xx, written in the new coordinates. An Armijo line search uses only values of ff and the slope ∇f⊤Δx\nabla f^\top \Delta x, which are also the same. So the iterates satisfy yk=T−1xky_k = T^{-1}x_k: Newton's method is affine invariant. Its speed does not depend on how you scale or rotate the variables, and so not on κ\kappa. Gradient descent is not: its step in yy is −T⊤∇f-T^\top\nabla f, which is −TT⊤∇f-TT^\top\nabla f in xx. This is why feature scaling matters for gradient descent and not for Newton.

    Quasi-Newton methods: the secant condition and BFGS #

    Computing and factorizing ∇2f\nabla^2 f costs O(d3)O(d^3) per step. But every step gives, almost for free, the pair

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

    By Taylor, yk≈∇2f sky_k \approx \nabla^2 f\, s_k: the change of the gradient shows how the Hessian acts on one direction. A quasi-Newton method keeps a matrix Bk≈∇2fB_k \approx \nabla^2 f (or Hk≈[∇2f]−1H_k \approx [\nabla^2 f]^{-1}) and asks the new matrix to reproduce the observed change. This is the secant condition:

    Bk+1 sk=yk,equivalentlyHk+1 yk=sk.B_{k+1}\, s_k = y_k, \qquad\text{equivalently}\qquad H_{k+1}\, y_k = s_k .

    In 1D it fixes Bk+1=(f′(xk+1)−f′(xk))/(xk+1−xk)B_{k+1} = \big(f'(x_{k+1}) - f'(x_k)\big)/(x_{k+1} - x_k): the secant method. In dd dimensions it gives dd equations for d(d+1)/2d(d+1)/2 unknowns, so we choose the smallest change that satisfies it.

    Derivation of BFGS. Change BB by a symmetric rank-2 matrix built from the two vectors we have: B+=B+a yy⊤+b (Bs)(Bs)⊤B^+ = B + a\, yy^\top + b\,(Bs)(Bs)^\top. The secant condition B+s=yB^+s = y reads

    Bs+a (y⊤s) y+b (s⊤Bs) Bs=y.Bs + a\,(y^\top s)\, y + b\,(s^\top B s)\, Bs = y .

    It holds when a (y⊤s)=1a\,(y^\top s) = 1 and b (s⊤Bs)=−1b\,(s^\top Bs) = -1. So

    B+=B+yy⊤y⊤s−Bss⊤Bs⊤Bs.B^+ = B + \frac{yy^\top}{y^\top s} - \frac{Bss^\top B}{s^\top Bs} .

    The Sherman–Morrison–Woodbury formula inverts this rank-2 change. With ρ=1/(y⊤s)\rho = 1/(y^\top s), the BFGS inverse update (Broyden, Fletcher, Goldfarb, Shanno, 1970) is

    H+=(I−ρ sy⊤) H (I−ρ ys⊤)+ρ ss⊤.H^+ = (I - \rho\, s y^\top)\, H\, (I - \rho\, y s^\top) + \rho\, s s^\top .

    Check of the secant condition: (I−ρ ys⊤) y=y−ρ y (s⊤y)=0(I - \rho\, ys^\top)\,y = y - \rho\,y\,(s^\top y) = 0, so the first term vanishes on yy and H+y=ρ s (s⊤y)=sH^+y = \rho\, s\,(s^\top y) = s. The method then steps along −Hk∇f(xk)-H_k\nabla f(x_k) with a line search. Each update costs O(d2)O(d^2) and no linear system is solved.

    Proposition 2 (BFGS keeps positive definiteness). If H≻0H \succ 0 and y⊤s>0y^\top s > 0, then H+≻0H^+ \succ 0.

    Proof.

    1. Take z≠0z \ne 0 and set w=(I−ρ ys⊤) z=z−ρ (s⊤z) yw = (I - \rho\, ys^\top)\,z = z - \rho\,(s^\top z)\, y.
    2. Then z⊤H+z=w⊤Hw+ρ (s⊤z)2z^\top H^+ z = w^\top H w + \rho\,(s^\top z)^2. Both terms are ≥0\ge 0, because H≻0H \succ 0 and ρ>0\rho > 0.
    3. If s⊤z≠0s^\top z \ne 0, the second term is >0> 0. If s⊤z=0s^\top z = 0, then w=z≠0w = z \ne 0 and the first term is >0> 0. In both cases z⊤H+z>0z^\top H^+ z > 0. ■\blacksquare

    Where y⊤s>0y^\top s > 0 comes from. For strictly convex ff it always holds. In general the Wolfe curvature condition gives it (lesson 03): ∇f(xk+1)⊤pk≥c2∇f(xk)⊤pk\nabla f(x_{k+1})^\top p_k \ge c_2 \nabla f(x_k)^\top p_k with c2<1c_2 < 1, so y⊤s=αk(∇f(xk+1)−∇f(xk))⊤pk≥(c2−1) αk∇f(xk)⊤pk>0y^\top s = \alpha_k\big(\nabla f(x_{k+1}) - \nabla f(x_k)\big)^\top p_k \ge (c_2 - 1)\,\alpha_k\nabla f(x_k)^\top p_k > 0, because ∇f(xk)⊤pk<0\nabla f(x_k)^\top p_k < 0. This is why BFGS runs with a Wolfe line search.

    Two facts about BFGS (Nocedal and Wright, ch. 6). Near a minimizer with ∇2f(x⋆)≻0\nabla^2 f(x^\star) \succ 0 it converges superlinearly: ∥ek+1∥≤ck∥ek∥\|e_{k+1}\| \le c_k\|e_k\| with ck→0c_k \to 0. On a strictly convex quadratic with exact line searches it stops after at most dd steps, with Hd=A−1H_d = A^{-1}.

    Interactive figure: loading…

    Press Step twice. Left: BFGS with exact line searches on f=12x⊤Axf = \tfrac12 x^\top A x, κ\kappa from the slider, starting from H0=IH_0 = I. Right: the ellipse {Hku:∥u∥=1}\{H_k u : \|u\| = 1\} of the current estimate (magenta) and of the true inverse Hessian A−1A^{-1} (dashed). After one step the two ellipses pass through the same point H1y^=A−1y^H_1\hat y = A^{-1}\hat y (orange arrow, y^=y/∥y∥\hat y = y/\|y\|): this is the secant condition. After two steps the ellipses coincide and x2=x⋆x_2 = x^\star.

    Quick check

    On a nonconvex function, a BFGS step gives y⊤s=−0.3y^\top s = -0.3. You apply the update anyway. What is wrong with H+H^+?

    L-BFGS: BFGS with a short memory #

    For d=106d = 10^6, the matrix HkH_k has 101210^{12} entries (8 TB). L-BFGS (limited-memory BFGS) stores only the mm newest pairs (si,yi)(s_i, y_i), with ρi=1/(yi⊤si)\rho_i = 1/(y_i^\top s_i). It defines HkH_k as the result of the BFGS updates with these pairs (oldest first), applied to H0=γIH^0 = \gamma I, where γ=s⊤y/y⊤y\gamma = s^\top y/y^\top y for the newest pair (a scalar estimate of the inverse curvature). The two-loop recursion computes p=−Hkgp = -H_k g without forming HkH_k:

    1. q←gq \leftarrow g. For ii from newest to oldest: αi←ρi si⊤q\alpha_i \leftarrow \rho_i\, s_i^\top q, then q←q−αiyiq \leftarrow q - \alpha_i y_i.
    2. r←γ qr \leftarrow \gamma\, q.
    3. For ii from oldest to newest: β←ρi yi⊤r\beta \leftarrow \rho_i\, y_i^\top r, then r←r+si (αi−β)r \leftarrow r + s_i\,(\alpha_i - \beta).
    4. p=−rp = -r.
    Why the two loops compute HkgH_k g

    One BFGS update is H+=V⊤HV+ρ ss⊤H^+ = V^\top H V + \rho\, ss^\top with V=I−ρ ys⊤V = I - \rho\, ys^\top. Unroll mm updates: HkgH_k g is a sum of terms of the form Vnewest⊤⋯Vi+1⊤ ρisisi⊤ Vi+1⋯Vnewest gV_{\text{newest}}^\top \cdots V^\top_{i+1}\,\rho_i s_i s_i^\top\,V_{i+1}\cdots V_{\text{newest}}\, g, plus Vnewest⊤⋯Voldest⊤ H0 Voldest⋯Vnewest gV^\top_{\text{newest}}\cdots V^\top_{\text{oldest}}\,H^0\,V_{\text{oldest}}\cdots V_{\text{newest}}\,g. The first loop applies the ViV_i to gg, newest first, and stores the scalars αi=ρisi⊤(⋅)\alpha_i = \rho_i s_i^\top(\cdot) that the terms need. The second loop applies the Vi⊤V_i^\top in the opposite order and adds the ρisisi⊤\rho_i s_i s_i^\top terms through si αis_i\,\alpha_i. Nocedal and Wright (Algorithm 7.4) give the full proof.

    Each loop costs mm dot products and mm vector updates: O(md)O(md) time per step and 2md2md stored numbers. Typical memories are m=3m = 3 to 2020 (SciPy's L-BFGS-B uses 10, torch.optim.LBFGS keeps 100). L-BFGS is the default method for smooth, full-batch problems of any size.

    Gauss–Newton for nonlinear least squares #

    Many problems have the form F(x)=12∥r(x)∥2=12∑iri(x)2F(x) = \tfrac12\|r(x)\|^2 = \tfrac12\sum_i r_i(x)^2, with residuals r:Rd→Rnr: \R^d \to \R^n (model minus data) and Jacobian J=∂r/∂xJ = \partial r/\partial x of size n×dn \times d. The chain rule (calculus 08) gives

    ∇F=J⊤r,∇2F=J⊤J+S,S=∑i=1nri ∇2ri.\nabla F = J^\top r, \qquad \nabla^2 F = J^\top J + S, \qquad S = \sum_{i=1}^n r_i\,\nabla^2 r_i .

    Linearize the residual, not the gradient: r(x+h)≈r+Jhr(x + h) \approx r + Jh. Then

    F(x+h)≈L(h)=12∥r+Jh∥2=F(x)+h⊤J⊤r+12 h⊤J⊤J h.F(x + h) \approx L(h) = \tfrac12\|r + Jh\|^2 = F(x) + h^\top J^\top r + \tfrac12\, h^\top J^\top J\, h .

    LL is a linear least-squares problem (linear algebra 12). Its minimizer is the Gauss–Newton step

    J⊤J  hgn=−J⊤r.J^\top J\; h_{\rm gn} = -J^\top r .

    This is the Newton equation with the residual-curvature term SS dropped. Three properties:

    • It needs only first derivatives of rr.
    • J⊤J⪰0J^\top J \succeq 0 always. If JJ has full column rank, then hgn⊤∇F=hgn⊤J⊤r=−hgn⊤J⊤Jhgn<0h_{\rm gn}^\top\nabla F = h_{\rm gn}^\top J^\top r = -h_{\rm gn}^\top J^\top J h_{\rm gn} < 0: the step is always a descent direction. A Newton step need not be.
    • Compute it as the least-squares solution of Jh≈−rJh \approx -r (QR or lstsq), not by forming J⊤JJ^\top J, because κ(J⊤J)=κ(J)2\kappa(J^\top J) = \kappa(J)^2.

    When is dropping SS safe? Near x⋆x^\star, ∇F(xk)≈(J⊤J+S) ek\nabla F(x_k) \approx (J^\top J + S)\,e_k, so

    ek+1=ek−(J⊤J)−1∇F(xk)≈−(J⊤J)−1S  ek(all at x⋆).e_{k+1} = e_k - (J^\top J)^{-1}\nabla F(x_k) \approx -(J^\top J)^{-1} S\; e_k \qquad (\text{all at } x^\star).
    • Zero residual, r(x⋆)=0r(x^\star) = 0: then S(x⋆)=0S(x^\star) = 0, and convergence is quadratic, like Newton.
    • Small residuals or nearly linear rr: SS is small and the linear rate is fast.
    • Large residuals and curved rr: the rate is the spectral radius of (J⊤J)−1S(x⋆)(J^\top J)^{-1}S(x^\star). If it is larger than 1, Gauss–Newton fails even close to x⋆x^\star (worked example (d)).

    Levenberg–Marquardt: damping as a trust region #

    The Levenberg–Marquardt (LM) step adds a damping term (here λ>0\lambda > 0 is the damping parameter, not an eigenvalue):

    (J⊤J+λI) hlm=−J⊤r.(J^\top J + \lambda I)\, h_{\rm lm} = -J^\top r .
    • λ→0\lambda \to 0: hlm→hgnh_{\rm lm} \to h_{\rm gn}, fast near a small-residual solution.
    • λ→∞\lambda \to \infty: hlm≈−J⊤r/λ=−∇F/λh_{\rm lm} \approx -J^\top r/\lambda = -\nabla F/\lambda, a short gradient step, safe far from the solution.
    • For every λ>0\lambda > 0 the matrix is positive definite, so hlmh_{\rm lm} is a descent direction.
    • Trust-region view. hlmh_{\rm lm} minimizes the model L(h)L(h) among all hh with ∥h∥≤∥hlm∥\|h\| \le \|h_{\rm lm}\| (Nocedal and Wright, Theorem 4.1). A large λ\lambda means a small trusted ball; λ\lambda is the Lagrange multiplier of the constraint (lesson 08).

    Choosing λ\lambda: the gain ratio. Compare the actual decrease with the decrease the model predicted:

    ϱ=F(x)−F(x+h)L(0)−L(h),L(0)−L(h)=12 h⊤(λh−J⊤r)>0.\varrho = \frac{F(x) - F(x + h)}{L(0) - L(h)}, \qquad L(0) - L(h) = \tfrac12\, h^\top(\lambda h - J^\top r) > 0 .

    If ϱ>0\varrho > 0, accept the step and set λ←λmax⁡{13, 1−(2ϱ−1)3}\lambda \leftarrow \lambda\max\{\tfrac13,\ 1 - (2\varrho - 1)^3\} and ν←2\nu \leftarrow 2. Otherwise reject it and set λ←λν\lambda \leftarrow \lambda\nu, ν←2ν\nu \leftarrow 2\nu. Start with λ0=τmax⁡i(J⊤J)ii\lambda_0 = \tau\max_i (J^\top J)_{ii}; τ=10−3\tau = 10^{-3} is a common choice (Madsen, Nielsen and Tingleff, Algorithm 3.16, Nielsen's rule). A good model (ϱ\varrho near 1) shrinks λ\lambda; a bad model grows it. Marquardt's variant uses diag⁡(J⊤J)\operatorname{diag}(J^\top J) in place of II, which makes the step independent of the scale of each parameter.

    Interactive figure: loading…

    Press Step, then try the presets. We fit y=a e−bty = a\,e^{-bt} to 9 data points. Left: contours of F(a,b)=12∥r∥2F(a, b) = \tfrac12\|r\|^2 with the paths of Gauss–Newton (magenta) and Levenberg–Marquardt (violet, adaptive λ\lambda). Right: the data and the current fits, and F(xk)−F⋆F(x_k) - F^\star on a log scale. With small residuals both methods converge in a few steps. "Start far away" (b0=3b_0 = 3): the first Gauss–Newton step jumps to b≈−16b \approx -16 and the fit explodes, while LM rejects bad steps, increases λ\lambda and converges. "Large residuals" (data that no decaying exponential fits well): the dropped term SS is no longer small, and the log chart shows a slower, linear rate. Choose "fixed λ\lambda" and move the slider: a huge λ\lambda gives tiny gradient steps.

    Quick check

    In Levenberg–Marquardt you set λ=106\lambda = 10^6, much larger than the entries of J⊤JJ^\top J. What is the step, approximately?

    Generalized Gauss–Newton, the Fisher matrix, and Hessian-free methods #

    For a loss ℓ(z)\ell(z) of a model output z=f(θ)z = f(\theta), the chain rule gives

    ∇θ2 ℓ(f(θ))=Jf⊤ ∇2ℓ  Jf+∑k∂ℓ∂zk ∇2fk(θ).\nabla^2_\theta\, \ell(f(\theta)) = J_f^\top\, \nabla^2\ell\; J_f + \sum_k \frac{\partial \ell}{\partial z_k}\,\nabla^2 f_k(\theta) .

    The generalized Gauss–Newton (GGN) matrix G=Jf⊤ ∇2ℓ JfG = J_f^\top\,\nabla^2\ell\,J_f keeps the first term. It is positive semidefinite when ℓ\ell is convex in zz. For the squared error it is J⊤JJ^\top J. When ℓ\ell is the negative log-likelihood of an exponential family with natural parameters zz (softmax cross-entropy is one), it equals the Fisher information matrix (Martens, arXiv 1412.1193). K-FAC and Shampoo approximate this matrix layer by layer (lesson 12).

    You never need the full matrix to use it. The conjugate gradient method (linear algebra 14) solves Gp=−∇ℓGp = -\nabla \ell with products GvGv only, and such products cost about two gradient evaluations (calculus 08). Stopping CG early gives truncated Newton or Newton-CG; with the GGN it is the Hessian-free optimization of Martens (2010). Lesson 11 uses the same Hessian-vector products to measure sharpness.

    Why not Newton for neural networks? #

    • Cost. For d=108d = 10^8 parameters, the Hessian has 101610^{16} entries, and a Cholesky factorization needs about d3/3≈3⋅1023d^3/3 \approx 3 \cdot 10^{23} operations per step.
    • Nonconvexity. The Hessian of a network loss has negative eigenvalues; pure Newton is attracted to saddle points.
    • Noise. Minibatch curvature is noisy; a quasi-Newton pair (s,y)(s, y) from two different minibatches measures noise more than curvature.

    What deep learning uses instead: diagonal scaling (Adam, lesson 06), structured approximations of the GGN or Fisher (K-FAC, Shampoo), and orthogonalized updates (Muon), all in lesson 12.

    Answers to section 1. (1) One step in both cases. The quadratic model is exact, and Newton is affine invariant, so the substitution x2=10z2x_2 = 10z_2 changes nothing. Gradient descent with the best step would need about ln⁡106/ln⁡(1001/999)≈6,908\ln 10^6/\ln(1001/999) \approx 6{,}908 steps at κ=1000\kappa = 1000. (2) Towards the maximum x=0x = 0: f′′(0.3)=3⋅0.09−1=−0.73<0f''(0.3) = 3 \cdot 0.09 - 1 = -0.73 < 0, the model parabola opens downward, and its stationary point is its maximum. The iterates go 0.3→−0.074→0.0008→⋯→00.3 \to -0.074 \to 0.0008 \to \dots \to 0. (3) Problems with zero residual at the solution, r(x⋆)=0r(x^\star) = 0, where S(x⋆)=0S(x^\star) = 0. If rr is linear, S=0S = 0 everywhere and one step solves the problem.

    4. Worked example #

    (a) Newton on a 2D quadratic. f=12(x12+10x22)f = \tfrac12(x_1^2 + 10x_2^2) and x0=(1,1)x_0 = (1, 1). Then ∇f(x0)=(1,10)\nabla f(x_0) = (1, 10) and ∇2f=diag⁡(1,10)\nabla^2 f = \operatorname{diag}(1, 10). The Newton step solves diag⁡(1,10) Δx=−(1,10)\operatorname{diag}(1, 10)\,\Delta x = -(1, 10), so Δx=(−1,−1)\Delta x = (-1, -1) and x1=(0,0)=x⋆x_1 = (0, 0) = x^\star.

    (b) Newton in 1D: the quadratic rate. f(x)=x4/4−xf(x) = x^4/4 - x, so f′(x)=x3−1f'(x) = x^3 - 1, f′′(x)=3x2f''(x) = 3x^2 and x⋆=1x^\star = 1. The Newton map is

    x+=x−x3−13x2=3x3−x3+13x2=2x3+13x2.x^+ = x - \frac{x^3 - 1}{3x^2} = \frac{3x^3 - x^3 + 1}{3x^2} = \frac{2x^3 + 1}{3x^2} .

    From x0=2x_0 = 2:

    kk xkx_k ek=xk−1e_k = x_k - 1 ek/ek−12e_k / e_{k-1}^2
    0 2 1
    1 1.416667 0.417 0.417
    2 1.110534 0.111 0.637
    3 1.010637 1.06⋅10−21.06\cdot10^{-2} 0.871
    4 1.000112 1.12⋅10−41.12\cdot10^{-4} 0.986
    5 1.0000000124 1.24⋅10−81.24\cdot10^{-8} 1.000

    The ratio in the last column tends to f′′′(x⋆)/(2f′′(x⋆))=6/(2⋅3)=1f'''(x^\star)/(2f''(x^\star)) = 6/(2 \cdot 3) = 1, so ek+1≈ek2e_{k+1} \approx e_k^2: the exponent doubles at each step.

    A bad start. From x0=0.1x_0 = 0.1, the curvature f′′(0.1)=0.03f''(0.1) = 0.03 is tiny. The pure step goes to x1=(2⋅0.001+1)/(3⋅0.01)=33.4x_1 = (2 \cdot 0.001 + 1)/(3 \cdot 0.01) = 33.4, where f≈3.1⋅105f \approx 3.1 \cdot 10^5 (it was −0.1-0.1). Far out, x+≈2x/3x^+ \approx 2x/3, so the iterates come back slowly (22.3, 14.8, 9.9, …) and reach 1.00011.0001 only at k=12k = 12. An Armijo line search would reject the first jump: this is the damped phase.

    (c) BFGS learns A−1A^{-1} in two steps. Same quadratic, A=diag⁡(1,10)A = \operatorname{diag}(1, 10), x0=(1,1)x_0 = (1, 1), H0=IH_0 = I, exact line searches α=g⊤g/(g⊤Ag)\alpha = g^\top g/(g^\top A g) for the direction −g-g.

    • k=0k = 0: g0=(1,10)g_0 = (1, 10), p0=−(1,10)p_0 = -(1, 10), α0=101/1001≈0.1009\alpha_0 = 101/1001 \approx 0.1009, so x1≈(0.8991,−0.0090)x_1 \approx (0.8991, -0.0090). Then y0⊤s0≈10.19>0y_0^\top s_0 \approx 10.19 > 0, and the update gives H1≈(1.009−0.00009−0.000090.1000)H_1 \approx \begin{pmatrix} 1.009 & -0.00009 \\ -0.00009 & 0.1000 \end{pmatrix}. It is already correct in the steep direction, which the first step explored.
    • k=1k = 1: the step −H1g1-H_1 g_1 with α1≈0.991\alpha_1 \approx 0.991 gives x2=(0,0)x_2 = (0, 0) up to rounding, and H2=diag⁡(1,0.1)=A−1H_2 = \operatorname{diag}(1, 0.1) = A^{-1}.

    (d) Gauss–Newton, Newton and LM with a nonzero residual (Madsen et al., Example 3.3). r(x)=(x+1, ax2+x−1)r(x) = (x + 1,\ a x^2 + x - 1) with one parameter xx. For a<1a < 1, x⋆=0x^\star = 0 is a local minimizer with r(x⋆)=(1,−1)r(x^\star) = (1, -1) and F(x⋆)=1F(x^\star) = 1: the residual is not zero. At x⋆x^\star:

    • J=(1, 2ax+1)⊤=(1,1)⊤J = (1,\ 2ax + 1)^\top = (1, 1)^\top, so J⊤J=2J^\top J = 2;
    • only r2r_2 is curved, with r2′′=2ar_2'' = 2a, so S=r2 r2′′=−2aS = r_2\, r_2'' = -2a and F′′(0)=2−2aF''(0) = 2 - 2a;
    • the Gauss–Newton error factor is −S/(J⊤J)=a-S/(J^\top J) = a.

    Three cases:

    • a=0a = 0: rr is linear, and one Gauss–Newton step solves the problem.
    • a=0.5a = 0.5, x0=0.1x_0 = 0.1: r=(1.1,−0.895)r = (1.1, -0.895), J=(1,1.1)⊤J = (1, 1.1)^\top, J⊤r=1.1−0.9845=0.1155J^\top r = 1.1 - 0.9845 = 0.1155 and J⊤J=2.21J^\top J = 2.21. Gauss–Newton: x1=0.1−0.1155/2.21=0.0477x_1 = 0.1 - 0.1155/2.21 = 0.0477, then 0.02330.0233, 0.01150.0115 (factor →0.5\to 0.5, linear). Newton uses F′′(0.1)=2.21+(−0.895)(1)=1.315F''(0.1) = 2.21 + (-0.895)(1) = 1.315: x1=0.0122x_1 = 0.0122, then 2.2⋅10−42.2 \cdot 10^{-4}, 7⋅10−87 \cdot 10^{-8} (quadratic).
    • a=−2a = -2: factor −2-2. From 0.10.1, Gauss–Newton jumps around (−0.303-0.303, 0.1370.137, −0.468-0.468, …) and never converges, although it starts close to x⋆x^\star.

    One LM step for a=0.5a = 0.5, x0=0.1x_0 = 0.1, λ=1\lambda = 1: h=−0.1155/(2.21+1)=−0.0360h = -0.1155/(2.21 + 1) = -0.0360, so x1=0.0640x_1 = 0.0640. The predicted decrease is 12h(λh−J⊤r)=12(−0.0360)(−0.0360−0.1155)=0.00273\tfrac12 h(\lambda h - J^\top r) = \tfrac12(-0.0360)(-0.0360 - 0.1155) = 0.00273. The actual decrease is F(0.1)−F(0.0640)=0.00333F(0.1) - F(0.0640) = 0.00333. So ϱ=1.22>0\varrho = 1.22 > 0: accept the step. The new damping is λ←max⁡{13, 1−(2.44−1)3}=max⁡{13,−1.99}=13\lambda \leftarrow \max\{\tfrac13,\ 1 - (2.44 - 1)^3\} = \max\{\tfrac13, -1.99\} = \tfrac13.

    Quick check

    In worked example (d), what is the Gauss–Newton error factor near x⋆=0x^\star = 0 when a=0.8a = 0.8, and does Gauss–Newton converge there?

    5. In code #

    The code checks examples (b), (c) and (d) and shows what SciPy's quasi-Newton methods learn. Fraction gives exact rational arithmetic, so the table of (b) has no rounding.

    from fractions import Fraction
    import numpy as np
    from scipy.optimize import minimize, least_squares, rosen, rosen_der, rosen_hess
    
    # (b) Newton on f(x) = x^4/4 - x: the map x+ = (2x^3 + 1)/(3x^2), in exact arithmetic
    x, errors = Fraction(2), []
    for k in range(6):
        errors.append(abs(x - 1))
        x = (2 * x**3 + 1) / (3 * x**2)
    print([f"{float(e):.2e}" for e in errors])
    # ['1.00e+00', '4.17e-01', '1.11e-01', '1.06e-02', '1.12e-04', '1.24e-08']
    print([round(float(errors[k + 1] / errors[k] ** 2), 3) for k in range(5)])
    # [0.417, 0.637, 0.871, 0.986, 1.0]
    
    # (c) BFGS on f = ½(x1² + 10 x2²) with exact line searches: H2 = A^{-1}
    A = np.diag([1.0, 10.0])
    x, H = np.array([1.0, 1.0]), np.eye(2)
    for k in range(2):
        g = A @ x
        p = -H @ g
        alpha = -(g @ p) / (p @ A @ p)          # exact line search on a quadratic
        s = alpha * p
        y = A @ (x + s) - g
        rho = 1.0 / (y @ s)
        V = np.eye(2) - rho * np.outer(y, s)
        H = V.T @ H @ V + rho * np.outer(s, s)  # BFGS inverse update
        x = x + s
    print(np.allclose(H, np.linalg.inv(A)), np.abs(x).max() < 1e-12)   # True True
    
    # Quasi-Newton on Rosenbrock from (-1.2, 1)
    x0 = np.array([-1.2, 1.0])
    for method in ["BFGS", "L-BFGS-B", "CG"]:
        res = minimize(rosen, x0, jac=rosen_der, method=method)
        print(f"{method:8s} iterations={res.nit:3d} gradient calls={res.njev:3d}")
    # BFGS 32/39, L-BFGS-B 36/44, CG (nonlinear conjugate gradient) 36/77 (SciPy 1.18)
    
    # BFGS learns the curvature: its H at the end vs the true inverse Hessian at (1, 1)
    res = minimize(rosen, x0, jac=rosen_der, method="BFGS")
    print(np.round(res.hess_inv, 3))                           # [[0.502 1.003] [1.003 2.01 ]]
    print(np.round(np.linalg.inv(rosen_hess(np.ones(2))), 3))  # [[0.5   1.   ] [1.    2.005]]
    
    # (d) Gauss-Newton factor and LM, Madsen et al. Example 3.3; local minimizer x* = 0
    def residual(x, a):
        return np.array([x[0] + 1, a * x[0] ** 2 + x[0] - 1])
    
    def jac(x, a):
        return np.array([[1.0], [2 * a * x[0] + 1]])
    
    for a in [0.0, 0.5, -2.0]:
        J, r = jac(np.zeros(1), a), residual(np.zeros(1), a)
        JtJ = (J.T @ J)[0, 0]
        F2 = JtJ + r[1] * 2 * a                 # F'' = JᵀJ + Σ r_i r_i''
        sol = least_squares(residual, [0.1], jac=jac, args=(a,), method="lm")
        print(f"a={a:4.1f}  JᵀJ={JtJ:.0f}  F''={F2:.0f}  GN factor={1 - F2 / JtJ:+.1f}  LM x={sol.x[0]:.0e}")
    # a= 0.0  JᵀJ=2  F''=2  GN factor=+0.0  LM x=-1e-16    r is linear: one step
    # a= 0.5  JᵀJ=2  F''=1  GN factor=+0.5  LM x=4e-05     linear rate; LM stops on its F tolerance
    # a=-2.0  JᵀJ=2  F''=6  GN factor=-2.0  LM x=1e-07     Gauss-Newton diverges, LM converges
    

    The iteration counts on Rosenbrock can change a little between SciPy versions. The final BFGS matrix is close to the true inverse Hessian: BFGS has learned the curvature from gradients alone.

    6. Where it shows up #

    • Logistic regression, generalized linear models, curve fitting. Newton's method for logistic regression is iteratively reweighted least squares (IRLS). scikit-learn's LogisticRegression uses L-BFGS by default. scipy.optimize.minimize uses BFGS by default (L-BFGS-B when there are bounds), and curve_fit uses Levenberg–Marquardt.
    • Physics-informed neural networks and other full-batch problems. PINN losses are badly conditioned because of the differential operators. Rathore et al. (ICML 2024) found that Adam followed by L-BFGS works better than either one alone. In PyTorch: torch.optim.LBFGS(params, line_search_fn="strong_wolfe"), with full batches.
    • Inverse problems with PDEs. Adjoint gradients plus L-BFGS or truncated Gauss–Newton; seismic full-waveform inversion is the classic case (Virieux and Operto, 2009).
    • Weather data assimilation. Strong-constraint 4D-Var finds the initial state x0x_0 that minimizes 12∥x0−xb∥B−12+12∑k∥yk−Hk(Mk(x0))∥Rk−12\tfrac12\|x_0 - x_b\|^2_{B^{-1}} + \tfrac12\sum_k \|y_k - \mathcal{H}_k(\mathcal{M}_k(x_0))\|^2_{R_k^{-1}} (xbx_b a prior "background" state, Mk\mathcal{M}_k the forecast model up to time tkt_k, Hk\mathcal{H}_k the observation operator, yky_k the observations, BB and RkR_k error covariances). This is nonlinear least squares. Incremental 4D-Var linearizes the model in an outer loop and solves the quadratic problem for the increment with conjugate gradients in an inner loop: a truncated Gauss–Newton method (Gratton, Lawless and Nichols, SIAM J. Optim. 2007).
    • Deep learning. Not plain Newton, but its approximations: the GGN and Fisher in Hessian-free optimization and K-FAC, Kronecker factors in Shampoo, diagonal scaling in Adam (lessons 06 and 12). Laplace approximations of the posterior also use the GGN.

    7. Common mistakes #

    • Inverting the Hessian. Solve the linear system with Cholesky. If Cholesky fails, the Hessian is not positive definite, and the Newton step may not be a descent direction.
    • Calling Newton "globally quadratic". The quadratic rate is local. Far away you need damping or a trust region (worked example (b), from x0=0.1x_0 = 0.1).
    • Pure Newton on a nonconvex function. It finds stationary points, including saddles and maxima. Check the curvature or use a modified Hessian.
    • BFGS with a line search that does not enforce the curvature condition. Without y⊤s>0y^\top s > 0, HH loses positive definiteness.
    • L-BFGS on noisy minibatch gradients. Gradient differences then measure noise, not curvature. Use it with full batches (or large, fixed batches).
    • Forming J⊤JJ^\top J in a badly conditioned problem. It squares the condition number of JJ. Use QR or lstsq on Jh≈−rJh \approx -r.

    8. Check yourself #

    1. Gauss–Newton on the Rosenbrock residuals r(x)=(1−x1, 10(x2−x12))r(x) = (1 - x_1,\ 10(x_2 - x_1^2)) from (−1.2,1)(-1.2, 1). Compute the first two steps. What happens to F=12∥r∥2F = \tfrac12\|r\|^2?
      AnswerJ=(−10−20x110)J = \begin{pmatrix} -1 & 0 \\ -20x_1 & 10 \end{pmatrix} is square and invertible, so h=−J−1rh = -J^{-1}r. Step 1: r=(2.2,−4.4)r = (2.2, -4.4) gives x1=(1,−3.84)x_1 = (1, -3.84). Step 2: r=(0,−48.4)r = (0, -48.4) gives x2=(1,1)x_2 = (1, 1), the solution. But FF rose from 12.1 to 1171.3 at step 1: LM or a line search would not take this step.
    2. Why do Newton's method on ff and on g(y)=f(Ty)g(y) = f(Ty) give corresponding iterates, and what does this mean for feature scaling?
      AnswerThe Newton step in yy is −(T⊤∇2f T)−1T⊤∇f=T−1Δxnt-(T^\top\nabla^2 f\,T)^{-1}T^\top\nabla f = T^{-1}\Delta x_{\rm nt}, and the Armijo test uses only values and slopes, which are the same. So yk=T−1xky_k = T^{-1}x_k. Rescaling the features does not change Newton's speed; it does change the speed of gradient descent.
    3. A BFGS step on a nonconvex ff gives y⊤s=−0.3y^\top s = -0.3. What do implementations do, and what prevents the case?
      AnswerThey skip the update (keep HkH_k) or use a damped update. A line search that satisfies the Wolfe curvature condition guarantees y⊤s>0y^\top s > 0, so the case does not happen.
    4. In LM, how does λ\lambda change after a step with ϱ=0.9\varrho = 0.9, and after one with ϱ=−0.2\varrho = -0.2?
      Answerϱ=0.9\varrho = 0.9: accept, and λ←λmax⁡{1/3, 1−0.83}=0.488 λ\lambda \leftarrow \lambda\max\{1/3,\ 1 - 0.8^3\} = 0.488\,\lambda (the model was good). ϱ=−0.2\varrho = -0.2: reject, λ←νλ\lambda \leftarrow \nu\lambda (for example 2λ2\lambda) and ν←2ν\nu \leftarrow 2\nu (the model was bad).
    5. L-BFGS with m=10m = 10 on d=106d = 10^6 parameters: memory and cost per direction, compared with BFGS?
      AnswerL-BFGS stores 2md=2⋅1072md = 2\cdot10^7 numbers (160 MB in float64) and does about 4md=4⋅1074md = 4\cdot10^7 multiplications per direction. BFGS would store d2=1012d^2 = 10^{12} numbers (8 TB).
    6. Write the Hessian of F=12∥r∥2F = \tfrac12\|r\|^2. Which term does Gauss–Newton drop, and when does it vanish?
      Answer∇2F=J⊤J+∑iri∇2ri\nabla^2 F = J^\top J + \sum_i r_i \nabla^2 r_i. Gauss–Newton drops ∑iri∇2ri\sum_i r_i\nabla^2 r_i. It vanishes at the solution when the residuals are zero there, and everywhere when rr is linear.
    Recall cardsAnswer in your head first, then reveal. Add the cards to your review deck to see them again just before you would forget.
    1. What is the Newton step at xx?

    2. What are the assumptions of local quadratic convergence of Newton's method?

    3. Under quadratic convergence with constant about 1, the error is 10−310^{-3}. What is it after the next step?

    4. What does "Newton's method is affine invariant" mean?

    5. State the secant condition.

    6. Why does BFGS need y⊤s>0y^\top s > 0, and what guarantees it?

    7. Memory and time per step of L-BFGS with memory mm in dimension dd?

    8. What matrix does Gauss–Newton use, and what does it drop?

    9. When does Gauss–Newton converge quadratically?

    10. Write the Levenberg–Marquardt step and its two limits.

    Open the review →

    9. Interview angle #

    • "Why not Newton for a large neural network?" — d2d^2 memory and O(d3)O(d^3) solves, an indefinite Hessian (saddles attract Newton), and noisy minibatch curvature. People use Hessian-vector products (Newton-CG), GGN or Fisher approximations (K-FAC, Shampoo) or Adam instead.
    • "Newton vs BFGS vs L-BFGS?" — Exact Hessian, quadratic local rate, O(d3)O(d^3) per step; learned inverse Hessian, superlinear, O(d2)O(d^2); mm pairs, O(md)O(md), the default for smooth full-batch problems.
    • "Why does BFGS need a Wolfe line search?" — The curvature condition gives y⊤s>0y^\top s > 0, which keeps HH positive definite, so every direction is a descent direction.
    • "Gauss–Newton vs Newton for least squares?" — Gauss–Newton drops ∑ri∇2ri\sum r_i\nabla^2 r_i, needs only JJ, always gives a descent direction, and is quadratic for zero residuals; with large residuals it can be slow or fail, and Levenberg–Marquardt makes it safe.
    • "What is 4D-Var, as an optimizer?" — Nonlinear least squares in the initial state, solved by incremental (truncated Gauss–Newton) iterations with adjoint gradients.

    10. Practice #

    The notebook for this lesson runs in Colab. It has four exercises, each with a check cell and a folded solution:

    1. Newton's method with backtracking for ℓ2\ell_2-regularized logistic regression on the breast cancer data set (standardized features); compare the number of iterations with gradient descent.
    2. Implement the BFGS inverse update; check the secant condition and positive definiteness; run BFGS with a Wolfe line search on Rosenbrock and compare with scipy.optimize.minimize(method="BFGS").
    3. Implement the L-BFGS two-loop recursion and check it against the dense BFGS matrix built from the same pairs.
    4. Gauss–Newton and Levenberg–Marquardt for an exponential curve fit; compare with scipy.optimize.least_squares(method="lm").

    11. Watch and read #

    The quadratic model, a numerical example, and "the good, the bad and the ugly" of Newton's method; compare with the 1D figure above.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    Damped Newton with backtracking, affine invariance, and the two-phase convergence analysis of section 3.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    The secant condition and the BFGS update, as in section 3.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    Gauss–Newton and Levenberg–Marquardt for curve fitting, as in the exponential-fit figure.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play