Your training loss falls for three steps, then climbs, then prints nan. You halve the learning rate and the same run settles. One number separates those two runs, and this week finds it. The bowl below is the loss , and the amber path is gradient descent from .
A bowl-shaped loss surface f(x, y) = (x² + 4y²) / 2 with its minimum at the origin. Gradient descent starts at (2.6, 1.4) with step size η = 0.375. It takes 16 steps and overshoots in y and zigzags in.
Drag the step size and watch the path. Below it slides down without overshoot. Between and it zigzags across the narrow direction and still lands. At it bounces forever, and past it it climbs the wall and leaves the bowl.
Why the line sits at 2/L#
The gradient of the bowl is , so one step of size maps and . The caption prints both factors. A coordinate shrinks only when its factor has magnitude below 1. For that needs , so . The steepest curvature, 4, sets the limit.
Smoothness: a curvature limit for any function#
A general loss has no single curvature. Smoothness puts a ceiling on it. A differentiable is -smooth if its gradient is -Lipschitz:
For with , the gradient is , and . So . The bowl has and , the curvature of its narrow direction.
Smoothness gives a quadratic upper bound:
With the linear lower bound of convexity (Week 2), a convex -smooth function lies between a plane and a bowl of curvature .
The descent lemma#
Put the step into the upper bound:
The bracket is positive when . That is the line you crossed in the bowl, now for every -smooth function. Past the bound promises nothing, and the bowl diverges. The term is largest at , which gives
This is the descent lemma. Each step removes at least of loss while the gradient is nonzero.
Convergence for convex smooth functions#
Start at with distance to an optimum . After steps of size on a convex -smooth function:
This is the sublinear rate. To halve the gap, you double the iterations. To reach accuracy , you need iterations.
Strong convexity and the condition number#
A function is -strongly convex if, for some ,
For a quadratic, . The bowl has , so its condition number is . The level sets are ellipses with axis ratio .
With step , GD converges linearly (Nesterov 2004, Theorem 2.1.15):
The error shrinks by a fixed factor every step, so accuracy costs iterations.
Worked example. For the bowl, , which is on the slider. The factors are for and for . Both have magnitude . Now compare . It sends to 0 in one step but leaves at factor . After 10 steps, keeps of its start, against . The fastest step balances the flat direction against the steep one, and it is not .
Large is the hard case. For , and the best factor is . GD then needs about 115 steps to cut the error by a factor of 10. Adding to a convex objective makes it -strongly convex, which raises , lowers , and is why ridge regression (Week 4) converges faster than plain least squares. Momentum (Week 7) cuts the cost to . Advanced Optimization goes further.
Knowledge Check#
If L = 10, the descent lemma guarantees a loss decrease for every step size η below ___.
In the bowl, set the step size to 2.1/L. Which coordinate leaves the bowl, and why?
Browser lab: step sizes and the 2/L boundary#
Run GD on 1D quadratic with . Compare (largest guaranteed decrease) vs (near-divergence) vs (divergence).
import numpy as np
import matplotlib.pyplot as plt
a = 5.0
L = 2 * a
x0 = 4.0
K = 20
def run_gd(eta, x0, K):
x = x0
vals = [a * x**2]
xs = [x]
for _ in range(K):
g = 2 * a * x
x = x - eta * g
xs.append(x)
vals.append(a * x**2)
return np.array(xs), np.array(vals)
etas = [0.5/L, 1/L, 1.8/L, 2.1/L]
labels = ["η=0.5/L", "η=1/L", "η=1.8/L (osc)", "η=2.1/L (diverge)"]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4.5))
ks = np.arange(K + 1)
for eta, lbl in zip(etas, labels):
xs, vals = run_gd(eta, x0, K)
ax1.plot(ks, vals, "o-", markersize=3, label=lbl)
ax2.plot(ks, np.abs(xs), "o-", markersize=3, label=lbl)
print(f"{lbl:18s} final |x| = {abs(xs[-1]):.3e} final loss = {vals[-1]:.3e}")
ax1.set_xlabel("Iteration k"); ax1.set_ylabel("f(x_k)")
ax1.set_title(f"Loss vs iteration (L={L})")
ax1.set_yscale("log"); ax1.legend()
ax2.set_xlabel("Iteration k"); ax2.set_ylabel("|x_k|")
ax2.set_title("Distance to optimum")
ax2.set_yscale("log"); ax2.legend()
plt.tight_layout()
plt.show()
print("Notice: η ≤ 2/L decreases the loss at every step; past 2/L the iterates oscillate and eventually diverge.")
Key takeaways#
- The step size limit comes from the steepest direction. In the bowl, has factor and leaves once .
- -smoothness bounds curvature. The descent lemma follows: every step with decreases the loss.
- Convex and -smooth gives the sublinear rate . Strong convexity upgrades it to a linear rate with factor .
- The fastest constant step, , balances the flat and the steep direction. It is not .
Further reading#
- Yurii Nesterov, Introductory Lectures on Convex Optimization (Springer, 2004). Chapter 2 defines smoothness and strong convexity and derives the basic gradient-method rates.
- Sébastien Bubeck, Convex Optimization: Algorithms and Complexity (2015). Sections 3.1–3.2 prove the and linear rates for smooth (strongly) convex GD. Freely available at arXiv:1405.4980.
- Jorge Nocedal & Stephen Wright, Numerical Optimization (2nd ed., Springer, 2006). Chapter 3 collects the step-size and convergence theory used here.
Reading is free. PDF and ePub unlock with the newsletter. Join once and every lesson opens in this browser.