Skip to content

Finding the Principal Subspace

Page 1003 settled the coordinates and left one term standing: xnBBxn2\lVert\mathbf{x}_n - \mathbf{B}\mathbf{B}^\top\mathbf{x}_n\rVert^2, with no z\mathbf{z} in it. §10.3.3 minimises that over bases — and the book’s own summary of where it ends up is worth reading before the derivation:

Therefore, we omit a derivation that is identical to the one presented in Section 10.2.

Two chapters’ worth of setup, two genuinely different objectives, and the same eigenvectors. This page shows why that had to happen, and what it costs to choose otherwise.

  • Equations 10.41–10.43b: four rewritings that turn a sum of squared norms into tr(S)\mathrm{tr}(\cdot\,\mathbf{S}) — each step using exactly one property, and every form measured to agree within 2.8×10132.8\times10^{-13}.
  • Equation 10.44, JM=j>MλjJ_M = \sum_{j>M}\lambda_j, and the one-line reason it forces the top-MM eigenvectors: you are choosing which eigenvalues to pay, so you discard the cheapest.
  • The conservation law nobody states: VM+JM=tr(S)V_M + J_M = \mathrm{tr}(\mathbf{S}) for every MM and every orthonormal B\mathbf{B} — measured constant to 2.3×10132.3\times10^{-13}. §10.2 and §10.3 are one optimisation with two signs.
  • Whether the eigenbasis is genuinely optimal, tested rather than assumed: 200,000200{,}000 random orthonormal bases, zero of them better, best one worse by 304.302698304.302698; and an L-BFGS search over B\mathbf{B} that lands back on the same subspace to 2.0×1072.0\times10^{-7} — with a different basis.
  • Why that last distinction matters: rotating B\mathbf{B} by any orthogonal R\mathbf{R} leaves JMJ_M exactly unchanged while moving the codes by 39.24353739.243537. §10.7’s Equation 10.78 will call this ambiguity by name.
  • The one thing only the eigenbasis gives you: a code whose components are uncorrelated — measured largest off-diagonal covariance 5.1×10145.1\times10^{-14} against 37.04685237.046852 after a rotation.

Intuition: you are not choosing what to keep, you are choosing what to pay

Section titled “Intuition: you are not choosing what to keep, you are choosing what to pay”

The trick of §10.3.3 is a change of viewpoint that Equation 10.38 already set up. The reconstruction error is built entirely from the directions you discarded — so write the objective in terms of those.

Once you do, the answer is arithmetic. Each discarded direction contributes its eigenvalue to the bill. Sixty-four eigenvalues, choose DMD - M of them to pay: take the small ones.

diagram Section 10.3.3 in four moves mermaid

Starting from Equation 10.38b, the displacement expanded in the discarded basis vectors:

JM=1Nn=1Nj=M+1D(bjxn)bj2(10.41)J_M = \frac{1}{N}\sum_{n=1}^{N}\left\lVert\sum_{j=M+1}^{D}(\mathbf{b}_j^\top\mathbf{x}_n)\mathbf{b}_j\right\rVert^2 \qquad \text{(10.41)}

Move one — expand the squared norm. The bj\mathbf{b}_j are orthonormal, so every cross term bjbk\mathbf{b}_j^\top\mathbf{b}_k with jkj \neq k is zero and the double sum collapses to a single one:

JM=1Nn=1Nj=M+1D(bjxn)2(10.42a)J_M = \frac{1}{N}\sum_{n=1}^{N}\sum_{j=M+1}^{D}(\mathbf{b}_j^\top\mathbf{x}_n)^2 \qquad \text{(10.42a)}

Move two — a scalar is its own transpose. (bjxn)2=bjxnxnbj(\mathbf{b}_j^\top\mathbf{x}_n)^2 = \mathbf{b}_j^\top\mathbf{x}_n\mathbf{x}_n^\top\mathbf{b}_j, which introduces the outer product:

JM=1Nn=1Nj=M+1Dbjxnxnbj(10.42b)J_M = \frac{1}{N}\sum_{n=1}^{N}\sum_{j=M+1}^{D}\mathbf{b}_j^\top\mathbf{x}_n\mathbf{x}_n^\top\mathbf{b}_j \qquad \text{(10.42b)}

Move three — swap the sums. The bj\mathbf{b}_j do not depend on nn, so the average over nn falls onto the outer products and S\mathbf{S} appears:

JM=j=M+1Dbj ⁣(1Nn=1Nxnxn) ⁣bj=j=M+1DbjSbj(10.43a)J_M = \sum_{j=M+1}^{D}\mathbf{b}_j^\top\!\left(\frac{1}{N}\sum_{n=1}^{N}\mathbf{x}_n\mathbf{x}_n^\top\right)\!\mathbf{b}_j = \sum_{j=M+1}^{D}\mathbf{b}_j^\top\mathbf{S}\mathbf{b}_j \qquad \text{(10.43a)}

Move four — the trace. A scalar equals its own trace, and the trace is cyclic:

JM=j=M+1Dtr ⁣(Sbjbj)=tr((j=M+1Dbjbj)projector onto US)(10.43b)J_M = \sum_{j=M+1}^{D}\mathrm{tr}\!\left(\mathbf{S}\mathbf{b}_j\mathbf{b}_j^\top\right) = \mathrm{tr}\Bigg(\underbrace{\bigg(\sum_{j=M+1}^{D}\mathbf{b}_j\mathbf{b}_j^\top\bigg)}_{\text{projector onto } U^\perp}\mathbf{S}\Bigg) \qquad \text{(10.43b)}

Minimizing the average squared reconstruction error is therefore equivalent to minimizing the projection of the data covariance matrix onto the orthogonal complement of the principal subspace. Equivalently, we maximize the variance of the projection that we retain in the principal subspace.

Every form, measured on the digit-”8” data:

MMEq 10.29Eq 10.41Eq 10.43aEq 10.43bEq 10.44
11589.590460589.590460589.590460589.590460589.590460589.590460589.590460589.590460589.590460589.590460
22501.876658501.876658501.876658501.876658501.876658501.876658501.876658501.876658501.876658501.876658
55320.123369320.123369320.123369320.123369320.123369320.123369320.123369320.123369320.123369320.123369
1010166.190803166.190803166.190803166.190803166.190803166.190803166.190803166.190803166.190803166.190803
202059.35180559.35180559.35180559.35180559.35180559.35180559.35180559.35180559.35180559.351805
40402.8922802.8922802.8922802.8922802.8922802.8922802.8922802.8922802.8922802.892280

Largest spread within any row, across all MM from 11 to 6363: 2.8×10132.8\times10^{-13}.

figure The five forms of J_M, and the budget that makes Sections 10.2 and 10.3 one problem matplotlib
Left, three curves of reconstruction error against M lying exactly on top of each other, falling steeply from about 590 to near zero by M equal to forty. Right, a filled area chart where a blue region grows and a red region shrinks, their total pinned at a dotted horizontal line marked 741.158872. Left, three curves of reconstruction error against M lying exactly on top of each other, falling steeply from about 590 to near zero by M equal to forty. Right, a filled area chart where a blue region grows and a red region shrinks, their total pinned at a dotted horizontal line marked 741.158872.
Left: measured directly, computed as a trace, and read off the spectrum — three routes, one curve. Right: the variance kept and the variance lost always sum to the trace of S, measured constant to 2.3e-13. There is no trade-off to negotiate; maximising one is minimising the other.

Equation 10.44, and why the choice is forced

Section titled “Equation 10.44, and why the choice is forced”

Minimising Equation 10.43b over orthonormal B\mathbf{B} is minimising j>MbjSbj\sum_{j>M}\mathbf{b}_j^\top\mathbf{S}\mathbf{b}_j over the discarded directions — the same Rayleigh-quotient problem §10.2 solved, with the sign flipped. The stationary points are eigenvectors, and:

JM=j=M+1Dλj(10.44)J_M = \sum_{j=M+1}^{D}\lambda_j \qquad \text{(10.44)}

To minimize (10.44) we need to select the smallest DMD-M eigenvalues, which then implies that their corresponding eigenvectors are the basis of the orthogonal complement of the principal subspace.

Which five of the 6464 eigenvectors you keep, measured:

kept directionsJMJ_M
the top 55 (Equation 10.44)320.123369\mathbf{320.123369}
every 1212th (1,13,25,37,491, 13, 25, 37, 49)570.187987570.187987
five from the middle (26263030)725.666168725.666168
the bottom 55741.158872741.158872

The last row is tr(S)\mathrm{tr}(\mathbf{S}) exactly — those five eigenvalues are the machine zeros from page 1001’s dead border pixels, so keeping them keeps nothing. You have built a five-dimensional subspace that stores no information at all, and the code is five numbers of noise.

figure Not one random subspace comes close, and neither does any other choice of five eigenvectors matplotlib
Left, a histogram of four thousand values clustered between about 640 and 720, with a solid vertical line far to their left at 320.12, a dashed line at 645.61 and a dotted line at 741.16. Right, a bar chart of four reconstruction errors: 320.12, 725.67, 570.19 and 741.16. Left, a histogram of four thousand values clustered between about 640 and 720, with a solid vertical line far to their left at 320.12, a dashed line at 645.61 and a dotted line at 741.16. Right, a bar chart of four reconstruction errors: 320.12, 725.67, 570.19 and 741.16.
The histogram is 4,000 random orthonormal bases at M = 5; the full run of 200,000 produced a best of 624.426067 and exactly zero that beat 320.123369. The right panel's last bar equals the trace of S — keeping the five smallest eigenvectors keeps literally nothing, because those eigenvalues are machine zero.

JMJ_M depends on B\mathbf{B} only through BB\mathbf{B}\mathbf{B}^\top. So for any orthogonal RRM×M\mathbf{R} \in \mathbb{R}^{M\times M}, (BR)(BR)=BRRB=BB(\mathbf{B}\mathbf{R})(\mathbf{B}\mathbf{R})^\top = \mathbf{B}\mathbf{R}\mathbf{R}^\top\mathbf{B}^\top = \mathbf{B}\mathbf{B}^\top, and the error cannot tell the two apart:

basis for the same 55-dimensional spanJMJ_MmaxBBBB\max\lvert\mathbf{B}\mathbf{B}^\top - \mathbf{B}_\star\mathbf{B}_\star^\top\rvert
the eigenvectors themselves320.123369320.1233690.00.0
rotated by a random R\mathbf{R}, draw 11320.123369320.1233691.1×10161.1\times10^{-16}
rotated by a random R\mathbf{R}, draw 22320.123369320.1233691.1×10161.1\times10^{-16}
rotated by a random R\mathbf{R}, draw 33320.123369320.1233698.3×10178.3\times10^{-17}
rotated by a random R\mathbf{R}, draw 44320.123369320.1233691.9×10161.9\times10^{-16}
figure Same subspace, same error, entirely different components matplotlib
Top row, four eight-by-eight red-and-blue images: two eigenvector images and two visibly different rotated versions. Bottom, two five-by-five covariance heatmaps — the left one is purely diagonal, the right one has substantial off-diagonal colour. Top row, four eight-by-eight red-and-blue images: two eigenvector images and two visibly different rotated versions. Bottom, two five-by-five covariance heatmaps — the left one is purely diagonal, the right one has substantial off-diagonal colour.
Both bases give J_M = 320.123369 and identical reconstructions. The codes are not identical: they differ by 39.243537, though their norms agree to 1.1e-14. The bottom row is what the rotation destroys — the eigenbasis leaves the code's covariance diagonal to 5.1e-14, while the rotated basis mixes it to 37.046852.

The book embeds MNIST’s “0”s and “1”s in the first two principal components and observes “a relatively clear separation” plus “the variation within the set of ‘0’ is significantly greater than the variation within the set of ‘1’.”

Worth noting what that does not mean. The labels were never used. PCA found the directions of greatest spread across all the images, and the classes happened to separate along them because “0” or “1” is a large part of what varies. When the dominant variation is something else — lighting, rotation, stroke width — the same two components will separate on that instead, and the classes will overlap. That is the difference between an unsupervised method and a supervised one, and Chapter 12 takes the other road.

pch.quizTag Does the projection derivation land?
  1. Which property makes the cross terms vanish when Equation 10.41's squared norm is expanded?

    pch.quizShowAnswer

    B — Orthonormality of the basis vectors — b_j-transpose b_k is zero for j not equal to k — Each of the four moves spends exactly one property: orthonormality collapses the double sum, a scalar equalling its own transpose introduces the outer product, independence of n lets the sums swap so S appears, and the trace being linear and cyclic gives Equation 10.43b. Measured, all five forms agree to 2.8e-13.

  2. Why must the DISCARDED directions be the ones with the smallest eigenvalues?

    pch.quizShowAnswer

    B — Because J_M is the sum of the eigenvalues of the directions you discard, so you discard the cheapest — Equation 10.44 makes the choice arithmetic. Measured at M = 5: keeping the top five costs 320.123369, five from the middle costs 725.666168, and keeping the bottom five costs 741.158872 — exactly the trace, because those eigenvalues are machine zero. That last subspace is five dimensions that store nothing.

  3. What is V_M + J_M, for any M and any orthonormal B?

    pch.quizShowAnswer

    B — Always the trace of S — measured constant at 741.158872 to within 2.3e-13 — The two projectors sum to the identity, so the two traces sum to the trace of S. That is why Sections 10.2 and 10.3 are one optimisation read from either end, and why the book can omit the second derivation entirely.

  4. You rotate B by an orthogonal M-by-M matrix R. What changes?

    pch.quizShowAnswer

    B — Nothing about the error or the reconstructions; the codes change completely and stop being uncorrelated — Measured: J_M stays at 320.123369 and B B-transpose matches to 1.1e-16, while the codes differ by 39.243537 with their norms preserved to 1.1e-14. The rotated code's covariance has off-diagonals up to 37.046852 against 5.1e-14 for the eigenbasis. Section 10.7's Equation 10.78 names this ambiguity, and Section 10.8 says it is why ICA exists.

Exercise 1 – From a sum of squares to a trace

Section titled “Exercise 1 – From a sum of squares to a trace”

Exercise 3 – Can any other subspace beat it?

Section titled “Exercise 3 – Can any other subspace beat it?”

Exercise 4 – The error cannot see the basis

Section titled “Exercise 4 – The error cannot see the basis”
  • Section 10.3.3 rewrites the reconstruction error four times and lands on a trace: the projection of the data covariance onto the orthogonal complement of the subspace you kept.
  • Each rewriting spends exactly one property — orthonormality, a scalar equalling its transpose, independence of the data index, and the trace being linear and cyclic. None of them touches the data.
  • All five forms of the error agree to 2.8e-13 across every code length from one to sixty-three.
  • Equation 10.44 makes the choice arithmetic: the error is the sum of the eigenvalues of the directions you discard, so you discard the smallest ones.
  • Keeping the five cheapest eigenvectors instead costs the entire trace, because those eigenvalues are machine zero — five dimensions that store nothing.
  • The variance kept and the variance lost always sum to the trace of S, measured constant to 2.3e-13. Sections 10.2 and 10.3 are one optimisation read from opposite ends.
  • Two hundred thousand random orthonormal bases, and none of them beats the eigenbasis. The best is worse by 304.302698.
  • A numerical optimiser over the basis finds the same subspace to 2.0e-07 and a different basis, differing by 0.351661 — which is the ambiguity the next sections name.
  • Rotating the basis by any orthogonal matrix leaves the error exactly unchanged, because the objective depends on B B-transpose alone.
  • But it changes the codes by 39.243537 while preserving their norms, and destroys the two properties the eigenbasis happens to add: sorted per-component variances, and uncorrelated components.
  • Those extra properties were never optimised for. Equation 10.78 states the ambiguity formally, and Section 10.8 says it is why independent component analysis exists.
  • Example 10.3’s class separation used no labels. PCA finds the directions of greatest spread; the classes separate only when the class is what varies most.

Next: Eigenvector Computation and Low-Rank Approximations — §10.4 connects the eigendecomposition to the SVD, and asks how you would compute any of this at scale.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading