Advanced Mathematics

Gradient Descent

Repeatedly stepping against the gradient, x⃗←x⃗−η∇f\vec x \leftarrow \vec x - \eta\nabla f, to walk downhill towards a minimum.

Needs a step first: 12

The gradient points uphill, so gradient descent keeps taking small steps against it, with a learning rate η\eta that sets the step size. Too small and it crawls; too large and it overshoots and can blow up, and the safe size depends on the steepest curvature. In long narrow valleys it zig-zags, which is what momentum and Adam were invented to fix. It is the engine of all model training: linear regression, neural networks and transformers are all fitted this way.

Where it shows up: Every learning method on this map, from linear regression to attention, is trained by some form of gradient descent.

How to hold it: Give it to the machine, then check

Let the computer run the iterations; your part is choosing the learning rate, knowing what too small and too large look like, and checking that the loss falls steadily to a sensible value.

What knowing it looks like

  • Carry out two steps of gradient descent on a two-variable function by hand.
  • Find the largest learning rate for which gradient descent on a quadratic still converges.
  • Explain from contour lines why it zig-zags in a narrow valley.

Test yourself

Minimise f(x,y)=x2+4y2f(x, y) = x^2 + 4y^2 by gradient descent from (2,1)(2, 1) with learning rate η=0.1\eta = 0.1. Give the point and ff after each of two steps. For which learning rates does the yy-coordinate converge to 0?
Show the worked answer
∇f=(2x,8y)\nabla f = (2x, 8y). Start: f=8f = 8. Step 1: gradient (4,8)(4, 8), new point (2−0.4, 1−0.8)=(1.6,0.2)(2 - 0.4,\ 1 - 0.8) = (1.6, 0.2), f=2.56+0.16=2.72f = 2.56 + 0.16 = 2.72. Step 2: gradient (3.2,1.6)(3.2, 1.6), new point (1.28,0.04)(1.28, 0.04), f=1.6384+0.0064=1.6448f = 1.6384 + 0.0064 = 1.6448. Each step multiplies yy by 1−8η1 - 8\eta, so y→0y \to 0 exactly when ∣1−8η∣<1|1 - 8\eta| < 1, that is 0<η<0.250 < \eta < 0.25. The steep direction sets the limit.

Needs a step first: 12

Learn it with an AI

Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.

Be my maths tutor. I'm learning "Gradient Descent" (Undergraduate I tier): Repeatedly stepping against the gradient, $\vec x \leftarrow \vec x - \eta\nabla f$, to walk downhill towards a minimum.
I already know: Optimisation in Many Variables.
Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away.
Finish by testing me with this: Minimise $f(x, y) = x^2 + 4y^2$ by gradient descent from $(2, 1)$ with learning rate $\eta = 0.1$. Give the point and $f$ after each of two steps. For which learning rates does the $y$-coordinate converge to 0?
Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.

On the way to

Recommended