SimuVeda

Mathematics · Simulator 046

Gradient Descent

Gradient descent finds a minimum by repeatedly stepping downhill. Pick a landscape and a starting point, set the learning rate, and watch the path. Too small and it crawls; too large and it zig-zags or flies off. Momentum can help it through long narrow valleys.

How the model works

Each step moves against the gradient (the direction of steepest increase):

θ ← θ − η ∇f(θ)

η is the learning rate. With momentum β, the update remembers a running velocity: v ← βv − η∇f, θ ← θ + v.

For a quadratic bowl f = ½(a x² + b y²), plain gradient descent converges only if η < 2 / max(a, b). Above that it diverges. When a and b differ a lot (an ill-conditioned problem), the safe η is set by the steep direction, so progress along the shallow direction is painfully slow. That is the classic zig-zag.

The Rosenbrock “banana” valley and a two-minimum landscape show curved valleys and how the starting point decides which minimum you reach.

Deterministic, full-gradient descent on 2-D toy functions; machine-learning training uses noisy mini-batch gradients in millions of dimensions.

Guided experiments

  1. Stable vs unstable. Bowl with a = 1, b = 10; η = 0.15, then 0.21. Prediction: the limit is 2/10 = 0.2. At 0.15 it zig-zags but converges; at 0.21 the y-oscillation grows and it diverges.
  2. Momentum. Same bowl, η = 0.05, momentum 0.8. Prediction: reaches the minimum in far fewer steps than without momentum (try β = 0).
  3. Which valley? Two minima; start at x = −0.2 vs x = +0.2. Prediction: each start rolls into the nearer basin. Gradient descent finds a local, not necessarily global, minimum.

Challenge

For f(x) = 2x², what is the largest learning rate that still converges? What happens at exactly η = 0.25?

Reveal the explanation

f′(x) = 4x, so the update is x ← x(1 − 4η). It converges when |1 − 4η| < 1, so η < 0.5. At η = 0.25, 1 − 4η = 0, so it jumps to the minimum in a single step: the ideal rate is 1/f″.

References

  • Goodfellow, Bengio & Courville, Deep Learning, §4.3 and §8.3.
  • Boyd & Vandenberghe, Convex Optimization, §9.3.