CalculusLesson 6 of 6
Partial derivatives and gradients
Partial derivatives and gradients
A surface has no single slope
Section titled “A surface has no single slope”A function can depend on several inputs. For , changing x and changing y generally have different effects. A partial derivative measures one of those effects while holding the other input fixed.
Freeze all but one
Section titled “Freeze all but one”Hold every input still except one. That cuts a slice through the surface, and the slice is an ordinary curve.
Stand at , where . Freeze : the slice is , with slope at . Freeze : the slice is , a line of slope 5.
These are the partial derivatives, written with a curly :
The notation means: “every other input was treated as a constant.” Differentiate as usual; the frozen inputs ride along like numbers. The common slip is to forget they are there. The -slope of is , not .
Check with an actual input change: . Predicted: .
Small changes add
Section titled “Small changes add”Change both inputs, by and by . For a differentiable function, evaluate both partial derivatives at the starting point. Their contributions add to give the first-order prediction:
A differentiable surface is locally approximated by a plane, tilted by the two partials. Two numbers predict the change in every direction. At with : predicted . Actual: .
The arrow that points uphill
Section titled “The arrow that points uphill”Stack the partials into a vector, the gradient:
The prediction above is a dot product: . A dot product is largest when the two vectors point the same way. For steps of a fixed length, the first-order predicted rise is largest along the gradient.
- The gradient points steepest uphill. Its length, at , is that steepest slope.
- Against it is steepest downhill.
- Perpendicular to a nonzero gradient, the directional derivative is zero. This direction is tangent to the contour through the point; a finite straight step may still change the function.
- For comparison, east 3 and north 4 make a gradient of length 5. Northeast is the unit step , so the slope is . More than either axis, less than the 5 available along the gradient.
Flat spots, and walking downhill
Section titled “Flat spots, and walking downhill”At an interior local minimum of a differentiable function, every slice is flat, so . That is setting the derivative to zero with many inputs. When solving for the minimum directly is impractical, we can try a gradient step:
The linear approximation predicts . When the gradient is nonzero, a sufficiently small step therefore decreases a differentiable loss. This update is gradient descent; neural-network optimizers often use variants of it. Backpropagation computes the gradients those updates need.
Go deeper: the definition, and a warning
Formally, , with never moving. One piece of fine print: having both partials does not by itself make the surface a valid linear approximation at that point. A function can have both partial derivatives at a point without being differentiable there. Continuous partial derivatives in a neighborhood of the point guarantee this linear approximation. The polynomial used here satisfies that condition.
Connect this to fitting a model
Section titled “Connect this to fitting a model”The complete dataset example applies the same gradient update to an actual squared-error loss. Backpropagation explains how to calculate those derivatives through many operations.
Use the reference to look up notation and rules. In practice, choose a rule, calculate a derivative or integral, and interpret what the answer means.