The Price of a Nudge
The Price of a Nudge
Scenario
Amber's test kiln has one knob this afternoon: temperature offset , in a unit where is the scheduled cone and is hotter. The energy the studio pays — fuel plus the risk of a bloated glaze — is
They are sitting at . The question is not "what is a derivative?" The question is: if we nudge the knob a tiny bit hotter, how much extra energy do we pay, per unit nudge?
That price is the whole of gradient descent in one dimension. Lesson 2 will call the same price a slope and draw it as an arrow that points uphill. Lesson 3 will walk the other way by a step times that price. Autodiff exists to compute this price when there are knobs. If the 1D price is fuzzy, every later picture is theater.
A few answers look almost right and are wrong:
- — you reported . That is the height of the hill, not the slope. You can stand high with a flat slope, or low with a steep one.
- — you formed a coarse chord from to : . That is a whole cone away. It is a cousin of the price, not the price at .
- — you took the slope as and dropped the linear term . At , . But the linear term is doing four times as much work as the cubic term here.
Keep every term. The exact price of a nudge at is .
Height is not slope
Let us evaluate the kiln's baseline state:
The kiln is currently below its nominal scheduled energy of (at ). That number is a height. It tells you where you stand on the hill, but it does not tell you which way the ground tilts under your boots. You can stand high on a wide plateau where nudging changes nothing, or you can stand at sea level on the edge of a sheer cliff.
Now define the price as a limit, so that "tiny nudge" is a mathematical contract rather than a loose vibe:
The numerator is extra energy. The denominator is the nudge. The ratio is extra energy per unit nudge.
Deriving the slope: expand the cubic
Do not simply recite the power rule as a magic spell. Look at what happens to the cubic term under a nudge :
Now assemble the nudged energy :
Subtract the baseline energy :
Divide by the nudge :
As the nudge shrinks to zero, the terms and vanish completely, leaving the exact instantaneous derivative:
At Amber's operating point :
The negative sign has an immediate physical meaning: a hotter nudge lowers energy. Uphill is to the left (colder). The knob at wants to turn hotter if you want to walk downhill.
At the stationary points where the price is zero:
The second derivative is . At , , so is a local minimum (). At , , so is a local maximum ().
[!IMPORTANT] Zero price means a stationary point, not automatically a bottom. Later in Lesson 4 and Lesson 13 we will encounter two-well landscapes and saddle points where the slope is zero yet you are standing on a ridge.
A chord is a cousin, not a twin
Suppose you do not have an analytical formula for . You only have a black-box kiln that you can query at two temperatures. You choose a nudge width and compute the two-sided difference quotient:
Two-sided differences are vastly superior to one-sided differences. Why? Because the Taylor expansions on both sides cancel the leading error term:
Subtract the two equations: the baseline cancels, and crucially, the quadratic curvature term cancels as well:
Divide by :
For Amber's cubic, the third derivative is constant: . Therefore , giving an exact identity:
The error is not "approximately" ; for any cubic with leading coefficient 1, it is identically !
In contrast, a one-sided chord retains the term. For Amber's kiln at , , so its error is .
The Home Numbers Table
Here is the exact comparison of prices and chords around :
| Quantity | Formula | Numerical Value | Error vs |
|---|---|---|---|
| Hill Height | N/A (different physical unit) | ||
| Instantaneous Price | (exact) | ||
| Two-sided chord () | |||
| Two-sided chord () | |||
| Two-sided chord () | |||
| One-sided chord () | |||
| One-sided chord () |
One timid downhill hop
How do we use this price to train the knob? Gradient descent updates the parameter by subtracting the slope scaled by a small step size :
Amber, being cautious with the studio kiln, picks from :
Notice how the two minus signs interact:
- The formula has a minus sign because we want to go downhill (opposite the gradient).
- The slope is (negative).
- The product is positive (), moving the knob rightward to .
Evaluating the new energy:
The energy fell from to . The hop succeeded.
The Wrong-Sign Disaster
What happens if you accidentally add the slope ()?
Evaluating energy:
Energy rose by toward the local maximum at . You walked uphill. In a production neural network, dropping that minus sign causes the loss to explode immediately.
[!NOTE] How far to hop is Lesson 3's business. In Lesson 3 we will study the learning rate in depth, and in Lesson 5 we will meet the Lipschitz constant that sets its ceiling. Here, we keep fixed solely to verify the direction of descent.
Interactive Workbench: Chord vs Tangent
Explore the relationship between the chord span , chord symmetry, and descent hops in the interactive laboratory below:
OPT-P2-NUDGE
Now examine the physical geometry on the 3D concept rig:
OPT-P2-ANATOMY
Try it: Transfer example
Work this problem on scratch paper before revealing the answer:
Consider the quadratic energy:
- Find the exact derivative .
- Compute the two-sided chord with .
- Compute the one-sided chord with .
- Why is the two-sided chord exact here?
Reveal solution
- Exact derivative:
- Two-sided chord (): Evaluate at and : The two-sided chord gives exactly!
- One-sided chord ():
- Why is the two-sided chord exact? Recall our Taylor error term: . For any quadratic function, and . The third derivative vanishes everywhere! Because there is no cubic or higher-order curvature, the Taylor series terminates, leaving zero chord error.
Runnable code verification
Run this in Python to confirm the calculations and observe machine precision limits:
e = lambda t: t**3 - 3*t + 0.5
de = lambda t: 3*t**2 - 3
print(e(0.5), de(0.5)) # -0.875 -2.25
# Two-sided chord error shrinks as h**2
for h in (0.5, 0.1, 0.01):
two = (e(0.5+h) - e(0.5-h)) / (2*h)
print(f"h={h:<4} chord={two:.6f} error={round(two - de(0.5), 6)} (= h**2)")
# Downhill hop
print("hop landing:", 0.5 - 0.05 * de(0.5)) # 0.6125
# The floor of finite differences: catastrophic cancellation
h_micro = 1e-13
two_micro = (e(0.5 + h_micro) - e(0.5 - h_micro)) / (2 * h_micro)
print(f"h=1e-13: error = {abs(two_micro - de(0.5)):.6e}") # ~4.4e-4 (worse than h=0.01!)
The Floor of Numerical Differentiation
Why does yield an error around , which is hundreds of times worse than ?
At , and agree in their first 13 decimal digits. When you subtract two numbers that agree to 13 digits in standard 64-bit IEEE floating-point arithmetic (which has roughly 15 to 17 digits of mantissa), the leading digits cancel completely. The remaining difference is dominated by round-off noise. Dividing that noise by magnifies the error enormously.
Tiny is a scale, not a personality trait. Finite differences check analytic derivatives at scales like ; pushing to machine epsilon causes catastrophic cancellation.
Failure modes this chapter names
- Reporting height as slope: Confusing where you stand () with the slope of the ground ().
- Dropping a term of : Taking only () and dropping .
- Treating a coarse chord as the derivative: Assuming gives the exact slope ( instead of ).
- Stepping and calling it descent: Walking uphill toward the local maximum.
- Calling a one-sided chord two-sided: Forgetting that one-sided chords carry an error that is much larger than .
Why autodiff is this price, not a second calculus
When the knob is a weight in a neural network, is the training loss, and is "how much extra loss we pay if we nudge ."
Reverse-mode automatic differentiation (backprop) computes every such 1D price in a single backward sweep. It does not invent a brand-new form of calculus. It is the chain rule, scheduled efficiently (which we will formalize in Chapter P5).
The desk problem asks for a two-sided chord with a whole-number so you can do it by hand. Expect it to differ from the exact slope by . The desk problem also does a hop like this on a different cubic. Work that problem on paper and type the integers into the desk quiz.
Next: P3 The Uphill List — what happens when the hill has more than one knob.
