Survey of Mathematics

5.10 Gradient descent, momentum and Newton's method

To minimise a function, repeatedly step against its gradient. On a quadratic the error after each step is multiplied by the matrix I minus eta times the Hessian, so the speed is set by the Hessian's eigenvalues and the condition number of 3.5, and the path zig-zags across narrow valleys. Momentum improves the rate from (k-1)/(k+1) to (sqrt k - 1)/(sqrt k + 1), stochastic gradients trade exactness for cost and leave a noise floor proportional to the step, Newton's method divides by the Hessian and converges quadratically near a minimum, and in high dimensions most critical points are saddles.

Taught in 375/376Apostol, not taughtBeyond the courseMATH 375, the lectures on the gradient and the total derivative, and Lecture 24 (Hessian, eigenvalues, saddle points)MATH 376, Homework 7 #3 and Worksheet 19 #2 (Newton's method as a contraction)Cauchy, Méthode générale pour la résolution des systèmes d'équations simultanées (1847)Robbins and Monro, A stochastic approximation method (1951)Polyak, Some methods of speeding up the convergence of iteration methods (1964)Boyd and Vandenberghe, Convex Optimization, ch. 9Nocedal and Wright, Numerical Optimization, ch. 3 and 6Goodfellow, Bengio and Courville, Deep Learning, ch. 4 and 8

You are standing somewhere on a hillside in thick fog and want to get to the bottom. You cannot see the valley, but you can feel which way is steepest underfoot. So you step downhill, feel again, and step again. That is gradient descent, and by 5.2 the gradient is exactly the instrument that feels the steepest direction. Almost every large model in machine learning is trained this way. Whether the walk reaches the bottom, how fast, and what goes wrong (overshooting, zig-zagging, getting stuck at a saddle) is decided by the second derivative: the Hessian of 5.6, its eigenvalues from 3.1, and the condition number of 3.5. This chapter proves what can be proved and shows the rest by computation.

Before you start

5.2: the gradient is the direction of steepest ascent. 5.6: the Hessian, positive definiteness and eigenvalues. 3.5: the condition number. 4.2: contractions and fixed points. 5.8: convex functions and the gradient inequality.

Quick checkAt a point aa with ∇f(a)≠O\nabla f(a) \ne O, in which direction does ff decrease fastest, per unit of distance?
Quick checkA symmetric matrix AA has eigenvalues 11 and 100100. What are its operator norm and condition number?
Quick checkA map TT of Rn\mathbb R^n satisfies ∥T(x)−T(y)∥≤0.9∥x−y∥\lVert T(x) - T(y)\rVert \le 0.9\lVert x - y\rVert for all x,yx, y. What do you know about the iteration xk+1=T(xk)x_{k+1} = T(x_k)?

The picture: a ball rolling down a valley

The function is 12(x2+25y2)\frac12(x^2 + 25y^2), a long narrow valley (the ellipses). Drag the start, then try these things in order. (1) Move the step-size slider: at t=ηL=1t = \eta L = 1 the steep coordinate is cancelled in a single step and the path runs straight along the valley floor; for tt between 11 and 22 the path zig-zags across the valley, more and more as tt approaches 22; above 22 it diverges. (2) Choose the best step, t≈1.92t \approx 1.92 here, and see that even then the path still zig-zags and crawls along the valley floor: the error in the long direction shrinks only by (κ−1)/(κ+1)=24/26(\kappa-1)/(\kappa+1) = 24/26 per step. (3) Turn up the momentum β\beta: the orange path damps the zig-zag and runs down the valley much faster. (4) Choose κ=100\kappa = 100, then the Rosenbrock banana, where plain descent crawls round a curved valley. (5) Choose the saddle and watch the path approach the saddle point and escape slowly along the downhill direction.

The idea, in words

At a point xx the gradient is the best linear summary of ff (5.3): f(x+s)≈f(x)+∇f(x)⋅sf(x + s) \approx f(x) + \nabla f(x)\cdot s. To lower ff we want ∇f(x)⋅s\nabla f(x)\cdot s as negative as possible for a step of given length, and by Cauchy–Schwarz that is s=−η∇f(x)s = -\eta\nabla f(x). The linear model, however, is only trusted for small steps. How small? The quadratic term of the Taylor formula (5.6) says: as small as the curvature allows. Too long a step along a direction of high curvature overshoots the valley floor and lands higher up the other wall; too short a step along a direction of low curvature barely moves. The Hessian’s largest eigenvalue LL limits the step; its smallest, μ\mu, limits the speed; and the ratio κ=L/μ\kappa = L/\mu is the whole story on a quadratic.

Where this came from· Cauchy's note of 1847

The method of steepest descent is usually traced to a three-page note by Augustin-Louis Cauchy, “Méthode générale pour la résolution des systèmes d’équations simultanées”, read to the Paris Academy of Sciences in October 1847. His motive was astronomical: to find the orbit of a heavenly body one has to solve simultaneous algebraic equations for the orbital elements, and eliminating the unknowns one at a time is hopeless by hand. He proposed to turn the system into the minimisation of a non-negative function of the unknowns (the sum of the squares of the equations is the natural choice) and to change the unknowns step by step in the direction in which that function decreases fastest, then repeat. It is the iteration xk+1=xk−ηk∇f(xk)x_{k+1} = x_k - \eta_k\nabla f(x_k) of this chapter. The same iteration, with the gradient computed by backpropagation (3.8), trains neural networks today.

Definitions

Definition A

Gradient descent

To minimise a differentiable scalar field ff on Rn\mathbb R^n, choose a start x0x_0 and a number η>0\eta \gt 0 and iterate xk+1=xk−η ∇f(xk)x_{k+1} = x_k - \eta\,\nabla f(x_k). This is gradient descent. Its fixed points are exactly the critical points of ff (∇f=O\nabla f = O), and the next sections ask when the iterates converge to one, and how fast.

In one lineThe iteration xk+1=xk−η ∇f(xk)x_{k+1} = x_k - \eta\,\nabla f(x_k), which moves from the current point against the gradient by a step proportional to its length.

Why it existsIt is the simplest rule that uses first-order information only and is guaranteed, for a small enough step, to lower the function at every step.

Definition A

Learning rate

The positive number η\eta multiplying the gradient is the learning rate (also step size). It may be fixed or change with the step number kk.

In one lineThe step-size multiplier η\eta in gradient descent; in machine learning it is the most important hyperparameter.

Why it existsIt decides between crawling and exploding: the theory below says the useful range is below 2/L2/L, where LL is the largest Hessian eigenvalue.

Definition A

Loss function

For a model with parameters w∈Rnw \in \mathbb R^n and data (xi,yi)i=1N(x_i, y_i)_{i = 1}^N, a loss function is a field ℓ(w)=1N∑i=1Nℓi(w)\ell(w) = \frac1N\sum_{i = 1}^N\ell_i(w), the average of the loss ℓi\ell_i on each example. For least squares, ℓi(w)=12(w⋅xi−yi)2\ell_i(w) = \frac12(w\cdot x_i - y_i)^2.

In one lineThe scalar field ℓ(w)\ell(w) of the parameters ww of a model that measures how badly the model fits the data; training means minimising it.

Why it existsIt turns 'fit the data' into the optimisation problem this chapter solves; for least squares it is 2.10's sum of squared errors.

One step lowers the function: the descent lemma

Lemma B standard (Nesterov, Introductory Lectures on Convex Optimization, 1.2.3)

Descent lemma

Let ff be continuously differentiable on Rn\mathbb R^n with ∥∇f(x)−∇f(y)∥≤L∥x−y∥\lVert\nabla f(x) - \nabla f(y)\rVert \le L\lVert x - y\rVert for all x,yx, y (we say ff is LL-smooth; for a C2C^2 field this holds when all Hessian eigenvalues lie in [−L,L][-L, L], by the mean value inequality of 5.7 applied to ∇f\nabla f). Then f(y)≤f(x)+∇f(x)⋅(y−x)+L2∥y−x∥2f(y) \le f(x) + \nabla f(x)\cdot(y - x) + \dfrac L2\lVert y - x\rVert^2. If y=x−η∇f(x)y = x - \eta\nabla f(x) with 0<η≤1L0 \lt \eta \le \frac1L then f(y)≤f(x)−η2∥∇f(x)∥2f(y) \le f(x) - \dfrac\eta2\lVert\nabla f(x)\rVert^2.

In one lineIf ∇f\nabla f is LL-Lipschitz, then f(y)≤f(x)+∇f(x)⋅(y−x)+L2∥y−x∥2f(y) \le f(x) + \nabla f(x)\cdot(y - x) + \frac L2\lVert y - x\rVert^2; consequently the step y=x−η∇f(x)y = x - \eta\nabla f(x) with η≤1L\eta \le \frac1L gives f(y)≤f(x)−η2∥∇f(x)∥2f(y) \le f(x) - \frac\eta2\lVert\nabla f(x)\rVert^2.

Why it is trueIt is the guarantee that gradient descent makes progress, and it says how much: the decrease is at least half the step times the squared gradient.

ProofNesterov 1.2.3
The idea: Write the change in f along the segment as an integral of the directional derivative, subtract the linear part, and bound the difference of gradients by the Lipschitz constant times the distance.
f(y)−f(x)=∫01∇f(x+t(y−x))⋅(y−x) dtf(y) - f(x) = \displaystyle\int_0^1\nabla f\big(x + t(y - x)\big)\cdot(y - x)\,dt.
Put g(t)=f(x+t(y−x))g(t) = f(x + t(y - x)). By the path theorem of 5.3, g′(t)=∇f(x+t(y−x))⋅(y−x)g'(t) = \nabla f(x + t(y - x))\cdot(y - x), continuous; fundamental theorem of calculus (1.5).
f(y)−f(x)−∇f(x)⋅(y−x)=∫01[∇f(x+t(y−x))−∇f(x)]⋅(y−x) dtf(y) - f(x) - \nabla f(x)\cdot(y - x) = \displaystyle\int_0^1\big[\nabla f(x + t(y - x)) - \nabla f(x)\big]\cdot(y - x)\,dt.
Subtract ∇f(x)⋅(y−x)=∫01∇f(x)⋅(y−x) dt\nabla f(x)\cdot(y - x) = \int_0^1\nabla f(x)\cdot(y - x)\,dt.
The integrand is at most Lt∥y−x∥2Lt\lVert y - x\rVert^2, and ∫01Lt dt=L2\int_0^1Lt\,dt = \frac L2. This is the first inequality.
Cauchy–Schwarz on each integrand and the Lipschitz bound: ∥∇f(x+t(y−x))−∇f(x)∥≤Lt∥y−x∥\lVert\nabla f(x + t(y - x)) - \nabla f(x)\rVert \le Lt\lVert y - x\rVert.
f(y)≤f(x)−η2∥∇f(x)∥2f(y) \le f(x) - \dfrac\eta2\lVert\nabla f(x)\rVert^2.
Put y−x=−η∇f(x)y - x = -\eta\nabla f(x): the linear term is −η∥∇f∥2-\eta\lVert\nabla f\rVert^2 and the quadratic term is L2η2∥∇f∥2\frac L2\eta^2\lVert\nabla f\rVert^2. So f(y)≤f(x)−η(1−Lη2)∥∇f(x)∥2f(y) \le f(x) - \eta\big(1 - \frac{L\eta}2\big)\lVert\nabla f(x)\rVert^2, and 1−Lη2≥121 - \frac{L\eta}2 \ge \frac12 when η≤1L\eta \le \frac1L. ■\blacksquare

Gradient descent on a quadratic: the eigenvalues decide

A quadratic is the model of every smooth function near a minimum (the second-order Taylor formula of 5.6), so this case matters.

Theorem B standard (Boyd and Vandenberghe 9.3; Nocedal and Wright 3.3)

Gradient descent on a quadratic

Let AA be symmetric positive definite with eigenvalues 0<μ=λ1≤⋯≤λn=L0 \lt \mu = \lambda_1 \le \dots \le \lambda_n = L and f(x)=12xTAx−bTxf(x) = \frac12x^{\mathsf T}Ax - b^{\mathsf T}x, with unique minimiser x∗=A−1bx^* = A^{-1}b (∇f(x)=Ax−b\nabla f(x) = Ax - b). For gradient descent with step η\eta, xk−x∗=(I−ηA)k(x0−x∗)x_k - x^* = (I - \eta A)^k(x_0 - x^*). (a) The iteration converges to x∗x^* for every x0x_0 if and only if 0<η<2/L0 \lt \eta \lt 2/L. (b) Then ∥xk−x∗∥≤ρk∥x0−x∗∥\lVert x_{k} - x^*\rVert \le \rho^k\lVert x_0 - x^*\rVert with ρ(η)=max⁡(∣1−ημ∣,∣1−ηL∣)\rho(\eta) = \max\big(|1 - \eta\mu|, |1 - \eta L|\big), and this rate is attained. (c) ρ\rho is smallest at η∗=2L+μ\eta^* = \dfrac2{L + \mu}, where ρ∗=L−μL+μ=κ−1κ+1\rho^* = \dfrac{L - \mu}{L + \mu} = \dfrac{\kappa - 1}{\kappa + 1}.

In one lineFor f(x)=12xTAx−bTxf(x) = \frac12x^{\mathsf T}Ax - b^{\mathsf T}x with AA symmetric positive definite with eigenvalues in [μ,L][\mu, L], gradient descent converges to x∗=A−1bx^* = A^{-1}b for every start if and only if 0<η<2/L0 \lt \eta \lt 2/L; the error is multiplied by max⁡(∣1−ημ∣,∣1−ηL∣)\max(|1 - \eta\mu|, |1 - \eta L|) per step, which is smallest, equal to κ−1κ+1\frac{\kappa - 1}{\kappa + 1} with κ=L/μ\kappa = L/\mu, at η=2L+μ\eta = \frac2{L + \mu}.

Why it is trueIt turns the speed of the algorithm into a number computed from the Hessian's extreme eigenvalues, and shows that it is the condition number of 3.5, not the size of the problem, that decides.

ProofBoyd and Vandenberghe 9.3
The idea: Subtract the fixed point from the update to get a linear recursion for the error. Diagonalise A with the spectral theorem: each coordinate of the error in the eigenbasis is multiplied by 1 minus eta times its eigenvalue at every step, so the slowest coordinate sets the rate. Choose eta to balance the two extreme coordinates.
ek+1=(I−ηA)eke_{k+1} = (I - \eta A)e_k for ek=xk−x∗e_k = x_k - x^*, hence ek=(I−ηA)ke0e_k = (I - \eta A)^ke_0.
∇f(x∗)=Ax∗−b=O\nabla f(x^*) = Ax^* - b = O, so xk+1−x∗=xk−x∗−η(Axk−b)=xk−x∗−ηA(xk−x∗)x_{k+1} - x^* = x_k - x^* - \eta(Ax_k - b) = x_k - x^* - \eta A(x_k - x^*).
In the eigenbasis, coordinate ii of the error is multiplied by (1−ηλi)(1 - \eta\lambda_i) at each step: ci(k)=(1−ηλi)kci(0)c_i^{(k)} = (1 - \eta\lambda_i)^kc_i^{(0)}.
Spectral theorem (3.1): A=QΛQTA = Q\Lambda Q^{\mathsf T} with QQ orthogonal. Then I−ηA=Q(I−ηΛ)QTI - \eta A = Q(I - \eta\Lambda)Q^{\mathsf T}, and QQ does not change lengths.
Every coordinate tends to 00 for every start if and only if ∣1−ηλi∣<1|1 - \eta\lambda_i| \lt 1 for all ii, that is 0<η<2/L0 \lt \eta \lt 2/L. This is (a).
A geometric sequence rkr^k tends to 00 if and only if ∣r∣<1|r| \lt 1. The condition ∣1−ηλi∣<1|1 - \eta\lambda_i| \lt 1 is 0<ηλi<20 \lt \eta\lambda_i \lt 2. It must hold for the largest eigenvalue LL; then it holds for all smaller ones.
So ∥ek∥≤ρk∥e0∥\lVert e_k\rVert \le \rho^k\lVert e_0\rVert with ρ=max⁡(∣1−ημ∣,∣1−ηL∣)\rho = \max(|1 - \eta\mu|, |1 - \eta L|), attained for a suitable start. This is (b).
∥ek∥2=∑i(1−ηλi)2k(ci(0))2≤max⁡i∣1−ηλi∣2k∥e0∥2\lVert e_k\rVert^2 = \sum_i(1 - \eta\lambda_i)^{2k}\big(c_i^{(0)}\big)^2 \le \max_i|1 - \eta\lambda_i|^{2k}\lVert e_0\rVert^2, with equality when e0e_0 is an eigenvector for the worst eigenvalue. The function λ↦∣1−ηλ∣\lambda \mapsto |1 - \eta\lambda| is convex on [μ,L][\mu, L], so its maximum is at an end.
η∗=2L+μ\eta^* = \dfrac2{L + \mu} and then ρ∗=1−2μL+μ=L−μL+μ\rho^* = 1 - \dfrac{2\mu}{L + \mu} = \dfrac{L - \mu}{L + \mu}. ■\blacksquare
As η\eta grows from 00, ∣1−ημ∣=1−ημ|1 - \eta\mu| = 1 - \eta\mu decreases and ∣1−ηL∣=ηL−1|1 - \eta L| = \eta L - 1 (once η>1/L\eta \gt 1/L) increases; the maximum of the two is smallest where they are equal: 1−ημ=ηL−11 - \eta\mu = \eta L - 1.
Why· Why the path zig-zags (the picture behind the proof)

At the best step η∗\eta^* the error coordinate along the eigenvector for μ\mu is multiplied by 1−η∗μ=+κ−1κ+11 - \eta^*\mu = +\frac{\kappa - 1}{\kappa + 1}: it shrinks slowly and keeps its sign. The coordinate along the eigenvector for LL is multiplied by 1−η∗L=−κ−1κ+11 - \eta^*L = -\frac{\kappa - 1}{\kappa + 1}: it shrinks equally slowly but flips sign at every step. So the path moves steadily along the valley while bouncing from one wall to the other, and the same number κ−1κ+1\frac{\kappa - 1}{\kappa + 1}, close to 11 when κ\kappa is large, limits both. Any larger step would make the bouncing grow; any smaller step would slow the long direction. This is the blue path in the picture above.

Proof workshopGive the reason for each line: gradient descent on a quadraticBoyd and Vandenberghe 9.3

Each line of the proof is shown in order. Choose the reason that justifies it, then press Check.

  1. ek+1=(I−ηA)eke_{k+1} = (I - \eta A)e_k where ek=xk−x∗e_k = x_k - x^*.
  2. In an orthonormal eigenbasis, coordinate ii is multiplied by 1−ηλi1 - \eta\lambda_i at each step.
  3. Convergence for all starts if and only if ∣1−ηλi∣<1|1 - \eta\lambda_i| \lt 1 for every ii, that is 0<η<2/L0 \lt \eta \lt 2/L.
  4. The error shrinks like ρk\rho^k with ρ=max⁡(∣1−ημ∣,∣1−ηL∣)\rho = \max(|1 - \eta\mu|, |1 - \eta L|).
  5. The best step solves 1−ημ=ηL−11 - \eta\mu = \eta L - 1, giving η∗=2L+μ\eta^* = \frac{2}{L + \mu} and ρ∗=κ−1κ+1\rho^* = \frac{\kappa - 1}{\kappa + 1}.
Worked example new (hand computation of the picture above)
Run gradient descent on f(x,y)=12(x2+10y2)f(x, y) = \frac12(x^2 + 10y^2) from (4,1)(4, 1) with η=0.15\eta = 0.15, and find the stable range of η\eta and the best step.

Solution.

  1. Gradient and eigenvalues. ∇f=(x,10y)\nabla f = (x, 10y) and the Hessian is diag(1,10)\mathrm{diag}(1, 10), so μ=1\mu = 1, L=10L = 10, κ=10\kappa = 10. The matrix is diagonal, so its eigenvalues are the diagonal entries.
  2. One step. xk+1=(1−η)xk=0.85xkx_{k+1} = (1 - \eta)x_k = 0.85x_k and yk+1=(1−10η)yk=−0.5yky_{k+1} = (1 - 10\eta)y_k = -0.5y_k. From (4,1)(4, 1): (3.4,−0.5)(3.4, -0.5), then (2.89,0.25)(2.89, 0.25), then (2.4565,−0.125)(2.4565, -0.125). Each coordinate has its own multiplier; the yy-multiplier is negative, so yy flips sign every step: the zig-zag.
  3. Stable range. Both multipliers must have absolute value below 11: ∣1−η∣<1|1 - \eta| \lt 1 and ∣1−10η∣<1|1 - 10\eta| \lt 1, so 0<η<0.2=2/L0 \lt \eta \lt 0.2 = 2/L. Theorem (a).
  4. Best step. η∗=210+1=211≈0.1818\eta^* = \dfrac2{10 + 1} = \dfrac2{11} \approx 0.1818, with rate ρ∗=10−110+1=911≈0.818\rho^* = \dfrac{10 - 1}{10 + 1} = \dfrac9{11} \approx 0.818. Both coordinates then shrink by 0.8180.818 per step in absolute value: xx by +911+\frac9{11} and yy by −911-\frac9{11}.
  5. Compare with η=0.15\eta = 0.15. The multipliers are 0.850.85 and −0.5-0.5, so ρ=0.85\rho = 0.85, slower than 0.8180.818 because the xx direction now limits. For η<η∗\eta \lt \eta^* the long direction (small eigenvalue) is the slow one.

Answer. Stable for 0<η<0.20 \lt \eta \lt 0.2; the best step is 211\frac2{11} with rate 911\frac9{11}. After kk steps at η=0.15\eta = 0.15 the error is about 0.85k0.85^k of the start.

Your answerFor gradient descent on f=12(x2+10y2)f = \frac12(x^2 + 10y^2), what is the largest learning rate η\eta for which the iteration converges from every start?
Your answerA quadratic has Hessian eigenvalues 11 and 100100. What is the best convergence factor per step (κ−1)/(κ+1)(\kappa - 1)/(\kappa + 1) of gradient descent with a fixed step? (Give a decimal.)
Your answerWith the factor ρ=99/101\rho = 99/101 per step, about how many steps shrink the error by a factor of 10610^6? (Give a decimal.)
Worked example new (links the normal equations of 2.10 to this chapter)
Least squares by gradient descent. Fit ww to minimise 12∥Xw−y∥2\frac12\lVert Xw - y\rVert^2 for X=[100111]X = \begin{bmatrix}1 & 0\\ 0 & 1\\ 1 & 1\end{bmatrix} and y=(1,2,2)y = (1, 2, 2). Find the best step and the first iterate from w0=Ow_0 = O.

Solution.

  1. The Hessian is XTXX^{\mathsf T}X. ∇12∥Xw−y∥2=XT(Xw−y)\nabla\frac12\lVert Xw - y\rVert^2 = X^{\mathsf T}(Xw - y) (3.8), so the Hessian is A=XTX=[2112]A = X^{\mathsf T}X = \begin{bmatrix}2 & 1\\ 1 & 2\end{bmatrix}. The loss is a quadratic with this matrix.
  2. Eigenvalues. μ=1\mu = 1 (eigenvector (1,−1)(1, -1)) and L=3L = 3 (eigenvector (1,1)(1, 1)), so κ=3\kappa = 3. Trace 44, determinant 33.
  3. The minimiser. The normal equations Aw=XTy=(3,4)Aw = X^{\mathsf T}y = (3, 4) give w∗=(23,53)w^* = \big(\frac23, \frac53\big). 2.10; solve the 2×22 \times 2 system.
  4. Best step and rate. η∗=23+1=12\eta^* = \dfrac2{3 + 1} = \dfrac12, ρ∗=3−13+1=12\rho^* = \dfrac{3 - 1}{3 + 1} = \dfrac12. The theorem.
  5. First iterate. w1=w0−η∗XT(Xw0−y)=O+12(3,4)=(1.5,2)w_1 = w_0 - \eta^*X^{\mathsf T}(Xw_0 - y) = O + \frac12(3, 4) = (1.5, 2). The error is w1−w∗=(56,13)w_1 - w^* = \big(\frac56, \frac13\big), which is (I−12A)(−23,−53)=(56,13)\big(I - \frac12A\big)\big(-\frac23, -\frac53\big) = \big(\frac56, \frac13\big). ✓ Check with the error recursion.

Answer. η∗=12\eta^* = \frac12, rate 12\frac12 per step (the error halves each time), w1=(1.5,2)w_1 = (1.5, 2), heading for (23,53)\big(\frac23, \frac53\big). In a realistic problem with a million columns XTXX^{\mathsf T}X is never formed or inverted; the product XT(Xw−y)X^{\mathsf T}(Xw - y) costs two matrix–vector products.

Same idea elsewhere· The conditioning of 3.5, squared

The Hessian of least squares is XTXX^{\mathsf T}X, whose condition number is κ(X)2\kappa(X)^2 (its eigenvalues are the squares of the singular values of XX, 3.4). A data matrix with κ(X)=10\kappa(X) = 10 gives κ=100\kappa = 100 and a rate 99101\frac{99}{101}; with κ(X)=1000\kappa(X) = 1000 the rate is 1−2×10−61 - 2\times10^{-6}, hopeless. This is why features are standardised (columns scaled to the same size) before training: it reduces κ(X)\kappa(X) and so speeds up gradient descent by orders of magnitude, and it is also why the normal equations lose precision (3.5, 2.10).

Corollary B standard; ties 4.2 and 5.7 to this chapter

Gradient descent is a contraction

Suppose f∈C2(Rn)f \in C^2(\mathbb R^n) and every eigenvalue of the Hessian lies in [μ,L][\mu, L] at every point, μ>0\mu \gt 0. Then for 0<η<2/L0 \lt \eta \lt 2/L the map T(x)=x−η∇f(x)T(x) = x - \eta\nabla f(x) satisfies ∥T(x)−T(y)∥≤ρ∥x−y∥\lVert T(x) - T(y)\rVert \le \rho\lVert x - y\rVert, ρ=max⁡(∣1−ημ∣,∣1−ηL∣)<1\rho = \max(|1 - \eta\mu|, |1 - \eta L|) \lt 1. Hence TT has exactly one fixed point x∗x^* (the point with ∇f(x∗)=O\nabla f(x^*) = O, the minimiser) and the iterates satisfy ∥xk−x∗∥≤ρk1−ρ∥x1−x0∥\lVert x_k - x^*\rVert \le \dfrac{\rho^k}{1 - \rho}\lVert x_1 - x_0\rVert.

In one lineIf ff is C2C^2 with μI⪯Hf(x)⪯LI\mu I \preceq H_f(x) \preceq LI everywhere on Rn\mathbb R^n and 0<η<2/L0 \lt \eta \lt 2/L, then T(x)=x−η∇f(x)T(x) = x - \eta\nabla f(x) is a contraction with constant ρ=max⁡(∣1−ημ∣,∣1−ηL∣)<1\rho = \max(|1 - \eta\mu|, |1 - \eta L|) \lt 1, so gradient descent converges to the unique minimiser x∗x^* and ∥xk−x∗∥≤ρk1−ρ∥x1−x0∥\lVert x_k - x^*\rVert \le \dfrac{\rho^k}{1 - \rho}\lVert x_1 - x_0\rVert.

Why it is trueIt proves convergence for every smooth strongly convex function, and not only quadratics, by the fixed-point theorem of 4.2, and gives a computable error bound.

Proof4.2 and 5.7
The idea: The Jacobian of T is I minus eta times the Hessian, a symmetric matrix with eigenvalues between 1 minus eta L and 1 minus eta mu; its operator norm is at most rho. The mean value inequality for fields turns that into the Lipschitz bound, and the Banach fixed point theorem finishes.
DT(x)=I−ηHf(x)DT(x) = I - \eta H_f(x).
D(∇f)=HfD(\nabla f) = H_f, the Hessian (5.6).
∥DT(x)∥≤ρ\lVert DT(x)\rVert \le \rho for every xx.
For a symmetric matrix the operator norm is the largest absolute eigenvalue (3.5). The eigenvalues of I−ηHI - \eta H are 1−ηλ1 - \eta\lambda with λ∈[μ,L]\lambda \in [\mu, L], and ∣1−ηλ∣≤ρ|1 - \eta\lambda| \le \rho for all such λ\lambda.
∥T(x)−T(y)∥≤ρ∥x−y∥\lVert T(x) - T(y)\rVert \le \rho\lVert x - y\rVert, and ρ<1\rho \lt 1 because 0<η<2/L0 \lt \eta \lt 2/L.
Mean value inequality for fields (5.7) on the convex set Rn\mathbb R^n.
TT has a unique fixed point x∗x^*, the iterates converge to it, and the bound holds.
Banach fixed point theorem (4.2) in the complete space Rn\mathbb R^n, with its a priori error bound d(xk,x∗)≤ρk1−ρd(x1,x0)d(x_k, x^*) \le \frac{\rho^k}{1 - \rho}d(x_1, x_0). A fixed point of TT satisfies η∇f(x∗)=O\eta\nabla f(x^*) = O. ■\blacksquare

Exact line search, and why the zig-zag is built in

If at each step we choose ηk\eta_k to minimise ff along the line xk−ηgkx_k - \eta g_k (an exact line search, where gk=∇f(xk)g_k = \nabla f(x_k)), then ddηf(xk−ηgk)=−∇f(xk+1)⋅gk=0\frac{d}{d\eta}f(x_k - \eta g_k) = -\nabla f(x_{k+1})\cdot g_k = 0: each new gradient is perpendicular to the previous one, gk+1⊥gkg_{k+1}\perp g_k. In two variables the path must turn through a right angle at every step. On a long narrow valley, this forces the zig-zag, however clever the step. For a quadratic with the worst start the error in the norm eTAe\sqrt{e^{\mathsf T}Ae} is multiplied by at most κ−1κ+1\frac{\kappa - 1}{\kappa + 1} per step, and by exactly that for the worst start (the Kantorovich inequality). It is the same number as the rate of the best fixed step, which the lab below measures.

Quick checkGradient descent on f=12(x2+100y2)f = \frac12(x^2 + 100y^2) uses η=0.025\eta = 0.025. What happens?
Quick checkWhich describes the zig-zag of gradient descent in a narrow valley?

Convex functions: progress without a second derivative

Theorem B standard (Nesterov, Introductory Lectures 2.1.5; Boyd and Vandenberghe 9.3)

Gradient descent on a convex smooth function

Let ff be convex and differentiable on Rn\mathbb R^n with LL-Lipschitz gradient and a minimiser x∗x^*. Gradient descent xi+1=xi−1L∇f(xi)x_{i+1} = x_i - \frac1L\nabla f(x_i) satisfies f(xk)−f(x∗)≤L∥x0−x∗∥22kf(x_k) - f(x^*) \le \dfrac{L\lVert x_0 - x^*\rVert^2}{2k} for k≥1k \ge 1.

In one lineIf ff is convex and LL-smooth with a minimiser x∗x^*, then gradient descent with η=1/L\eta = 1/L satisfies f(xk)−f(x∗)≤L∥x0−x∗∥22kf(x_k) - f(x^*) \le \dfrac{L\lVert x_0 - x^*\rVert^2}{2k}.

Why it is trueIt guarantees convergence for any convex smooth problem with no assumption on the smallest eigenvalue: the price is a slower rate (inversely proportional to the number of steps) than the geometric rate on a strongly convex problem.

ProofNesterov 2.1.5
The idea: Track the squared distance to the minimiser. The gradient inequality (convexity) says the gradient points away from the minimiser by at least the function gap; the descent lemma says the function gap controls the squared gradient. Together they make the distance decrease and sum up to a telescoping bound.
∥xi+1−x∗∥2=∥xi−x∗∥2−2η gi⋅(xi−x∗)+η2∥gi∥2\lVert x_{i+1} - x^*\rVert^2 = \lVert x_i - x^*\rVert^2 - 2\eta\,g_i\cdot(x_i - x^*) + \eta^2\lVert g_i\rVert^2.
Expand ∥xi−ηgi−x∗∥2\lVert x_i - \eta g_i - x^*\rVert^2 with gi=∇f(xi)g_i = \nabla f(x_i) and η=1/L\eta = 1/L.
∥xi+1−x∗∥2≤∥xi−x∗∥2−2η(f(xi)−f(x∗))+η2∥gi∥2\lVert x_{i+1} - x^*\rVert^2 \le \lVert x_i - x^*\rVert^2 - 2\eta\big(f(x_i) - f(x^*)\big) + \eta^2\lVert g_i\rVert^2.
Gradient inequality for convex ff (5.8) with y=x∗y = x^*: f(x∗)≥f(xi)+gi⋅(x∗−xi)f(x^*) \ge f(x_i) + g_i\cdot(x^* - x_i), that is gi⋅(xi−x∗)≥f(xi)−f(x∗)g_i\cdot(x_i - x^*) \ge f(x_i) - f(x^*).
∥xi+1−x∗∥2≤∥xi−x∗∥2−2η(f(xi+1)−f(x∗))\lVert x_{i+1} - x^*\rVert^2 \le \lVert x_i - x^*\rVert^2 - 2\eta\big(f(x_{i+1}) - f(x^*)\big).
Descent lemma with η=1/L\eta = 1/L: f(xi+1)≤f(xi)−η2∥gi∥2f(x_{i+1}) \le f(x_i) - \frac\eta2\lVert g_i\rVert^2, so η2∥gi∥2≤2η(f(xi)−f(xi+1))\eta^2\lVert g_i\rVert^2 \le 2\eta\big(f(x_i) - f(x_{i+1})\big).
2η∑i=1k(f(xi)−f(x∗))≤∥x0−x∗∥22\eta\displaystyle\sum_{i = 1}^k\big(f(x_i) - f(x^*)\big) \le \lVert x_0 - x^*\rVert^2.
Add the inequalities for i=0,…,k−1i = 0, \dots, k - 1: the squared distances telescope, and ∥xk−x∗∥2≥0\lVert x_k - x^*\rVert^2 \ge 0.
k(f(xk)−f(x∗))≤∥x0−x∗∥22ηk\big(f(x_k) - f(x^*)\big) \le \dfrac{\lVert x_0 - x^*\rVert^2}{2\eta}.
By the descent lemma f(xi)f(x_i) is non-increasing, so every term is at least f(xk)−f(x∗)f(x_k) - f(x^*). Divide by 2ηk=2k/L2\eta k = 2k/L. ■\blacksquare
Proof workshopRebuild the proof that gradient descent on a convex smooth function has error at most L times the squared distance over 2kNesterov 2.1.5

Tap the lines in the order a proof would write them. Each line can only use what is already above it.

    Python labGradient descent on an ill-conditioned quadratic: the zig-zag, the rate, and momentum
    import numpy as np
    import matplotlib
    matplotlib.use("Agg")
    import matplotlib.pyplot as plt
    
    kappa = 100.0
    A = np.diag([1.0, kappa]); x0 = np.array([100.0, 1.0])          # f(x) = x^T A x / 2, minimum at the origin
    
    def run(step, beta=0.0, n=800):
        x, xp, err = x0.copy(), x0.copy(), []
        for _ in range(n):
            err.append(np.linalg.norm(x))
            x, xp = x - step * (A @ x) + beta * (x - xp), x          # heavy-ball step (beta = 0 is plain descent)
        return np.array(err)
    
    L, mu = kappa, 1.0
    plain = run(2 / (L + mu))                                           # best fixed step
    mom = run(4 / (np.sqrt(L) + np.sqrt(mu)) ** 2, beta=((np.sqrt(kappa) - 1) / (np.sqrt(kappa) + 1)) ** 2)
    rate = lambda e, a, b: (e[b] / e[a]) ** (1 / (b - a))
    print("plain: measured rate", round(rate(plain, 300, 400), 4), "  theory (k-1)/(k+1) =", round(99 / 101, 4))
    print("momentum: measured rate", round(rate(mom, 100, 150), 4), "  theory (sqrt(k)-1)/(sqrt(k)+1) =", round(9 / 11, 4))
    for name, e in (("plain", plain), ("momentum", mom)):
        print(name, "steps to shrink the error by 1e-6:", int(np.argmax(e < 1e-6 * e[0])))
    print("step 2.02/L, error after 400 steps:", round(run(2.02 / L, n=400)[-1], 1), "(diverges)")
    plt.semilogy(plain, label="plain descent"); plt.semilogy(mom, label="momentum")
    plt.xlabel("step"); plt.ylabel("distance to minimum"); plt.legend()

    Try this. Run it. Plain descent with the best step has measured rate 0.9802 = 99/101 and needs 691 steps to shrink the error a million times; momentum has measured rate 0.8246, close to the theoretical 9/11 = 0.8182 (the extra is a polynomial factor at the edge of the stable region), and needs 83 steps. Step 2.02/L is slightly above the limit 2/L and the error grows. Change kappa to 10 and then to 1000: the plain step count scales like kappa (69, 691 and 6908 steps: about 6.9 kappa, which is (kappa/2) ln 10^6), and the momentum count like the square root of kappa (26, 83 and 264 steps). Print the first few x values of plain descent to see the y-coordinate flipping sign, and change x0 to (1, 1) to see how the start affects the transient but not the rate.

    Momentum

    Definition A

    Momentum

    Momentum (Polyak’s heavy ball) replaces gradient descent by xk+1=xk−η∇f(xk)+β(xk−xk−1)x_{k+1} = x_k - \eta\nabla f(x_k) + \beta(x_k - x_{k-1}) with 0≤β<10 \le \beta \lt 1. Equivalently the ‘velocity’ vk=xk−xk−1v_k = x_k - x_{k-1} satisfies vk+1=βvk−η∇f(xk)v_{k+1} = \beta v_k - \eta\nabla f(x_k) and xk+1=xk+vk+1x_{k+1} = x_k + v_{k+1}: a ball with friction rolling in the landscape.

    In one lineThe modification xk+1=xk−η∇f(xk)+β(xk−xk−1)x_{k+1} = x_k - \eta\nabla f(x_k) + \beta(x_k - x_{k-1}) that adds a fraction β\beta of the previous step to the gradient step (the heavy-ball method of Polyak).

    Why it existsIt lets the iterate build up speed along a valley floor, where the gradients keep pointing the same way, and cancels the sideways bouncing, where the gradients alternate; on quadratics it improves the rate from κ\kappa to κ\sqrt\kappa steps.

    Theorem B Polyak 1964; Goh, Why Momentum Really Works (2017)

    Momentum on a quadratic

    Let f(x)=12xTAx−bTxf(x) = \frac12x^{\mathsf T}Ax - b^{\mathsf T}x with the eigenvalues of AA in [μ,L][\mu, L]. With η=4(L+μ)2\eta = \dfrac4{(\sqrt L + \sqrt\mu)^2} and β=(κ−1κ+1)2\beta = \Big(\dfrac{\sqrt\kappa - 1}{\sqrt\kappa + 1}\Big)^2 the heavy-ball errors satisfy ∥ek∥≤C(1+k)(κ−1κ+1)k\lVert e_k\rVert \le C(1 + k)\Big(\dfrac{\sqrt\kappa - 1}{\sqrt\kappa + 1}\Big)^k.

    In one lineFor a quadratic with eigenvalues in [μ,L][\mu, L], the heavy-ball method with η=4(L+μ)2\eta = \dfrac4{(\sqrt L + \sqrt\mu)^2} and β=(κ−1κ+1)2\beta = \Big(\dfrac{\sqrt\kappa - 1}{\sqrt\kappa + 1}\Big)^2 makes the error decay at the rate κ−1κ+1\dfrac{\sqrt\kappa - 1}{\sqrt\kappa + 1} (up to a factor polynomial in kk).

    Why it is trueIt shows that the right amount of memory turns the condition number κ\kappa into κ\sqrt\kappa in the iteration count: for κ=104\kappa = 10^4, about 100100 times fewer steps.

    ProofPolyak 1964; Goh 2017
    The idea: Diagonalise as before. In each eigen-direction the error obeys a two-term linear recurrence whose characteristic roots are complex, of the same absolute value square root of beta, whenever one plus beta minus eta times the eigenvalue is at most two root beta in absolute value. The chosen eta and beta make this hold exactly across the whole range of eigenvalues.
    For eigenvalue λ\lambda: ck+1=(1+β−ηλ) ck−β ck−1c_{k+1} = (1 + \beta - \eta\lambda)\,c_k - \beta\,c_{k-1}.
    Subtract the minimiser from the update and use ∇f(x)=A(x−x∗)\nabla f(x) = A(x - x^*): ek+1=ek−ηAek+β(ek−ek−1)e_{k+1} = e_k - \eta Ae_k + \beta(e_k - e_{k-1}). In an orthonormal eigenbasis of AA (spectral theorem) coordinate ii evolves independently.
    The roots are z=τ±τ2−4β2z = \dfrac{\tau \pm \sqrt{\tau^2 - 4\beta}}2 with τ=1+β−ηλ\tau = 1 + \beta - \eta\lambda.
    A two-term recurrence ck+1=τck−βck−1c_{k+1} = \tau c_k - \beta c_{k-1} has solutions built from the roots of z2−τz+β=0z^2 - \tau z + \beta = 0.
    Both roots have absolute value exactly β\sqrt\beta, so ∣ck∣≤C(1+k)(β)k|c_k| \le C(1 + k)(\sqrt\beta)^k (the factor 1+k1 + k appears only when the roots coincide).
    If ∣τ∣≤2β|\tau| \le 2\sqrt\beta the square root is imaginary (or zero) and ∣z∣2=τ2+(4β−τ2)4=β|z|^2 = \frac{\tau^2 + (4\beta - \tau^2)}{4} = \beta.
    So the condition ∣τ∣≤2β|\tau| \le 2\sqrt\beta holds for every eigenvalue in [μ,L][\mu, L], with β=κ−1κ+1\sqrt\beta = \dfrac{\sqrt\kappa - 1}{\sqrt\kappa + 1}. ■\blacksquare
    Write s=κs = \sqrt\kappa. Then β=(s−1)2(s+1)2\beta = \frac{(s - 1)^2}{(s + 1)^2}, ηL=4s2(s+1)2\eta L = \frac{4s^2}{(s + 1)^2} and ημ=4(s+1)2\eta\mu = \frac4{(s + 1)^2}. So τ=1+β−ηλ\tau = 1 + \beta - \eta\lambda ranges over [1+β−ηL, 1+β−ημ]=[−2(s−1)s+1, 2(s−1)s+1]=[−2β,2β][1 + \beta - \eta L,\ 1 + \beta - \eta\mu] = \Big[-\dfrac{2(s - 1)}{s + 1},\ \dfrac{2(s - 1)}{s + 1}\Big] = [-2\sqrt\beta, 2\sqrt\beta] as λ\lambda runs over [μ,L][\mu, L].The recipe for η\eta and β\beta was designed to make the two ends of the eigenvalue range land exactly on the edge of the oscillating region.
    Worked example
    Compare plain descent and momentum for κ=100\kappa = 100.

    Solution.

    1. Plain descent. ρ∗=99101=0.9802\rho^* = \dfrac{99}{101} = 0.9802; steps for a factor 10−610^{-6}: ln⁡106ln⁡(101/99)≈691\dfrac{\ln10^6}{\ln(101/99)} \approx 691. Theorem on quadratics.
    2. Momentum parameters. κ=10\sqrt\kappa = 10, so β=(911)2=81121=0.669\beta = \Big(\dfrac9{11}\Big)^2 = \dfrac{81}{121} = 0.669 and, for μ=1\mu = 1, L=100L = 100, η=4(10+1)2=4121=0.0331\eta = \dfrac4{(10 + 1)^2} = \dfrac4{121} = 0.0331. Formulas of the theorem.
    3. Rate. κ−1κ+1=911=0.8182\dfrac{\sqrt\kappa - 1}{\sqrt\kappa + 1} = \dfrac9{11} = 0.8182; the ideal count is ln⁡106ln⁡(11/9)≈69\dfrac{\ln10^6}{\ln(11/9)} \approx 69 steps. Same formula as plain descent with κ\sqrt\kappa in place of κ\kappa.
    4. In practice. The lab above measures a rate of 0.82460.8246 and 8383 steps (the factor 1+k1 + k and the transient add some). The bound has a polynomial factor in front.

    Answer. About 690690 steps against about 7070 to 8585: a factor of 88 to 1010, which is κ\sqrt\kappa. For κ=104\kappa = 10^4 the gap is a factor of 100100.

    Your answerFor a quadratic with κ=100\kappa = 100, what is the per-step convergence rate (κ−1)/(κ+1)(\sqrt\kappa - 1)/(\sqrt\kappa + 1) of optimally tuned momentum?
    Quick checkIn the heavy-ball method, what happens as the momentum β\beta approaches 11 with the step size fixed?
    Beyond the course: for understanding· Nesterov's acceleration, and conjugate gradients

    Yurii Nesterov (1983) modified the method by evaluating the gradient at a point ahead of the current one, xk+β(xk−xk−1)x_k + \beta(x_k - x_{k-1}), instead of at xkx_k. For smooth convex functions (no strong convexity) this improves the bound O(1/k)O(1/k) above to O(1/k2)O(1/k^2), which is optimal among first-order methods; for strongly convex functions it gives a rate of order 1−1/κ1 - 1/\sqrt\kappa per step without needing a quadratic. On quadratics the method of conjugate gradients (MATH 340) reaches the same rate by choosing the step and the momentum at each iteration from the data, with no tuning, and finds the exact minimiser in at most nn steps in exact arithmetic.

    Stochastic gradient descent

    A loss in machine learning is an average over data, ℓ(w)=1N∑i=1Nℓi(w)\ell(w) = \frac1N\sum_{i = 1}^N\ell_i(w), with NN in the millions. Its gradient is the average of NN per-example gradients, and computing it costs NN backward passes. The idea of stochastic gradient descent is to use the gradient of one randomly chosen term.

    Definition A

    Stochastic gradient descent

    Let ℓ=1N∑ℓi\ell = \frac1N\sum\ell_i. Stochastic gradient descent (SGD) is wk+1=wk−ηk∇ℓik(wk)w_{k+1} = w_k - \eta_k\nabla\ell_{i_k}(w_k) where iki_k is chosen uniformly at random from {1,…,N}\{1, \dots, N\} at each step. Because each index has probability 1N\frac1N, the average of the step over the random choice is −ηk∇ℓ(wk)-\eta_k\nabla\ell(w_k): the stochastic gradient is an unbiased estimate of the true gradient. A minibatch of BB examples uses the average of BB such gradients.

    In one lineThe iteration wk+1=wk−ηk∇ℓik(wk)w_{k+1} = w_k - \eta_k\nabla\ell_{i_k}(w_k) in which iki_k is an example chosen at random; each step costs one example instead of NN.

    Why it existsIts step is, on average, the true gradient step, but costs NN times less, which is what makes training on huge datasets possible.

    Where this came from· Robbins and Monro, 1951

    Herbert Robbins and Sutton Monro published “A stochastic approximation method” in the Annals of Mathematical Statistics in 1951. Their problem was not machine learning. To find the level xx at which an unknown response function M(x)M(x) equals a target value α\alpha one can only run experiments, and every experiment returns M(x)M(x) plus random noise. They proposed to adjust the level after each experiment by a step proportional to the observed discrepancy, with step sizes aka_k shrinking so that the sum of the aka_k is infinite (the search can travel anywhere) and the sum of the ak2a_k^2 is finite (the noise is eventually averaged out), for example ak=1/ka_k = 1/k, and proved convergence in probability. Stochastic gradient descent is the Robbins–Monro scheme with the response function replaced by a gradient. The two conditions on the step sizes are still the textbook ones.

    Theorem B standard; the one-dimensional model of Robbins and Monro (1951)

    Noise floor of stochastic gradient descent

    Let a1,…,aNa_1, \dots, a_N be numbers with mean aˉ\bar a and variance σ2=1N∑(ai−aˉ)2\sigma^2 = \frac1N\sum(a_i - \bar a)^2, ℓi(w)=12(w−ai)2\ell_i(w) = \frac12(w - a_i)^2, so ℓ(w)=1N∑ℓi(w)\ell(w) = \frac1N\sum\ell_i(w) is minimised at aˉ\bar a. Run wk+1=wk−η(wk−aik)w_{k+1} = w_k - \eta(w_k - a_{i_k}) with iki_k drawn uniformly and independently. Then with ek=wk−aˉe_k = w_k - \bar a: (a) E[ek+1]=(1−η)E[ek]\mathrm{E}[e_{k+1}] = (1 - \eta)\mathrm{E}[e_k]; (b) E[ek+12]=(1−η)2E[ek2]+η2σ2\mathrm{E}[e_{k+1}^2] = (1 - \eta)^2\mathrm{E}[e_k^2] + \eta^2\sigma^2, so for 0<η<20 \lt \eta \lt 2, E[ek2]→ησ22−η\mathrm{E}[e_k^2] \to \dfrac{\eta\sigma^2}{2 - \eta}. (c) With ηk=1k+1\eta_k = \frac1{k + 1} and w0w_0 arbitrary, wkw_k is the average of the first kk sampled values ai0,…,aik−1a_{i_0}, \dots, a_{i_{k-1}}, and E[ek2]=σ2/k\mathrm{E}[e_k^2] = \sigma^2/k.

    In one lineFor the loss 1N∑12(w−ai)2\frac1N\sum\frac12(w - a_i)^2, whose minimiser is the mean aˉ\bar a, SGD with a fixed step η∈(0,2)\eta \in (0, 2) has E[wk]−aˉ→0\mathrm{E}[w_k] - \bar a \to 0 but E[(wk−aˉ)2]→ησ22−η\mathrm{E}[(w_k - \bar a)^2] \to \dfrac{\eta\sigma^2}{2 - \eta}, where σ2\sigma^2 is the variance of the aia_i; with steps ηk=1k+1\eta_k = \frac1{k + 1} the iterate is the running average and the error tends to 00.

    Why it is trueIt shows the central trade-off of stochastic methods in one formula: the noise floor is proportional to the learning rate, so a constant step cannot converge exactly, and decreasing steps are needed.

    Proofstandard
    The idea: Write the error update as a contraction of the old error plus a fresh zero-mean noise term. The noise is independent of the old error, so the variances add.
    ek+1=(1−η)ek+ηξke_{k+1} = (1 - \eta)e_k + \eta\xi_k with ξk=aik−aˉ\xi_k = a_{i_k} - \bar a, which has average 00 and average square σ2\sigma^2 and is independent of eke_k.
    wk+1−aˉ=(1−η)(wk−aˉ)+η(aik−aˉ)w_{k+1} - \bar a = (1 - \eta)(w_k - \bar a) + \eta(a_{i_k} - \bar a).
    E[ek+1]=(1−η)E[ek]\mathrm{E}[e_{k+1}] = (1 - \eta)\mathrm{E}[e_k].
    Take averages: E[ξk]=0\mathrm{E}[\xi_k] = 0. This is (a).
    E[ek+12]=(1−η)2E[ek2]+η2σ2\mathrm{E}[e_{k+1}^2] = (1 - \eta)^2\mathrm{E}[e_k^2] + \eta^2\sigma^2. This is (b)‘s recursion.
    Square the update: ek+12=(1−η)2ek2+2η(1−η)ekξk+η2ξk2e_{k+1}^2 = (1 - \eta)^2e_k^2 + 2\eta(1 - \eta)e_k\xi_k + \eta^2\xi_k^2. The cross term has average E[ek]E[ξk]=0\mathrm{E}[e_k]\mathrm{E}[\xi_k] = 0 by independence.
    E[ek2]→η2σ2η(2−η)=ησ22−η\mathrm{E}[e_k^2] \to \dfrac{\eta^2\sigma^2}{\eta(2 - \eta)} = \dfrac{\eta\sigma^2}{2 - \eta}.
    The recursion vk+1=γvk+cv_{k+1} = \gamma v_k + c with γ=(1−η)2<1\gamma = (1 - \eta)^2 \lt 1 converges to the fixed point v=c1−γv = \frac c{1 - \gamma}. Here 1−γ=1−(1−η)2=η(2−η)1 - \gamma = 1 - (1 - \eta)^2 = \eta(2 - \eta).
    This gives (c).
    With ηk=1k+1\eta_k = \frac1{k + 1}: wk+1=kk+1wk+1k+1aikw_{k+1} = \frac{k}{k + 1}w_k + \frac1{k + 1}a_{i_k}, which is the running average (induction). The average of kk independent samples has variance σ2/k\sigma^2/k. ■\blacksquare
    Worked example
    A loss has per-example optima aia_i with variance σ2=4\sigma^2 = 4. What noise floor does SGD with η=0.1\eta = 0.1 have, and what does a minibatch of B=10B = 10 do?

    Solution.

    1. Single example. E[e2]→ησ22−η=0.1⋅41.9=0.2105\mathrm{E}[e^2] \to \dfrac{\eta\sigma^2}{2 - \eta} = \dfrac{0.1\cdot4}{1.9} = 0.2105, so the typical error is 0.2105=0.459\sqrt{0.2105} = 0.459. The theorem. The iterate fluctuates around aˉ\bar a with this standard deviation even though the step is small.
    2. Minibatch of 10. The average of 1010 independent terms has variance σ2/10=0.4\sigma^2/10 = 0.4, so the floor becomes 0.1⋅0.41.9=0.0211\dfrac{0.1\cdot0.4}{1.9} = 0.0211, ten times lower. Replace σ2\sigma^2 by σ2/B\sigma^2/B in the recursion.
    3. Halve the step. η=0.05\eta = 0.05 halves the floor (to ≈0.103\approx 0.103) but also halves the speed of forgetting the start, which is (1−η)k(1 - \eta)^k. The trade-off of the theorem.

    Answer. 0.21050.2105; with minibatch 1010, 0.02110.0211. The learning-rate schedules used in practice (large first, then decayed, e.g. ηk∝1/k\eta_k \propto 1/k) are the Robbins–Monro conditions in disguise: large steps to forget the start quickly, small steps at the end to average the noise out.

    Your answerSGD on 1N∑12(w−ai)2\frac1N\sum\frac12(w - a_i)^2 with σ2=4\sigma^2 = 4 and η=0.1\eta = 0.1: what is the long-run E[(wk−aˉ)2]\mathrm{E}[(w_k - \bar a)^2]? (Give a decimal.)
    Quick checkWhy does SGD with a constant learning rate not converge exactly to the minimiser?

    Newton’s method in many variables

    Gradient descent uses a linear model of ff and has to guess how far to trust it. If we also use the second derivative, we can ask for the minimum of the quadratic model.

    Definition A

    Newton's method

    For a root-finding problem F(x)=OF(x) = O with F:Rn→RnF: \mathbb R^n \to \mathbb R^n and Jacobian matrix JFJ_F, Newton’s method is xk+1=xk−JF(xk)−1F(xk)x_{k+1} = x_k - J_F(x_k)^{-1}F(x_k), that is, solve the linear system JF(xk) s=−F(xk)J_F(x_k)\,s = -F(x_k) and set xk+1=xk+sx_{k+1} = x_k + s: replace FF by its linearization (5.3) and solve exactly. To minimise ff take F=∇fF = \nabla f, so JF=HfJ_F = H_f, the Hessian (5.6). In one variable this is the Newton iteration of 4.2.

    In one lineThe iteration xk+1=xk−Hf(xk)−1∇f(xk)x_{k+1} = x_k - H_f(x_k)^{-1}\nabla f(x_k) for minimising ff, which is Newton's method for solving the system ∇f=O\nabla f = O, and jumps to the minimum of the second-order Taylor model at each step.

    Why it existsIt corrects the step in each direction by the curvature in that direction, so it does not care how badly conditioned the problem is, and near a minimum it converges quadratically.

    Why· Two ways to see the same step

    (1) Linearise the gradient. ∇f(x+s)≈∇f(x)+Hf(x)s\nabla f(x + s) \approx \nabla f(x) + H_f(x)s; setting it to OO gives s=−Hf(x)−1∇f(x)s = -H_f(x)^{-1}\nabla f(x). (2) Minimise the quadratic model. The second-order Taylor formula (5.6) says f(x+s)≈f(x)+∇f(x)⋅s+12sTHf(x)sf(x + s) \approx f(x) + \nabla f(x)\cdot s + \frac12s^{\mathsf T}H_f(x)s; if Hf(x)H_f(x) is positive definite, this is a quadratic in ss with a unique minimiser, found where its gradient ∇f+Hfs\nabla f + H_fs is OO: the same ss. On a quadratic function the model is the function, so Newton’s method finds the minimum in one step, from any start, whatever the condition number: x−A−1(Ax−b)=A−1bx - A^{-1}(Ax - b) = A^{-1}b.

    Theorem B standard (Nocedal and Wright 3.5; Kantorovich); 376 HW7 #3 for one variable

    Quadratic convergence of Newton's method

    Let F:Rn→RnF: \mathbb R^n \to \mathbb R^n be C1C^1 near a root x∗x^*, with JF(x∗)J_F(x^*) invertible, β0=∥JF(x∗)−1∥\beta_0 = \lVert J_F(x^*)^{-1}\rVert, and ∥JF(x)−JF(y)∥≤M∥x−y∥\lVert J_F(x) - J_F(y)\rVert \le M\lVert x - y\rVert for x,yx, y in a ball around x∗x^* containing the iterates. If ∥x0−x∗∥≤r:=12β0M\lVert x_0 - x^*\rVert \le r := \dfrac1{2\beta_0M}, then every iterate is defined, and ∥xk+1−x∗∥≤β0M∥xk−x∗∥2≤12∥xk−x∗∥\lVert x_{k+1} - x^*\rVert \le \beta_0M\lVert x_k - x^*\rVert^2 \le \frac12\lVert x_k - x^*\rVert.

    In one lineIf F(x∗)=OF(x^*) = O, JF(x∗)J_F(x^*) is invertible with ∥JF(x∗)−1∥≤β0\lVert J_F(x^*)^{-1}\rVert \le \beta_0 and JFJ_F is MM-Lipschitz near x∗x^*, then for ∥x0−x∗∥≤12β0M\lVert x_0 - x^*\rVert \le \dfrac1{2\beta_0M} the Newton iterates satisfy ∥xk+1−x∗∥≤β0M∥xk−x∗∥2\lVert x_{k+1} - x^*\rVert \le \beta_0M\lVert x_k - x^*\rVert^2: the number of correct digits doubles at each step.

    Why it is trueIt explains the speed seen in practice (five or six steps to machine precision) and says exactly what 'close enough to start' means, in terms of the curvature of FF and the invertibility of its Jacobian.

    ProofNocedal and Wright 3.5
    The idea: Subtract the root from the Newton update and rewrite the right side as the inverse Jacobian applied to the remainder of the linear approximation. The remainder is at most M over two times the squared error, and the Jacobian is invertible with norm at most twice its norm at the root, close to the root.
    The matrix J(xk)J(x_k) is invertible: ∥(I+E)v∥≥∥v∥−12∥v∥=12∥v∥\lVert(I + E)v\rVert \ge \lVert v\rVert - \frac12\lVert v\rVert = \frac12\lVert v\rVert, so I+EI + E is one-to-one, hence invertible, and ∥(I+E)−1∥≤2\lVert(I + E)^{-1}\rVert \le 2. Therefore ∥J(xk)−1∥≤2β0\lVert J(x_k)^{-1}\rVert \le 2\beta_0.
    Put e=xk−x∗e = x_k - x^* with ∥e∥≤r\lVert e\rVert \le r. ∥J(xk)−J(x∗)∥≤M∥e∥≤12β0\lVert J(x_k) - J(x^*)\rVert \le M\lVert e\rVert \le \frac1{2\beta_0}. Then J(xk)=J(x∗)(I+E)J(x_k) = J(x^*)\big(I + E\big) with E=J(x∗)−1(J(xk)−J(x∗))E = J(x^*)^{-1}(J(x_k) - J(x^*)) and ∥E∥≤β0⋅12β0=12\lVert E\rVert \le \beta_0\cdot\frac1{2\beta_0} = \frac12.
    xk+1−x∗=J(xk)−1Rx_{k+1} - x^* = J(x_k)^{-1}R with R=F(x∗)−F(xk)−J(xk)(x∗−xk)R = F(x^*) - F(x_k) - J(x_k)(x^* - x_k).
    xk+1−x∗=xk−x∗−J(xk)−1F(xk)=J(xk)−1[J(xk)(xk−x∗)−F(xk)]x_{k+1} - x^* = x_k - x^* - J(x_k)^{-1}F(x_k) = J(x_k)^{-1}\big[J(x_k)(x_k - x^*) - F(x_k)\big] and F(x∗)=OF(x^*) = O, so the bracket equals +[F(x∗)−F(xk)−J(xk)(x∗−xk)]+\big[F(x^*) - F(x_k) - J(x_k)(x^* - x_k)\big].
    ∥R∥≤M2∥e∥2\lVert R\rVert \le \dfrac M2\lVert e\rVert^2.
    Fundamental theorem of calculus along the segment (5.3): F(x∗)−F(xk)=∫01J(xk+t(x∗−xk))(x∗−xk) dtF(x^*) - F(x_k) = \int_0^1J(x_k + t(x^* - x_k))(x^* - x_k)\,dt. So R=∫01[J(xk+t(x∗−xk))−J(xk)](x∗−xk) dtR = \int_0^1\big[J(x_k + t(x^* - x_k)) - J(x_k)\big](x^* - x_k)\,dt, and the Lipschitz bound gives ∥R∥≤∫01Mt∥e∥2 dt=M2∥e∥2\lVert R\rVert \le \int_0^1Mt\lVert e\rVert^2\,dt = \frac M2\lVert e\rVert^2.
    ∥xk+1−x∗∥≤β0M∥e∥2≤12∥e∥\lVert x_{k+1} - x^*\rVert \le \beta_0M\lVert e\rVert^2 \le \frac12\lVert e\rVert.
    Multiply the bounds: 2β0⋅M2∥e∥2=β0M∥e∥22\beta_0\cdot\frac M2\lVert e\rVert^2 = \beta_0M\lVert e\rVert^2. And β0M∥e∥≤β0Mr=12\beta_0M\lVert e\rVert \le \beta_0Mr = \frac12. Induction keeps xk+1x_{k+1} inside the ball. ■\blacksquare
    Worked example MATH 376 HW7 #3 and Worksheet 19 #2 (one variable)
    Heron's method for 2\sqrt2 is Newton's method for x2−2=0x^2 - 2 = 0. Show that the error is squared at each step, and run four steps from x0=1.5x_0 = 1.5.

    Solution.

    1. The Newton map. For f(x)=x2−2f(x) = x^2 - 2: N(x)=x−x2−22x=12(x+2x)N(x) = x - \dfrac{x^2 - 2}{2x} = \dfrac12\Big(x + \dfrac2x\Big). One-variable Newton: subtract f/f′f/f'. The fixed point is 2\sqrt2.
    2. The error identity. N(x)−2=x2−22 x+22x=(x−2)22xN(x) - \sqrt2 = \dfrac{x^2 - 2\sqrt2\,x + 2}{2x} = \dfrac{(x - \sqrt2)^2}{2x}. Put everything over the common denominator 2x2x; the numerator is a perfect square.
    3. Read it. With ek=xk−2e_k = x_k - \sqrt2: ek+1=ek22xk≈0.354 ek2e_{k+1} = \dfrac{e_k^2}{2x_k} \approx 0.354\,e_k^2 once xk≈2x_k \approx \sqrt2. The error is squared, times the constant f′′2f′=122\frac{f''}{2f'} = \frac1{2\sqrt2} at the root. This is the theorem above with β0=122\beta_0 = \frac1{2\sqrt2} and M=2M = 2.
    4. Run it. x0=1.5x_0 = 1.5 has e0=0.0858e_0 = 0.0858. Then x1=1.416667x_1 = 1.416667 (e1=2.5×10−3e_1 = 2.5\times10^{-3}), x2=1.41421569x_2 = 1.41421569 (e2=2.1×10−6e_2 = 2.1\times10^{-6}), x3=1.41421356237469x_3 = 1.41421356237469 (e3=1.6×10−12e_3 = 1.6\times10^{-12}), and x4x_4 is 2\sqrt2 to machine precision. Check one step: 0.08582/3=0.002450.0858^2/3 = 0.00245. The number of correct digits goes 1,2,5,11,161, 2, 5, 11, 16: roughly doubling.

    Answer. ek+1=ek2/(2xk)e_{k+1} = e_k^2/(2x_k); four steps give 2\sqrt2 to full double precision.

    Worked example new (the standard test problem)
    Newton's method on the Rosenbrock function f(x,y)=(1−x)2+100(y−x2)2f(x, y) = (1 - x)^2 + 100(y - x^2)^2 from (−1.2,1)(-1.2, 1).

    Solution.

    1. Gradient and Hessian. ∇f=(−2(1−x)−400x(y−x2), 200(y−x2))\nabla f = \big(-2(1 - x) - 400x(y - x^2),\ 200(y - x^2)\big) and Hf=[2−400(y−x2)+800x2−400x−400x200]H_f = \begin{bmatrix}2 - 400(y - x^2) + 800x^2 & -400x\\ -400x & 200\end{bmatrix}. Direct differentiation; at the minimum (1,1)(1, 1), H=[802−400−400200]H = \begin{bmatrix}802 & -400\\ -400 & 200\end{bmatrix} with eigenvalues 0.40.4 and 1001.61001.6, so κ≈2500\kappa \approx 2500.
    2. First step. At (−1.2,1)(-1.2, 1): f=24.2f = 24.2, ∇f=(−215.6,−88)\nabla f = (-215.6, -88), H=[1330480480200]H = \begin{bmatrix}1330 & 480\\ 480 & 200\end{bmatrix}. Solving Hs=−∇fHs = -\nabla f gives s=(0.0247,0.3807)s = (0.0247, 0.3807) and x1=(−1.1753,1.3807)x_1 = (-1.1753, 1.3807), f=4.73f = 4.73. Solve a 2×22 \times 2 linear system.
    3. Second step. From x1x_1 Newton jumps to (0.7631,−3.1750)(0.7631, -3.1750) with f=1412f = 1412: the function went up. Far from the minimum the quadratic model is a poor guide, and Newton’s method only aims for a critical point, not for descent.
    4. Then convergence. x3=(0.7634,0.5828)x_3 = (0.7634, 0.5828), f=0.056f = 0.056; x4=(0.99999,0.944)x_4 = (0.99999, 0.944); x5=(0.999996,0.999991)x_5 = (0.999996, 0.999991) with f=1.9×10−11f = 1.9\times10^{-11}; x6=(1,1)x_6 = (1, 1) to machine precision. Once close, the error is squared at each step: 0.056→0.31→10−11→10−200.056 \to 0.31 \to 10^{-11} \to 10^{-20} in ff.
    5. Compare. Plain gradient descent with a step near the stability limit (η=10−3\eta = 10^{-3}; the largest Hessian eigenvalue is 15061506 at the start, so 2/L=0.00132/L = 0.0013) has f=0.0038f = 0.0038 after 50005000 steps and 1.9×10−81.9\times10^{-8} after 2000020000. The valley is curved and narrow (κ≈2500\kappa \approx 2500 at the minimum), and the step is limited by the steepest wall.

    Answer. Newton converges in 66 steps against tens of thousands for gradient descent, but its path is erratic (step 2 lands at f=1412f = 1412). Practical implementations add a line search or a trust region (they cut the step when the function rises) and fall back on a descent direction when the Hessian is not positive definite.

    Watch out· Newton's method is attracted to every critical point, saddles and maxima included

    For f(x)=−x2f(x) = -x^2 (a maximum at 00), Newton gives x−−2x−2=x−x=0x - \frac{-2x}{-2} = x - x = 0 in one step: it lands exactly on the maximum. For f=x2−y2f = x^2 - y^2 it jumps to the saddle at the origin. It is solving ∇f=O\nabla f = O, which has no preference between minima, maxima and saddles. Gradient descent, in contrast, is repelled from maxima and almost never settles at saddles.

    Same idea elsewhere· Cost: why neural networks do not use Newton's method

    Newton needs the Hessian, n2n^2 numbers, and a solve with it, about n3n^3 operations. A network with n=106n = 10^6 weights has a Hessian with 101210^{12} entries, which in 4-byte floats is 44 terabytes. Quasi-Newton methods (BFGS and its low-memory form L-BFGS) build an approximation of H−1H^{-1} from the last few gradients and are used for smaller problems; for deep networks, ‘diagonal’ rescalings of the gradient (Adam, Kingma and Ba, 2014) approximate the idea cheaply, dividing each coordinate’s step by a running estimate of its gradient size.

    Quick checkNewton's method is applied to f(x)=−x2+3f(x) = -x^2 + 3 starting at x0=5x_0 = 5. Where does it go?

    Training a small neural network

    A neural network is a composition of differentiable maps, so by the chain rule of 5.4 its loss is a differentiable field of the weights, and its gradient is computed by backpropagation (3.8): the computational graph is traversed backwards, multiplying Jacobians. Everything in this chapter applies. As a concrete case, a tiny network with 22 inputs, 33 tanh hidden units and 11 linear output (1313 parameters) learns XOR: the four inputs (0,0),(0,1),(1,0),(1,1)(0, 0), (0, 1), (1, 0), (1, 1) with targets −1,+1,+1,−1-1, +1, +1, -1. No linear model can do this (the points are not linearly separable), but a hidden layer can.

    Python labTrain a 2-3-1 network on XOR with backpropagation and gradient descent
    import numpy as np
    
    X = np.array([[0., 0.], [0., 1.], [1., 0.], [1., 1.]]); y = np.array([-1., 1., 1., -1.])   # XOR
    
    def loss_grads(P):
        W1, b1, w2, b2 = P
        h = np.tanh(X @ W1 + b1); out = h @ w2 + b2; d_out = (out - y) / len(y)
        d_pre = np.outer(d_out, w2) * (1 - h ** 2)        # backpropagation (3.8): chain rule from the loss backwards
        return 0.5 * np.mean((out - y) ** 2), out, [X.T @ d_pre, d_pre.sum(0), h.T @ d_out, d_out.sum(keepdims=True)]
    
    def init(seed, H=3):
        rng = np.random.default_rng(seed)
        return [rng.normal(0, 1, (2, H)), np.zeros(H), rng.normal(0, 1, H), np.zeros(1)]
    
    P = init(1); G = loss_grads(P)[2]; worst = 0.0
    for p, g in zip(P, G):                                 # gradient check by central differences, one parameter at a time
        for i in np.ndindex(p.shape):
            old = p[i]; p[i] = old + 1e-6; up = loss_grads(P)[0]; p[i] = old - 1e-6; dn = loss_grads(P)[0]; p[i] = old
            worst = max(worst, abs((up - dn) / 2e-6 - g[i]))
    print("backprop vs central differences, largest error over the 13 parameters:", f"{worst:.1e}")
    
    def train(seed, eta=0.1, steps=3000, H=3, show=False):
        P = init(seed, H)
        for k in range(steps + 1):
            loss, out, G = loss_grads(P)
            if show and k in (0, 10, 100, 200, 300, 400, 500, 1000, 3000):
                print(f"{k:5d}  loss {loss:.3e}  |grad| {np.sqrt(sum(np.sum(g**2) for g in G)):.3e}")
            for p, g in zip(P, G): p -= eta * g
        return loss, out
    
    train(1, show=True)
    print("final loss for seeds 0..9:", [f"{train(s)[0]:.0e}" for s in range(10)])
    loss, out = train(2); print("seed 2 stalls at loss", round(loss, 3), "with outputs", out.round(2))

    Try this. Run it. The gradient check at the top compares the backpropagation gradient with central differences for all 13 parameters and agrees to about 1e-10: backpropagation is the chain rule applied to the whole network. The loss then falls slowly for about 200 steps (a plateau where the gradient is small), drops fast, and ends below 1e-20: the network represents XOR exactly. The last line shows a failure: for seed 2 the same code is still at loss 0.25 after 3000 steps, with two of the four outputs at 0. Training a non-convex loss depends on the starting point. Try eta = 1.0: eight of the ten seeds still converge (and seed 2 now escapes its stall), but seeds 0 and 7 give nan (the step is above the stability limit 2/L near their start). Try H = 2 and H = 8 hidden units and count how many of the ten seeds succeed.

    Saddle points in high dimension

    Critical points of a smooth function (5.6) are classified by the signs of the Hessian’s eigenvalues. A strict local minimum needs all nn of them positive. For a loss with a million parameters this is an extremely demanding requirement, and a critical point with both positive and negative eigenvalues is a saddle.

    Proposition B standard (the exact solution of the linear case)

    Gradient descent near a saddle

    Let f(x,y)=12(ax2−γy2)f(x, y) = \frac12(ax^2 - \gamma y^2) with a,γ>0a, \gamma \gt 0 and η<2/a\eta \lt 2/a. Gradient descent gives xk+1=(1−ηa)xkx_{k+1} = (1 - \eta a)x_k and yk+1=(1+ηγ)yky_{k+1} = (1 + \eta\gamma)y_k. So xk→0x_k \to 0 and yk=(1+ηγ)ky0y_k = (1 + \eta\gamma)^ky_0, which grows without bound unless y0=0y_0 = 0. The number of steps to grow from ∣y0∣|y_0| to 11 is ln⁡(1/∣y0∣)ln⁡(1+ηγ)≈ln⁡(1/∣y0∣)ηγ\dfrac{\ln(1/|y_0|)}{\ln(1 + \eta\gamma)} \approx \dfrac{\ln(1/|y_0|)}{\eta\gamma}.

    In one lineFor f=12(ax2−γy2)f = \frac12(ax^2 - \gamma y^2) with a,γ>0a, \gamma \gt 0, gradient descent with step η\eta has yk=(1+ηγ)ky0y_k = (1 + \eta\gamma)^ky_0: it leaves the saddle exponentially fast but with a time of order 1ηγln⁡1∣y0∣\dfrac1{\eta\gamma}\ln\dfrac1{|y_0|}, which is long when the negative curvature γ\gamma is small.

    Why it is trueIt shows why training stalls near saddles: where the downhill curvature is small the gradient is tiny and escape takes many steps, though it always happens unless the start is exactly on the stable direction.

    Proofstandard
    The idea: The gradient is (a x, minus gamma y), so each coordinate is multiplied by a constant at every step. The second constant exceeds one.
    xk+1=(1−ηa)xkx_{k+1} = (1 - \eta a)x_k and yk+1=(1+ηγ)yky_{k+1} = (1 + \eta\gamma)y_k.
    ∇f=(ax,−γy)\nabla f = (ax, -\gamma y), so the update xk+1=xk−ηaxkx_{k+1} = x_k - \eta ax_k and yk+1=yk+ηγyky_{k+1} = y_k + \eta\gamma y_k.
    xk→0x_k \to 0 and ∣yk∣=(1+ηγ)k∣y0∣→∞|y_k| = (1 + \eta\gamma)^k|y_0| \to \infty if y0≠0y_0 \ne 0.
    Geometric sequences: ∣1−ηa∣<1|1 - \eta a| \lt 1 for 0<η<2/a0 \lt \eta \lt 2/a, while 1+ηγ>11 + \eta\gamma \gt 1.
    k=ln⁡(1/∣y0∣)ln⁡(1+ηγ)k = \dfrac{\ln(1/|y_0|)}{\ln(1 + \eta\gamma)}.
    Solve (1+ηγ)k∣y0∣=1(1 + \eta\gamma)^k|y_0| = 1 for kk, and use ln⁡(1+u)≈u\ln(1 + u) \approx u for small uu. ■\blacksquare
    Worked example
    A saddle with weak negative curvature: f=12(x2−0.01y2)f = \frac12(x^2 - 0.01y^2), η=0.1\eta = 0.1, start at y0=10−6y_0 = 10^{-6}. How long does descent take to leave?

    Solution.

    1. Setup. a=1a = 1, γ=0.01\gamma = 0.01, ηγ=0.001\eta\gamma = 0.001, so yk=(1.001)ky0y_k = (1.001)^ky_0. The proposition.
    2. Steps to reach ∣y∣=1|y| = 1. k=ln⁡106ln⁡1.001=13.81550.0009995≈13,822k = \dfrac{\ln10^6}{\ln1.001} = \dfrac{13.8155}{0.0009995} \approx 13{,}822. Solve (1.001)k⋅10−6=1(1.001)^k\cdot10^{-6} = 1.
    3. Meaning. The iterate sits within 10−610^{-6} of the saddle for most of those steps, where the gradient is about 10−810^{-8}: the loss curve looks flat, as if training had converged. The gradient norm in yy is γ∣yk∣\gamma|y_k|, tiny until the very end.

    Answer. About 13,80013{,}800 steps; with a tenfold stronger curvature (γ=0.1\gamma = 0.1) it would take about 13801380.

    Your answerIn the saddle example (ηγ=0.001\eta\gamma = 0.001, y0=10−6y_0 = 10^{-6}), about how many steps does gradient descent take for ∣y∣|y| to grow from 10−610^{-6} to 11? (Give a decimal.)
    Beyond the course: for understanding· Why saddles dominate in high dimension (a heuristic), and what is known

    Suppose that at a critical point each of the nn Hessian eigenvalues were independently positive or negative with equal chance. Then the chance that all are positive is 2−n2^{-n}: for n=1000n = 1000, about 10−30110^{-301}. So most critical points would be saddles, and the few minima would be extraordinarily rare. Real Hessians are not like this (their eigenvalues are strongly correlated), but the experience with large networks is consistent with it: the main obstacle in practice is long plateaus near saddles, and the local minima that gradient methods find tend to have loss close to the best known. A theorem in the same direction (proved with the stable manifold theorem, so beyond this book): gradient descent with a small fixed step from a random start almost surely avoids saddles that have at least one strictly negative eigenvalue. The minibatch noise of SGD helps further: the random kicks push the iterate off the unstable ridge sooner than the deterministic computation above.

    Quick checkAt a critical point of a loss with 10610^6 parameters, the Hessian has 999,999 positive eigenvalues and one eigenvalue equal to −0.001-0.001. What is it, and what does gradient descent do near it?

    Where it is used

    Used inside maths· Inside maths: fixed points, ODEs and eigenvalue algorithms

    Gradient descent is the fixed-point iteration of 4.2 for T(x)=x−η∇f(x)T(x) = x - \eta\nabla f(x), and the contraction corollary above is a direct application of the Banach theorem; the same fixed-point idea proves existence for ODEs by Picard’s iteration (7.1). Its continuous-time limit, x′(t)=−∇f(x(t))x'(t) = -\nabla f(x(t)) (the gradient flow), is an ordinary differential equation, along which ff decreases: ddtf(x(t))=−∥∇f∥2\frac d{dt}f(x(t)) = -\lVert\nabla f\rVert^2 by the path theorem. Newton’s method is the multivariable form of the iteration whose local contraction was proved in 4.2, and its convergence proof above uses exactly the mean value and invertibility arguments of 5.7. With exact line search on a quadratic, steepest descent is the template that conjugate gradients improves on.

    Used in the real world· AI: training a model, in numbers

    A language model with n=109n = 10^9 parameters is trained by minibatch SGD or Adam on trillions of tokens. Each step computes a gradient of 10910^9 numbers by backpropagation, at a cost comparable to a few forward passes (3.8). The learning rate is typically chosen by trial, then warmed up from near 00 over the first thousand steps (to avoid the instability when the gradient is large and the step is above 2/L2/L of the starting region) and decayed afterwards (the Robbins–Monro conditions: large steps to travel, small steps to average out the noise). A linear regression with 10610^6 features and 10710^7 rows has XTXX^{\mathsf T}X with 101210^{12} entries; gradient descent never forms it, and costs two products with XX per step (2×10132\times10^{13} operations) instead of the 101810^{18} of solving the normal equations. If the features are not standardised, κ(X)\kappa(X) can be 10310^3, making κ(XTX)=106\kappa(X^{\mathsf T}X) = 10^6 and the rate 1−2×10−61 - 2\times10^{-6}: half a million steps per ee-fold of error. Standardising can bring κ(X)\kappa(X) down to 1010, so κ=100\kappa = 100 and about 350350 steps give a thousandfold reduction of the error.

    Traps

    Watch out· A small learning rate is only small relative to the curvature

    The stability limit is 2/L2/L, where LL is the largest Hessian eigenvalue. A learning rate of 0.10.1 is safe for L=1L = 1 and explosive for L=100L = 100. If the loss goes to ∞\infty or nan\mathtt{nan} in the first steps, cut the rate by a factor of 1010.

    Watch out· Zig-zag is not a bug

    Plain gradient descent on a narrow valley must zig-zag (consecutive exact line-search gradients are perpendicular, and at the best fixed step the steep coordinate flips sign every step). Do not conclude the gradient is wrong. Cures: momentum, preconditioning (rescaling the variables to reduce κ\kappa), or second-order information.

    Watch out· A flat loss curve is not convergence

    Near a saddle (or in a very flat valley) the gradient is tiny and the loss barely moves for thousands of steps, then drops suddenly. Check the gradient norm and the Hessian spectrum before stopping.

    Watch out· SGD with a constant rate has a noise floor

    The loss curve of SGD fluctuates around a level proportional to the learning rate. It does not mean the model has stopped improving: lowering the rate lowers the floor (the schedule of Robbins and Monro).

    Watch out· The loss can go up

    Gradient descent with a small enough step lowers ff at every step (descent lemma). Newton’s method does not (the Rosenbrock example went from 4.74.7 to 14121412), SGD does not, and momentum does not. The ‘decrease every step’ check belongs only to the first.

    Watch out· Convex and non-convex are different problems

    For a convex function, any local minimum is global and gradient descent finds it. A neural network’s loss is not convex, and the final loss depends on the starting weights (the lab: seed 2 is stuck at 0.250.25 while nine other seeds reach 10−2910^{-29}).

    Problems

    check

    For f(x,y)=12(2x2+8y2)f(x, y) = \frac12(2x^2 + 8y^2), what are LL, μ\mu, κ\kappa, the stable range of η\eta, and the best step?

    Solution

    The Hessian is diag(2,8)\mathrm{diag}(2, 8), so μ=2\mu = 2, L=8L = 8, κ=4\kappa = 4. Gradient descent converges iff 0<η<2/L=0.250 \lt \eta \lt 2/L = 0.25. The best step is η∗=2L+μ=210=0.2\eta^* = \dfrac2{L + \mu} = \dfrac2{10} = 0.2, with rate κ−1κ+1=35\dfrac{\kappa - 1}{\kappa + 1} = \dfrac35 (check: ∣1−0.2⋅2∣=0.6|1 - 0.2\cdot2| = 0.6 and ∣1−0.2⋅8∣=0.6|1 - 0.2\cdot8| = 0.6).

    check

    Do one step of gradient descent with η=0.1\eta = 0.1 on f(x,y)=x2+5y2f(x, y) = x^2 + 5y^2 from (3,1)(3, 1).

    Solution

    ∇f=(2x,10y)=(6,10)\nabla f = (2x, 10y) = (6, 10), so the new point is (3−0.6, 1−1.0)=(2.4,0)(3 - 0.6,\ 1 - 1.0) = (2.4, 0). The yy-coordinate was killed in one step because 1−0.1⋅10=01 - 0.1\cdot10 = 0 (the Hessian is diag(2,10)\mathrm{diag}(2, 10) and η=1/L\eta = 1/L). ff fell from 32+5=143^2 + 5 = 14 to 5.765.76.

    check

    Newton’s method for f(x)=x4f(x) = x^4 is x↦x−4x312x2=23xx \mapsto x - \dfrac{4x^3}{12x^2} = \frac23x. Is the convergence quadratic? Why or why not?

    Solution

    The iterates xk=(23)kx0x_k = (\frac23)^kx_0 converge only linearly (the error is multiplied by 23\frac23 each time). The quadratic convergence theorem needs an invertible Hessian at the minimiser, and f′′(0)=0f''(0) = 0 here: the hypothesis fails.

    check

    True or false: gradient descent with exact line search on a quadratic in two variables moves along perpendicular directions in consecutive steps. Why?

    Solution

    True. The exact step minimises ϕ(η)=f(xk−ηgk)\phi(\eta) = f(x_k - \eta g_k), so ϕ′(ηk)=−∇f(xk+1)⋅gk=0\phi'(\eta_k) = -\nabla f(x_{k+1})\cdot g_k = 0: the new gradient is perpendicular to the old one. (This holds for any smooth ff, not only quadratics.)

    usenew (least squares by gradient descent)

    For f(w)=12∥Xw−y∥2f(w) = \frac12\lVert Xw - y\rVert^2 with XTX=[5335]X^{\mathsf T}X = \begin{bmatrix}5 & 3\\ 3 & 5\end{bmatrix}, find the best fixed learning rate and the number of steps to reduce the error by a factor 10−310^{-3}.

    Solution

    The eigenvalues of XTXX^{\mathsf T}X are 22 and 88, so μ=2\mu = 2, L=8L = 8, κ=4\kappa = 4. The best step is η∗=210=0.2\eta^* = \frac2{10} = 0.2 with rate ρ∗=35=0.6\rho^* = \frac35 = 0.6. We need 0.6k≤10−30.6^k \le 10^{-3}: k≥ln⁡1000ln⁡(1/0.6)=6.9080.5108=13.5k \ge \dfrac{\ln1000}{\ln(1/0.6)} = \dfrac{6.908}{0.5108} = 13.5, so 1414 steps.

    usenew (momentum numbers)

    For μ=1\mu = 1 and L=400L = 400, give the optimal heavy-ball parameters and the rate, and compare the predicted number of steps with plain descent for a factor 10−610^{-6}.

    Solution

    κ=400\kappa = 400, κ=20\sqrt\kappa = 20. β=(1921)2=0.8186\beta = \big(\frac{19}{21}\big)^2 = 0.8186, η=4(20+1)2=4441=0.00907\eta = \frac4{(20 + 1)^2} = \frac4{441} = 0.00907 (with L+μ=21\sqrt L + \sqrt\mu = 21), rate 1921=0.9048\frac{19}{21} = 0.9048. Steps: ln⁡106ln⁡(21/19)=13.820.1001≈138\frac{\ln10^6}{\ln(21/19)} = \frac{13.82}{0.1001} \approx 138. Plain descent: rate 399401\frac{399}{401}, steps 13.82ln⁡(401/399)=13.820.005000≈2763\frac{13.82}{\ln(401/399)} = \frac{13.82}{0.005000} \approx 2763. The ratio is about 20=κ20 = \sqrt\kappa.

    usenew (SGD)

    An SGD run with η=0.05\eta = 0.05 on a one-parameter least-squares loss has per-example variance σ2=9\sigma^2 = 9. Find the long-run variance of the iterate, and the batch size that brings it below 0.010.01.

    Solution

    Floor =ησ22−η=0.451.95=0.2308= \dfrac{\eta\sigma^2}{2 - \eta} = \dfrac{0.45}{1.95} = 0.2308. With batch size BB: ησ2/B2−η=0.2308B<0.01\dfrac{\eta\sigma^2/B}{2 - \eta} = \dfrac{0.2308}{B} \lt 0.01 needs B>23.1B \gt 23.1, so B=24B = 24.

    usenew (Newton in two variables)

    Do one Newton step for f(x,y)=x2+xy+2y2−3xf(x, y) = x^2 + xy + 2y^2 - 3x from (0,0)(0, 0) and verify that it lands on the minimiser.

    Solution

    ∇f=(2x+y−3, x+4y)\nabla f = (2x + y - 3,\ x + 4y), which at the origin is (−3,0)(-3, 0). H=[2114]H = \begin{bmatrix}2 & 1\\ 1 & 4\end{bmatrix} (constant, positive definite: trace 66, determinant 77). Solve Hs=(3,0)Hs = (3, 0): from the second row s1=−4s2s_1 = -4s_2; the first gives −8s2+s2=3-8s_2 + s_2 = 3, s2=−37s_2 = -\frac37, s1=127s_1 = \frac{12}7. So the new point is (127,−37)\big(\frac{12}7, -\frac37\big). Check: ∇f=(247−37−3, 127−127)=(0,0)\nabla f = \big(\frac{24}7 - \frac37 - 3,\ \frac{12}7 - \frac{12}7\big) = (0, 0). ✓ A quadratic is solved in one step.

    prove

    Prove that gradient descent with η≤1/L\eta \le 1/L on an LL-smooth function satisfies ∑k=0K−1∥∇f(xk)∥2≤2(f(x0)−fmin⁡)η\sum_{k = 0}^{K-1}\lVert\nabla f(x_k)\rVert^2 \le \dfrac{2\big(f(x_0) - f_{\min}\big)}{\eta} if ff is bounded below by fmin⁡f_{\min}, so that min⁡k∥∇f(xk)∥→0\min_k\lVert\nabla f(x_k)\rVert \to 0 at the rate K−1/2K^{-1/2} (no convexity needed).

    Solution

    Plan. Sum the descent lemma over the steps.

    By the descent lemma, f(xk+1)≤f(xk)−η2∥∇f(xk)∥2f(x_{k+1}) \le f(x_k) - \frac\eta2\lVert\nabla f(x_k)\rVert^2. Summing from k=0k = 0 to K−1K - 1 telescopes: f(xK)≤f(x0)−η2∑k=0K−1∥∇f(xk)∥2f(x_K) \le f(x_0) - \frac\eta2\sum_{k = 0}^{K-1}\lVert\nabla f(x_k)\rVert^2. Since f(xK)≥fmin⁡f(x_K) \ge f_{\min}, ∑k=0K−1∥∇f(xk)∥2≤2η(f(x0)−fmin⁡)\sum_{k = 0}^{K-1}\lVert\nabla f(x_k)\rVert^2 \le \frac2\eta\big(f(x_0) - f_{\min}\big). The smallest of the KK terms is at most the average, so min⁡k∥∇f(xk)∥2≤2(f(x0)−fmin⁡)ηK\min_k\lVert\nabla f(x_k)\rVert^2 \le \frac{2(f(x_0) - f_{\min})}{\eta K}. ■\blacksquare For a non-convex loss this is the strongest general statement: the gradient becomes small, though the point need not be near a minimum.

    provenew (unbiasedness)

    Show that the minibatch gradient g=1B∑j=1B∇ℓij(w)g = \frac1B\sum_{j = 1}^B\nabla\ell_{i_j}(w) with the iji_j drawn independently and uniformly from {1,…,N}\{1, \dots, N\} has average ∇ℓ(w)\nabla\ell(w), and in the one-dimensional model of the SGD theorem has variance σ2/B\sigma^2/B.

    Solution

    Plan. Linearity of averages for the mean; independence for the variance.

    For one index, the average of ∇ℓi(w)\nabla\ell_i(w) over the uniform choice is 1N∑i∇ℓi(w)=∇ℓ(w)\frac1N\sum_i\nabla\ell_i(w) = \nabla\ell(w), since the gradient of a sum is the sum of the gradients. A minibatch averages BB such terms, so its average is ∇ℓ(w)\nabla\ell(w). In the model ∇ℓi(w)=w−ai\nabla\ell_i(w) = w - a_i, so the minibatch gradient is w−aˉBw - \bar a_B where aˉB\bar a_B is the average of BB independent samples with variance σ2\sigma^2 each; the variance of an average of BB independent terms is σ2/B\sigma^2/B. ■\blacksquare

    provenew (the stability limit is sharp)

    Show that for f=12λx2f = \frac12\lambda x^2 with λ>0\lambda \gt 0 in one variable, gradient descent converges for every start iff 0<η<2/λ0 \lt \eta \lt 2/\lambda, and for η=2/λ\eta = 2/\lambda it oscillates forever without converging (unless started at 00).

    Solution

    Plan. The update is multiplication by a constant.

    xk+1=xk−ηλxk=(1−ηλ)xkx_{k+1} = x_k - \eta\lambda x_k = (1 - \eta\lambda)x_k, so xk=(1−ηλ)kx0x_k = (1 - \eta\lambda)^kx_0. This tends to 00 for all x0x_0 iff ∣1−ηλ∣<1|1 - \eta\lambda| \lt 1, i.e. 0<ηλ<20 \lt \eta\lambda \lt 2. At ηλ=2\eta\lambda = 2 the multiplier is −1-1 and xk=(−1)kx0x_k = (-1)^kx_0 does not converge for x0≠0x_0 \ne 0. For ηλ>2\eta\lambda \gt 2 the multiplier is below −1-1 and ∣xk∣|x_k| grows. ■\blacksquare

    provenew (Newton is affine invariant)

    Let AA be an invertible n×nn \times n matrix and g(z)=f(Az)g(z) = f(Az). Show that the Newton iterates for gg started at z0z_0 are zk=A−1xkz_k = A^{-1}x_k, where xkx_k are the Newton iterates for ff started at x0=Az0x_0 = Az_0, whereas gradient descent does not have this property.

    Solution

    Plan. Use the chain rule (5.4) for the gradient and the Hessian of gg.

    ∇g(z)=AT∇f(Az)\nabla g(z) = A^{\mathsf T}\nabla f(Az) and Hg(z)=ATHf(Az)AH_g(z) = A^{\mathsf T}H_f(Az)A. The Newton step for gg at zz is −Hg−1∇g=−A−1Hf−1A−TAT∇f(Az)=−A−1Hf(Az)−1∇f(Az)-H_g^{-1}\nabla g = -A^{-1}H_f^{-1}A^{-\mathsf T}A^{\mathsf T}\nabla f(Az) = -A^{-1}H_f(Az)^{-1}\nabla f(Az), so Azk+1=Azk−Hf(Azk)−1∇f(Azk)Az_{k+1} = Az_k - H_f(Az_k)^{-1}\nabla f(Az_k), which is the Newton step for ff at xk=Azkx_k = Az_k. By induction xk=Azkx_k = Az_k. The gradient descent step for gg is −ηAT∇f(Az)-\eta A^{\mathsf T}\nabla f(Az), whose image under AA is −ηAAT∇f-\eta AA^{\mathsf T}\nabla f, not −η∇f-\eta\nabla f unless AAT=IAA^{\mathsf T} = I: changing variables changes the conditioning, and gradient descent notices. ■\blacksquare (Newton’s method does not care about the condition number; this is why preconditioning is an approximation to it.)

    stretchnew (momentum on a one-dimensional quadratic)

    For f(x)=12λx2f(x) = \frac12\lambda x^2 the heavy-ball recursion is xk+1=(1+β−ηλ)xk−βxk−1x_{k+1} = (1 + \beta - \eta\lambda)x_k - \beta x_{k-1}. Take β=0.5\beta = 0.5, ηλ=0.5\eta\lambda = 0.5 and compute x2,x3,x4x_2, x_3, x_4 from x0=x1=1x_0 = x_1 = 1; then show that the rate is β\sqrt\beta when ∣1+β−ηλ∣≤2β|1 + \beta - \eta\lambda| \le 2\sqrt\beta.

    Solution

    Here 1+β−ηλ=11 + \beta - \eta\lambda = 1, so xk+1=xk−0.5xk−1x_{k+1} = x_k - 0.5x_{k-1}. x2=1−0.5=0.5x_2 = 1 - 0.5 = 0.5, x3=0.5−0.5=0x_3 = 0.5 - 0.5 = 0, x4=0−0.25=−0.25x_4 = 0 - 0.25 = -0.25. The condition ∣1∣≤20.5=1.414|1| \le 2\sqrt{0.5} = 1.414 holds, so the roots of z2−z+0.5=0z^2 - z + 0.5 = 0 are 1±i2\frac{1 \pm i}2, of absolute value 0.5=0.707=β\sqrt{0.5} = 0.707 = \sqrt\beta: the sequence rotates and decays, which is the oscillation visible in the numbers (positive, zero, negative). In general for ∣τ∣≤2β|\tau| \le 2\sqrt\beta the roots of z2−τz+βz^2 - \tau z + \beta are complex conjugates (or equal) with product β\beta, hence each has absolute value β\sqrt\beta; the error is a combination of zkz^k and zˉk\bar z^k, so it decays like (β)k(\sqrt\beta)^k (times 1+k1 + k in the double root case).

    stretchnew (the contraction view)

    For f(x)=12x2+ln⁡(1+ex)f(x) = \frac12x^2 + \ln(1 + e^{x}) in one variable, show that gradient descent converges for η=1\eta = 1 using the contraction corollary, and find the contraction constant.

    Solution

    f′(x)=x+ex1+exf'(x) = x + \dfrac{e^x}{1 + e^x} and f′′(x)=1+ex(1+ex)2∈[1,54]f''(x) = 1 + \dfrac{e^x}{(1 + e^x)^2} \in \big[1, \frac54\big] (since ex(1+ex)2≤14\frac{e^x}{(1 + e^x)^2} \le \frac14, with the maximum at x=0x = 0). So μ=1\mu = 1 and L=54L = \frac54, and η=1<2/L=1.6\eta = 1 \lt 2/L = 1.6. The map T(x)=x−f′(x)T(x) = x - f'(x) has T′(x)=1−f′′(x)=−ex(1+ex)2∈[−14,0]T'(x) = 1 - f''(x) = -\dfrac{e^x}{(1 + e^x)^2} \in \big[-\frac14, 0\big], so ∣T′∣≤14|T'| \le \frac14: TT is a contraction with constant ρ=14=max⁡(∣1−μ∣,∣1−L∣)=max⁡(0,14)\rho = \frac14 = \max(|1 - \mu|, |1 - L|) = \max(0, \frac14). By Banach, gradient descent converges to the unique solution of f′(x)=0f'(x) = 0 (here x+ex1+ex=0x + \frac{e^x}{1 + e^x} = 0, near −0.4-0.4), with error at most (1/4)k3/4∣x1−x0∣\frac{(1/4)^k}{3/4}|x_1 - x_0|.

    Summary

    • Gradient descent xk+1=xk−η∇f(xk)x_{k+1} = x_k - \eta\nabla f(x_k) follows the steepest descent direction of 5.2. For an LL-smooth function a step η≤1/L\eta \le 1/L lowers ff by at least η2∥∇f∥2\frac\eta2\lVert\nabla f\rVert^2 (descent lemma).
    • On a quadratic the error is multiplied by I−ηAI - \eta A: it converges iff 0<η<2/L0 \lt \eta \lt 2/L, with rate max⁡(∣1−ημ∣,∣1−ηL∣)\max(|1 - \eta\mu|, |1 - \eta L|), best at η=2L+μ\eta = \frac2{L + \mu} where the rate is κ−1κ+1\frac{\kappa - 1}{\kappa + 1}. The condition number κ\kappa of 3.5 sets the number of steps (about κ2ln⁡1ε\frac\kappa2\ln\frac1\varepsilon), and the path zig-zags because the steep coordinate flips sign at every step. For least squares κ=κ(X)2\kappa = \kappa(X)^2.
    • For any C2C^2 function with Hessian eigenvalues in [μ,L][\mu, L], x↦x−η∇f(x)x \mapsto x - \eta\nabla f(x) is a contraction (Banach, 4.2). For convex smooth ff, f(xk)−f∗≤L∥x0−x∗∥22kf(x_k) - f^* \le \frac{L\lVert x_0 - x^*\rVert^2}{2k}.
    • Momentum xk+1=xk−η∇f(xk)+β(xk−xk−1)x_{k+1} = x_k - \eta\nabla f(x_k) + \beta(x_k - x_{k-1}) with the tuned η,β\eta, \beta improves the rate to κ−1κ+1\frac{\sqrt\kappa - 1}{\sqrt\kappa + 1}: κ\sqrt\kappa steps instead of κ\kappa.
    • Stochastic gradient descent uses one example (or a minibatch) per step; the step is unbiased, the iterate has a noise floor proportional to ησ2/B\eta\sigma^2/B, and steps must decrease (∑ηk=∞\sum\eta_k = \infty, ∑ηk2<∞\sum\eta_k^2 \lt \infty; Robbins and Monro, 1951) to converge exactly.
    • Newton’s method x−H−1∇fx - H^{-1}\nabla f minimises the quadratic model, solves quadratics in one step, is invariant to conditioning, and converges quadratically near a minimiser with invertible Hessian; but it costs n2n^2 memory and n3n^3 time, is not monotone, and is attracted to saddles and maxima.
    • Training a network is gradient descent on a non-convex loss with the gradient from backpropagation (3.8): results depend on the start (one seed in ten failed in the lab).
    • In high dimension, saddle points are far more numerous than minima; near a saddle with weak negative curvature γ\gamma, descent leaves after about ln⁡(1/∣y0∣)ηγ\frac{\ln(1/|y_0|)}{\eta\gamma} steps, so a flat loss curve is not proof of convergence.

    Watch and read

    The same ideas explained by someone else. Use these when an explanation here does not land.

    Where this sits

    Comes from
    3.1 Symmetric matrices and the spectral theorem
    3.5 Matrix norms, conditioning, and why numerics fail
    3.8 Matrix calculus and backpropagation
    4.2 Convergence, completeness and the contraction mapping theorem
    5.3 The total derivative, the Jacobian matrix and tangent planes
    5.6 Taylor's formula, the Hessian and extrema
    5.7 Inverse and implicit functions
    5.8 Constrained extrema and Lagrange multipliers
    Leads to
    15.1 Numerical analysis
    Same idea elsewhere
    MATH 340 / CS 532: Gradient descent, line search, conjugate gradients, Newton and quasi-Newton methods (BFGS) are the first chapters of numerical optimisation. The rate (κ-1)/(κ+1) of this chapter is the one that conjugate gradients improves to (√κ-1)/(√κ+1), the same as momentum.
    MATH 521 / 541: Gradient descent as the fixed-point iteration x to x - η∇f(x) connects to the contraction principle of 4.2, and its continuous-time limit x' = -∇f(x) is a gradient flow, an ODE of the kind studied in Unit 7.
    AI and machine learning: Every neural network is trained by a stochastic variant of this chapter: minibatch SGD with momentum, or Adam, which rescales each coordinate of the gradient. The learning rate is the most important hyperparameter, and its stability limit is 2/L for the largest Hessian eigenvalue L.
    Statistics: Least squares can be solved by the normal equations (2.10) or by gradient descent; the second is what is done when the data matrix has a million columns. The condition number of X^T X is the square of that of X (3.5), which is why standardising the features speeds up training.