Gradient descent

Level UniversityDifficulty ★★★★★Application⌖ Open in the map

What is it?

Repeat θ←θ−η ∇L(θ)\theta \leftarrow \theta - \eta\,\nabla L(\theta): take a small step against the gradient. Cauchy proposed it in 1847; today it (and its stochastic, adaptive variants) trains essentially every neural network.

Why does it exist?

Setting ∇L=0\nabla L = 0 and solving is impossible for a network with millions of parameters and a non-linear loss. But evaluating ∇L\nabla L at one point is cheap (backpropagation), and the gradient says which direction decreases the loss fastest. Iterate.

Intuition

A ball rolling downhill in fog, one step at a time. The learning rate η\eta is the step length: too small and it crawls; too large and it overshoots, bouncing between valley walls or flying off. In a narrow valley the gradient points across the valley rather than along it, so the path zigzags — try the elongated bowl in the demo.

Formal definition

θk+1=θk−η ∇L(θk).\theta_{k+1} = \theta_k - \eta\,\nabla L(\theta_k).

If ∇L\nabla L is LL-Lipschitz and η≤1/L\eta \le 1/L, then L(θk+1)≤L(θk)−η2∥∇L(θk)∥2L(\theta_{k+1}) \le L(\theta_k) - \frac\eta2\norm{\nabla L(\theta_k)}^2 (descent lemma): the loss decreases at every step and min⁡j≤k∥∇L(θj)∥2=O(1/k)\min_{j\le k}\norm{\nabla L(\theta_j)}^2 = O(1/k). If LL is μ\mu-strongly convex, convergence is linear with rate 1−μ/L1 - \mu/L.

Formulas

θk+1=θk−η ∇L(θk)\theta_{k+1} = \theta_k - \eta\,\nabla L(\theta_k)
L(θ−ηg)≈L(θ)−η ∥g∥2(g=∇L)L(\theta - \eta g) \approx L(\theta) - \eta\,\norm{g}^2 \quad (g = \nabla L)
why it works: first-order Taylor

How is it computed?

θ = initial guess
for k in 1..K:
    g = ∇L(θ)          # backpropagation
    θ = θ − η · g
    if ‖g‖ < tol: break

Interactive visualization

Click anywhere to drop the ball there. Colour is height (log scale), lines are level curves; the gradient is perpendicular to them. Try the narrow valley with plain gradient descent, then with momentum.

Why does it matter?

It is the inner loop of the AI industry: trillions of gradient steps per day. Every optimizer used in practice (SGD, momentum, Adam) is a modification of this one line.

The mathematics behind it

  • Derivative★★★★★fundamental

    Each step moves the parameter against the derivative of the loss: w←w−η L′(w)w \leftarrow w - \eta\,L'(w).

  • Gradient★★★★★fundamental

    The update θ←θ−η∇L(θ)\theta \leftarrow \theta - \eta\nabla L(\theta) is the gradient, used as a direction.

  • Lipschitz continuity★★★★★fundamental

    The safe learning rate is set by the Lipschitz constant of the gradient: η<2/L\eta < 2/L.

  • Convergence of sequences★★★★★frequent

    Convergence theorems guarantee f(xk)→f∗f(x_k) \to f^\ast under conditions on the step size.

  • Critical points and derivative tests★★★★★fundamental

    Gradient descent stops where the derivative vanishes — at a critical point.

  • Order of convergence★★★★★frequent

    On strongly convex problems GD converges linearly, at a rate set by the condition number L/μL/\mu.

  • Taylor polynomial★★★★★fundamental

    The first-order model f(x−ηg)≈f(x)−η∥g∥2f(x - \eta g) \approx f(x) - \eta\norm g^2 is why a small step downhill decreases ff.

  • Directional derivative★★★★★fundamental

    Among unit steps, u=−∇f/∥∇f∥u = -\nabla f/\norm{\nabla f} minimizes DufD_u f: the justification of the method.

  • Euler's method★★★★★advanced

    GD is explicit Euler on θ˙=−∇L\dot\theta = -\nabla L; the learning rate is the time step and inherits its stability limit.

  • Equilibria and stability★★★★★advanced

    Strict minima are stable fixed points of GD exactly when η<2/λmax⁡(H)\eta < 2/\lambda_{\max}(H).

  • Monotone and bounded sequences★★★★★frequent

    With a small enough step the loss decreases monotonically and is bounded below, so the loss values converge.

  • Mean value theorem★★★★★advanced

    Convergence proofs bound the decrease per step with the MVT applied to the gradient.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

Exercises

1AI

For L(θ)=a2θ2L(\theta) = \frac a2\theta^2, show that GD converges iff 0<η<2/a0 < \eta < 2/a. What happens at η=1/a\eta = 1/a?

Solution

θk+1=(1−ηa)θk\theta_{k+1} = (1 - \eta a)\theta_k, which tends to 0 iff ∣1−ηa∣<1|1 - \eta a| < 1. With η=1/a\eta = 1/a it jumps to the minimum in one step.

↑ ↓ to navigate · ↵ · Esc