Md. Asif Uddin

    Book I · Problem set

    Where the chapters meet

    A problem here uses two or more chapters at once. That is the whole purpose of the set: a reader who finishes this book should be able to take a cost derived in one chapter and a parameter count from another and answer a question neither chapter asked.

    8/8 problemsthe first book: none earlier to reach back into

    The problems

    Numerical instantiationLimiting caseProbabilisticCost accountingConstructed failureDimensional algebraDifferentiationProof or impossibility

    Problem I.BOOK.B01

    XOR, from the perceptron to one step of training

    numeric▲▲△

    Exact values where possible; six decimal places otherwise.

    STATEMENT

    Show that no perceptron computes XOR, that a two-unit ReLU network does, and then backpropagate through that network after one of its weights has been disturbed and take a gradient step.

    GIVEN

    The four XOR examples: (0,0)↦0(0,0)\mapsto0, (0,1)↦1(0,1)\mapsto1, (1,0)↦1(1,0)\mapsto1, (1,1)↦0(1,1)\mapsto0. The network, with s=x1+x2s=x_1+x_2:

    h1=relu⁡(s),h2=relu⁡(s−1),y=h1+v2h2,v2=−2.\begin{aligned} h_1&=\operatorname{relu}(s),\\ h_2&=\operatorname{relu}(s-1),\\ y&=h_1+v_2h_2,\\ v_2&=-2. \end{aligned}

    The loss is the mean squared error over the four examples. For the second part, v2=−1.8v_2=-1.8 and the step size is 11.

    FIND

    Why no threshold unit 1[w1x1+w2x2+b>0]\mathbf 1[w_1x_1+w_2x_2+b>0] fits the data; the network’s outputs; after disturbing v2v_2, the loss and the gradients with respect to v2v_2, the bias of h2h_2 and the bias of h1h_1; the new v2v_2.

    STRATEGY

    Write the perceptron’s four conditions as inequalities (I.2). For the network, only the example (1,1)(1,1) has an error after the disturbance, so the backward pass of I.6 runs through one example.

    SOLUTION

    No perceptron. The examples require b≤0b\leq0 for (0,0)(0,0), w2+b>0w_2+b>0 and w1+b>0w_1+b>0 for the two positives, and w1+w2+b≤0w_1+w_2+b\leq0 for (1,1)(1,1). Adding the middle two gives w1+w2+2b>0w_1+w_2+2b>0, so w1+w2+b>−b≥0w_1+w_2+b>-b\geq0, contradicting the last. The positives and negatives are not linearly separable (I.2.P04), and no learning rule changes that.

    The network. At s=0,1,1,2s=0,1,1,2 the hidden units are (0,0)(0,0), (1,0)(1,0), (1,0)(1,0) and (2,1)(2,1), so

    y=(0,  1,  1,  2−2)=(0,1,1,0).\begin{aligned} y&=(0,\;1,\;1,\;2-2)\\ &=(0,1,1,0). \end{aligned}

    The ReLU’s kink at s=1s=1 is what a linear map cannot supply (I.3.P01): the network bends the line ss once and folds the fourth example back to zero.

    Disturbed. With v2=−1.8v_2=-1.8 the last output is 2−1.8=0.22-1.8=0.2 and the others are unchanged. The loss is 0.22/4=0.010.2^2/4=0.01. The output error is δ=2(0.2−0)/4=0.1\delta=2(0.2-0)/4=0.1 at (1,1)(1,1) and zero elsewhere, so

    ∂L∂v2=δ h2=0.1,∂L∂b2=δ v2relu⁡′(1)=−0.18,∂L∂b1=δrelu⁡′(2)=0.1.\begin{aligned} \frac{\partial\mathcal L}{\partial v_2}&=\delta\,h_2=0.1,\\ \frac{\partial\mathcal L}{\partial b_2}&=\delta\,v_2\operatorname{relu}'(1)\\ &=-0.18,\\ \frac{\partial\mathcal L}{\partial b_1}&=\delta\operatorname{relu}'(2)=0.1. \end{aligned}

    One step. Gradient descent moves v2v_2 to −1.8−1⋅0.1=−1.9-1.8-1\cdot0.1=-1.9, back towards −2-2. The gradient supplied the direction and the step size of 11 was a choice (I.7.P01). Repeating the step halves the remaining error each time: −1.95-1.95, then −1.975-1.975, approaching −2-2 without reaching it.

    Answer

    The four perceptron inequalities contradict each other. The network outputs (0,1,1,0)(0,1,1,0). Disturbed: loss 0.010.01, gradients 0.10.1, −0.18-0.18 and 0.10.1; after one step v2=−1.9v_2=-1.9.

    Check — sanity

    The gradient with respect to v2v_2 is positive because raising v2v_2 makes the wrong output 0.20.2 larger. The script confirms it with a central finite difference.

    Check — numeric · i-book-checks.py

    The complete reproduction script uses only the Python standard library. From a checkout of the repository, run:

    python3 scripts/snippets/i-book-checks.py

    It checks all eight problems of the Book I set. For this one it also searches 15,62515{,}625 perceptrons on a grid and confirms none fits XOR.

    Executed in CI. The digits above are the digits it printed.

    Where this breaks

    The network computes a function of ss alone, so it cannot represent the other three Boolean functions of two inputs that need x1x_1 and x2x_2 separately. Two hidden units suffice for XOR because XOR is symmetric.

    Variation

    With v2=−2v_2=-2 every error is zero and so is every gradient: XOR is a global minimum. Disturbing the bias of h2h_2 instead moves the kink, and then several examples err at once.

    Problem I.BOOK.B02

    Three ways a gradient crosses many steps

    limit▲▲△

    Six significant figures.

    STATEMENT

    Compare the derivative of a quantity LL steps downstream with respect to its start, for a saturating stack, a plain recurrence, a gated carry line and a residual stack, and find the limit of each as LL grows.

    GIVEN

    Four scalar chains, each evaluated where its per-step derivative is constant:

    • a sigmoid stack at its centre, derivative σ′(0)=0.25\sigma'(0)=0.25 per step (I.3);
    • a recurrence ht=tanh⁡(wht−1)h_t=\tanh(wh_{t-1}) near 00 with w=0.9w=0.9 (I.9);
    • an LSTM carry line with forget value f=0.95f=0.95 (I.10);
    • a residual stack xl+1=xl+atanh⁡(xl)x_{l+1}=x_l+a\tanh(x_l) near 00, with a=+0.05a=+0.05, a=−0.05a=-0.05 or a=−1a=-1 (I.11).

    FIND

    Each per-step factor; the product after L=20L=20 and L=100L=100 steps; the limit as L→∞L\to\infty; what sets each base.

    STRATEGY

    By the chain rule (I.6), the derivative across LL steps is the product of the per-step derivatives. Each chain here has a constant per-step factor, so each product is a power.

    SOLUTION

    Per-step factors. The sigmoid stack multiplies by 0.250.25. The recurrence by wtanh⁡′(0)=0.9w\tanh'(0)=0.9. The carry line by f=0.95f=0.95. The residual stack by 1+atanh⁡′(0)=1+a1+a\tanh'(0)=1+a: 1.051.05, 0.950.95 or 00.

    Products.

    factorL=20L=20L=100L=100
    0.250.259.09495×10−139.09495\times10^{-13}6.22302×10−616.22302\times10^{-61}
    0.90.90.1215770.1215772.65614×10−52.65614\times10^{-5}
    0.950.950.3584860.3584860.005920.00592
    1.051.052.653302.65330131.501131.501

    The rows are the sigmoid stack, the recurrence, the carry line and the residual stack with a=+0.05a=+0.05.

    The residual stack with a=−0.05a=-0.05 gives the carry line’s numbers, and with a=−1a=-1 the product is exactly 00 after one step.

    Limits. Every product of a constant base is geometric: it goes to 00 when the base is below 11 in size and grows without bound when it is above. Only a base of exactly 11 survives every depth. None of the four mechanisms abolishes the geometry; they differ in what sets the base.

    What sets each base. In the sigmoid stack it is the activation’s slope, at most 0.250.25, so depth alone destroys the signal (I.3.P02). In the recurrence it is a weight times a slope, and pushing it towards 11 means asking a weight matrix to have norm near one everywhere (I.9.P02). On the carry line it is a learned gate, close to 11 without any weight matrix being involved (I.10.P02). In the residual stack it is 11 plus the branch’s slope, near 11 when the branch is small, and it can be driven to 00 by a branch that cancels the identity (I.11.X09).

    Answer

    At L=20L=20: 9.09×10−139.09\times10^{-13}, 0.1220.122, 0.3580.358 and 2.652.65; at L=100L=100: 6.22×10−616.22\times10^{-61}, 2.66×10−52.66\times10^{-5}, 0.005920.00592 and 132132. All are geometric in LL: below one they vanish, above one they explode.

    Check — sanity

    The carry line keeps 3636 per cent after twenty steps where the plain recurrence keeps 1212 per cent, although its factor differs by only 0.050.05: small differences in the base compound.

    Where this breaks

    Real chains have factors that vary from step to step, and vectors whose Jacobians are matrices. Then the products are of matrices, the relevant quantity is a norm or a spectral radius, and the residual and gated paths add terms that can reinforce or cancel, as I.10.B02 showed.

    Variation

    To keep half the signal across L=100L=100 steps, the base must be 0.51/100=0.9930920.5^{1/100}=0.993092. A forget bias of ln⁡(0.993092/0.006908)=4.97\ln(0.993092/0.006908)=4.97 sets that gate value at initialisation (I.10.T2).

    Problem I.BOOK.B03

    The reduction sets the step, the batch sets the noise

    probability▲▲△

    Six decimal places.

    STATEMENT

    For one parameter whose per-example gradients are independent, compare the mean and the variance of a gradient step under a mean reduction and a sum reduction, then change the batch size.

    GIVEN

    Per-example gradients gig_i with mean μ\mu and variance σ2=4\sigma^2=4, independent across examples. A batch of B=32B=32. Learning rate η=0.1\eta=0.1. The step is −η-\eta times the batch gradient, where the batch gradient is either gˉ=1B∑gi\bar g=\tfrac1B\sum g_i or ∑gi\sum g_i.

    FIND

    The variance of each batch gradient; the standard deviation of each step; the learning rate that makes the sum’s step match the mean’s; the mean’s variance at B=128B=128.

    STRATEGY

    Variance scales with the square of a constant and adds over independent terms (Variance and covariance 0.PR.03).

    SOLUTION

    Variances. The sum of BB independent terms has variance Bσ2=128B\sigma^2=128. Dividing by BB divides the variance by B2B^2: Var⁡gˉ=σ2/B=0.125\operatorname{Var}\bar g=\sigma^2/B=0.125.

    Steps. With η=0.1\eta=0.1 the mean’s step has standard deviation 0.10.125=0.0353550.1\sqrt{0.125}=0.035355 and the sum’s 0.1128=1.1313710.1\sqrt{128}=1.131371, exactly B=32B=32 times larger. Its expected size, ηBμ\eta B\mu, is also 3232 times larger. The two runs are not the same algorithm with different noise; the sum is the mean with a learning rate 3232 times higher.

    Matching. The sum’s step equals the mean’s when ηsum=η/B=0.003125\eta_{\text{sum}}=\eta/B=0.003125. The reduction is part of the loss (I.4.P04): changing it silently changes the learning rate by the batch size.

    Larger batch. At B=128B=128 the mean’s variance is 4/128=0.031254/128=0.03125, a quarter of the value at 3232. Quadrupling the batch halves the standard deviation of the step and leaves its expected value unchanged. The batch size is a statement about gradient noise (I.7.P02); the direction it estimates does not depend on it.

    Answer

    Variances 0.1250.125 for the mean and 128128 for the sum; step standard deviations 0.0353550.035355 and 1.1313711.131371; matching learning rate 0.0031250.003125; at B=128B=128 the mean’s variance is 0.031250.03125.

    Check — sanity

    The ratio of the two standard deviations is 1.131371/0.035355=32=B1.131371/0.035355=32=B, as the scaling argument requires.

    Where this breaks

    Adaptive optimisers such as Adam divide the gradient by a running estimate of its size, so multiplying the loss by a constant leaves their steps nearly unchanged (I.7). The reduction then matters mainly through ϵ\epsilon and through any penalty added to the loss with its own coefficient. Correlated examples, such as frames from one video, make the variance shrink more slowly than 1/B1/B.

    Variation

    A common heuristic raises the learning rate in proportion to the batch size, keeping η/B\eta/B fixed so that the noise per unit of progress stays roughly constant. It holds only while the step is small compared with the curvature of the loss, which is why it fails at very large batches.

    Problem I.BOOK.B04

    One sequence, three architectures

    complexity▲▲△

    Exact.

    STATEMENT

    Let the last element of a sequence of length 6464 depend on the first, and count what a recurrent network, a dilated causal convolution and message passing on the path graph each need to achieve that.

    GIVEN

    Length T=64T=64, width d=128d=128. Each architecture uses layers with two d×dd\times d weight matrices and one bias:

    • a recurrent layer, ht=tanh⁡(Uxt+Wht−1+b)\vec h_t=\tanh(\mat U\vec x_t+\mat W\vec h_{t-1}+\vec b) (I.9);
    • a causal convolution with kernel width 22 and dilations 1,2,4,…1,2,4,\ldots, one weight matrix per tap (I.9.P03, I.11);
    • a message-passing layer on the path graph 11–22–⋯\cdots–6464, H′=σ(HW0+AHW1)\mat H'=\sigma(\mat H\mat W_0+\mat A\mat H\mat W_1) (I.14).

    FIND

    Parameters per layer; the number of layers each needs; total parameters; the number of steps that must run one after another.

    STRATEGY

    A recurrent layer reaches every earlier step. A dilated stack’s receptive field adds the dilation times one less than the kernel width at each layer. Message passing reaches one hop per layer (I.14.T2).

    SOLUTION

    Per layer. Each has 2d2+d=2⋅16,384+128=32,8962d^2+d=2\cdot16{,}384+128=32{,}896 parameters.

    Recurrent. One layer suffices: h64\vec h_{64} depends on x1\vec x_1 through the state (I.9.P01). Total 32,89632{,}896 parameters. But step tt needs step t−1t-1, so 6464 steps run one after another.

    Dilated convolution. With kernel width 22 the receptive field after LL layers is 1+(1+2+⋯+2L−1)=2L1+(1+2+\cdots+2^{L-1})=2^L. Reaching 6464 positions takes L=6L=6 layers, 197,376197{,}376 parameters. Every position of a layer can be computed at once, so only 66 stages run in sequence.

    Message passing. Node 6464 is 6363 hops from node 11, so 6363 layers are needed and 2,072,4482{,}072{,}448 parameters, with 6363 stages in sequence. The graph network also lacks what the other two have for free: it cannot tell the node before from the node after (I.14.P02), so it does not even know which end of the path is the start.

    layersparametersserial
    recurrent1132,89632{,}8966464
    dilated66197,376197{,}37666
    graph63632,072,4482{,}072{,}4486363

    Answer

    32,89632{,}896 parameters per layer. Recurrent: 11 layer, 6464 sequential steps. Dilated convolution: 66 layers, 197,376197{,}376 parameters, 66 stages. Message passing: 6363 layers, 2,072,4482{,}072{,}448 parameters, 6363 stages.

    Check — sanity

    Each count follows from one rule: the recurrence carries state across steps, the dilated stack doubles its reach per layer, and message passing adds one hop per layer. 26=642^6=64 and 64−1=6364-1=63.

    Where this breaks

    Reaching a position is not using it. The recurrence’s influence decays geometrically (I.9, I.10), the convolution’s receptive field has holes when dilations skip positions (I.9.X10), and 6363 rounds of averaging over-smooth a graph network’s states (I.14.P03). Book II’s attention reaches every position in one layer, at a cost quadratic in TT.

    Variation

    With kernel width 33 the dilated stack’s field after LL layers is 1+2(2L−1)1+2(2^L-1). Five layers reach 6363 positions, one short, so six are still needed; they cover 127127 positions with 6(3d2+d)=295,6806(3d^2+d)=295{,}680 parameters. A wider kernel buys range only in the steps the dilation schedule allows.

    Problem I.BOOK.B05

    A zero training loss that taught nothing

    counterexample▲▲△

    Exact values where possible; six decimal places otherwise.

    STATEMENT

    Fit labels drawn by coin flips exactly with a small ReLU network, compare it with a straight line, and show that the zero training loss predicts nothing about new points.

    GIVEN

    Inputs x=0,1,2,3x=0,1,2,3 with labels (0,1,0,1)(0,1,0,1), which were drawn by fair coin flips. The network is f(x)=x−2relu⁡(x−1)+2relu⁡(x−2)f(x)=x-2\operatorname{relu}(x-1)+2\operatorname{relu}(x-2). The line is the least-squares fit y=a+bxy=a+bx. New inputs 0.50.5, 1.51.5 and 2.52.5 get labels from fresh coin flips. Losses are mean squared errors.

    FIND

    The network’s training loss; the line and its training loss; the expected loss of each, and of the constant 0.50.5, on the new points.

    STRATEGY

    Evaluate the network piece by piece. For a prediction pp and a label that is 00 or 11 with probability one half, the expected squared error is (p−12)2+14(p-\tfrac12)^2+\tfrac14.

    SOLUTION

    The network. Its slopes are 11 before x=1x=1, −1-1 between 11 and 22, and 11 after 22. So f(0)=0f(0)=0, f(1)=1f(1)=1, f(2)=0f(2)=0, f(3)=1f(3)=1: the labels exactly, training loss 00. Two ReLU units and a linear term were enough to put a kink at every change of label (I.5.P02).

    The line. With xˉ=1.5\bar x=1.5 and yˉ=0.5\bar y=0.5, the slope is ∑(x−xˉ)(y−yˉ)/∑(x−xˉ)2=1/5=0.2\sum(x-\bar x)(y-\bar y)/\sum(x-\bar x)^2=1/5=0.2 and the intercept 0.5−0.2⋅1.5=0.20.5-0.2\cdot1.5=0.2. Its residuals are −0.2-0.2, 0.60.6, −0.6-0.6 and 0.20.2, so its training loss is 0.20.2.

    New points. The network predicts 0.50.5 at all three, so its expected loss is 14=0.25\tfrac14=0.25, exactly that of the constant 0.50.5. The line predicts 0.30.3, 0.50.5 and 0.70.7, with expected loss 13(0.04+0+0.04)+0.25=0.276667\tfrac13(0.04+0+0.04)+0.25=0.276667.

    So the network with zero training loss does no better than a constant on new points, and the line, which fitted worse, does slightly worse still. Neither number on the training set said anything about the new points, because the labels carried no pattern to learn. That is I.1.P05: the training loss cannot tell memorisation from generalisation.

    The same failure, twice more. Chapter I.12 met it in the autoencoder as wide as its input, whose zero loss reconstructed points far from the data just as exactly (I.12.X04), and in the width-one decoder that threaded a curve through every training point (I.12.B04). In all three the capacity to fit was the problem, and only held-out data revealed it.

    Answer

    Network training loss 00; line y=0.2+0.2xy=0.2+0.2x with training loss 0.20.2. On new coin-flip labels: network 0.250.25, line 0.2766670.276667, constant 0.250.25.

    Check — sanity

    No predictor can beat 0.250.25 in expectation on fair coin flips, since (p−12)2+14(p-\tfrac12)^2+\tfrac14 is smallest at p=12p=\tfrac12. Both the network and the constant reach that floor on these three points.

    Where this breaks

    With labels that follow a pattern, the same architecture can generalise: capacity permits memorisation without forcing it. What separates the two cases is not the training loss but a held-out evaluation drawn from the same distribution.

    Variation

    With nn distinct inputs on a line, a network with n−2n-2 ReLU kinks and a linear term interpolates any labels, so a network of that size reaches zero training loss on every labelling, patterned or not.

    Problem I.BOOK.B06

    Shapes through a convolutional VAE

    shape▲▲△

    Exact.

    STATEMENT

    Trace every shape through a convolutional variational autoencoder for 28×2828\times28 images, count its parameters, and find the line of a colleague’s code that would fail.

    GIVEN

    Encoder: two 3×33\times3 convolutions with stride 22 and padding 11, from 11 channel to 1616 and from 1616 to 3232; a flatten; a linear layer to 2k2k numbers with k=16k=16, split into μ\vec\mu and log⁡σ2\log\vec\sigma^2. Decoder: a linear layer from kk back to the flattened size; a reshape; two transposed convolutions with the same kernel, stride and padding and output padding 11, from 3232 channels to 1616 and from 1616 to 11. All layers have biases. The colleague wrote the encoder’s linear layer as taking 32⋅8⋅832\cdot8\cdot8 inputs.

    FIND

    Every spatial size; the flattened size; the shapes of μ\vec\mu, σ\vec\sigma, ε\vec\varepsilon and z\vec z for a batch of BB; each layer’s parameters and the total; the colleague’s error.

    STRATEGY

    Use (I.11.4) for the convolutions and (I.11.5) for the transposed ones. The reparameterisation of (I.13.6) acts coordinate by coordinate, so it keeps the code’s shape.

    SOLUTION

    Encoder sizes. ⌊(28+2−3)/2⌋+1=14\lfloor(28+2-3)/2\rfloor+1=14, then ⌊(14+2−3)/2⌋+1=7\lfloor(14+2-3)/2\rfloor+1=7. The feature map is 32×7×732\times7\times7, which flattens to 1,5681{,}568 numbers.

    The code. The linear layer returns (B,32)(B,32), split into μ\vec\mu and log⁡σ2\log\vec\sigma^2, each (B,16)(B,16). The noise ε\vec\varepsilon and the code z=μ+σ⊙ε\vec z=\vec\mu+\vec\sigma\odot\vec\varepsilon are (B,16)(B,16).

    Decoder sizes. The linear layer returns (B,1568)(B,1568), reshaped to (B,32,7,7)(B,32,7,7). Each transposed layer gives (n−1)⋅2−2+2+1+1=2n(n-1)\cdot2-2+2+1+1=2n: 7→147\to14 and 14→2814\to28. Without the output padding the sizes would be 1313 and 2525, as I.12.B05 found.

    Parameters.

    layerparameters
    conv 1→161\to1616⋅9+16=16016\cdot9+16=160
    conv 16→3216\to3232⋅16⋅9+32=4,64032\cdot16\cdot9+32=4{,}640
    linear 1568→321568\to321568⋅32+32=50,2081568\cdot32+32=50{,}208
    linear 16→156816\to156816⋅1568+1568=26,65616\cdot1568+1568=26{,}656
    transposed 32→1632\to1632⋅16⋅9+16=4,62432\cdot16\cdot9+16=4{,}624
    transposed 16→116\to116⋅9+1=14516\cdot9+1=145

    The total is 86,43386{,}433. Almost nine tenths of it, 76,86476{,}864, sits in the two linear layers on either side of the code.

    The error. 32⋅8⋅8=2,04832\cdot8\cdot8=2{,}048, but the feature map is 7×77\times7, so the flattened tensor has 1,5681{,}568 entries. The matrix product fails at the first batch. The colleague halved 2828 to 1414 and then to 88, rounding the wrong way; (I.11.4) takes the floor and gives 77.

    The loss. Each example’s reconstruction term sums over 784784 pixels and its KL over 1616 coordinates, both then averaged over the batch. Averaging the reconstruction over pixels as well would train with β=784\beta=784 (I.13.X07).

    Answer

    Spatial sizes 28→14→728\to14\to7 and back 7→14→287\to14\to28; flattened 1,5681{,}568; μ\vec\mu, σ\vec\sigma, ε\vec\varepsilon and z\vec z all (B,16)(B,16); 86,43386{,}433 parameters; the colleague’s 2,0482{,}048 should be 1,5681{,}568.

    Check — sanity

    The decoder’s sizes are the encoder’s read backwards, and its linear layer mirrors the encoder’s with kk inputs where the encoder had 2k2k outputs: 26,65626{,}656 against 50,20850{,}208.

    Where this breaks

    The shapes say nothing about whether the code is used. With the reductions consistent, a decoder this size can still ignore z\vec z if the KL weight is too high (I.13.T3).

    Variation

    With k=2k=2 for a code that can be plotted, the encoder’s linear layer shrinks to 1568⋅4+4=6,2761568\cdot4+4=6{,}276 and the decoder’s to 2⋅1568+1568=4,7042\cdot1568+1568=4{,}704, and the total to 20,54920{,}549.

    Problem I.BOOK.B07

    Cross-entropy through a graph convolution

    gradient▲▲△

    Six decimal places.

    STATEMENT

    Classify the four nodes of the paw graph with one graph convolution and a softmax, derive the gradient with respect to the weights, take one step, and read off what the averaging did to the node whose own features disagree with its neighbours’.

    GIVEN

    The paw graph of I.14, with A^\hat{\mat A} from (I.14.5). Node features X\mat X have rows (1,0)(1,0), (1,0)(1,0), (0,1)(0,1), (0,1)(0,1), and the labels are classes 11, 11, 22, 22. Logits Z=A^XW\mat Z=\hat{\mat A}\mat X\mat W with W=I\mat W=\mat I at the start, a softmax on each row, and the mean cross-entropy over the four nodes. Step size 11.

    FIND

    A^X\hat{\mat A}\mat X; the loss; the gradient ∂L/∂W\partial\mathcal L/\partial\mat W; the loss after one step; each node’s probability of its own class.

    STRATEGY

    Softmax with cross-entropy has the gradient P−Y\mat P-\mat Y with respect to the logits (I.4.P03). Divide by four for the mean, then apply the chain rule for a matrix product (I.6).

    SOLUTION

    Averaged features. With degrees (3,3,4,2)(3,3,4,2) counted with self-loops,

    A^X=((0.666667,  0.288675),(0.666667,  0.288675),(0.577350,  0.603553),(0,  0.853553)),\begin{aligned} &\hat{\mat A}\mat X=\\ &\quad\big((0.666667,\;0.288675),\\ &\quad(0.666667,\;0.288675),\\ &\quad(0.577350,\;0.603553),\\ &\quad(0,\;0.853553)\big), \end{aligned}

    one row per node. Node 33‘s row mixes its own class-22 feature with two class-11 neighbours, and the two entries come out almost equal.

    Loss. With W=I\mat W=\mat I these rows are the logits. Each node’s probability of its own class is 0.5933890.593389 for nodes 11 and 22, 0.5065500.506550 for node 33 and 0.7013120.701312 for node 44, and the mean cross-entropy is 0.5196860.519686.

    Gradient. With G=(P−Y)/4\mat G=(\mat P-\mat Y)/4, the chain rule gives

    ∂L∂W=(A^X)TG.\frac{\partial\mathcal L}{\partial\mat W}=(\hat{\mat A}\mat X)^{\mathsf T}\mat G.

    Its first row is (−0.064314, 0.064314)(-0.064314,\,0.064314) and its second (0.079503, −0.079503)(0.079503,\,-0.079503).

    Each row sums to zero because each row of P−Y\mat P-\mat Y does: adding the same number to both logits of a node changes no probability.

    One step. W←W−∂L/∂W\mat W\leftarrow\mat W-\partial\mathcal L/\partial\mat W lowers the loss to 0.4993560.499356. The step strengthens the link from the first averaged feature to class 11 and from the second to class 22.

    What the averaging did. Node 33‘s own features say class 22 with no doubt. After one convolution its probability of class 22 is 0.5065500.506550, barely above a coin: its two class-11 neighbours contribute 0.5773500.577350 to its average, against 0.6035530.603553 from itself and node 44. A sum layer with its own self-weight, (I.14.3), could keep that evidence; the convolution’s fixed average cannot. This is the first round of the smoothing in I.14.P03.

    Answer

    A^X\hat{\mat A}\mat X as above; loss 0.5196860.519686; gradient rows (−0.064314, 0.064314)(-0.064314,\,0.064314) and (0.079503, −0.079503)(0.079503,\,-0.079503); loss 0.4993560.499356 after one step. Own-class probabilities 0.5933890.593389, 0.5933890.593389, 0.5065500.506550, 0.7013120.701312.

    Check — sanity

    Node 44, whose only neighbour is node 33, is the most confident: its average has no class-11 feature at all, so its first logit is 00.

    Where this breaks

    The gradient would be the same for any relabelling of the nodes, since both A^X\hat{\mat A}\mat X and P−Y\mat P-\mat Y would be permuted together and the product sums over nodes. A model that needs to treat node 33 differently from its neighbours needs features or layers that keep it apart.

    Variation

    The script checks all four entries of the gradient against central finite differences. Replacing the convolution by the sum layer XW0+AXW1\mat X\mat W_0+\mat A\mat X\mat W_1 with W0=I\mat W_0=\mat I, W1=0\mat W_1=\mat 0 recovers each node’s own features as logits, and node 33‘s own-class probability returns to 1/(1+e−1)=0.7310591/(1+e^{-1})=0.731059.

    Problem I.BOOK.B08

    Depth adds nothing to a linear autoencoder

    proof▲▲▲

    Exact.

    STATEMENT

    Prove that a deep linear autoencoder, of any depth and widths, attains no lower reconstruction loss than principal components with as many components as its narrowest layer, and that it attains exactly that loss. Connect the result to the linear β-VAE of I.13 as β goes to zero.

    GIVEN

    Centred data with covariance eigenvalues λ1≥⋯≥λd\lambda_1\geq\cdots\geq\lambda_d. A linear autoencoder x^=WL⋯W1x\hat{\vec x}=\mat W_L\cdots\mat W_1\vec x whose layer widths are d=n0,n1,…,nL−1,nL=dd=n_0,n_1,\ldots,n_{L-1},n_L=d, with k=min⁡ℓnℓ<dk=\min_\ell n_\ell<d. For the numbers, the four points of I.12, with widths 2,3,1,3,22,3,1,3,2.

    FIND

    A lower bound on the loss, a choice of weights that attains it, and the loss for the four points; the link to I.13.T3.

    STRATEGY

    The product of the layers is one matrix whose rank is limited by the narrowest layer. Then I.12.T1 applies to that one matrix.

    SOLUTION

    The product is one map. Without nonlinearities the network computes M=WL⋯W1\mat M=\mat W_L\cdots\mat W_1, a single linear map (I.3.B05). Every vector that leaves the narrowest layer lies in a space of dimension kk, so the image of M\mat M has dimension at most kk: rank⁡M≤k\operatorname{rank}\mat M\leq k (Rank, eigenvalues and the singular value decomposition 0.LA.04).

    The bound. The loss depends on the weights only through M\mat M, as tr⁡((I−M)S(I−M)T)\operatorname{tr}\big((\mat I-\mat M)\mat S(\mat I-\mat M)^{\mathsf T}\big) (I.12.2). A matrix of rank at most kk factors as DE\mat D\mat E with E\mat E of shape k×dk\times d, so I.12.T1 applies: L≥λk+1+⋯+λd\mathcal L\geq\lambda_{k+1}+\cdots+\lambda_d. ■\blacksquare

    Attaining it. Let Uk\mat U_k hold the top kk eigenvectors. Map the input to UkTx\mat U_k^{\mathsf T}\vec x in the first layers, carry those kk numbers unchanged through every later layer, padding with zeros where a layer is wider than kk, and map back with Uk\mat U_k at the end. Every width is at least kk, so each step is possible, and the product is UkUkT\mat U_k\mat U_k^{\mathsf T}, which attains the bound. ■\blacksquare

    The four points. With widths 2,3,1,3,22,3,1,3,2, the narrowest is 11. The layers [0.80.60010]\begin{bmatrix}0.8&0.6\\0&0\\1&0\end{bmatrix}, [100]\begin{bmatrix}1&0&0\end{bmatrix}, [100]\begin{bmatrix}1\\0\\0\end{bmatrix} and [0.8000.600]\begin{bmatrix}0.8&0&0\\0.6&0&0\end{bmatrix} multiply to [0.640.480.480.36]=u1u1T\begin{bmatrix}0.64&0.48\\0.48&0.36\end{bmatrix}=\vec u_1\vec u_1^{\mathsf T}, and the loss is 1=λ21=\lambda_2. The extra rows in the first layer and the extra width in the third change nothing: depth and width beyond the bottleneck buy no expressiveness here.

    The link to I.13. By I.13.T3 the linear β-VAE has distortion λ2+⋯+λd+βσ2\lambda_2+\cdots+\lambda_d+\beta\sigma^2, which tends to the same bound as β→0\beta\to0. A deterministic linear autoencoder of any depth, and a linear VAE whose code becomes free, end at one point: the principal subspace.

    Answer

    L≥λk+1+⋯+λd\mathcal L\geq\lambda_{k+1}+\cdots+\lambda_d with kk the narrowest width, attained by passing the top kk principal scores through every layer. For the four points with widths 2,3,1,3,22,3,1,3,2 the loss is 11, which is also the linear β-VAE’s distortion as β→0\beta\to0.

    Check — sanity

    If every width were at least dd, then k=dk=d, the bound would be an empty sum, and the identity would be reachable: depth cannot make a linear autoencoder compress unless some layer is narrow.

    Where this breaks

    The result is about the minimum, not the path to it. Gradient descent on the deep factorisation meets saddles that the one-layer problem does not have (I.12.T2), and its trajectory depends on depth, as I.3.B05 noted. With nonlinear layers the bound no longer applies, which is the point of making them nonlinear.

    Variation

    A two-dimensional code, widths 2,3,2,3,22,3,2,3,2, makes k=2=dk=2=d: the loss can be 00, and the network can copy. The narrowest layer, not the depth, decides what is lost.