Skip to content

Chapter 5 Formula Sheet

Reference, not teaching. Each entry names the book’s number, states the result, gives the shape of every object, and names the condition it needs. Read the concept pages first; come back here when you are working.

The whole chapter is one rule applied at four levels of generality:

f(x)scalar    fR1×nscalar of a vector    JRm×nvector of a vector    tensorsmatrix of a matrix\underbrace{f'(x)}_{\text{scalar}} \;\subset\; \underbrace{\nabla f \in \mathbb{R}^{1\times n}}_{\text{scalar of a vector}} \;\subset\; \underbrace{\mathbf{J} \in \mathbb{R}^{m\times n}}_{\text{vector of a vector}} \;\subset\; \underbrace{\text{tensors}}_{\text{matrix of a matrix}}

and at every level the chain rule is the same matrix product, read left to right, with the shapes lining up. That is the payoff of §5.2’s decision to make the gradient a row vector.

The shape rule, which subsumes most of the chapter

Section titled “The shape rule, which subsumes most of the chapter”

The derivative’s shape is the output’s shape followed by the input’s shape.

ff mapsdf/dx\mathrm{d}f/\mathrm{d}x shapeName
RR\mathbb{R} \to \mathbb{R}scalarderivative
RnR\mathbb{R}^n \to \mathbb{R}1×n1 \times ngradient (Eq 5.40)
RnRm\mathbb{R}^n \to \mathbb{R}^mm×nm \times nJacobian (Eq 5.56)
RnR\mathbb{R}^n \to \mathbb{R}, twicen×nn \times nHessian (Eq 5.147)
RnRm\mathbb{R}^{n} \to \mathbb{R}^{m}, twicem×n×nm \times n \times na tensor (§5.7 Remark)
Rp×qRm×n\mathbb{R}^{p\times q} \to \mathbb{R}^{m\times n}(m×n)×(p×q)(m\times n)\times(p\times q)a 4-tensor (§5.4)

If you can state the shape before computing anything, the rest is bookkeeping. Every dimension error in this chapter is a violation of that one line.

§5.1 Differentiation of univariate functions

Section titled “§5.1 Differentiation of univariate functions”
#ResultCondition
Def 5.1difference quotient δyδx=f(x+δx)f(x)δx\dfrac{\delta y}{\delta x} = \dfrac{f(x+\delta x) - f(x)}{\delta x}
Def 5.2derivative f(x)=limh0f(x+h)f(x)hf'(x) = \lim\limits_{h\to0}\dfrac{f(x+h)-f(x)}{h}limit must exist
product: (uv)=uv+uv(uv)' = u'v + uv'both differentiable
quotient: (uv)=uvuvv2\left(\dfrac{u}{v}\right)' = \dfrac{u'v - uv'}{v^2}v0v \neq 0
sum: (u+v)=u+v(u+v)' = u' + v'both differentiable
Eq 5.32chain rule: (g(f(x)))=g(f(x))f(x)\bigl(g(f(x))\bigr)' = g'(f(x))f'(x)inner differentiable at xx, outer at f(x)f(x)
Def 5.3Taylor polynomial Tn(x)=k=0nf(k)(x0)k!(xx0)kT_n(x) = \sum_{k=0}^{n}\dfrac{f^{(k)}(x_0)}{k!}(x-x_0)^kff nn times differentiable at x0x_0
Def 5.4Taylor series: the same sum to \inftyfCf \in C^\infty; convergence is a separate question

§5.2 Partial differentiation and gradients

Section titled “§5.2 Partial differentiation and gradients”
#ResultShape
Def 5.5fxi=limh0f(x1,,xi+h,,xn)f(x)h\dfrac{\partial f}{\partial x_i} = \lim\limits_{h\to0}\dfrac{f(x_1,\dots,x_i+h,\dots,x_n) - f(\mathbf{x})}{h}scalar
Eq 5.40xf=dfdx=[fx1fxn]\nabla_\mathbf{x}f = \dfrac{\mathrm{d}f}{\mathrm{d}\mathbf{x}} = \begin{bmatrix}\dfrac{\partial f}{\partial x_1} & \cdots & \dfrac{\partial f}{\partial x_n}\end{bmatrix}1×n1 \times n, a row
Eq 5.46product rule: x(f(x)g(x))=fxg+fgx\dfrac{\partial}{\partial\mathbf{x}}\bigl(f(\mathbf{x})g(\mathbf{x})\bigr) = \dfrac{\partial f}{\partial\mathbf{x}}g + f\dfrac{\partial g}{\partial\mathbf{x}}1×n1 \times n
Eq 5.47sum rule1×n1 \times n
Eq 5.48chain rule: x(gf)=gffx\dfrac{\partial}{\partial\mathbf{x}}(g\circ f) = \dfrac{\partial g}{\partial f}\dfrac{\partial f}{\partial\mathbf{x}}1×n1 \times n
Eq 5.49dfdt=fx1x1t+fx2x2t\dfrac{\mathrm{d}f}{\mathrm{d}t} = \dfrac{\partial f}{\partial x_1}\dfrac{\partial x_1}{\partial t} + \dfrac{\partial f}{\partial x_2}\dfrac{\partial x_2}{\partial t}scalar
Eq 5.50dfd(s,t)=fxx(s,t)\dfrac{\mathrm{d}f}{\mathrm{d}(s,t)} = \dfrac{\partial f}{\partial\mathbf{x}}\dfrac{\partial\mathbf{x}}{\partial(s,t)}1×21 \times 2

Two facts about the gradient, both measurable. It points in the direction of steepest ascent, and the steepest rate equals its norm — swept over 360 directions, nothing beats f\lVert\nabla f\rVert and the exact gradient direction attains it to 101210^{-12}. And it is perpendicular to the level set: measured across a whole field, the worst normalised deviation is 101210^{-12}.

§5.3 Gradients of vector-valued functions

Section titled “§5.3 Gradients of vector-valued functions”
#ResultShape
Eq 5.55fxiRm\dfrac{\partial \mathbf{f}}{\partial x_i} \in \mathbb{R}^{m}, a columnm×1m \times 1
Eq 5.56Jacobian J=xf=[fx1fxn]\mathbf{J} = \nabla_\mathbf{x}\mathbf{f} = \begin{bmatrix}\dfrac{\partial\mathbf{f}}{\partial x_1} & \cdots & \dfrac{\partial\mathbf{f}}{\partial x_n}\end{bmatrix}m×nm \times n
Eq 5.58Jij=fixjJ_{ij} = \dfrac{\partial f_i}{\partial x_j}
Def 5.6detJ\det\mathbf{J} is the local volume scale factorn=mn = m
Eq 5.68chain rule for a composition, as a matrix product(m×k)(k×n)(m\times k)(k\times n)

Linear maps have constant Jacobians. For f(x)=Ax\mathbf{f}(\mathbf{x}) = \mathbf{A}\mathbf{x}, J=A\mathbf{J} = \mathbf{A} everywhere. For a nonlinear map the Jacobian is only local — measured on a fold-free patch, the ratio of a small square’s image area to detJ\lvert\det\mathbf{J}\rvert converges to 11 at first order in the patch size.

#ResultShape
dfdA\dfrac{\mathrm{d}\mathbf{f}}{\mathrm{d}\mathbf{A}} for fRm\mathbf{f}\in\mathbb{R}^m, ARp×q\mathbf{A}\in\mathbb{R}^{p\times q}m×(p×q)m \times (p \times q)
Eq 5.85f=Ax\mathbf{f} = \mathbf{A}\mathbf{x}: fiAi,:=x\dfrac{\partial f_i}{\partial A_{i,:}} = \mathbf{x}^\top, and 0\mathbf{0} for every other row1×n1 \times n per slice
dKdR\dfrac{\mathrm{d}\mathbf{K}}{\mathrm{d}\mathbf{R}} for K=RR\mathbf{K} = \mathbf{R}^\top\mathbf{R}(n×n)×(m×n)(n\times n)\times(m\times n)

Two ways to organise the same numbers. Either keep the tensor shape, or flatten the matrix to a pqpq-vector and get an ordinary Jacobian. The book does both; the flattened form is what a library computes, and the tensor form is what makes the shapes comprehensible.

With the book’s Equations 5.99 to 5.108. Every one of these is verified numerically on the identities page.

#Identity
Eq 5.99Xf(X)=(f(X)X)\dfrac{\partial}{\partial\mathbf{X}}\mathbf{f}(\mathbf{X})^\top = \left(\dfrac{\partial \mathbf{f}(\mathbf{X})}{\partial\mathbf{X}}\right)^\top
Eq 5.100Xtr(f(X))=tr(f(X)X)\dfrac{\partial}{\partial\mathbf{X}}\mathrm{tr}\bigl(\mathbf{f}(\mathbf{X})\bigr) = \mathrm{tr}\left(\dfrac{\partial \mathbf{f}(\mathbf{X})}{\partial\mathbf{X}}\right)
Eq 5.101Xdet(f(X))=det(f(X))tr(f(X)1f(X)X)\dfrac{\partial}{\partial\mathbf{X}}\det\bigl(\mathbf{f}(\mathbf{X})\bigr) = \det\bigl(\mathbf{f}(\mathbf{X})\bigr)\mathrm{tr}\left(\mathbf{f}(\mathbf{X})^{-1}\dfrac{\partial \mathbf{f}(\mathbf{X})}{\partial\mathbf{X}}\right)
Eq 5.102Xf(X)1=f(X)1f(X)Xf(X)1\dfrac{\partial}{\partial\mathbf{X}}\mathbf{f}(\mathbf{X})^{-1} = -\mathbf{f}(\mathbf{X})^{-1}\dfrac{\partial \mathbf{f}(\mathbf{X})}{\partial\mathbf{X}}\mathbf{f}(\mathbf{X})^{-1}
Eq 5.103aX1bX=(X1)ab(X1)\dfrac{\partial \mathbf{a}^\top\mathbf{X}^{-1}\mathbf{b}}{\partial\mathbf{X}} = -(\mathbf{X}^{-1})^\top\mathbf{a}\mathbf{b}^\top(\mathbf{X}^{-1})^\top
Eq 5.104xax=a\dfrac{\partial \mathbf{x}^\top\mathbf{a}}{\partial\mathbf{x}} = \mathbf{a}^\top
Eq 5.105aXbX=ab\dfrac{\partial \mathbf{a}^\top\mathbf{X}\mathbf{b}}{\partial\mathbf{X}} = \mathbf{a}\mathbf{b}^\top
Eq 5.106xBxx=x(B+B)\dfrac{\partial \mathbf{x}^\top\mathbf{B}\mathbf{x}}{\partial\mathbf{x}} = \mathbf{x}^\top(\mathbf{B} + \mathbf{B}^\top)
Eq 5.107s(xAs)W(xAs)=2(xAs)WA\dfrac{\partial}{\partial\mathbf{s}}(\mathbf{x} - \mathbf{A}\mathbf{s})^\top\mathbf{W}(\mathbf{x}-\mathbf{A}\mathbf{s}) = -2(\mathbf{x}-\mathbf{A}\mathbf{s})^\top\mathbf{W}\mathbf{A}
Eq 5.108the same for symmetric W\mathbf{W}

§5.6 Backpropagation and automatic differentiation

Section titled “§5.6 Backpropagation and automatic differentiation”
#Result
Eq 5.109the example function f(x)=x2+exp(x2)+cos(x2+exp(x2))f(x) = \sqrt{x^2+\exp(x^2)} + \cos(x^2+\exp(x^2))
Eq 5.110its explicit derivative — 11 operations, and it recomputes x2x^2 and exp(x2)\exp(x^2)
Eq 5.111f0=x\mathbf{f}_0 = \mathbf{x}, fi=σi(Ai1fi1+bi1)\mathbf{f}_i = \sigma_i(\mathbf{A}_{i-1}\mathbf{f}_{i-1} + \mathbf{b}_{i-1})
Eq 5.115–5.118the cascade: Lθi\dfrac{\partial L}{\partial\boldsymbol{\theta}_i} extends the previous product by one factor
Eq 5.119–5.121forward and reverse mode as two bracketings of one product of Jacobians
Eq 5.123–5.128Example 5.14’s forward pass, six intermediates
Eq 5.129–5.134its elementary local derivatives
Eq 5.135–5.142its reverse sweep
Eq 5.143–5.145the general algorithm; Eq 5.145’s sum is over all children of a node

The costs, measured. Reverse mode costs one sweep per output, forward mode one per input. On Example 5.14: 6 forward operations against 16 in the reverse sweep — a factor of 2.672.67, a constant rather than a blow-up. With a scalar loss the crossover is at n=3n = 3, so for a network with millions of parameters reverse mode is not a preference but the only option. And AD’s error was 2.2×10162.2\times10^{-16} against the best of 200 central differences at 9.8×10129.8\times10^{-12}.

#ResultCondition
2fyx=y ⁣(fx)\dfrac{\partial^2 f}{\partial y\,\partial x} = \dfrac{\partial}{\partial y}\!\left(\dfrac{\partial f}{\partial x}\right): the operator nearest ff acts first
Eq 5.1462fxy=2fyx\dfrac{\partial^2 f}{\partial x\,\partial y} = \dfrac{\partial^2 f}{\partial y\,\partial x}twice continuously differentiable
Eq 5.147H=[xx2fxy2fxy2fyy2f]H = \begin{bmatrix}\partial^2_{xx}f & \partial^2_{xy}f \\ \partial^2_{xy}f & \partial^2_{yy}f\end{bmatrix}, symmetric, written x,y2f\nabla^2_{x,y}fn×nn \times n in general
curvature along a unit d\mathbf{d} is dHd\mathbf{d}^\top H\mathbf{d}, bounded by the eigenvalues and attaining bothHH symmetric
Remarka vector field’s Hessian is an (m×n×n)(m\times n\times n) tensor

The second-order test has four outcomes. All eigenvalues positive: minimum. All negative: maximum. Mixed: saddle. Some zero: the test says nothing — and x12+x24x_1^2+x_2^4, x12+x23x_1^2+x_2^3 and x12x24x_1^2-x_2^4 all share the Hessian [2000]\begin{bmatrix}2&0\\0&0\end{bmatrix} at the origin while being, respectively, a strict minimum and two non-optima.

§5.8 Linearization and multivariate Taylor series

Section titled “§5.8 Linearization and multivariate Taylor series”
#ResultShape
Eq 5.148f(x)f(x0)+(xf)(x0)(xx0)f(\mathbf{x}) \approx f(\mathbf{x}_0) + (\nabla_\mathbf{x}f)(\mathbf{x}_0)(\mathbf{x}-\mathbf{x}_0)(1×D)(D×1)(1\times D)(D\times 1)
Def 5.7 / Eq 5.151f(x)=k=0Dxkf(x0)k!δkf(\mathbf{x}) = \sum_{k=0}^{\infty}\dfrac{D^k_\mathbf{x}f(\mathbf{x}_0)}{k!}\boldsymbol{\delta}^k, δ:=xx0\boldsymbol{\delta} := \mathbf{x}-\mathbf{x}_0
Def 5.8 / Eq 5.152Tn(x)=k=0nDxkf(x0)k!δkT_n(\mathbf{x}) = \sum_{k=0}^{n}\dfrac{D^k_\mathbf{x}f(\mathbf{x}_0)}{k!}\boldsymbol{\delta}^k
Eq 5.153δ2=δδ=δδ\boldsymbol{\delta}^2 = \boldsymbol{\delta}\otimes\boldsymbol{\delta} = \boldsymbol{\delta}\boldsymbol{\delta}^\top, entries δiδj\delta_i\delta_jD×DD\times D
Eq 5.154δ3\boldsymbol{\delta}^3, entries δiδjδk\delta_i\delta_j\delta_kD×D×DD\times D\times D
Eq 5.155Dkfδk=i1ikDkf[i1..ik]δi1δikD^k f\,\boldsymbol{\delta}^k = \sum_{i_1}\cdots\sum_{i_k} D^kf[i_1..i_k]\delta_{i_1}\cdots\delta_{i_k}scalar
Eq 5.156k=0k=0: f(x0)f(\mathbf{x}_0)scalar
Eq 5.157k=1k=1: xf(x0)δ\nabla_\mathbf{x}f(\mathbf{x}_0)\boldsymbol{\delta}einsum("i,i", Df1, d)scalar
Eq 5.158k=2k=2: tr(Hδδ)=δHδ\mathrm{tr}(H\boldsymbol{\delta}\boldsymbol{\delta}^\top) = \boldsymbol{\delta}^\top H\boldsymbol{\delta}scalar
Eq 5.159=ijHijδiδj= \sum_i\sum_j H_{ij}\delta_i\delta_jeinsum("ij,i,j", Df2, d, d)scalar
Eq 5.160k=3k=3einsum("ijk,i,j,k", Df3, d, d, d)scalar

The measured facts. The order-nn error scales like rn+1r^{n+1}: fitted slopes 1.0671.067, 2.0052.005, 3.0193.019 against the predicted 11, 22, 33. But that is a statement about r0r \to 0 — on a fixed window a higher-order model can be worse, and at r=3.2r = 3.2 a quadratic model’s error of 7.777.77 was five times the constant model’s 1.401.40.

The cost. DkD^k entries at order kk; (D+k1k)\binom{D+k-1}{k} distinct after Equation 5.146’s symmetry. At D=106D = 10^6: 5.0×10115.0\times10^{11} at k=2k = 2 (4 TB in float32) and 1.7×10171.7\times10^{17} at k=3k = 3. Symmetry halves the constant and does nothing to the exponent.

QuantityValueWhere
max of the sigmoid’s derivativeexactly 14\tfrac14, at x=0x = 0Exercise 5.2
reverse-vs-forward crossover, scalar lossn=3n = 3§5.6
reverse sweep vs forward pass, Example 5.142.67×2.67\times§5.6
AD error vs best central difference2.2e-162.2\text{e-}16 vs 9.8e-129.8\text{e-}12§5.6
cost of dropping Eq 5.137’s second term9.5% to 47.8%, worst for small xx§5.6
second-difference truncation floorexactly 2h22h^2, and positive§5.7
Schwarz counterexample, gap at the originexactly 22, at every step size§5.7
Newton vs gradient descent, convex test8 steps vs 426, 3 of 4 rates diverged§5.7
gradient-descent steps vs κ\kappa18, 94, 939, 9384 for κ\kappa = 2, 10, 100, 1000§5.7
P(random symmetric HH positive definite)0.4980.498, 0.1450.145, 0.02720.0272, 0.00240.0024 for nn = 1 to 4§5.7
fitted Taylor error orders1.0671.067, 2.0052.005, 3.0193.019§5.8
Hessian entries at D=106D = 10^6101210^{12} stored, 5.0×10115.0\times10^{11} distinct§5.8
non-symmetric quadratic-form shortcut error62.5% relativeEq 5.106
dropping Exercise 5.9’s direct path102% relative, and a sign flipExercise 5.9
#Answer
5.14sin(x3)x+12x2logxcos(x3)\dfrac{4\sin(x^3)}{x} + 12x^2\log\lvert x\rvert\cos(x^3) — simplify log(x4)=4logx\log(x^4) = 4\log\lvert x\rvert first
5.2f(1f)f(1-f), a function of the output; maximum 14\tfrac14
5.3xμσ2f(x)-\dfrac{x-\mu}{\sigma^2}f(x) — a multiple of itself
5.4coefficients cycle +1,+1,1,1+1, +1, -1, -1, because sinx+cosx=2sin(x+π/4)\sin x + \cos x = \sqrt2\sin(x + \pi/4)
5.51×21\times2; 1×n1\times n; n×n×nn\times n\times n with entries δikxj+xiδjk\delta_{ik}x_j + x_i\delta_{jk}
5.6cos(logtt)2ttt\cos(\log\mathbf{t}^\top\mathbf{t})\dfrac{2\mathbf{t}^\top}{\mathbf{t}^\top\mathbf{t}}; and (BA)(\mathbf{B}\mathbf{A})^\top via the cyclic trace
5.72x1+xx\dfrac{2\mathbf{x}^\top}{1+\mathbf{x}^\top\mathbf{x}}; and diag(cosz)A\operatorname{diag}(\cos\mathbf{z})\mathbf{A}
5.8fyS1-f\cdot\mathbf{y}^\top\mathbf{S}^{-1}; 2x2\mathbf{x}^\top; diag(1tanh2z)A\operatorname{diag}(1-\tanh^2\mathbf{z})\mathbf{A}
5.9(zlogpzlogq)νtνlogq\left(\partial_z\log p - \partial_z\log q\right)\partial_\nu t - \partial_\nu\log qtwo paths to ν\boldsymbol{\nu}
SectionUsed in
§5.1 chain ruleeverywhere; §5.6 is this applied mechanically
§5.2 gradient as a rowChapter 7’s optimality conditions, Chapter 9’s normal equations
§5.3 JacobianChapter 6’s change of variables (§6.7), normalising flows
§5.4 matrix gradientsChapter 9’s linear regression, Chapter 10’s PCA
§5.5 identitiesanywhere a closed-form gradient beats differentiating
§5.6 backpropagationevery neural network ever trained
§5.7 HessianChapter 7’s Newton and convexity, the Laplace approximation
§5.8 TaylorChapter 7’s trust regions, Gauss–Newton, the Laplace approximation

The eight mistakes this chapter is designed to prevent

Section titled “The eight mistakes this chapter is designed to prevent”
  1. Writing the gradient as a column. Equation 5.40 makes it a row so the chain rule is a left-to-right matrix product. Get this wrong and every subsequent shape needs a transpose you will forget.
  2. Using 2xB2\mathbf{x}^\top\mathbf{B} for a quadratic form’s derivative. It is x(B+B)\mathbf{x}^\top(\mathbf{B}+\mathbf{B}^\top) unless B\mathbf{B} is symmetric. Measured cost of the shortcut on a non-symmetric matrix: 62.5%.
  3. Forgetting Equation 5.145’s sum at a node with more than one child. Costs 9.5% to 47.8% on Example 5.14, and looks plausible.
  4. Testing a Hessian eigenvalue against zero. The differencing floor is +2h2+2h^2, so a singular Hessian reads as positive definite at every hh.
  5. Treating a zero eigenvalue as “no optimum”. It means ask a higher derivative: three functions share one singular Hessian and have three different answers.
  6. Expecting Newton’s method to find a minimum. It solves f=0\nabla f = \mathbf{0}, with no preference. On x12x22x_1^2 - x_2^2 one step lands exactly on the saddle and reports success.
  7. Reading “higher order is better” as a statement about your window. It is a statement about r0r \to 0; at r=3.2r = 3.2 the quadratic model was five times worse than the constant one.
  8. Dropping the second path in a total derivative when a variable appears more than once. Exercise 5.9’s truncated gradient is 102% wrong and points the opposite way.
TaskCall
numerical gradient(f(x+h) - f(x-h)) / (2*h), per component
Jacobian, column by columnsame, stacked with np.column_stack
local volume factornp.linalg.det(J)
contract Eq 5.157np.einsum("i,i", Df1, d)
contract Eq 5.159np.einsum("ij,i,j", Df2, d, d)
contract Eq 5.160np.einsum("ijk,i,j,k", Df3, d, d, d)
quadratic form, cheaplyd @ H @ d, never np.trace(H @ np.outer(d, d))
Hessian eigenvaluesnp.linalg.eigvalsh(H) — symmetric only, and it does not check
is HH positive definitenp.linalg.cholesky(H) in a try, about half the cost
Newton stepx - np.linalg.solve(H, grad), never inv(H) @ grad
elementwise Jacobian times a matrixnp.cos(z)[:, None] * A, never np.diag(...) @ A
pch.quizTag Check your understanding
  1. What single rule determines the shape of every derivative in this chapter?

    pch.quizShowAnswer

    B — The derivative's shape is the output's shape followed by the input's shape — so a scalar of a vector is 1 by n, a vector of a vector is m by n, and a matrix of a vector is m by n by n — Every dimension error in the chapter is a violation of that one line. Stating the shape before computing anything turns the rest into bookkeeping, which is exactly why Exercises 5.7 and 5.8 ask for the dimensions explicitly.

  2. Why does the book make the gradient a ROW vector in Equation 5.40?

    pch.quizShowAnswer

    B — So the chain rule is a plain left-to-right matrix product with the shapes lining up, and it generalises to vector-valued functions without changing conventions — a 1 by n times an n by 1 is the scalar you want — The book gives both reasons at Equation 5.40. The practical consequence appears at Eq 5.148, where grad f times (x - x0) needs no transpose at all.

  3. Equation 5.158 gives the second-order Taylor term as trace(H delta delta-transpose) and as delta-transpose H delta. Which should you compute?

    pch.quizShowAnswer

    B — The quadratic form. Both give the same number, but the trace form builds a D by D rank-one intermediate — at D = 1000000 that is 4 TB allocated to produce one scalar — The trace form is the right way to STATE the term, because it generalises to arbitrary k. The quadratic form is the right way to compute it: two matrix-vector products and nothing bigger than D.

  4. What do the four outcomes of the second-order test tell you when an eigenvalue is zero?

    pch.quizShowAnswer

    B — Nothing at all — ask a higher derivative. x1^2+x2^4, x1^2+x2^3 and x1^2-x2^4 share the Hessian [[2,0],[0,0]] at the origin and are respectively a strict minimum and two non-optima — And numerically it is worse: the differencing floor is +2h^2, so a singular Hessian tests as positive definite at every step size. Compare eigenvalues against a tolerance scaled to the entries, never against zero.

  5. Reverse-mode AD costs about 2.67 times the forward pass on Example 5.14. Why is a constant factor the interesting part?

    pch.quizShowAnswer

    B — Because the naive expectation is a blow-up: Equation 5.110's explicit derivative is 11 operations and recomputes x-squared and exp(x-squared). A constant factor is what makes training feasible at all, and it comes from reusing stored forward values — The book calls this counterintuitive itself. The mechanism is reuse: the reverse sweep reads the forward values instead of recomputing them, which is exactly the 'unnecessary overhead' symbolic differentiation pays.

  • The shape rule subsumes the chapter: the derivative’s shape is the output’s shape followed by the input’s. Scalar of a vector is 1 by n, vector of a vector is m by n, matrix of a vector is m by n by n.
  • Equation 5.40 makes the gradient a ROW, so the chain rule is a left-to-right matrix product and Equation 5.148 needs no transpose.
  • Equation 5.32’s chain rule is the only rule in the chapter. §5.2, §5.3, §5.6 and §5.8 are all it, at increasing levels of generality.
  • Equation 5.56’s Jacobian is m by n, and det J is the local volume scale factor — local only, and meaningless where it changes sign.
  • Equation 5.106: the derivative of a quadratic form is x-transpose (B + B-transpose), not 2 x-transpose B. Measured cost of the shortcut on a non-symmetric B: 62.5 percent.
  • Equation 5.145 sums over a node’s children. Example 5.14’s node a is the only one with two, and dropping the second term costs 9.5 to 47.8 percent, worst for small x.
  • Reverse mode is one sweep per OUTPUT, forward mode one per INPUT. Crossover at n = 3 for a scalar loss, and the reverse sweep costs 2.67 times the forward pass on Example 5.14 — a constant, not a blow-up.
  • AD has no step size: 2.2e-16 against the best of 200 central differences at 9.8e-12.
  • Equation 5.146 needs its hypothesis — twice CONTINUOUSLY differentiable. The standard counterexample’s two iterated limits at the origin are -1 and +1, gap exactly 2.
  • Equation 5.147’s Hessian is symmetric, so §4.2 applies, and the curvature along a unit d is d-transpose H d, squeezed between the eigenvalues and attaining both.
  • The second-order test has FOUR outcomes, and the fourth — some eigenvalue zero — means ask a higher derivative. Three functions share [[2,0],[0,0]] and have three different answers.
  • Never test an eigenvalue against zero: the second-difference floor is exactly 2h^2 and it is positive.
  • Newton’s method solves grad f = 0, not “find a minimum”. 8 steps against gradient descent’s 426 on a convex test, and exactly onto the saddle on x1^2 - x2^2.
  • The condition number is the price gradient descent pays: 18, 94, 939, 9384 steps for kappa of 2, 10, 100, 1000.
  • Definition 5.7’s delta-to-the-k is a k-fold OUTER product, and the order-k tensor has D^k entries — 1e12 at a million parameters, which is where practice stops.
  • Taylor error goes like r to the (n+1) as r goes to zero, measured 1.067, 2.005, 3.019 — and on a fixed window a higher order can be five times worse.

Next: Vector Calculus Overview for the map of the chapter, or on to Chapter 6, Probability and Distributions.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading