SimuVeda/ Mathematics

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.

Class 11–12CollegeBuilds on Class 12 Maths: Application of Derivatives (maxima and minima)

Experiments 0 of 0 Challenge not tried

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.

Related simulators

Worked example

Bowl f = ½(x² + 10y²), so a = 1 and b = 10, starting at (−1.8, 1.5).

Each step multiplies x by (1 − η a) and y by (1 − η b).

η = 0.1: y is multiplied by 0, so it is fixed in one step, but x only by 0.9. After 10 steps x = −1.8 × 0.9¹⁰ ≈ −0.63, still far from 0.

η = 0.15: x shrinks by 0.85 per step (x ≈ −0.35 after 10), and y by −0.5, flipping sign each step: the zig-zag. It still converges.

η = 0.21: y is multiplied by −1.1, growing each step, so it diverges. The limit is η < 2 / max(a, b) = 0.2. Set a = 1, b = 10 and try η = 0.1, 0.15 and 0.21.

Common questions

What is gradient descent?

A way to find a minimum by repeatedly stepping downhill, against the gradient: θ ← θ − η∇f. It is the method used to train most machine-learning models.

How do you choose the learning rate?

Too small and progress is slow; too large and the steps overshoot and diverge. For a quadratic bowl it must be below 2 divided by the largest curvature.

Why does momentum help?

It keeps a running velocity, so steps along a long shallow valley add up while the side-to-side zig-zags cancel out. The minimum is reached in far fewer steps.

Keyboard shortcuts

Space
Play or pause
S
Step
R
Reset
F
Full screen
?
Show this list