Gradient Descent
Repeatedly stepping against the gradient, , 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 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 by gradient descent from with learning rate . Give the point and after each of two steps. For which learning rates does the -coordinate converge to 0?
Show the worked answer
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.
Needs first
Leads to
- Stochastic Gradient Descent and AdamGradient descent using the gradient of a small random batch instead of all the data, plus momentum and per-parameter step sizes (Adam).Frontier · Optimisation & Information
- Linear Regression as LearningFitting by choosing the parameters that minimise the mean squared error: the simplest model that learns from data.Undergraduate II · Machine Learning
- Reinforcement LearningLearning what to do from rewards alone: an agent acts, sees rewards, and improves its policy to maximise discounted future reward.Frontier · Machine Learning
On the way to
Recommended
- Mathematics for Machine LearningDeisenroth, Faisal and Ong (Cambridge University Press) · BookA free book that gathers exactly the linear algebra, vector calculus, probability and optimisation machine learning uses, then applies them to regression, PCA and classification.
- Convex OptimizationStephen Boyd and Lieven Vandenberghe · BookThe standard text on convex sets, duality and Lagrange multipliers, free as a PDF from Stanford along with lecture slides and exercises.
- Information Theory, Inference, and Learning AlgorithmsDavid MacKay · BookMacKay's book connecting entropy, coding, Bayesian inference and neural networks, free to read online and still the one recommended for information theory with intuition.