Derivatives Just in Time
Goal
By the end of this lesson, you can interpret a derivative as local sensitivity, predict its sign from a simple curve, and compare a numerical finite-difference estimate with an exact derivative.
A derivative answers a small-change question
You do not need to begin with a page of calculus symbols.
Start with this question:
If I nudge the input a tiny amount to the right, does the output rise or fall, and how quickly?
That local rate of change is the derivative.
Read derivative sign from a bowl-shaped function
Consider:
f(w) = (w - 3)²
The function is smallest at w = 3.
At w = 1, moving right toward 3 makes the function smaller. The derivative is negative.
At w = 5, moving right moves farther away from 3 and makes the function larger. The derivative is positive.
At w = 3, a tiny movement in either direction increases the function symmetrically, so the derivative is zero.
The exact derivative is:
f'(w) = 2(w - 3)
Now the formula matches the geometry you already reasoned about.
Estimate the derivative numerically
A centered finite difference uses a small step h:
(f(w+h) - f(w-h)) / (2h)
This compares nearby values on both sides of the point.
If h is reasonably small, the estimate should be close to the exact derivative for this smooth function.
If h is huge, you are averaging behavior across a wide region rather than measuring a truly local slope.
Extremely tiny h can also create floating-point precision problems in real numerical code. Gradient checking therefore uses a sensible small scale rather than “as small as possible.”
Compare exact and numerical slopes in the Lab
- Click Run and compare the numerical derivative with
2*(w-3). - Set the evaluation point to
w = 3and predict the sign/value before running. - Try
w = 5and predict the sign again. - Increase the finite-difference step substantially and observe whether the approximation changes.
- Reset the starter afterward.
Loading lab…
How derivative sign connects to gradient descent
Gradient descent subtracts the derivative or gradient.
- negative derivative → subtracting it moves the parameter upward;
- positive derivative → subtracting it moves the parameter downward;
- near-zero derivative → the local update becomes small.
For this bowl-shaped function, those movements point toward the minimum at 3.
Debugging derivative code
When a derivative estimate looks wrong, check:
- the function you are differentiating;
- the evaluation point;
- the step size;
- subtraction order;
- whether you are comparing the same scalar objective.
Reversing f(w+h) - f(w-h) flips the estimated sign, which can reverse a training update.
Read a derivative as a local sensitivity
Suppose a small change in w from 2.00 to 2.01 changes loss from 4.00 to about 4.06.
A rough local sensitivity is:
change in loss / change in w
≈ 0.06 / 0.01
≈ 6
That does not mean increasing w by 1 will always increase loss by exactly 6. A derivative describes the slope near the current point.
This local nature is why gradient descent takes repeated steps and recomputes gradients after parameters move.
Sign and magnitude answer different questions
- positive derivative: increasing the variable locally raises the output;
- negative derivative: increasing the variable locally lowers the output;
- large magnitude: the output is locally sensitive to that variable;
- near zero: small local movement has little first-order effect.
Do not interpret a zero derivative as “this parameter can never matter.” Nonlinear networks can have regions where a local slope is zero even though the parameter affects behavior elsewhere.
Quick Check
Key Takeaways
- A derivative measures local sensitivity.
- Its sign tells whether the function locally rises or falls as the input increases.
- Finite differences provide an independent numerical gradient check.
- Derivative signs explain gradient-descent update direction.
Next Lesson
Next, you will compute the local derivative pieces in code, combine them, and verify that one parameter update moves loss in the predicted direction.
References
- PyTorch, Autograd.
Completion is stored locally on this device.