English interface, partly translated: navigation, lab, projects, series, about and contact are; the home page sections, the site search and the content itself (articles, tutorials, research) are still in French.

Interactive lab

Gradient descent

Pick a function, a starting point and a learning rate, then watch the point walk downhill: convergence, oscillations, divergence, local minima.

Level
Beginner
Topics
Optimisation · Learning rate · Dérivée
−3 −2 −1 0 1 2 3 0 2 4 6 8 −η·f′(x) x₀
Figure 1 — The point follows the slope downhill. Tangent in orange, next move −η·f′(x) in blue. Iteration 0. Drag the starting point along the curve, or use the x₀ slider.
0 2 4 6 0 5 10 15 20 25 30 35 40 iteration k
Figure 2 — Loss f(xₖ) at each iteration.
Scenarios
Parameters
2.5
0.1
40
8

Diagnosis

Stable convergence. The slope drops below 10⁻³ at iteration 39.

Computation of the iteration k = 0

x0 = 2.5   f(x0) = 6.25   f′(x0) = 5
x1 = x0 − η·f′(x0) = 2.5 − 0.1 × (5) = 2
f(x)=x2f′(x)=2xf(x) = x^2 \qquad f'(x) = 2x
All iterations
Values computed at each iteration
kxkf(xk)f′(xk)
02.56.255
1244
21.62.563.2
31.281.63842.56
41.0241.0485762.048
50.81920.6710891.6384
60.655360.4294971.31072
70.5242880.2748781.048576
80.419430.1759220.838861
90.3355440.112590.671089
100.2684350.0720580.536871
110.2147480.0461170.429497
120.1717990.0295150.343597
130.1374390.0188890.274878
140.1099510.0120890.219902
150.0879610.0077370.175922
160.0703690.0049520.140737
170.0562950.0031690.11259
180.0450360.0020280.090072
190.0360290.0012980.072058
200.0288230.0008310.057646
210.0230580.0005320.046117
220.0184470.000340.036893
230.0147570.0002180.029515
240.0118060.0001390.023612
250.0094458.92·10^−50.018889
260.0075565.71·10^−50.015112
270.0060453.65·10^−50.012089
280.0048362.34·10^−50.009671
290.0038691.5·10^−50.007737
300.0030959.58·10^−60.00619
310.0024766.13·10^−60.004952
320.0019813.92·10^−60.003961
330.0015852.51·10^−60.003169
340.0012681.61·10^−60.002535
350.0010141.03·10^−60.002028
360.0008116.58·10^−70.001623
370.0006494.21·10^−70.001298
380.0005192.7·10^−70.001038
390.0004151.73·10^−70.000831
400.0003321.1·10^−70.000665

Understanding gradient descent

Gradient descent looks for a minimum of a function ff by repeating one simple move: measure the slope, then take a step in the downhill direction.

xk+1=xk−η f′(xk)x_{k+1} = x_k - \eta \, f'(x_k)
  • f′(xk)f'(x_k) is the derivative at the current point: its sign tells which way the function rises, its magnitude how steep the slope is;
  • η\eta (eta) is the learning rate: it sets the length of the step;
  • the minus sign moves against the slope, hence downhill.

In a neural network, xx becomes the vector of all weights and ff the loss function, but the rule is the same, applied to every coordinate.

Why the learning rate decides everything

Take f(x)=x2f(x) = x^2, whose derivative is 2x2x. The update becomes:

xk+1=xk−η⋅2xk=(1−2η) xkx_{k+1} = x_k - \eta \cdot 2x_k = (1 - 2\eta)\,x_k

At each iteration, xx is multiplied by the same factor r=1−2ηr = 1 - 2\eta. The whole behaviour can be read from that factor:

Rate η\eta Factor rr Behaviour
0<η<0.50 < \eta < 0.5 0<r<10 < r < 1 steady convergence, from one side
η=0.5\eta = 0.5 r=0r = 0 minimum reached in a single step
0.5<η<10.5 < \eta < 1 −1<r<0-1 < r < 0 damped oscillations around the minimum
η=1\eta = 1 r=−1r = -1 perpetual oscillation, no progress
η>1\eta > 1 r<−1r < -1 divergence: each step moves away

More generally, for a function of curvature LL (here L=2L = 2), descent is stable as long as η<2/L\eta < 2/L. That is why the same rate can suit one function and make another diverge.

What the demo lets you observe

  1. Stable convergence: a moderate rate brings the point closer to the minimum at each step.
  2. Slow convergence: a tiny rate moves by tiny steps; the iteration budget is not enough.
  3. Oscillations: the point jumps from one side of the minimum to the other while getting closer.
  4. Divergence: beyond the stability bound, the loss grows at every iteration.
  5. Influence of the starting point: on a non-convex function (double well), two different starts lead to two different minima. Gradient descent only finds a local minimum.
  6. Plateau: where the slope is almost zero, so are the steps, whatever η\eta.

Limits and next steps

"Plain" descent is sensitive to curvature: in a narrow valley, it zigzags. Variants with momentum and Adam fix this by remembering past slopes; they are compared in the optimizers demo.

Other demos

  • Optimizers: gradient, momentum, Adam

    Artificial intelligence, Intermediate

    Three optimizers start from the same point on a two-variable surface. Compare their trajectories over the level curves: zigzag, momentum, adaptive step.

  • K-Means step by step

    Artificial intelligence, Beginner

    Assign, update, assign… Follow the centroids until convergence, and discover where K-Means goes wrong: bad start, stretched clusters, rings.

  • Linear regression

    Artificial intelligence, Beginner

    Move the points and watch the least squares line follow. Then learn the same line by gradient descent and compare.