Verifying Quadratic Remainder Decay of the Jacobian
Empirical Check
Shrinking the step \boldsymbol{\delta} tenfold at a time confirms that the relative linear approximation error \|\mathbf{f}(\mathbf{x}_0 + \boldsymbol{\delta}) - \mathbf{f}(\mathbf{x}_0) - \mathbf{J}(\mathbf{x}_0)\boldsymbol{\delta}\| / \|\boldsymbol{\delta}\| vanishes linearly with \|\boldsymbol{\delta}\|:
|delta| = 2.2e-01 error / |delta| = 9.0e-02
|delta| = 2.2e-02 error / |delta| = 9.0e-03
|delta| = 2.2e-03 error / |delta| = 9.0e-04
|delta| = 2.2e-04 error / |delta| = 9.0e-05
Sufficient condition for a Jacobian: Just as in §34.2, existence of partial derivatives alone is not enough (2xy/(x^2+y^2) at \mathbf{0} has none); if all partials \partial f_i / \partial x_j are continuous near \mathbf{x}, \mathbf{f} is differentiable at \mathbf{x} and smooth (C^2) maps have O(\|\boldsymbol{\delta}\|^2) error.
Catching Square-Matrix Transpose Bugs in Code
Numerical Verification
We can test the matrix-product backward rules directly by differentiating the scalar probe s = \langle \bar{\mathbf{Y}}, \mathbf{X}\mathbf{W}\rangle on random square nonsymmetric 3 \times 3 matrices alongside plausible transpose errors of the same shape:
grad x^T A x: (A + A^T) x True | wrong guess 2 A x False
Xbar : Ybar W^T True | wrong guess Ybar W False
Wbar : X^T Ybar True | wrong guess (X^T Ybar)^T False
Every derived rule prints True, while every plausible wrong guess (2 A x, Ybar W, and (X^T Ybar)^T) prints False. Always test custom backward rules on nonsymmetric matrices.
Hand-Tracing All Weight Gradients of the 2-2-1 Network
Complete Layer Sweep
Applying our three local VJP rules backward from \bar{g} = 1 at \mathbf{x} = (1, 1)^\top (where \mathbf{a} = (3, -2)^\top, mask \mathbf{m} = (1, 0)^\top, \mathbf{h} = (3, 0)^\top) yields every parameter gradient of the 2-2-1 network:
- Output layer g = \mathbf{w}_2^\top\mathbf{h}: \bar{\mathbf{h}} = \bar{g}\mathbf{w}_2 = (2, -1)^\top and \bar{\mathbf{w}}_2 = \bar{g}\mathbf{h} = (3, 0)^\top.
- \mathrm{ReLU} & bias \mathbf{h} = \boldsymbol{\varphi}(\mathbf{a}), \mathbf{a} = \mathbf{W}_1\mathbf{x} + \mathbf{b}: \bar{\mathbf{a}} = \mathbf{m} \odot \bar{\mathbf{h}} = (2, 0)^\top and \bar{\mathbf{b}} = \bar{\mathbf{a}} = (2, 0)^\top.
- First linear layer: \bar{\mathbf{W}}_1 = \bar{\mathbf{a}}\mathbf{x}^\top = \begin{pmatrix} 2 & 2 \\ 0 & 0 \end{pmatrix} and \bar{\mathbf{x}} = \mathbf{W}_1^\top\bar{\mathbf{a}} = (2, 4)^\top.
dg/dW1 = (w2*m) x^T: [[2.0, 2.0], [0.0, 0.0]] autograd: [[2.0, 2.0], [0.0, 0.0]]
dg/db = w2*m : [2.0, 0.0] autograd: [2.0, 0.0]
dg/dw2 = h : [3.0, 0.0] autograd: [3.0, 0.0]
Verifying Softmax Spectrum and Two-Hot Target Pitfall
Code Verification
At logits \mathbf{z} = (1, -0.5, 2)^\top, the softmax Jacobian has one zero eigenvalue (along \mathbf{1}) and two positive eigenvalues, while an unnormalized two-hot target \mathbf{y} = (1, 1, 0)^\top (\sum_i y_i = 2) has gradient 2\mathbf{p} - \mathbf{y} rather than \mathbf{p} - \mathbf{y}:
eigenvalues of J: [0. 0.079 0.378]
y = [0. 1. 0.]: d loss / d z = [ 0.2537 -0.9434 0.6897], p - y = [ 0.2537 -0.9434 0.6897]
y = [1. 1. 0.]: d loss / d z = [-0.4926 -0.8868 1.3793], p - y = [-0.7463 -0.9434 0.6897]