The Geometry of Gradient Descent
Why the negative gradient is the direction of steepest descent — and what the learning rate is really controlling.
- optimization
- calculus
- machine-learning
Gradient descent is the workhorse of modern machine learning, and yet the reason it works is a single, elegant fact from multivariable calculus. This note walks through that fact from the ground up.
The setup
We want to minimize a differentiable loss over parameters . Starting from a point , we take a small step and ask how the loss changes. A first-order Taylor expansion gives
where is the gradient — the vector of partial derivatives .
Why the negative gradient?
We want to choose the step direction that decreases as fast as possible. Restricting to unit-length directions , the change in loss is the inner product . By the Cauchy–Schwarz inequality,
with equality exactly when points opposite the gradient:
Steepest descent
Among all unit-norm directions, the negative gradient produces the most negative first-order change in the loss. That is the whole justification for the update rule below.
Scaling that direction by a step size gives the familiar update:
The update loop
In code
The whole algorithm is a handful of lines. Everything interesting lives in the
grad function you pass in.
import numpy as np
def gradient_descent(grad, theta, lr=0.1, steps=100):
"""Minimize a function given its gradient."""
history = [theta]
for _ in range(steps):
theta = theta - lr * grad(theta)
history.append(theta)
return theta, np.array(history)Choosing the learning rate
The step size is the one knob that decides whether the iteration converges at all.
| Regime | Behaviour |
|---|---|
| too small | slow, creeping convergence |
| well-tuned | steady, monotone descent |
| too large | overshoot, oscillation, blow-up |
The learning rate is the single hyperparameter that can turn a clean convergence proof into a divergence in practice.
For a convex, -smooth loss, any fixed guarantees the loss never increases — a rare and reassuring guarantee in a field with few of them.