Skip to content

Gradients of Vector-Valued Functions

The previous page ended with a 1×n1\times n row. This page stacks mm of them.

That is genuinely all the new content — and the fact that it is so little is the payoff for §5.2’s row convention. Under the column convention this page would need transposes; under the row convention the gradient of a function with mm outputs is just mm gradients written one above the other, and the shape rule stays (rows are outputs, columns are inputs) all the way up.

What is new is what the resulting matrix means. Its determinant is a volume magnifier, which is where Chapter 6’s change-of-variables formula comes from. And the chain rule becomes an honest matrix product, which is where backpropagation comes from.

  • Definition 5.6: the Jacobian of f:RnRmf:\mathbb{R}^n\to\mathbb{R}^m as an m×nm\times n matrix.
  • The numerator layout the book uses, its transpose the denominator layout, and how to tell which one a source is using.
  • Example 5.9: d(Ax)/dx=A\mathrm{d}(\mathbf{A}\mathbf{x})/\mathrm{d}\mathbf{x} = \mathbf{A}, exactly — the identity every linear layer’s backward pass is.
  • The Jacobian determinant as the factor by which areas and volumes scale, verified by counting rather than quoting §4.1.
  • Why that is only a local statement for a nonlinear map, measured — and what happens where the determinant vanishes.
  • Example 5.10 and 5.11: the chain rule as a matrix product, and the least-squares gradient that Chapter 9 is built on.

A function with one output has one thing to say about how it changes: a single gradient row. A function with mm outputs has mm things to say, one per output coordinate, and each is a row.

Stack them and you have a matrix. Row ii is “how output ii responds to each input”; column jj is “how input jj affects each output”. Both readings are useful, and they are the two ways to slice the same object.

The determinant then answers a question neither row nor column does: how much does the map stretch space? A unit square in the domain lands on a parallelogram in the codomain, and detJ\lvert\det\mathbf{J}\rvert is the ratio of their areas.

diagram Diagram mermaid

As a special case, a function f:RnR1f:\mathbb{R}^n\to\mathbb{R}^1 has a Jacobian that is a row vector of dimension 1×n1\times n — which is exactly Equation 5.40. §5.2 was not a different construction; it was this one with m=1m = 1.

The two differ unless the Jacobian happens to be square, so this is not a convention you can leave unresolved. A quick test on any source: find a Jacobian of a map with different input and output dimensions and read its shape. R3R4\mathbb{R}^3\to\mathbb{R}^4 gives 4×34\times3 in numerator layout and 3×43\times4 in denominator layout.

§4.1 showed the determinant computes the area of a parallelogram. Given b1=[1,0]\mathbf{b}_1 = [1,0]^\top, b2=[0,1]\mathbf{b}_2 = [0,1]^\top as the sides of a unit square,

det[1001]=1(5.60)\left\lvert\det\begin{bmatrix}1&0\\0&1\end{bmatrix}\right\rvert = 1 \tag{5.60}

and for a parallelogram with sides c1=[2,1]\mathbf{c}_1 = [-2,1]^\top, c2=[1,1]\mathbf{c}_2 = [1,1]^\top,

det[2111]=3=3(5.61)\left\lvert\det\begin{bmatrix}-2&1\\1&1\end{bmatrix}\right\rvert = \lvert-3\rvert = 3 \tag{5.61}

so that parallelogram has three times the area of the unit square. The mapping that takes one to the other is linear, with transformation matrix

J=[2111](5.62)\mathbf{J} = \begin{bmatrix}-2&1\\1&1\end{bmatrix} \tag{5.62}

satisfying Jb1=c1\mathbf{J}\mathbf{b}_1 = \mathbf{c}_1 and Jb2=c2\mathbf{J}\mathbf{b}_2 = \mathbf{c}_2.

And if the same map is written out in coordinates,

y1=2x1+x2,y2=x1+x2(5.63-5.64)y_1 = -2x_1 + x_2,\qquad y_2 = x_1 + x_2 \tag{5.63-5.64}

then its Jacobian, computed from Definition 5.6, is

dydx=[y1x1y1x2y2x1y2x2]=[2111](5.66)\frac{\mathrm{d}\mathbf{y}}{\mathrm{d}\mathbf{x}} = \begin{bmatrix}\dfrac{\partial y_1}{\partial x_1} & \dfrac{\partial y_1}{\partial x_2}\\[6pt] \dfrac{\partial y_2}{\partial x_1} & \dfrac{\partial y_2}{\partial x_2}\end{bmatrix} = \begin{bmatrix}-2&1\\1&1\end{bmatrix} \tag{5.66}

— the same matrix. So the Jacobian is the coordinate transformation, and:

That word “approximates” carries the whole caveat, and the second figure below measures exactly how much of one.

Example 5.9 — the identity every linear layer uses

Section titled “Example 5.9 — the identity every linear layer uses”

f(x)=Axf(\mathbf{x}) = \mathbf{A}\mathbf{x} with f(x)RMf(\mathbf{x})\in\mathbb{R}^M, ARM×N\mathbf{A}\in\mathbb{R}^{M\times N}, xRN\mathbf{x}\in\mathbb{R}^N.

Step 1 — the shape, before any calculus. Since f:RNRMf:\mathbb{R}^N\to\mathbb{R}^M, it follows that df/dxRM×N\mathrm{d}f/\mathrm{d}\mathbf{x}\in\mathbb{R}^{M\times N}. Doing this first catches most errors before they happen.

Step 2 — the entries.

fi(x)=j=1NAijxj    fixj=Aij(5.67)f_i(\mathbf{x}) = \sum_{j=1}^{N}A_{ij}x_j \implies \frac{\partial f_i}{\partial x_j} = A_{ij} \tag{5.67}

because every term in that sum except the jj-th is constant with respect to xjx_j.

Step 3 — collect.

dfdx=[A11A1NAM1AMN]=ARM×N(5.68)\frac{\mathrm{d}f}{\mathrm{d}\mathbf{x}} = \begin{bmatrix}A_{11}&\cdots&A_{1N}\\ \vdots&&\vdots\\ A_{M1}&\cdots&A_{MN}\end{bmatrix} = \mathbf{A} \in \mathbb{R}^{M\times N} \tag{5.68}

The Jacobian of a linear map is the matrix itself. Verified numerically for shapes 4×34\times3, 2×52\times5, 3×33\times3 and 5×15\times1, each agreeing with A\mathbf{A} to about 101010^{-10}.

This is the single most-used derivative in machine learning. Every dense layer’s backward pass is this identity plus the chain rule.

Example 5.10 — the chain rule, with the shapes checked first

Section titled “Example 5.10 — the chain rule, with the shapes checked first”

h:RRh:\mathbb{R}\to\mathbb{R}, h(t)=(fg)(t)h(t) = (f\circ g)(t), with

f(x)=exp(x1x22),x=[x1x2]=g(t)=[tcosttsint](5.71-5.72)f(\mathbf{x}) = \exp(x_1x_2^2),\qquad \mathbf{x} = \begin{bmatrix}x_1\\x_2\end{bmatrix} = g(t) = \begin{bmatrix}t\cos t\\ t\sin t\end{bmatrix} \tag{5.71-5.72}

The book notes the shapes before computing anything:

fxR1×2,gtR2×1(5.73)\frac{\partial f}{\partial\mathbf{x}} \in \mathbb{R}^{1\times2},\qquad \frac{\partial g}{\partial t}\in\mathbb{R}^{2\times1} \tag{5.73}

so their product is 1×11\times1 — a scalar, as it must be for h:RRh:\mathbb{R}\to\mathbb{R}.

dhdt=fxxt=[fx1fx2][x1tx2t](5.74a)\frac{\mathrm{d}h}{\mathrm{d}t} = \frac{\partial f}{\partial\mathbf{x}}\frac{\partial\mathbf{x}}{\partial t} = \begin{bmatrix}\dfrac{\partial f}{\partial x_1} & \dfrac{\partial f}{\partial x_2}\end{bmatrix} \begin{bmatrix}\dfrac{\partial x_1}{\partial t}\\[6pt] \dfrac{\partial x_2}{\partial t}\end{bmatrix} \tag{5.74a}

Filling in the pieces:

=[exp(x1x22)x222exp(x1x22)x1x2][costtsintsint+tcost]= \begin{bmatrix}\exp(x_1x_2^2)\,x_2^2 & 2\exp(x_1x_2^2)\,x_1x_2\end{bmatrix} \begin{bmatrix}\cos t - t\sin t\\ \sin t + t\cos t\end{bmatrix} =exp(x1x22)[x22(costtsint)+2x1x2(sint+tcost)]= \exp(x_1x_2^2)\Bigl[x_2^2(\cos t - t\sin t) + 2x_1x_2(\sin t + t\cos t)\Bigr]

Checked against a central difference in tt at six values, agreeing to between 9×10129\times10^{-12} and 9×10109\times10^{-10} relative:

ttchain rulecentral difference
0.300.300.0364762250.0364762250.0364762240.036476224
0.700.700.7062888610.7062888610.7062888610.706288861
1.001.001.5293766731.5293766731.5293766731.529376673
1.501.503.602659477-3.6026594773.602659476-3.602659476
2.002.000.486106309-0.4861063090.486106309-0.486106309
2.502.500.0369776930.0369776930.0369776930.036977693

Example 5.11 — the least-squares gradient

Section titled “Example 5.11 — the least-squares gradient”

This is the one that Chapter 9 runs on. Given the linear model

y=Φθ(5.75)\mathbf{y} = \boldsymbol{\Phi}\boldsymbol{\theta} \tag{5.75}

with θRD\boldsymbol{\theta}\in\mathbb{R}^D a parameter vector, ΦRN×D\boldsymbol{\Phi}\in\mathbb{R}^{N\times D} the input features and yRN\mathbf{y}\in\mathbb{R}^N the observations, define

L(e):=e2,e(θ):=yΦθ(5.76-5.77)L(\mathbf{e}) := \lVert\mathbf{e}\rVert^2,\qquad \mathbf{e}(\boldsymbol{\theta}) := \mathbf{y} - \boldsymbol{\Phi}\boldsymbol{\theta} \tag{5.76-5.77}

Shape first: L/θR1×D\partial L/\partial\boldsymbol{\theta}\in\mathbb{R}^{1\times D} (Equation 5.78). Then the chain rule:

Lθ=Leeθ(5.79)\frac{\partial L}{\partial\boldsymbol{\theta}} = \frac{\partial L}{\partial\mathbf{e}}\frac{\partial\mathbf{e}}{\partial\boldsymbol{\theta}} \tag{5.79}

Using e2=ee\lVert\mathbf{e}\rVert^2 = \mathbf{e}^\top\mathbf{e} from §3.2,

Le=2eR1×N,eθ=ΦRN×D(5.81-5.82)\frac{\partial L}{\partial\mathbf{e}} = 2\mathbf{e}^\top \in \mathbb{R}^{1\times N}, \qquad \frac{\partial\mathbf{e}}{\partial\boldsymbol{\theta}} = -\boldsymbol{\Phi} \in \mathbb{R}^{N\times D} \tag{5.81-5.82}

so

  Lθ=2eΦ=2(yθΦ)1×NΦN×DR1×D  (5.83)\boxed{\;\frac{\partial L}{\partial\boldsymbol{\theta}} = -2\mathbf{e}^\top\boldsymbol{\Phi} = -2\underbrace{(\mathbf{y}^\top - \boldsymbol{\theta}^\top\boldsymbol{\Phi}^\top)}_{1\times N}\underbrace{\boldsymbol{\Phi}}_{N\times D} \in \mathbb{R}^{1\times D}\;} \tag{5.83}

Note how the shapes carry the derivation: (1×N)(N×D)=1×D(1\times N)(N\times D) = 1\times D, which is what Equation 5.78 predicted before any differentiating happened.

Verified for N=30N = 30, D=4D = 4: the analytic gradient [86.449975, 161.597514, 43.111249, 73.585580][-86.449975,\ 161.597514,\ 43.111249,\ 73.585580] agrees with a central-difference Jacobian to 9.3×10109.3\times10^{-10} relative, the two forms of Equation 5.83 agree exactly (0.0e+00), and at the least-squares solution the gradient is 2.5×10142.5\times10^{-14} — zero, as an optimum requires.

sketch The Jacobian as a local linear map p5.js
A grid in the domain, pushed through a map you can switch between linear and nonlinear. The amber parallelogram is what the Jacobian at the marked point predicts; the blue patch is where the map actually sends that square. Shrink the square and the two converge — that is the whole content of 'the Jacobian approximates the map locally'.
sketch One row per output p5.js
Pick the number of outputs and inputs and watch the Jacobian's shape follow. Each row is highlighted as you scrub through the outputs, and the readout names what that row means. The point is that the shape rule never changes: rows are outputs, columns are inputs.
jacobian_from_scratch.py
import numpy as np
 
def numeric_jac(f, x, h=1e-6):
    """Definition 5.6: one column per input, one row per output."""
    x = np.asarray(x, dtype=float).ravel()
    f0 = np.asarray(f(x)).ravel()
    J = np.zeros((f0.size, x.size))              # (outputs, inputs) -- numerator layout
    for j in range(x.size):
        e = np.zeros_like(x)
        e[j] = h
        J[:, j] = (np.asarray(f(x + e)).ravel() - np.asarray(f(x - e)).ravel()) / (2 * h)
    return J
 
rng = np.random.default_rng(3)
 
print("Example 5.9: d(Ax)/dx = A")
for (M, N) in [(4, 3), (2, 5), (3, 3), (5, 1)]:
    A = rng.normal(size=(M, N))
    x = rng.normal(size=N)
    J = numeric_jac(lambda v: A @ v, x)
    print(f"  A is {M}x{N}  ->  df/dx is {J.shape}  and equals A to {np.abs(J - A).max():.1e}")
 
print()
print("Example 5.10: h(t) = exp(x1 x2^2) with x = (t cos t, t sin t)")
h_of_t = lambda t: np.exp((t * np.cos(t)) * (t * np.sin(t)) ** 2)
 
def dh_chain(t):
    x1, x2 = t * np.cos(t), t * np.sin(t)
    e = np.exp(x1 * x2 ** 2)
    df_dx = np.array([[e * x2 ** 2, e * 2 * x1 * x2]])              # 1 x 2, Eq 5.73
    dx_dt = np.array([[np.cos(t) - t * np.sin(t)],
                      [np.sin(t) + t * np.cos(t)]])                 # 2 x 1, Eq 5.73
    return float((df_dx @ dx_dt).item())                            # (1x2)(2x1) -> (1,1)
 
print(f"{'t':>6}  {'chain rule':>18}  {'central difference':>20}  {'rel gap':>10}")
for t in (0.3, 0.7, 1.0, 1.5, 2.0, 2.5):
    ch = dh_chain(t)
    hh = 1e-6
    nu = (h_of_t(t + hh) - h_of_t(t - hh)) / (2 * hh)
    print(f"{t:>6.2f}  {ch:>18.9f}  {nu:>20.9f}  {abs(ch-nu)/max(abs(ch),1e-12):>10.1e}")
 
print()
print("Example 5.11: the least-squares gradient")
rng = np.random.default_rng(11)
N, D = 30, 4
Phi = rng.normal(size=(N, D))
theta_true = rng.normal(size=D)
y = Phi @ theta_true + 0.3 * rng.normal(size=N)
theta = rng.normal(size=D)
 
L = lambda th: (y - Phi @ th) @ (y - Phi @ th)
e0 = y - Phi @ theta
ana = (-2 * e0 @ Phi).reshape(1, -1)                                # Eq 5.83
num = numeric_jac(lambda v: np.array([L(v)]), theta)
ana2 = (-2 * (y.T - theta.T @ Phi.T) @ Phi).reshape(1, -1)          # Eq 5.83, expanded
 
print(f"  shape {ana.shape}  -- Eq 5.78 predicted 1 x D with D = {D}")
print(f"  analytic {np.round(ana[0], 6)}")
print(f"  numeric  {np.round(num[0], 6)}")
print(f"  relative error {np.abs(ana - num).max() / np.abs(ana).max():.1e}")
print(f"  the two forms of Eq 5.83 agree to {np.abs(ana2 - ana).max():.1e}")
th_star = np.linalg.lstsq(Phi, y, rcond=None)[0]
print(f"  at the least-squares optimum the gradient is "
      f"{np.abs(-2 * (y - Phi @ th_star) @ Phi).max():.1e}")
output
Example 5.9: d(Ax)/dx = A
  A is 4x3  ->  df/dx is (4, 3)  and equals A to 9.2e-11
  A is 2x5  ->  df/dx is (2, 5)  and equals A to 1.9e-10
  A is 3x3  ->  df/dx is (3, 3)  and equals A to 2.9e-10
  A is 5x1  ->  df/dx is (5, 1)  and equals A to 4.7e-11
 
Example 5.10: h(t) = exp(x1 x2^2) with x = (t cos t, t sin t)
     t          chain rule    central difference     rel gap
  0.30         0.036476225           0.036476224     8.8e-10
  0.70         0.706288861           0.706288861     9.3e-12
  1.00         1.529376673           1.529376673     1.6e-11
  1.50        -3.602659477          -3.602659476     1.2e-10
  2.00        -0.486106309          -0.486106309     4.4e-11
  2.50         0.036977693           0.036977693     3.5e-10
 
Example 5.11: the least-squares gradient
  shape (1, 4)  -- Eq 5.78 predicted 1 x D with D = 4
  analytic [-86.449975 161.597514  43.111249  73.58558 ]
  numeric  [-86.449975 161.597514  43.111249  73.58558 ]
  relative error 9.3e-10
  the two forms of Eq 5.83 agree to 0.0e+00
  at the least-squares optimum the gradient is 2.5e-14

Three things.

The shape line for Example 5.11 is the point of doing Equation 5.78 first: the gradient came out (1,4)(1, 4) exactly as predicted, and if it had come out (4,1)(4, 1) you would know immediately that a transpose went the wrong way — before looking at a single number.

The two forms of Equation 5.83 agree to 0.0e+00, exactly. That is not luck: 2eΦ-2\mathbf{e}^\top\boldsymbol{\Phi} and 2(yθΦ)Φ-2(\mathbf{y}^\top - \boldsymbol{\theta}^\top\boldsymbol{\Phi}^\top)\boldsymbol{\Phi} are the same floating-point operations in the same order once e=yΦθ\mathbf{e} = \mathbf{y}-\boldsymbol{\Phi}\boldsymbol{\theta} is substituted.

And at the least-squares solution the gradient is 2.5×10142.5\times10^{-14} — which is the condition Chapter 9 solves for. Setting Equation 5.83 to zero gives ΦΦθ=Φy\boldsymbol{\Phi}^\top\boldsymbol{\Phi}\boldsymbol{\theta} = \boldsymbol{\Phi}^\top\mathbf{y}, the normal equations.

figure The book's Figure 5.5, with the area counted matplotlib
A blue unit square and an amber parallelogram overlaid on the same axes, with basis arrows b1 and b2 for the square and c1 and c2 for the parallelogram, and a panel of measured areas. A blue unit square and an amber parallelogram overlaid on the same axes, with basis arrows b1 and b2 for the square and c1 and c2 for the parallelogram, and a panel of measured areas.
The unit square maps to the parallelogram spanned by c1 = [-2,1] and c2 = [1,1]. det J = -3.0000, so |det J| = 3. A Monte-Carlo estimate over 400000 samples gives 3.0049 from 200329 hits, a gap of 0.0049 — the determinant claim verified by counting rather than by quoting §4.1. Note the sign: det is negative, so orientation flips.
figure 'Approximates locally', measured matplotlib
Left, a nonlinear map bending two nested squares into curved patches. Right, a log-log plot of the gap between the measured area ratio and the Jacobian determinant against the side length, falling along a line of slope one. Left, a nonlinear map bending two nested squares into curved patches. Right, a log-log plot of the gap between the measured area ratio and the Jacobian determinant against the side length, falling along a line of slope one.
At (0.4, 0.3) the Jacobian determinant is 0.856000. The measured area ratio converges to it as the square shrinks: 0.640 at side 0.4, 0.811 at 0.1, 0.852 at 0.01 — with the gap falling in exact proportion to the side length, so the approximation is first order.
figure Definition 5.6's one rule, and every special case of it matplotlib
A table of functions, their derivatives and the resulting shapes, from the general m by n case down to the scalar derivative, with notes on where each appears in the chapter. A table of functions, their derivatives and the resulting shapes, from the general m by n case down to the scalar derivative, with notes on where each appears in the chapter.
Rows indexed by the output, columns by the input — the numerator layout. Everything the chapter differentiates is this one rule: m = 1 gives §5.2's row, n = 1 gives a column, f(x) = Ax gives A itself, and a matrix argument gives a fourth-order tensor.

From the area figure. The determinant is 3-3 and the area ratio is 33, and both facts matter. The magnitude is the magnifier; the sign says the map reverses orientation, which the picture shows by c1\mathbf{c}_1 and c2\mathbf{c}_2 being swapped in handedness relative to b1\mathbf{b}_1 and b2\mathbf{b}_2.

The Monte-Carlo estimate is 3.00493.0049 against an exact 33, from 200329200\,329 hits out of 400000400\,000. The gap of 0.00490.0049 is sampling noise — σbox areap(1p)/n0.005\sigma \approx \text{box area}\sqrt{p(1-p)/n} \approx 0.005 — so this is a check that passes, not a discrepancy. It matters because the estimate never touches the determinant: it counts points inside the image using coordinates in the (b1,b2)(\mathbf{b}_1,\mathbf{b}_2) frame, so agreement is independent evidence rather than a restatement.

From the local figure. This is the figure that puts a number on the word “approximates”. The gap between the measured area ratio and detJ\lvert\det\mathbf{J}\rvert:

sidearea / side²gap
0.40.40.6400000.6400002.16×1012.16\times10^{-1}
0.20.20.7600000.7600009.60×1029.60\times10^{-2}
0.10.10.8110000.8110004.50×1024.50\times10^{-2}
0.050.050.8342500.8342502.18×1022.18\times10^{-2}
0.020.020.8474800.8474808.52×1038.52\times10^{-3}
0.010.010.8517700.8517704.23×1034.23\times10^{-3}

Every halving of the side halves the gap. First order — which is exactly what you should expect, because the Jacobian is the best linear approximation and the error is dominated by the first neglected term.

Note the base point: (0.4,0.3)(0.4, 0.3), not somewhere arbitrary. This map’s determinant is 11.2uv1 - 1.2uv, which vanishes on the hyperbola uv=0.8333uv = 0.8333. Base the squares at (0.8,0.6)(0.8, 0.6) instead and the largest one reaches uv=1.2uv = 1.2, past the fold — and then the shoelace formula returns the difference of two oppositely-oriented areas rather than the area, giving a measured ratio of 0.040.04 against a determinant of 0.4240.424. That is not a convergence failure; it is a folded polygon, and the figure avoids it deliberately.

From the shapes figure. The row worth pausing on is the last: a matrix argument gives a fourth-order tensor. §5.4 is about making that computable, and the figure previews the two ways — flatten, or partition into blocks.

functionJacobianshapenote
f:RnRmf:\mathbb{R}^n\to\mathbb{R}^mfi/xj\partial f_i/\partial x_jm×nm\times nDefinition 5.6, the general rule
f:RnRf:\mathbb{R}^n\to\mathbb{R}the gradient1×n1\times n§5.2’s Equation 5.40
f:RRmf:\mathbb{R}\to\mathbb{R}^ma columnm×1m\times1a curve’s velocity
f(x)=Axf(\mathbf{x}) = \mathbf{A}\mathbf{x}A\mathbf{A}M×NM\times NExample 5.9, constant everywhere
f(x)=xf(\mathbf{x}) = \mathbf{x}I\mathbf{I}n×nn\times ndet=1\det = 1: no stretching
a rotationthe rotation matrixn×nn\times ndet=+1\det = +1: no stretching, no flip
L(θ)=yΦθ2L(\boldsymbol{\theta}) = \lVert\mathbf{y}-\boldsymbol{\Phi}\boldsymbol{\theta}\rVert^22eΦ-2\mathbf{e}^\top\boldsymbol{\Phi}1×D1\times DExample 5.11, Chapter 9’s gradient
pch.quizTag Check your understanding
  1. Why does §5.3 add so little to §5.2?

    pch.quizShowAnswer

    B — Because §5.2 already chose the row convention, so a function with m outputs is just m of those rows stacked — the shape rule 'rows are outputs, columns are inputs' extends with nothing to transpose — Definition 5.6 with m = 1 IS Equation 5.40. The book says so in a remark right after the definition. That is the payoff the row convention was chosen for.

  2. The Monte-Carlo area estimate in the first figure came out as 3.0049 against an exact 3. Why is that worth showing rather than just quoting det J = -3?

    pch.quizShowAnswer

    B — Because the estimate never touches the determinant — it counts sampled points inside the image using coordinates in the original basis, so agreement is independent evidence rather than a restatement of §4.1 — The 0.0049 gap is sampling noise of the expected size for 400000 samples. A check that shares no code with the thing being checked is worth more than a tighter one that does.

  3. For a nonlinear map, the measured area ratio approached |det J| with the gap halving each time the side halved. What does that exponent tell you?

    pch.quizShowAnswer

    B — That the approximation is first order, which is what a LINEAR approximation must be — the error is dominated by the first neglected term, the quadratic one — 0.216, 0.096, 0.045, 0.0218, 0.00852, 0.00423 as the side goes 0.4 down to 0.01 — proportional to the side throughout. 'The Jacobian approximates the map locally' has a rate, and this is it.

  4. In the same figure, basing the squares at (0.8, 0.6) gave a measured ratio of 0.04 against a determinant of 0.424. What went wrong?

    pch.quizShowAnswer

    B — Nothing about the calculus. det J = 1 - 1.2uv vanishes at uv = 0.8333 and that square reaches uv = 1.2, so the map FOLDS — and a signed area formula counts the two folded halves with opposite signs. The assumption broke, not the derivative — This is why Chapter 6's change-of-variables formula requires an invertible transformation. Where the Jacobian determinant vanishes you are not in a regime where 'volume magnifier' means anything.

  5. Example 5.11 states the shape 1 x D before doing any calculus. What does that buy?

    pch.quizShowAnswer

    B — The cheapest possible error check: a wrong transpose usually produces shapes that do not compose at all, so the mistake surfaces before any arithmetic. The derivation then just fills in a (1 x N)(N x D) product — And note where the check stops working: for a square Jacobian the shape composes either way, so you lose it. That is also when the numerator and denominator layouts become indistinguishable by shape.

Exercise 1 – Example 5.9, at four shapes

Section titled “Exercise 1 – Example 5.9, at four shapes”

Exercise 3 – Example 5.11, and the normal equations

Section titled “Exercise 3 – Example 5.11, and the normal equations”

Exercise 4 – The determinant as an area magnifier

Section titled “Exercise 4 – The determinant as an area magnifier”

Exercise 5 – ‘Locally’ has a rate, and a boundary

Section titled “Exercise 5 – ‘Locally’ has a rate, and a boundary”
  • The Jacobian is m gradient rows stacked: an m by n matrix with J(i,j) = the partial of output i with respect to input j — Definition 5.6, Equation 5.58.
  • §5.2 was this with m = 1. Equation 5.40’s row vector is Definition 5.6’s special case, which is the payoff for choosing rows.
  • Numerator layout means rows are outputs; the denominator layout is its transpose. They differ unless the Jacobian is square — and when it is square, the shape cannot tell them apart.
  • The Jacobian of a linear map is the matrix itself, everywhere. Verified at four shapes, agreeing to about 1e-10.
  • |det J| is the volume magnifier. For the book’s Figure 5.5, det J = −3 so areas triple and orientation flips; a Monte-Carlo count over 400000 samples gives 3.0049.
  • For a nonlinear map that is only local, and the rate is first order. Measured: the gap between the area ratio and |det J| halves each time the side halves — 0.216 at side 0.4 down to 0.0042 at 0.01.
  • Where det J = 0 the map folds, and a signed area formula then counts two halves against each other. That is why Chapter 6’s change of variables requires invertibility.
  • The chain rule is a matrix product whose shapes are stated first. Equation 5.73 gives (1×2)(2×1); Equation 5.78 gives 1×D before any calculus happens.
  • The least-squares gradient is −2 e-transpose Phi, shape 1 by D — Example 5.11, and Chapter 9’s whole starting point. Setting it to zero gives the normal equations.
  • A (1,1) NumPy array is not a float. float() on it raises, and that is the shapes composing correctly. Use .item().

Next: Gradients of Matrices — where the derivative becomes a fourth-order tensor, and the two ways to make that computable.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading