S1426 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S14 · Lesson 26 · Training networks

Gradient descent on a quadratic bowl, the largest stable learning rate and the best one, how the condition number sets the convergence rate, momentum, stochastic minibatch gradients and their noise, and Adam with its bias correction

Backpropagation gives the gradient; something still has to walk downhill. Plain gradient descent is simple and, near a minimum, its behavior can be predicted exactly: the error surface looks like a quadratic bowl, each direction converges at its own rate, and one badly shaped direction can slow everything or make the whole run explode. Momentum and adaptive methods like Adam exist to fix that, and minibatches make each step cheap at the cost of noise. These are the knobs every training run turns.

  • Gradient descent on E=12(λ1w12+λ2w22) with λ1 = 1 and an adjustable λ2. Each weight evolves as wk=(1−ηλ)kw0.
  • Raise η and the steep direction (λ2) starts to oscillate, then diverges once η>2/λ2. Lower it and the shallow direction crawls.
  • The best compromise is η=2/(λ1+λ2), and even then the slow rate is (κ−1)/(κ+1) for condition number κ=λ2/λ1.

Predict

A quadratic bowl has curvatures 1 and 100. With the best fixed learning rate, roughly how many gradient-descent steps reduce the error in every direction by a factor of a million?

Name it

Gradient descent near a minimum

Near a minimum, E≈E0+12Δ𝐰THΔ𝐰. In the Hessian's eigenvector directions, the update 𝐰←𝐰−η∇E multiplies each component by 1−ηλi every step.

  • Stability needs |1−ηλi|<1 for all i: η<2/λmax⁡.
  • The best fixed rate is η=2/(λmin⁡+λmax⁡), giving a factor (κ−1)/(κ+1) per step with κ=λmax⁡/λmin⁡.

Badly conditioned problems (large κ) converge slowly, which is why inputs are normalized and why tricks like batch normalization help.

Momentum

The heavy-ball update keeps a velocity: 𝐯←μ𝐯−η∇E, 𝐰←𝐰+𝐯. Tuned on a quadratic, its factor improves to (κ−1)/(κ+1).

Stochastic gradients

Stochastic gradient descent estimates the gradient from a minibatch of B examples. If single-example gradients have standard deviation σ, the minibatch average has σ/√B: cheaper steps, more noise. A decaying learning rate tames the noise near the end.

Adam

Adam keeps exponential averages of the gradient, m←β1m+(1−β1)g, and of its square, v←β2v+(1−β2)g2, and steps by ηm^/(v^+ϵ). Both averages start at 0, so they're divided by 1−βt after t steps (bias correction). The step size is then about η in every direction, whatever the gradient's scale: a per-weight normalization that eases bad conditioning.

Worked example

For curvatures 1 and 100, find the stability limit and the best rate, and what happens at η = 0.015.

Show the solution
  1. Stability limit. η<2/100=0.02
  2. Best rate. η=2/101=0.0198
  3. Factors at η = 0.015. The steep direction's factor (fast, oscillating decay), then the shallow one's: 1−1.5=−0.51−0.015=0.985
  4. Steps needed. The shallow direction dominates: 915 steps for 10−6.

Answer the stability limit is η = 0.02 and the best rate 0.0198; at η = 0.015 the shallow direction sets the pace, taking 915 steps to reach 10−6.

Worked example

With Adam's β₁ = 0.9 and β₂ = 0.999, what are m and v after one step with gradient g, and what step results?

Show the solution
  1. Moments after one step. m=0.1g,v=0.001g2
  2. Step without correction. η×0.1g0.0316|g|=3.16ηsign(g)
  3. Bias correction. It divides m by 0.1 and v by 0.001, giving m̂ = g and v̂ = g², and a step of exactly ηsign(g) (for small ε).

Answer m = 0.1g and v = 0.001g², and the corrected step is exactly η sign(g), against 3.16η sign(g) without correction.

Worked example

Gradient descent on a quadratic starts from zero with η = 0.01 and stops after 1000 steps. What fraction of the solution has it learned along directions of curvature 1 and 0.01? Compare with ridge regression at λ = 1/(kη) = 0.1.

Show the solution
  1. Gradient descent. Along an eigendirection of curvature c, each step closes a fraction ηc of the remaining gap, so after k steps the fraction learned is 1−(1−ηc)k
  2. The two directions. For c = 1 and c = 0.01: 1−0.991000=0.999961−0.99991000=0.095
  3. Ridge. Ridge keeps c/(c+λ): 1/1.1=0.9090.01/0.11=0.091
  4. Compare. Both learn the well-determined direction and suppress the poorly determined one by about the same amount, so stopping early acts as a regularizer with λ≈1/(kη), and the number of steps is a hyperparameter to choose on validation data.

Answer gradient descent has learned 0.99996 of the solution along curvature 1 and 0.095 along curvature 0.01, against ridge's 0.909 and 0.091.

Check

The Hessian's largest eigenvalue is 50. What's the largest learning rate for which gradient descent is stable?

Check

The Hessian's eigenvalues run from 2 to 20. What fixed learning rate converges fastest?

Check

A problem has condition number 100. With the best fixed learning rate, how many gradient-descent steps reduce the error by a factor of 0.001?

Check

With well-tuned momentum, what factor per step does gradient descent achieve on a quadratic with condition number 100?

Check

Adam's first-moment average starts at 0 with β₁ = 0.9. After 20 steps with constant gradient 0.2, what's the uncorrected m?

Check

Single-example gradients have standard deviation 2. What's the standard deviation of a minibatch gradient over 16 examples?

Check

Gradient descent with rate 0.01 runs 1000 steps from zero on a quadratic.

(a)

What fraction of the solution has it learned along a direction of curvature 0.1?

(b)

What fraction would ridge regression with λ = 1/(kη) keep along that direction?

Check

A quadratic's Hessian eigenvalues run from a to b; gradient descent uses heavy-ball momentum.

Step 1

What learning rate is optimal?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why does a badly conditioned error surface slow gradient descent, and how do momentum and Adam help?

Practice

Keep practicing

10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.