PCA in High Dimensions
§10.4 asked how to compute the eigenvectors. §10.5 asks a sharper question: is even the right matrix to decompose?
For example, if our are images with pixels (e.g., pixel images), we would need to compute the eigendecomposition of a covariance matrix.
That matrix is GiB and its decomposition is cubic in . If you have images, almost all of it is zeros.
What you’ll learn
Section titled “What you’ll learn”- Why makes enormously redundant — and exactly how redundant: measured, a covariance built from points has eigenvalues at machine zero.
- Equation 10.56’s substitution , turning a eigenproblem into an one with the same nonzero eigenvalues — measured agreement .
- Equation 10.57’s recovery of from , and the one-line remark after it that is not optional: measured, skipping the normalisation turns a reconstruction error of into .
- What it actually saves: at rising to at , with the top five eigenvalues agreeing to ; and GiB of memory against KiB.
- Two claims in §10.5 that centred data contradicts. The book says the rank of is , and that “has rank and is invertible”. Both are off by one: centring puts in the null space, so the rank is and the Gram matrix is singular — measured condition number .
- Why §10.8 says this idea “can be pushed to the extreme”: the matrix is built entirely from inner products, which is the door to kernel PCA.
Intuition: fifty points cannot span ten thousand directions
Section titled “Intuition: fifty points cannot span ten thousand directions”points span at most an -dimensional subspace — once you have subtracted their mean. Every direction outside it has exactly zero variance in the data, so has a huge null space that was never interesting.
Decomposing spends work to discover that of its eigenvalues are zero. The Gram matrix carries the same information in numbers, because it never leaves the subspace the data occupies.
flowchart TD A["S b_m = lambda_m b_m
D x D, Equation 10.55"] A -->|"multiply by X' from the left"| B["(1/N) X'X (X'b_m) = lambda_m (X'b_m)
Equation 10.56"] B -->|"c_m := X' b_m"| C["an N x N eigenproblem
same nonzero lambda_m"] C -->|"multiply by X from the left"| D["S (X c_m) = lambda_m (X c_m)
Equation 10.57"] D -->|"then normalise -- the remark"| E["b_m = X c_m / ||X c_m||"]
§10.5 The substitution
Section titled “§10.5 The substitution”Starting from the eigenvector equation with :
Multiply both sides by from the left:
” remains eigenvalue, which confirms our results from Section 4.5.3 that the nonzero eigenvalues of equal the nonzero eigenvalues of .”
Measured on synthetic images in dimensions:
| from the | from the | gap | |
|---|---|---|---|
Nonzero eigenvalues in the matrix: . Largest gap across all of them: . Largest of eigenvalues through of the big matrix: .
And to get back:
Remark. If we want to apply the PCA algorithm that we discussed in Section 10.6, we need to normalize the eigenvectors of so that they have norm .
That remark is the whole recipe, not a footnote
Section titled “That remark is the whole recipe, not a footnote”points the right way and is the wrong length. Measured:
| angle to | ||
|---|---|---|
| deg | ||
| deg | ||
| deg | ||
| deg | ||
| deg |
(Measured on the digit-”8” images used in the exercises below. The synthetic -dimensional set gives norms in the hundreds instead, and the same angles.)
Every downstream formula — Equation 10.32’s , Equation 10.34’s , page 1004’s — assumed . Page 1003 already measured what happens when it isn’t. Here, on the digit-”8” images with and :
| built from | reconstruction error |
|---|---|
| , used as is | |
| the same, normalised | |
| the direct eigenvectors of |
Two off-by-one claims in §10.5
Section titled “Two off-by-one claims in §10.5”The book states, of the case:
If there are no duplicate data points, the rank of the covariance matrix is , so it has many eigenvalues that are .
Those two halves are inconsistent: rank implies zeros, not . And later:
Assuming we have no duplicate data points, this matrix has rank and is invertible.
Both are true for uncentred data and false for the centred data §10.5 assumes in its first sentence (“Assume we have a centered dataset”). Centring makes the rows of sum to zero, so and is in the null space of :
| smallest eigenvalue | ||||
|---|---|---|---|---|
| uncentred | ||||
| centred, as §10.5 assumes |
What it saves
Section titled “What it saves”The book’s own example, pixel images:
| object | size in memory, float64 |
|---|---|
| , | GiB |
| the Gram matrix, | KiB |
Measured, at fixed , forming the matrix and decomposing it:
| route | route | speed-up | top- eigenvalues agree to | |
|---|---|---|---|---|
| ms | ms | |||
| ms | ms | |||
| ms | ms | |||
| ms | ms |
-
With N = 50 centred points in D = 784 dimensions, how many nonzero eigenvalues does S have?
Measured: 49 nonzero, 735 at machine zero. The book's count of D minus N plus one zeros is right; its statement that the rank is N is off by one for the centred data it assumes two paragraphs earlier. Centring puts the all-ones vector in the null space of X-transpose X.
pch.quizShowAnswer
B — 49 — N points give N minus one directions once the mean is subtracted — Measured: 49 nonzero, 735 at machine zero. The book's count of D minus N plus one zeros is right; its statement that the rank is N is off by one for the centred data it assumes two paragraphs earlier. Centring puts the all-ones vector in the null space of X-transpose X.
-
What does Equation 10.56 achieve?
Multiply S b = lambda b by X-transpose from the left, and X-transpose b becomes the eigenvector of the N-by-N Gram matrix with the same eigenvalue. Measured agreement on the top five: 3.4e-13. The eigenvectors come back via Equation 10.57, X c_m — after normalising.
pch.quizShowAnswer
B — It turns the D-by-D eigenproblem into an N-by-N one with exactly the same nonzero eigenvalues — Multiply S b = lambda b by X-transpose from the left, and X-transpose b becomes the eigenvector of the N-by-N Gram matrix with the same eigenvalue. Measured agreement on the top five: 3.4e-13. The eigenvectors come back via Equation 10.57, X c_m — after normalising.
-
Why is the remark about normalising X c_m not optional?
The directions are exact — measured to under two millionths of a degree. The lengths are not: on the digit data the norms run from 18.52 to 54.37. Using them as is gives a reconstruction error of 6.269e+04 against 1.160e+01, which is page 1003's non-orthonormal-basis measurement all over again.
pch.quizShowAnswer
B — Because every formula from Equation 10.32 onwards assumes B-transpose B equals the identity, and these columns have norms in the hundreds — The directions are exact — measured to under two millionths of a degree. The lengths are not: on the digit data the norms run from 18.52 to 54.37. Using them as is gives a reconstruction error of 6.269e+04 against 1.160e+01, which is page 1003's non-orthonormal-basis measurement all over again.
-
What is the entry (i, j) of the matrix Equation 10.56 decomposes?
The dimension D appears nowhere in the matrix, only in the cost of forming each entry. Section 10.8 pushes that to infinite-dimensional features: replace the inner product with a kernel and the whole of this page still works. That is kernel PCA, and Chapter 12 uses the same substitution on the support vector machine.
pch.quizShowAnswer
B — An inner product between data points i and j, divided by N — which is why the kernel trick applies — The dimension D appears nowhere in the matrix, only in the cost of forming each entry. Section 10.8 pushes that to infinite-dimensional features: replace the inner product with a kernel and the whole of this page still works. That is kernel PCA, and Chapter 12 uses the same substitution on the support vector machine.
Exercises
Section titled “Exercises”Exercise 1 – How much of S is empty
Section titled “Exercise 1 – How much of S is empty”Exercise 2 – Equation 10.56, and the eigenvalues that survive
Section titled “Exercise 2 – Equation 10.56, and the eigenvalues that survive”Exercise 3 – The book says invertible; check it
Section titled “Exercise 3 – The book says invertible; check it”Exercise 4 – Equation 10.57, with and without the remark
Section titled “Exercise 4 – Equation 10.57, with and without the remark”Exercise 5 – The whole pipeline, both ways
Section titled “Exercise 5 – The whole pipeline, both ways”Recall card
Section titled “Recall card”- Section 10.5 is for the case where you have far fewer data points than dimensions, which is the normal situation with images.
- N centred points span N minus one directions, so the D-by-D covariance matrix has D minus N plus one eigenvalues at machine zero. Measured: 49 nonzero out of 784 for fifty points.
- Equation 10.56 multiplies the eigenvector equation by X-transpose from the left, turning the D-by-D problem into an N-by-N one with exactly the same nonzero eigenvalues — measured agreement 3.4e-13.
- Equation 10.57 recovers the eigenvectors as X times c, and the remark after it says to normalise them.
- That remark is the whole recipe, not a footnote. The columns have norms in the tens or hundreds, and using them unnormalised turns a reconstruction error of 11.6 into 62,687.
- The book says the Gram matrix has rank N and is invertible. For the centred data it assumes, the rank is N minus one and the condition number is 4.15e+17 — the all-ones vector is in the null space.
- Nothing in Section 10.5 needs that inverse. Take at most N minus one components and the singularity never bites.
- The saving is large and grows: 47.9 times faster at D equal to 500, and 4565 times at D equal to 4000, for eigenvalues agreeing to 5.5e-12.
- And in memory, 0.75 GiB against 19.5 KiB for the book’s own hundred-by-hundred pixel example.
- Every entry of the N-by-N matrix is an inner product between two data points, and the dimension appears nowhere in the matrix itself.
- That is the door to kernel PCA, which Section 10.8 names, and to the same substitution Chapter 12 makes in the support vector machine.
Next: Key Steps of PCA in Practice — §10.6 assembles everything into a six-step recipe, including the standardisation step that changes the answer.
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading