§2.11–2.12The Determinant · Example: Principal Components Analysis

Part I DL pp. 47–52 · ~5 min read

  • determinant
  • principal components analysis
  • design matrix

§2.11 The determinant

The determinant det(A)\det(\boldsymbol{A}) maps a square matrix to a scalar — and it is simply the product of all the eigenvalues. Its absolute value measures how much multiplication by A\boldsymbol{A} expands or contracts volume:

  • det=0\det = 0: space is contracted completely along at least one dimension — all volume is lost (the matrix is singular);
  • det=1|\det| = 1: the transformation preserves volume.

You have already seen this: in the EigenLens of the previous section, det = λ₁λ₂ is exactly the area of the image ellipse relative to the unit circle — set λ₂ = 0 there and watch the volume vanish.

Worked example

A=[3113]\boldsymbol{A} = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix} from last section has λ1=4\lambda_1 = 4, λ2=2\lambda_2 = 2, so det(A)=8\det(\boldsymbol{A}) = 8: the unit square maps to a parallelogram of area 8. Check by the 2×2 formula: 3311=83·3 - 1·1 = 8 ✓.

§2.12 Example: PCA from linear algebra alone

The chapter’s payoff: deriving a real machine learning algorithm — principal components analysis — using only what these pages built.

The setup. We have mm points {x(1),,x(m)}Rn\{\boldsymbol{x}^{(1)}, \dots, \boldsymbol{x}^{(m)}\} \subset \mathbb{R}^n and want lossy compression: store them with less memory, losing as little precision as possible. Encode each point as a lower-dimensional code c(i)Rl\boldsymbol{c}^{(i)} \in \mathbb{R}^l (l<nl < n) with an encoder f(x)=cf(\boldsymbol{x}) = \boldsymbol{c} and decoder xg(f(x))\boldsymbol{x} \approx g(f(\boldsymbol{x})) — the same encoder/decoder shape as chapter 1’s autoencoder , but purely linear. PCA is defined by its decoder choice: matrix multiplication,

Term by term

g(c)=Dc,DRn×lg(\boldsymbol{c}) = \boldsymbol{D}\boldsymbol{c}, \qquad \boldsymbol{D} \in \mathbb{R}^{n \times l}
c\boldsymbol{c}the compact code for one pointl×1, l < n
D\boldsymbol{D}the decoding matrix — its l columns are the directions the code can mix; constrained to ORTHONORMAL columns (DᵀD = I) to make the math clean and the solution uniquen×l
g(c)g(\boldsymbol{c})the reconstruction back in the original spacen×1

(Orthonormal columns kill two problems at once: without unit norm, any scaling of D:,i\boldsymbol{D}_{:,i} could be undone by shrinking cic_i — infinitely many equivalent solutions; and orthogonality will make the encoder trivial. Note D\boldsymbol{D} still isn’t technically “an orthogonal matrix” unless l=nl = n.)

Step 1 — the optimal code for a fixed decoder

Minimize the distance between a point and its reconstruction:

Finding c* (eqs 2.54 → 2.65) — one move per step
c=argmincxg(c)2\boldsymbol{c}^* = \arg\min_{\boldsymbol{c}} \|\boldsymbol{x} - g(\boldsymbol{c})\|_2

step 1/9: Measure reconstruction error with the L² norm (eq 2.54).

So the encoder is f(x)=Dxf(\boldsymbol{x}) = \boldsymbol{D}^\top\boldsymbol{x} and the whole PCA reconstruction is

r(x)=g(f(x))=DDx.r(\boldsymbol{x}) = g(f(\boldsymbol{x})) = \boldsymbol{D}\boldsymbol{D}^\top\boldsymbol{x}.

What this really says

With an orthonormal D\boldsymbol{D}, encoding is just reading off coordinates along the chosen directions, and reconstruction is projection onto their span. All that remains is choosing the directions — and that is where the data comes in.

Step 2 — the optimal directions

D\boldsymbol{D} is shared by all points, so now the whole dataset matters. Stack the points into the design matrix XRm×n\boldsymbol{X} \in \mathbb{R}^{m \times n}, Xi,:=x(i)\boldsymbol{X}_{i,:} = \boldsymbol{x}^{(i)\top}, and (for l=1l = 1, where D\boldsymbol{D} is a single unit vector d\boldsymbol{d}):

Finding d* (eqs 2.68 → 2.84) — the trace identities earn their keep
D=argminDi,j(xj(i)r(x(i))j)2    s.t.  DD=Il\boldsymbol{D}^* = \arg\min_{\boldsymbol{D}} \sqrt{\textstyle\sum_{i,j} \big(x_j^{(i)} - r(\boldsymbol{x}^{(i)})_j\big)^2} \;\; \text{s.t.}\; \boldsymbol{D}^\top\boldsymbol{D} = \boldsymbol{I}_l

step 1/9: Minimize the error over ALL points and dimensions at once (eq 2.68) — D is shared, so points can no longer be treated in isolation.

See the arg-min with your hands

Rotate d; the reconstruction error is minimized exactly at the top eigenvector of XᵀX
dblue: data x⁽ⁱ⁾ · green: reconstructions ddᵀx⁽ⁱ⁾ · red: error segments

total squared error: 42.4

variance captured: 77.2%

Rotate d and watch the arg-min from the derivation: error is minimized exactly when d is the eigenvector of XᵀX with the largest eigenvalue.

Linear algebra is the first of the fundamental mathematical disciplines this book rests on. The other one, ubiquitous in machine learning, is probability theory — chapter 3.

Check yourself — determinant and PCA

1.det(A) = 0 tells you what, geometrically?

2.Why does PCA constrain D to have orthonormal columns?

3.In the c* derivation, why is switching from ‖·‖₂ to ‖·‖₂² 'legal'?

4.In the PCALab, you rotate d away from the snapped position. Predict the readouts.

5.For codes of dimension l > 1, what is the optimal D?

5 questions