M0.3 A Drifting Thermometer: Total Derivatives, Integral Differentiation, and JVPs
Builds on2 notes
The reading increased
A thermometer on a floating buoy reports a rise from 18.0 to 18.6 degrees over ten minutes.
Did the river warm up?
Perhaps the buoy merely drifted into a warmer region. How can we distinguish temporal warming from spatial movement?
As with Taylor approximation, examine the separate input changes over a short interval.
DiscussionQ1
Which functions compose the reading, and which contributions do we want to separate?
Show the reasoning
Treating temperature only as a function of time hides the moving location.
There are two functions: a field and a path . The field varies both across space and over time.
The reported reading is their composition .
We want to split its derivative into fixed-location change and movement through different temperatures. This is the multivariable chain rule.
Walking on an escalator
Your height rises because the escalator moves and because you walk. The two rates add.
A measurement of the total alone cannot identify both contributions. Independently measuring one permits recovering the other.
Fixed-location warming corresponds to escalator motion; drifting across the temperature field corresponds to walking.
Figure: total change combines a time partial derivative and a spatial directional derivative.
Express the two contributions
For a differentiable field and differentiable path,
The partial derivative holds position fixed. The gradient is taken with respect to position, and its inner product with drift velocity measures the experienced spatial contribution. Their sum is the total derivative along the path.
DetailsDerive the sum from first-order Taylor expansion
Over time , position changes by . Expand both inputs:
Differentiability makes their leading contributions add linearly. Divide by and take the limit. A jump in the temperature field can invalidate this argument at the crossing.
Differentiation under an integral. Now average many fixed-location readings with a fixed weight:
Finite weighted sums differentiate term by term. Under appropriate conditions, their continuous counterpart does too:
This is the Leibniz rule. One sufficient local condition is existence of the time derivative and an integrable, time-independent dominating bound for its weighted magnitude. The integration domain is fixed. Moving boundaries require extra terms.
One moving reading cannot identify both sources
The observed rise is the integral of both contributions along the path. A spatially uniform field removes the movement term, but one drifting thermometer cannot establish that uniformity.
Measure the spatial gradient and buoy velocity at its current location, or the local time derivative there. A fixed thermometer only at the starting point need not describe downstream warming.
For , with distance in meters and time in seconds, drifting at 0.5 m/s for ten minutes contributes 0.3 degrees through motion and 0.3 through temporal warming.
At a discontinuity between unmixed streams, a classical spatial derivative may not exist. An abrupt reading change should not simply be interpreted as gradual temporal warming.
Compute the total derivative in a program
For a high-dimensional vector field, the spatial derivative is a Jacobian. Explicitly forming a dense matrix can require quadratic storage and many derivative sweeps.
We only need that matrix applied to one direction: a Jacobian-vector product (JVP). Forward-mode automatic differentiation computes this directly, commonly at a constant multiple of function-evaluation cost. Include a unit time tangent to obtain the total derivative.
import torch
from torch.func import jvp
def T(x, t):
return 20 + 0.3*torch.exp(-((x-300)/100)**2) + 0.0005*t
x0, t0, xdot = torch.tensor(250.), torch.tensor(0.), torch.tensor(0.5)
reading, dg_dt = jvp(T, (x0, t0), (xdot, torch.tensor(1.)))
_, fixed = jvp(T, (x0, t0), (torch.tensor(0.), torch.tensor(1.)))
print(f"reading {reading:.3f}; total {dg_dt:.6f}; fixed {fixed:.6f}; drift {dg_dt-fixed:.6f}")
jvp returns the function value and derivative along the supplied tangents. Here the total is about 0.001668, the fixed-position term 0.0005, and motion about 0.001168. The same interface extends to compatible vector inputs and outputs without constructing the Jacobian.
Check your understanding
References
- Strang, G. Calculus. Wellesley-Cambridge Press; MIT OpenCourseWare RES.18-001
- Baydin, A. G., Pearlmutter, B. A., Radul, A. A., Siskind, J. M. Automatic Differentiation in Machine Learning: a Survey. JMLR 2018.
- PyTorch documentation, torch.func.jvp.