The Jacobian
雅可比矩阵
Track how several outputs respond to several inputs, with a fixed shape convention and checked forward and reverse products.
jacobianTwo knobs, three readings
Imagine a toy sensor with two inputs, a and b, and three readings: , , and . Turn the first knob a little. All three readings may move. Turn the second knob: the third reading stays still. A single slope cannot record this behavior. A table with one row per reading and one column per knob can.
That table is the Jacobian. It describes the local linear response of a differentiable vector-valued function. The entries need not stay constant as the knobs move. For a linear map they do; for a nonlinear sensor they must be evaluated at a specified input. MML, Section 5.3
Rows are outputs; columns are inputs
Let be differentiable at x. Throughout this encyclopedia, inputs and scalar-loss gradients are column vectors. The Jacobian has shape :
The limit is as nonzero h tends to zero. It means the leftover error is small compared with the input displacement, in every direction. Merely having all coordinate partial derivatives at a point does not guarantee this property. Continuous partial derivatives in a neighborhood are a useful sufficient condition. MML uses a row convention for a scalar derivative; here the scalar Jacobian is the row , keeping the column-gradient convention explicit.
For the sensor at ,
These are first-order predicted changes. The actual changes in the first two readings are 0.34 and 0.28: the omitted terms are and . Halving h quarters those particular remainders. The sine remainder has a second-order bound from its bounded second derivative, but is not the same polynomial.
For another differentiable map , substitute the two local approximations. The chain rule becomes
The shapes are . The order follows the computation: first change the sensor readings, then change g. Swapping the factors is generally meaningless or incorrect.
Check the table without an autodiff library
This complete standard-library program compares the analytic table with central finite differences. The sensor and matvec helper assume matching dimensions; finite_jacobian validates its own vector and output contract. It is a diagnostic for small smooth functions, not a general automatic differentiation engine.
import math
def sensor(x):
a, b = x
return [a*a+b, a*b, math.sin(a)]
def sensor_jacobian(x):
a, b = x
return [[2*a, 1.], [b, a], [math.cos(a), 0.]]
def finite_jacobian(f, x, step=1e-5):
x = list(x)
if not x or not all(math.isfinite(t) for t in x) or not math.isfinite(step) or step <= 0:
raise ValueError("finite nonempty input and positive finite step required")
base = list(f(x))
if not base or not all(math.isfinite(t) for t in base):
raise ValueError("finite nonempty vector output required")
result = [[0.]*len(x) for _ in base]
for j in range(len(x)):
plus, minus = x.copy(), x.copy()
plus[j] += step; minus[j] -= step
if plus[j] == x[j] or minus[j] == x[j]:
raise ValueError("step is too small for this input scale")
fp, fm = list(f(plus)), list(f(minus))
if len(fp) != len(base) or len(fm) != len(base) or not all(math.isfinite(t) for t in fp+fm):
raise ValueError("output shape changed or became nonfinite")
for i in range(len(base)):
result[i][j] = (fp[i]-fm[i])/(2*step)
if not math.isfinite(result[i][j]):
raise ArithmeticError("nonfinite finite difference")
return result
def matvec(a, v):
return [sum(t*s for t,s in zip(row,v)) for row in a]
x = [1., 2.]
j = sensor_jacobian(x)
approx = finite_jacobian(sensor, x)
assert max(abs(a-b) for r,s in zip(j,approx) for a,b in zip(r,s)) < 1e-9
v = [.2, -.1]
assert all(abs(a-b)<1e-12 for a,b in zip(matvec(j,v), [.3,.3,.2*math.cos(1)]))
g = [2., -1., 0.]
pullback = matvec(list(zip(*j)), g)
assert pullback == [2.,1.]
assert abs(sum(a*b for a,b in zip(g,matvec(j,v)))-sum(a*b for a,b in zip(pullback,v))) < 1e-12
For n inputs and m outputs it makes function calls, uses storage, and performs work outside those calls, including copying n-element input vectors. Smoothness, step size, roundoff, and the cost of f all matter. A tiny step can round back to the original input; a large one can measure a secant far from the desired derivative. A successful check at one x is evidence about that case, not a proof for all x.
Usually you need a product, not the whole table
A direction v produces a Jacobian–vector product, . A scalar loss L on the outputs sends back . With an arbitrary column seed g, this reverse product obeys
For the sensor, gives . This identity checks both shape and transpose choices. Some libraries call the reverse operation a vector–Jacobian product because they write the seed as a row. The mathematical content is the same after converting conventions. Forward and reverse automatic differentiation can compute these products without storing a dense Jacobian. Baydin et al., Sections 3.1–3.2
At a ReLU kink there is no ordinary Jacobian; a framework’s selected derivative is an implementation convention. Stochastic functions also need fixed randomness for a meaningful finite-difference comparison. For square, nonsingular Jacobians, determinants describe local volume scaling. Rectangular Jacobians still describe derivatives perfectly well, even though an ordinary determinant is unavailable.
Follow the shape before multiplying
- A function maps five numbers to two. What is its Jacobian shape? Answer: ; a reverse seed has length two and returns a length-five input gradient.
- Why does the first reading change by 0.34 rather than 0.3? Answer: the linear prediction omits the quadratic term .
- For , what is ? Answer: .
- Does a zero third-column derivative prove an output never depends on that input? Answer: no. A derivative may vanish only at the tested point, as the derivative of does at zero.
From local response to learning systems
A network is a composition of maps, so the same chain rule connects input sensitivity, parameter gradients, and local changes of representation. A large singular value of a Jacobian indicates a direction of strong local amplification; it does not by itself establish global behavior or robustness. Continue with the Hessian for how a scalar gradient itself changes, or automatic differentiation for computing products through a program.
Make a prediction, then check
Five inputs map to two outputs. What is the Jacobian shape?
Learning objectives
- Derive a composite Jacobian using output rows and input columns.
- Check shapes and sensitivity with forward and reverse products.
Prerequisites & connections
Explore related knowledge →References
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020 - Automatic Differentiation in Machine Learning: a Survey
Atilim Gunes Baydin; Barak A. Pearlmutter; Alexey Andreyevich Radul; Jeffrey Mark Siskind · 2018
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: specified-source comparison, derivation checks, independent numerical checks, and paragraph-level bilingual comparison; no independent human peer review.
- Compared analytic chain rules with central differences for 50 nonlinear compositions; checked JVP/VJP duality, changing output shapes, and steps rounded away.
- Recomputed sensor changes and quadratic remainders; unified column gradients and output rows, and did not equate existing partial derivatives with differentiability.
- Compared bilingual assumptions, claims, numbers, exercise answers and citations; structural checks additionally compare formulas, code, main anchors and source IDs.
- Static link checking found an abbreviated autodiff route; verified the target article and corrected it to the stable ID automatic-differentiation.
Source locations checked:
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft) · §5.3, printed pp.149–152 / PDF pp.155–158; explicit conversion from the book’s scalar row convention
- Automatic Differentiation in Machine Learning: a Survey · §§3.1–3.2: forward/reverse accumulation and Jacobian products
Related topics