Machine Learning

Gradient Descent — Optimization (Explained)

Watch gradient descent find a minimum — and fail to. Compare plain gradient descent, momentum, Nesterov, RMSProp and Adam on bowls, narrow valleys, the Rosenbrock banana, Himmelblau's four minima and a saddle point; change the learning rate and starting point and see paths, divergence and loss curves.
Runs in your browserInteractive

Narrow valley: x² + 10y²

Ill-conditioned: plain gradient descent zig-zags; momentum and Adam cope better.

100

Settings

0.05
100

Start: (-1.80, 1.20)

Results

OptimiserFinal pointf(x, y)Distance to nearest minimumStatus
Gradient descent(-0.0000, 0.0000)2.286e-94.78e-5Converged
Momentum (β = 0.9)(-0.0067, 0.0016)7.153e-56.92e-3Not there yet
Adam (β₁ = 0.9, β₂ = 0.999)(-0.0024, -0.0036)1.337e-44.33e-3Not there yet
17.642.3e-9stepf(x, y) (log scale)

How to use this tool

  1. 1Choose a function; the cross marks its minimum (or minima).
  2. 2Click the map to choose a starting point (orange).
  3. 3Pick the optimisers to compare and set the learning rate and number of steps.
  4. 4Scrub through the steps and compare the loss curves; too large a learning rate makes a method diverge.

Frequently asked questions

Yes. The update rules match PyTorch’s torch.optim (SGD with momentum and Nesterov, RMSprop with ρ = 0.9, Adam with β₁ = 0.9 and β₂ = 0.999), step for step.

If the learning rate is too large for the steepness of the function, each step overshoots the minimum by more than the last. On x² + 10y² this happens when the learning rate exceeds 0.1.

Non-convex functions such as Himmelblau’s have several valleys; gradient methods only follow the slope downhill from where they start.

No. Everything is calculated in your browser; nothing you enter is sent to MuhammadLab.