Partial derivatives & the gradient
Step 9 of 18 in Foundations · Concept · Easy
With many inputs, each partial derivative is the slope along one axis; together they form the gradient, the direction of steepest increase.
The lesson
With several inputs, a partial derivative is the slope along one of them with the others held still. Stack all the partials into a vector and you have the gradient, ∇f.
The gradient points in the direction where f rises fastest, and its length says how steep that is. So −∇f is the fastest way down. Gradient descent is nothing more than stepping along −∇f repeatedly.
- ∂f/∂x = 2x = 2 (y treated as a constant)
- ∂f/∂y = 6y = 12 (x treated as a constant)
- ∇f = [2, 12]. Here f rises six times faster along y. To go downhill, step along [−2, −12].
The gradient is perpendicular to the contour lines. Along a contour f does not change, so the steepest direction has no part along it.
Common mistake. The gradient is not one slope. It is a vector with one entry per input. A model with a million weights has a gradient with a million entries, one nudge per weight.
Check yourself
f(x, y) = x²y. What is ∂f/∂x at (3, 2)?
Show the answer
12. Treat y as a constant: ∂f/∂x = 2xy = 2·3·2 = 12.
Same f. What is ∂f/∂y at (3, 2)?
Show the answer
9. Treat x as a constant: ∂f/∂y = x² = 9.
To reduce f as fast as possible from where you stand, move along:
- ∇f
- a direction perpendicular to ∇f
- −∇f
Show the answer
−∇f. ∇f is steepest ascent, so its negative is steepest descent. Perpendicular to it you move along a contour and f does not change.
Build it
Gradient field
Compute and plot the gradient arrows of f(x, y) = x² + 3y² on a grid, over its contour plot.
Done when: Arrows point uphill and are perpendicular to contour lines.
Resources
Earn this star
On the map, your answers are marked and you log what you built. Finish the step and its star lights.
Open this step on the map