Math

Gradient Descent

Gradient descent follows the negative gradient to minimize a function. Adjust the learning rate and see how step size changes convergence.

7 minLevel 3/3The interactive stage stays ad-free.
x2.500f(x)6.250Steps0Learning rate0.25

x_new = x − η·f′(x) = 2.50 − 0.25 × (5.00) = 1.25

Drag the ball or use arrow keys to choose a start.

The ball follows the negative slope. The dashed tangent and ghost point show the next update. Small rates crawl, a well-chosen rate settles, and a rate that is too large overshoots or diverges. Drag the ball, click the curve, or focus the canvas and use the arrow keys to choose a start.

What you are seeing

1

The curve is a loss function. The goal is to find the lowest point.

2

At each step, the algorithm computes the slope and moves in the opposite direction.

3

A learning rate that is too small crawls; too large overshoots or diverges. Momentum can smooth the path.

Why it matters

Gradient descent is the workhorse of machine learning. Neural networks, logistic regression, and many optimization problems are trained with variants of this idea.

Complexity & details

Each step costs O(d) for d parameters. Convergence depends on the learning rate and the function’s curvature.

Frequently asked questions

What happens if the learning rate is too high?+

The steps can jump over the minimum, oscillate, or diverge entirely. A smaller rate is safer but slower.

Why use momentum?+

Momentum accumulates past gradients to smooth noisy updates and accelerate through flat regions.