Part I — Calculus, Optimization & Gradients · Chapter 7

Gradient descent

Hook

You know the slope at a point. How do you actually use it to walk downhill to the minimum — and what goes wrong if your steps are too big?

Intuition
Step 0

Each click takes one step: move a little in the direction that decreases ff, based on the slope right where you're standing. Watch the trail of dots — that's the path down.

Formalize

That's gradient descent. Starting from some x0x_0, repeat:

xn+1=xnηf(xn)x_{n+1} = x_n - \eta \, \nabla f(x_n)
  • xnx_n — the current position, before this step.
  • xn+1x_{n+1} — the new position, after taking the step.
  • η\eta — the learning rate: how big a step to take (read "eta").
  • f(xn)\nabla f(x_n) — the gradient evaluated at the current position, pointing uphill.
  1. Eta is the learning rate

    η\eta (eta) is the learning rate — how big a step you take.

  2. Direction versus distance

    The gradient tells you which way is uphill; η\eta decides how far you step away from it.

Play
Step 0 — x = 7.50, ∇f(x) = 11.00

Drag η\eta up and take a few steps. Too small and it crawls; push it high enough and it overshoots the minimum, bouncing back and forth — or worse, flies further away with every step.

Worked example

From x0=5x_0 = 5 with η=0.1\eta = 0.1:

  1. Take the first step
    x1=50.1(254)=50.6=4.4x_1 = 5 - 0.1(2 \cdot 5 - 4) = 5 - 0.6 = 4.4
  2. Take the second step
    x2=4.40.1(24.44)=4.40.48=3.92x_2 = 4.4 - 0.1(2 \cdot 4.4 - 4) = 4.4 - 0.48 = 3.92
  3. Read what happened

    Each step shrinks the distance to the minimum at x=2x^* = 2 by the same factor — that's what a stable learning rate looks like.

Checkpoint

Tune η and take steps until ∇f(x) is within 0.05 of zero — 15 steps or fewer. Too small and you’ll run out of steps; too large and you’ll overshoot.

Step 0 / 15 — ∇f(x) = 11.00
0/15 steps used
Set a learning rate and take a step to try it
Summary
xn+1=xnηf(xn)x_{n+1} = x_n - \eta \, \nabla f(x_n)

Gradient descent repeatedly steps against the gradient. The learning rate η\eta trades off speed against stability: too small converges slowly, too large overshoots or diverges entirely.