Skip to content

Problem Setting

Chapter 9 fitted a function to labelled data. Chapter 10 has no labels at all — only x\mathbf{x}, and a request: “find projections x~n\tilde{\mathbf{x}}_n of data points xn\mathbf{x}_n that are as similar to the original data points as possible, but which have a significantly lower intrinsic dimensionality.”

This page is §10.1: three equations, one worked example, and a phrase in Equation 10.1’s preamble that decides whether any of it works.

  • Equations 10.1–10.3: the data covariance matrix, the code z=Bx\mathbf{z} = \mathbf{B}^\top\mathbf{x}, and the projection matrix B\mathbf{B}.
  • The four words “with mean 0\mathbf{0} attached to Equation 10.1 — and what breaks without them. Measured on 174174 images of the digit “8”: the leading direction moves 87.999687.9996^\circ, landing 0.28510.2851^\circ from the mean image, which says nothing about how the digits differ.
  • Why BB\mathbf{B}^\top\mathbf{B} and BB\mathbf{B}\mathbf{B}^\top are different objects. The first is IM\mathbf{I}_M exactly; the second is D×DD\times D with tr=M\mathrm{tr} = M — §10.3 will call it “the best rank-MM approximation of the identity”.
  • Example 10.1, run three ways: the same M=1M = 1 budget gives reconstruction errors 5.0000005.000000, 3.0000003.000000 and 0.0000000.000000. Choosing b\mathbf{b} is the entire rest of the chapter.
  • The book’s own notation warning: data points are the columns of X\mathbf{X} here, not the rows. Every matrix shape in Chapter 10 depends on it.
  • What “overcomplete” measures out to: rank 5252 of 6464, 1212 pixels with exactly zero variance, and 5757 of 13261326 pixel pairs correlated above 0.50.5.

Intuition: a bottleneck you choose the shape of

Section titled “Intuition: a bottleneck you choose the shape of”

Compression is a promise about what you are allowed to forget. Figure 10.2 draws it as a funnel: xRD\mathbf{x} \in \mathbb{R}^D goes in, a code zRM\mathbf{z} \in \mathbb{R}^M comes out the narrow part, and a reconstruction x~RD\tilde{\mathbf{x}} \in \mathbb{R}^D comes out the far side. The reconstruction has DD numbers in it again — but only MM of them are free.

Two decisions live in that picture and they are not the same decision:

How narrow is the neck? That is MM, and it is yours to pick. It fixes the storage bill and nothing else.

Which directions survive it? That is B\mathbf{B}, and §10.1 does not answer it. It only says the columns are orthonormal. Example 10.1 below shows two bases with the identical M=1M = 1 budget producing errors of 55 and 33 on the same vector — and a third reaching 00. §10.2 and §10.3 are two derivations of the same answer to this second question.

diagram Figure 10.2, and which arrow each section is about mermaid

The dataset is i.i.d., X={x1,,xN}\mathcal{X} = \{\mathbf{x}_1, \ldots, \mathbf{x}_N\} with xnRD\mathbf{x}_n \in \mathbb{R}^D, with mean 0\mathbf{0}, and it “possesses the data covariance matrix”

S=1Nn=1Nxnxn(10.1)\mathbf{S} = \frac{1}{N}\sum_{n=1}^{N} \mathbf{x}_n\mathbf{x}_n^\top \qquad \text{(10.1)}

There is assumed to exist a low-dimensional compressed representation (code)

zn=BxnRM(10.2)\mathbf{z}_n = \mathbf{B}^\top\mathbf{x}_n \in \mathbb{R}^M \qquad \text{(10.2)}

with the projection matrix

B:=[b1,,bM]RD×M(10.3)\mathbf{B} := [\mathbf{b}_1, \ldots, \mathbf{b}_M] \in \mathbb{R}^{D\times M} \qquad \text{(10.3)}

whose columns are orthonormal: bibj=0\mathbf{b}_i^\top\mathbf{b}_j = 0 for iji \neq j and bibi=1\mathbf{b}_i^\top\mathbf{b}_i = 1. The projected data are x~=BBxRD\tilde{\mathbf{x}} = \mathbf{B}\mathbf{B}^\top\mathbf{x} \in \mathbb{R}^D, living in a subspace URDU \subseteq \mathbb{R}^D with dim(U)=M<D\dim(U) = M < D.

symbolshapewhat it is
xn\mathbf{x}_nD×1D\times 1one data point
X\mathbf{X}D×ND\times Nall of them, as columns
S\mathbf{S}D×DD\times DEquation 10.1
B\mathbf{B}D×MD\times MEquation 10.3, orthonormal columns
zn\mathbf{z}_nM×1M\times 1the code, Equation 10.2
BB\mathbf{B}^\top\mathbf{B}M×MM\times Mexactly IM\mathbf{I}_M
BB\mathbf{B}\mathbf{B}^\topD×DD\times Da projection, rank MM

Equation 10.1 is introduced as “the data covariance matrix”. It is one only because of the clause before it: “with mean 0\mathbf{0}. Written out, 1Nxnxn\frac{1}{N}\sum \mathbf{x}_n\mathbf{x}_n^\top is the matrix of second moments, and the covariance is

Cov[X]=1Nn=1Nxnxnμμ\mathrm{Cov}[\mathcal{X}] = \frac{1}{N}\sum_{n=1}^{N}\mathbf{x}_n\mathbf{x}_n^\top - \boldsymbol\mu\boldsymbol\mu^\top

The two agree exactly when μ=0\boldsymbol\mu = \mathbf{0} and not otherwise. §10.6 will list centring as “Step 1” and call it “not strictly necessary but reduces the risk of numerical problems” — which understates it. Measured on the running dataset:

quantityvalue
μ\lVert\boldsymbol\mu\rVert of the raw images57.26457857.264578
maxSrawScentred\max\lvert\mathbf{S}_{\text{raw}} - \mathbf{S}_{\text{centred}}\rvert196.805423196.805423
and that gap is μμ\boldsymbol\mu\boldsymbol\mu^\top, to5.7×10145.7\times10^{-14}
tr(Scentred)\mathrm{tr}(\mathbf{S}_{\text{centred}}) — the total variance741.158872741.158872
tr(Sraw)\mathrm{tr}(\mathbf{S}_{\text{raw}})4020.3908054020.390805, a factor of 5.4245\mathbf{5.4245}

The trace is what §10.2 is about to start maximising, so inflating it by 5.45.4 is not a rounding concern. Where it actually lands:

angle betweendegrees
centred b1\mathbf{b}_1 and the mean image88.069988.0699
uncentred b1\mathbf{b}_1 and the mean image0.2851\mathbf{0.2851}
centred b1\mathbf{b}_1 and uncentred b1\mathbf{b}_187.999687.9996
figure Equation 10.1 is a covariance only when the mean is zero matplotlib
Top left, a tilted elliptical cloud of points sitting well away from the origin; a yellow line runs from the origin through the cloud's centre while a blue line runs along the cloud's own long axis, nearly perpendicular to it. Top right, a horizontal bar chart of three angles: 88.07, 0.29 and 88.00 degrees. Bottom, three eight-by-eight images: a blurry grey average digit, a red-and-blue image that looks like that same average, and a third red-and-blue image with a quite different structure. Top left, a tilted elliptical cloud of points sitting well away from the origin; a yellow line runs from the origin through the cloud's centre while a blue line runs along the cloud's own long axis, nearly perpendicular to it. Top right, a horizontal bar chart of three angles: 88.07, 0.29 and 88.00 degrees. Bottom, three eight-by-eight images: a blurry grey average digit, a red-and-blue image that looks like that same average, and a third red-and-blue image with a quite different structure.
Skip the centring and the leading direction rotates 87.9996 degrees, to within 0.2851 degrees of the mean image — a direction along which every data point has nearly the same coordinate, and which therefore carries almost no information about how the digits differ from each other. The bottom row is the same statement as pictures.

Example 10.1, and the question §10.1 does not answer

Section titled “Example 10.1, and the question §10.1 does not answer”

The book’s example is deliberately plain: in R2\mathbb{R}^2 with the canonical basis, [5,3]=5e1+3e2[5, 3]^\top = 5\mathbf{e}_1 + 3\mathbf{e}_2, while any vector of the form [0,z][0, z]^\top needs only the single coordinate zz with respect to e2\mathbf{e}_2. The set of such vectors is a subspace with dim(U)=1\dim(U) = 1, because U=span[e2]U = \mathrm{span}[\mathbf{e}_2].

Run it as a compression problem instead, on the vector [5,3][5,3]^\top itself, with M=1M = 1 throughout:

basis b\mathbf{b}code z\mathbf{z}x~\tilde{\mathbf{x}}xx~\lVert\mathbf{x} - \tilde{\mathbf{x}}\rVert
e2\mathbf{e}_2[3][3][0,3][0, 3]^\top5.0000005.000000
e1\mathbf{e}_1[5][5][5,0][5, 0]^\top3.0000003.000000
x/x\mathbf{x}/\lVert\mathbf{x}\rVert[5.830952][5.830952][5,3][5, 3]^\top0.000000\mathbf{0.000000}
figure One code length, three bases, three answers matplotlib
Left, a red cross at coordinates five, three with three coloured lines through the origin — vertical, horizontal and diagonal — and a dotted drop line from the cross to each. The diagonal line passes through the cross itself. Right, a bar chart of three reconstruction errors: five, three, and zero. Left, a red cross at coordinates five, three with three coloured lines through the origin — vertical, horizontal and diagonal — and a dotted drop line from the cross to each. The diagonal line passes through the cross itself. Right, a bar chart of three reconstruction errors: five, three, and zero.
Every row spends exactly one number. The book's Section 10.1 fixes M and requires orthonormal columns, and stops there — nothing said so far prefers any of these three. Sections 10.2 and 10.3 are two different derivations of the same preference.

The book’s running example is MNIST: 60,00060{,}000 handwritten digits at 28×2828\times28 pixels, so xR784\mathbf{x} \in \mathbb{R}^{784}. The pages here use the 8×88\times8 version of the same corpus that ships inside scikit-learn, which needs no download and reproduces to the digit — D=64D = 64, and N=174N = 174 images of the digit “8”. Everything on this page scales; only the numbers change.

figure The reconstruction has 64 numbers in it and M degrees of freedom matplotlib
Top row, six small eight-by-eight greyscale images: an original handwritten eight, then five reconstructions at code lengths one, two, five, ten and twenty, labelled with the fraction of raw storage each uses. Bottom row, the five residual images in red and blue, fading steadily towards blank as the code length grows. Top row, six small eight-by-eight greyscale images: an original handwritten eight, then five reconstructions at code lengths one, two, five, ten and twenty, labelled with the fraction of raw storage each uses. Bottom row, the five residual images in red and blue, fading steadily towards blank as the code length grows.
The top row is Figure 10.2 run end to end. Each reconstruction is a full 64-pixel image, but the matrix of all 174 of them has rank exactly M — measured at 1, 2, 5, 10 and 20. The bottom row is what was thrown away: the residual visibly drains as M grows, and the error norm falls 25.92, 23.99, 20.06, 15.36, 9.35.

The storage arithmetic is worth doing once, because it is the only reason to compress at all. Keeping the codes and the basis costs NM+DM=M(N+D)NM + DM = M(N+D) numbers against NDND raw:

MMrank of X~\tilde{\mathbf{X}}numbers storedshare of 11,13611{,}136
11112382382.1%2.1\%
22224764764.3%4.3\%
55551190119010.7%10.7\%
101010102380238021.4%21.4\%
202020204760476042.7%42.7\%

BB\mathbf{B}^\top\mathbf{B} and BB\mathbf{B}\mathbf{B}^\top are built from the same D×MD\times M matrix and are nothing alike.

BB=IMRM×M,BB=m=1MbmbmRD×D\mathbf{B}^\top\mathbf{B} = \mathbf{I}_M \in \mathbb{R}^{M\times M}, \qquad \mathbf{B}\mathbf{B}^\top = \sum_{m=1}^{M}\mathbf{b}_m\mathbf{b}_m^\top \in \mathbb{R}^{D\times D}

The first is the orthonormality assumption restated. The second is the projection onto span[b1,,bM]\mathrm{span}[\mathbf{b}_1,\ldots,\mathbf{b}_M] — §10.3 arrives at it as Equation 10.39 and notes it is “the best rank-MM approximation of the identity matrix”. Measured, using the same tests page 909 ran on the linear-regression hat matrix:

MMBBI\lvert\mathbf{B}^\top\mathbf{B} - \mathbf{I}\rvertP2P\lvert P^2 - P\rvertPP\lvert P - P^\top\rverttr(P)\mathrm{tr}(P)
114.4×10164.4\times10^{-16}6.9×10176.9\times10^{-17}0.00.01.0000001.000000
223.3×10163.3\times10^{-16}8.3×10178.3\times10^{-17}0.00.02.0000002.000000
556.7×10166.7\times10^{-16}2.2×10162.2\times10^{-16}0.00.05.0000005.000000
10101.3×10151.3\times10^{-15}4.2×10164.2\times10^{-16}0.00.010.00000010.000000

The trace of a projection is its rank, which is the same fact page 909 used to explain Equation 9.22’s (NK)/N(N-K)/N bias. Chapter 10 will use it again in Equation 10.43b.

The chapter’s opening claim is that high-dimensional data “is often overcomplete, i.e., many dimensions are redundant and can be explained by a combination of other dimensions”, and that dimensions “are often correlated so that the data possesses an intrinsic lower-dimensional structure.” On the digit-”8” images:

claimmeasurement
dimensions are redundantthe centred 64×17464\times174 matrix has rank 52\mathbf{52}, not 6464
some carry nothing at all12\mathbf{12} pixels have exactly zero variance; 1919 have variance below 11
dimensions are correlatedmean corr\lvert\text{corr}\rvert between live pixels =0.152872= 0.152872
strongly, in places57\mathbf{57} of 13261326 pixel pairs exceed corr=0.5\lvert\text{corr}\rvert = 0.5

Twelve dead pixels is a free dimensionality reduction that needs no eigendecomposition: they are the image border, always black in every “8”. The other 1212 lost ranks are the interesting part — no single pixel is redundant, but the 5252 live directions span everything.

pch.quizTag Is the setup clear?
  1. Equation 10.1 defines S as the average of x x-transpose. When is that the data covariance matrix?

    pch.quizShowAnswer

    B — Only when the data has mean zero; otherwise it exceeds the covariance by mu mu-transpose — Measured on 174 images of the digit 8: the gap between the raw second-moment matrix and the true covariance matches mu mu-transpose to 5.7e-14, the trace is inflated by a factor of 5.4245, and the leading direction rotates 87.9996 degrees onto the mean image itself — 0.2851 degrees from it.

  2. B is D-by-M with orthonormal columns. What is B-transpose times B, and what is B times B-transpose?

    pch.quizShowAnswer

    B — B-transpose B is the M-by-M identity; B B-transpose is D-by-D with rank M and trace M — Measured at M = 1, 2, 5 and 10: B-transpose B matches the identity to 1.3e-15 at worst, while B B-transpose is exactly symmetric, idempotent to 4.2e-16, and has trace exactly M. The trace of a projection is its rank — the same fact page 909 used on the regression hat matrix.

  3. Section 10.1 fixes M and requires orthonormal columns. What does it NOT do?

    pch.quizShowAnswer

    B — It does not choose the basis — nothing in Section 10.1 prefers one orthonormal B over another — Example 10.1 run as a compression problem: the vector [5, 3] with M = 1 gives reconstruction errors 5.000000 with b = e2, 3.000000 with b = e1, and 0.000000 with b along x itself. Same budget, same orthonormality, three answers. Sections 10.2 and 10.3 are two derivations of the same choice.

  4. For the 174 digit-8 images with D = 64, at what M does storing codes plus basis stop saving anything?

    pch.quizShowAnswer

    B — M = 47, because the basis costs D*M numbers on top of the N*M codes — M(N + D) < N*D fails at M >= 11136/238 = 46.79. The basis is a fixed cost paid once, so it only disappears when N is large — with 60,000 MNIST images it is negligible and the ratio is essentially M/D. When N is comparable to D it is not, which is the regime Section 10.5 addresses.

Exercise 1 – Equation 10.1 is a covariance only if you centre

Section titled “Exercise 1 – Equation 10.1 is a covariance only if you centre”

Exercise 2 – Where the uncentred direction actually points

Section titled “Exercise 2 – Where the uncentred direction actually points”

Exercise 3 – Two matrices, two shapes, one projection

Section titled “Exercise 3 – Two matrices, two shapes, one projection”

Exercise 4 – Example 10.1 as a compression problem

Section titled “Exercise 4 – Example 10.1 as a compression problem”

Exercise 5 – When does compressing stop saving anything?

Section titled “Exercise 5 – When does compressing stop saving anything?”
  • Chapter 10 has no labels. The data is just x, and the request is a projection of it that keeps most of what the original said while needing far fewer numbers.
  • Equation 10.1’s S is the data covariance matrix only because the data is assumed to have mean zero. Applied to raw data it is the second-moment matrix, larger by the outer product of the mean with itself.
  • Measured on 174 images of the digit eight, skipping the centring moves the leading direction by 87.9996 degrees, to within 0.2851 degrees of the mean image — a direction on which every point has nearly the same coordinate.
  • It also inflates the total variance by a factor of 5.4245, and the total variance is exactly what Section 10.2 is about to maximise.
  • The code is z = B-transpose x and the reconstruction is x-tilde = B B-transpose x. B is D by M with orthonormal columns.
  • B-transpose B is the M by M identity; B B-transpose is D by D with rank M. They are built from the same matrix and are not the same object.
  • The trace of B B-transpose is exactly M, measured at M equal to 1, 2, 5 and 10. The trace of a projection is its rank, which is the same fact page 909 used on the regression hat matrix.
  • Section 10.1 fixes the code length and requires orthonormality, and chooses nothing else. Example 10.1’s vector with M equal to one gives errors of 5, 3 and 0 under three different orthonormal bases.
  • Chapter 10 stores data points as the columns of X, not the rows, so X is D by N and every shape in the chapter follows from that.
  • Storage costs M times N plus D, against N times D raw. With 174 images and 64 pixels, a code of length 47 already saves nothing, because the basis is a fixed cost paid once.
  • Overcomplete, measured: the 64 by 174 centred matrix has rank 52, twelve pixels have exactly zero variance, and 57 of 1326 pixel pairs are correlated above one half.

Next: The Maximum Variance Perspective — the first of two derivations that answer the question §10.1 leaves open, by asking which direction keeps the most variance.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading