Skip to content

Chapter 10 Formula Sheet

One page for the whole chapter. Equation numbers are the book’s; the measured columns are this module’s, computed on 174174 images of the digit “8” at D=64D = 64 unless stated otherwise.

Two derivations, one answer.

§10.2 maximum variance§10.3 minimum reconstruction error§10.7 probabilistic PCA
what is optimisedVMV_M, the variance keptJMJ_M, the error paida likelihood
the objectivetr(BBS)\mathrm{tr}(\mathbf{B}\mathbf{B}^\top\mathbf{S})tr(BBS)\mathrm{tr}(\mathbf{B}_\perp\mathbf{B}_\perp^\top\mathbf{S})p(x)=N(μ,BB+σ2I)p(\mathbf{x}) = \mathcal{N}(\boldsymbol\mu, \mathbf{B}\mathbf{B}^\top+\sigma^2\mathbf{I})
at the optimummMλm\sum_{m\le M}\lambda_mj>Mλj\sum_{j>M}\lambda_jσML2=1DMj>Mλj\sigma^2_{\mathrm{ML}} = \frac{1}{D-M}\sum_{j>M}\lambda_j
the answertop MM eigenvectorstop MM eigenvectorsthe same subspace, shrunk
the two sum totr(S)=741.158872\mathrm{tr}(\mathbf{S}) = 741.158872, measured constant to 2.3×10132.3\times10^{-13}
whatequation
data covariance matrixS=1Nnxnxn\mathbf{S} = \frac1N\sum_n\mathbf{x}_n\mathbf{x}_n^\top10.1, mean 0\mathbf{0} assumed
the codezn=BxnRM\mathbf{z}_n = \mathbf{B}^\top\mathbf{x}_n \in \mathbb{R}^M10.2
the projection matrixB=[b1,,bM]RD×M\mathbf{B} = [\mathbf{b}_1,\ldots,\mathbf{b}_M] \in \mathbb{R}^{D\times M}, orthonormal columns — 10.3
the reconstructionx~=BBxRD\tilde{\mathbf{x}} = \mathbf{B}\mathbf{B}^\top\mathbf{x} \in \mathbb{R}^D
the layoutXRD×N\mathbf{X} \in \mathbb{R}^{D\times N} — data points are the columns
whatequation
variance of the first coordinateV1=1Nnz1n2V_1 = \frac1N\sum_n z_{1n}^2, z1n=b1xnz_{1n} = \mathbf{b}_1^\top\mathbf{x}_n10.7, 10.8
in matrix formV1=b1Sb1V_1 = \mathbf{b}_1^\top\mathbf{S}\mathbf{b}_110.9b
the constrained problemmax b1Sb1\max\ \mathbf{b}_1^\top\mathbf{S}\mathbf{b}_1 s.t. b12=1\lVert\mathbf{b}_1\rVert^2 = 110.10
the LagrangianL=b1Sb1+λ1(1b1b1)\mathfrak{L} = \mathbf{b}_1^\top\mathbf{S}\mathbf{b}_1 + \lambda_1(1-\mathbf{b}_1^\top\mathbf{b}_1)10.11
stationaritySb1=λ1b1\mathbf{S}\mathbf{b}_1 = \lambda_1\mathbf{b}_110.13
the variance keptV1=λ1V_1 = \lambda_110.15
the deflationX^=Xi<mbibiX\hat{\mathbf{X}} = \mathbf{X} - \sum_{i<m}\mathbf{b}_i\mathbf{b}_i^\top\mathbf{X}10.17
shared eigenvectorsS^bm=Sbm=λmbm\hat{\mathbf{S}}\mathbf{b}_m = \mathbf{S}\mathbf{b}_m = \lambda_m\mathbf{b}_m10.21
used-up directionsS^bi=0\hat{\mathbf{S}}\mathbf{b}_i = \mathbf{0} for i<mi<m10.22
total kept, total lostVM=mMλmV_M = \sum_{m\le M}\lambda_m, JM=j>MλjJ_M = \sum_{j>M}\lambda_j10.24, 10.25
whatequation
the objectiveJM=1Nnxnx~n2J_M = \frac1N\sum_n\lVert\mathbf{x}_n-\tilde{\mathbf{x}}_n\rVert^210.29
the reconstructionx~n=mzmnbm=Bzn\tilde{\mathbf{x}}_n = \sum_m z_{mn}\mathbf{b}_m = \mathbf{B}\mathbf{z}_n10.28
the optimal coordinateszin=bixnz_{in} = \mathbf{b}_i^\top\mathbf{x}_n10.32
the general projectionx~=B(BB)1Bx=BBx\tilde{\mathbf{x}} = \mathbf{B}(\mathbf{B}^\top\mathbf{B})^{-1}\mathbf{B}^\top\mathbf{x} = \mathbf{B}\mathbf{B}^\top\mathbf{x}10.34
the displacementxnx~n=j>M(bjxn)bj\mathbf{x}_n - \tilde{\mathbf{x}}_n = \sum_{j>M}(\mathbf{b}_j^\top\mathbf{x}_n)\mathbf{b}_j10.38b
the projectormMbmbm=BB\sum_{m\le M}\mathbf{b}_m\mathbf{b}_m^\top = \mathbf{B}\mathbf{B}^\top, symmetric, rank MM10.39
equivalentlyJM=1Nn(IBB)xn2J_M = \frac1N\sum_n\lVert(\mathbf{I}-\mathbf{B}\mathbf{B}^\top)\mathbf{x}_n\rVert^210.40b
as a traceJM=j>MbjSbj=tr((j>Mbjbj)S)J_M = \sum_{j>M}\mathbf{b}_j^\top\mathbf{S}\mathbf{b}_j = \mathrm{tr}\big(\big(\sum_{j>M}\mathbf{b}_j\mathbf{b}_j^\top\big)\mathbf{S}\big)10.43a, 10.43b
the minimumJM=j>MλjJ_M = \sum_{j>M}\lambda_j10.44
the auto-encoder1NnxnBBxn2\frac1N\sum_n\lVert\mathbf{x}_n - \mathbf{B}^\top\mathbf{B}\mathbf{x}_n\rVert^210.76
whatequation
the covariance, factoredS=1NXX\mathbf{S} = \frac1N\mathbf{X}\mathbf{X}^\top10.45
the SVDX=UΣV\mathbf{X} = \mathbf{U}\boldsymbol\Sigma\mathbf{V}^\top10.47
which givesS=1NUΣΣU\mathbf{S} = \frac1N\mathbf{U}\boldsymbol\Sigma\boldsymbol\Sigma^\top\mathbf{U}^\top10.48
the relationλd=σd2/N\lambda_d = \sigma_d^2/N10.49
the best rank-MM approximationX~M=argminrk(A)MXA2\tilde{\mathbf{X}}_M = \arg\min_{\mathrm{rk}(\mathbf{A})\le M}\lVert\mathbf{X}-\mathbf{A}\rVert_210.50
Eckart–YoungX~M=UMΣMVM\tilde{\mathbf{X}}_M = \mathbf{U}_M\boldsymbol\Sigma_M\mathbf{V}_M^\top10.51
power iterationxk+1=Sxk/Sxk\mathbf{x}_{k+1} = \mathbf{S}\mathbf{x}_k / \lVert\mathbf{S}\mathbf{x}_k\rVert10.52
whatequation
the eigenvector equationSbm=1NXXbm=λmbm\mathbf{S}\mathbf{b}_m = \frac1N\mathbf{X}\mathbf{X}^\top\mathbf{b}_m = \lambda_m\mathbf{b}_m10.55
the substitution1NXXcm=λmcm\frac1N\mathbf{X}^\top\mathbf{X}\,\mathbf{c}_m = \lambda_m\mathbf{c}_m, cm:=Xbm\mathbf{c}_m := \mathbf{X}^\top\mathbf{b}_m10.56
the recoveryS(Xcm)=λm(Xcm)\mathbf{S}(\mathbf{X}\mathbf{c}_m) = \lambda_m(\mathbf{X}\mathbf{c}_m)10.57
the remarknormalise Xcm\mathbf{X}\mathbf{c}_m to unit length
measured, N=50N = 50 in D=784D = 784value
nonzero eigenvalues4949, not 5050 — centring costs one rank
top-55 agreement between the two routes3.4×10133.4\times10^{-13}
the Gram matrix’s condition number4.15×10174.15\times10^{17}singular, contrary to the book
speed-up at D=4000D = 4000, N=50N = 504565.2×\mathbf{4565.2\times}
memory, D=10,000D = 10{,}0000.7450.745 GiB against 19.519.5 KiB
unnormalised reconstruction error (digits, M=5M=5)6.269×1046.269\times10^{4} against 1.160×1011.160\times10^{1}
stepequation
1. subtract the mean
2. divide by σd\sigma_dx(d)(x(d)μd)/σdx_*^{(d)} \leftarrow (x_*^{(d)}-\mu_d)/\sigma_d10.58
3. eigendecompose S\mathbf{S}§10.4
4. projectx~=BBx\tilde{\mathbf{x}}_* = \mathbf{B}\mathbf{B}^\top\mathbf{x}_*, z=Bx\mathbf{z}_* = \mathbf{B}^\top\mathbf{x}_*10.59, 10.60
5. undo the standardizationx~(d)x~(d)σd+μd\tilde{x}_*^{(d)} \leftarrow \tilde{x}_*^{(d)}\sigma_d + \mu_d10.61
the error as a function of MM1Nnxnx~n2=i>Mλi\frac1N\sum_n\lVert\mathbf{x}_n-\tilde{\mathbf{x}}_n\rVert^2 = \sum_{i>M}\lambda_i10.62
whatequation
the modelx=Bz+μ+ϵ\mathbf{x} = \mathbf{B}\mathbf{z} + \boldsymbol\mu + \boldsymbol\epsilon, ϵN(0,σ2I)\boldsymbol\epsilon\sim\mathcal{N}(\mathbf{0},\sigma^2\mathbf{I})10.63
the generative processznN(0,I)\mathbf{z}_n\sim\mathcal{N}(\mathbf{0},\mathbf{I}); xnznN(Bzn+μ,σ2I)\mathbf{x}_n\mid\mathbf{z}_n\sim\mathcal{N}(\mathbf{B}\mathbf{z}_n+\boldsymbol\mu,\sigma^2\mathbf{I})10.65, 10.66
the likelihoodE[x]=μ\mathbb{E}[\mathbf{x}] = \boldsymbol\mu, V[x]=BB+σ2I\mathbb{V}[\mathbf{x}] = \mathbf{B}\mathbf{B}^\top+\sigma^2\mathbf{I}10.69, 10.70b
the cross-covarianceCov[x,z]=B\mathrm{Cov}[\mathbf{x},\mathbf{z}] = \mathbf{B}10.71
the jointN ⁣([μ;0], [BB+σ2I, B; B, I])\mathcal{N}\!\big([\boldsymbol\mu;\mathbf{0}],\ [\mathbf{B}\mathbf{B}^\top+\sigma^2\mathbf{I},\ \mathbf{B};\ \mathbf{B}^\top,\ \mathbf{I}]\big)10.72
the posterior meanm=B(BB+σ2I)1(xμ)\mathbf{m} = \mathbf{B}^\top(\mathbf{B}\mathbf{B}^\top+\sigma^2\mathbf{I})^{-1}(\mathbf{x}-\boldsymbol\mu)10.74
the posterior covarianceC=IB(BB+σ2I)1B\mathbf{C} = \mathbf{I}-\mathbf{B}^\top(\mathbf{B}\mathbf{B}^\top+\sigma^2\mathbf{I})^{-1}\mathbf{B}10.75, no x\mathbf{x} in it
ML parametersμML=xˉ\boldsymbol\mu_{\mathrm{ML}} = \bar{\mathbf{x}}; BML=T(Λσ2I)1/2R\mathbf{B}_{\mathrm{ML}} = \mathbf{T}(\boldsymbol\Lambda-\sigma^2\mathbf{I})^{1/2}\mathbf{R}; σML2=1DMj>Mλj\sigma^2_{\mathrm{ML}} = \frac{1}{D-M}\sum_{j>M}\lambda_j10.7710.79
quantityvaluepage
tr(S)\mathrm{tr}(\mathbf{S}), digit “8”741.158872741.1588721001
λ1\lambda_1151.568412151.568412 (20.45%20.45\% of the total)1002
uncentred b1\mathbf{b}_1 vs the mean image0.28510.2851^\circ1001
centred vs uncentred b1\mathbf{b}_187.999687.9996^\circ1001
rank of the centred data matrix5252 of 6464; 1212 dead pixels1001
storage break-evenM=47M = 47, i.e. ND/(N+D)=46.79ND/(N+D) = 46.791001
bmSbm\mathbf{b}_m^\top\mathbf{S}\mathbf{b}_m vs λm\lambda_m8.5×10148.5\times10^{-14}1002
200,000200{,}000 random unit vectors vs λ1\lambda_137.18%37.18\%1002
components for 50/90/99%50/90/99\% of the variance55 / 1818 / 36361002
measured JMJ_M vs j>Mλj\sum_{j>M}\lambda_j2.8×10132.8\times10^{-13} over all MM1002, 1004
Eq 10.32 vs a 100,001100{,}001-point grid search4.9193504.919350 vs 4.9193604.9193601003
the Pythagoras identity, 200,000200{,}000 random z\mathbf{z}1.7×10151.7\times10^{-15}1003
non-orthonormal basis, same subspace24.72840924.728409 vs 16.31627216.3162721003
share of the error in UU^\perp1.0000000000001.0000000000001003
VM+JMtr(S)V_M + J_M - \mathrm{tr}(\mathbf{S})2.3×10132.3\times10^{-13}1004
200,000200{,}000 random orthonormal bases, M=5M=5best 624.426067624.426067 vs 320.123369320.123369; 00 beat it1004
rotating B\mathbf{B}: JMJ_M, codesunchanged; 39.24353739.2435371004
code covariance off-diagonal, eigenbasis vs rotated5.1×10145.1\times10^{-14} vs 37.04685237.0468521004
λd\lambda_d vs σd2/N\sigma_d^2/N1.4×10131.4\times10^{-13}1005
κ(S)/κ(X)\kappa(\mathbf{S})/\kappa(\mathbf{X})246.8358=κ(X)246.8358 = \kappa(\mathbf{X})1005
eigh at κ=1010\kappa = 10^{10}5.3×1035.3\times10^{3} relative, 1818 negatives1005
Eckart–Young spectral error vs σM+1\sigma_{M+1}7×10147\times10^{-14}1005
power-iteration rate, predicted vs observed0.5787080.578708 vs 0.5785410.5785411005
steps to 10610^{-6} deg at λ2/λ1=0.99\lambda_2/\lambda_1 = 0.9917691769, against 2727 at 0.50.51005
N=50N = 50 in D=784D = 784: nonzero eigenvalues49491006
Gram matrix condition number (centred)4.15×10174.15\times10^{17}1006
N×NN\times N speed-up at D=4000D = 40004565.2×4565.2\times1006
unnormalised Xcm\mathbf{X}\mathbf{c}_m6.269×1046.269\times10^{4} vs 1.160×1011.160\times10^{1}1006
metres vs millimetres, unstandardised77.398277.3982^\circ; standardised, 1.2×1061.2\times10^{-6}1007
tr\mathrm{tr}, raw vs standardised386.429897386.429897 vs 2.000000=D2.000000 = D1007
NaNs from Equation 10.582,0882{,}0881007
test statistics vs training statistics15.40025015.400250 vs 15.78199215.7819921007
Eq 10.70b by 400,000400{,}000 samples2.1×1032.1\times10^{-3} relative (floor 1.6×1031.6\times10^{-3})1008
C\mathbf{C} over 200200 observations0.000×1000.000\times10^{0} change1008
CmmC_{mm} vs σ2/λm\sigma^2/\lambda_moff-diagonal 9.7×10169.7\times10^{-16}1008
σML2\sigma^2_{\mathrm{ML}} vs JM/(DM)J_M/(D-M)identical to 88 decimals1008
PPCA shrinkage at σ2=40\sigma^2 = 400.7360930.736093 down to 0.2368340.2368341008
M=0M = 0 baseline, RMS27.22423327.2242331009
four rules for MM11, 1818, 2525, 38381009
rotation vs rescaling equivariance8.0×10168.0\times10^{-16} vs 59.221459.2214^\circ1009
PPCA imputation vs mean-filling36.8%36.8\% better at 10%10\% missing1009
novelty: digit “0” flagged100.0%100.0\%1009
a noisy circle’s eigenvalues0.5010380.501038, 0.4976060.4976061009
kernel PCA on two ringsseparation 0.05977.52990.0597 \to 7.52991009
  1. Equation 10.1 is a covariance only if you centre. Skip it and the leading direction becomes the mean, 0.28510.2851^\circ from it.
  2. §10.1 fixes MM and chooses nothing else. Example 10.1’s vector gives errors 55, 33 and 00 under three orthonormal bases.
  3. Variance is a quadratic form, so maximising it under a norm constraint is an eigenvalue problem — Equation 10.15 makes the answer readable off the spectrum.
  4. The deflation in Equation 10.17 is a proof, not an algorithm. One eigendecomposition gives every component.
  5. §10.3 minimises something different and lands in the same place, because VM+JM=tr(S)V_M + J_M = \mathrm{tr}(\mathbf{S}) is fixed.
  6. The optimal coordinates are the orthogonal projection — geometry, not data — which is why §10.3.3 has only half a problem left.
  7. Equation 10.32 assumes orthonormality and fails quietly without it, 24.7324.73 against 16.3216.32.
  8. The objective sees BB\mathbf{B}\mathbf{B}^\top, not B\mathbf{B}. Hence Equation 10.78’s arbitrary R\mathbf{R}, and hence ICA.
  9. Use the SVD of X\mathbf{X}, not the eigendecomposition of S\mathbf{S}, whenever the small eigenvalues matter.
  10. When NDN \ll D, decompose the N×NN\times N Gram matrix4565×4565\times faster at D=4000D = 4000 — and remember to normalise.
  11. Standardising is a modelling decision. 77.398277.3982^\circ says so, and so does the fact that the raw trace has no units.
  12. PPCA is PCA with a story attached, and the story buys imputation, novelty and a posterior whose width you know in advance.

Back to the start: Dimensionality Reduction Overview

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading