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 with = 1 and an adjustable . Each weight evolves as .
- Raise η and the steep direction () starts to oscillate, then diverges once . Lower it and the shallow direction crawls.
- The best compromise is , and even then the slow rate is for condition number .
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?
The best rate, η = 2/101, gives both directions the factor (κ − 1)/(κ + 1) = 99/101 = 0.980 per step. Reducing by takes ln(10⁻⁶)/ln(0.980) = 691 steps. Momentum improves the factor to (√κ − 1)/(√κ + 1) = 9/11, about 69 steps: ten times fewer.
Name it
Gradient descent near a minimum
Near a minimum, . In the Hessian's eigenvector directions, the update multiplies each component by every step.
- Stability needs for all i: .
- The best fixed rate is , giving a factor per step with .
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: , . Tuned on a quadratic, its factor improves to .
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, , and of its square, , and steps by . Both averages start at 0, so they're divided by 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
- Stability limit.
- Best rate.
- Factors at η = 0.015. The steep direction's factor (fast, oscillating decay), then the shallow one's:
- Steps needed. The shallow direction dominates: 915 steps for .
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 .
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
- Moments after one step.
- Step without correction.
- Bias correction. It divides m by 0.1 and v by 0.001, giving m̂ = g and v̂ = g², and a step of exactly (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
- 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
- The two directions. For c = 1 and c = 0.01:
- Ridge. Ridge keeps :
- 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 , 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°.
Step 2
What momentum coefficient goes with it?
Explain why
Why does a badly conditioned error surface slow gradient descent, and how do momentum and Adam help?
Gradient descent uses one learning rate for every direction, and that rate must stay below 2/λ for the steepest direction or the run diverges. Directions with small curvature then move by only a small fraction of their distance each step, so convergence is set by the ratio of the largest to the smallest curvature. Momentum accumulates velocity along directions where the gradient keeps pointing the same way, so shallow directions speed up while oscillations in steep ones partly cancel, improving the rate from depending on κ to depending on √κ. Adam rescales each weight's step by its own gradient magnitude, which acts like a per-weight learning rate and compensates for curvatures that differ along the coordinate axes.
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.