Skip to content

The Latent Variable Perspective

Six sections of PCA and not one probability. §10.7 adds one, and the book is direct about why:

On the one hand, this approach may be appealing as it allows us to sidestep all the mathematical difficulties that come with probability theory, but on the other hand, a probabilistic model would offer us more flexibility and useful insights.

The payoff list is eight items long, and it is the same list Chapter 9 earned by going from §9.2 to §9.3: a likelihood, model comparison by marginal likelihood, a generative model, missing data by Bayes’ theorem, and a notion of novelty.

  • Equations 10.63–10.66: the generative process, and what it means that the arrow points from z\mathbf{z} to x\mathbf{x}.
  • Equations 10.69–10.70b: p(x)=N(μ, BB+σ2I)p(\mathbf{x}) = \mathcal{N}(\boldsymbol\mu,\ \mathbf{B}\mathbf{B}^\top + \sigma^2\mathbf{I}) — checked by 400,000400{,}000 ancestral samples, agreeing to 2.1×1032.1\times10^{-3} relative, the Monte-Carlo floor.
  • Equation 10.71: the cross-covariance Cov[x,z]\mathrm{Cov}[\mathbf{x},\mathbf{z}] is exactly B\mathbf{B}.
  • Equations 10.73–10.75: the posterior over the code. C\mathbf{C} does not depend on x\mathbf{x} — measured, exactly 00 change across 200200 observations — which is the same structural fact page 907 measured for SN\mathbf{S}_N.
  • A closed form the book does not give: C=σ2(BB+σ2I)1\mathbf{C} = \sigma^2(\mathbf{B}^\top\mathbf{B} + \sigma^2\mathbf{I})^{-1}, which for the ML B\mathbf{B} is diagonal with entries σ2/λm\sigma^2/\lambda_m — measured to 9.7×10169.7\times10^{-16}.
  • Equations 10.77–10.79: σML2\sigma^2_{\mathrm{ML}} is page 1004’s JMJ_M divided by DMD-M, matched to eight decimals.
  • PPCA is PCA with shrinkage. The reconstruction is the PCA projection scaled by (λmσ2)/λm(\lambda_m-\sigma^2)/\lambda_m on each axis — measured to six decimals at four noise levels — and converges to PCA as σ0\sigma\to0.

Intuition: PCA describes the data, PPCA claims to have made it

Section titled “Intuition: PCA describes the data, PPCA claims to have made it”

Everything before this page is a statement about a dataset you already have: here is the subspace that keeps the most variance. Nothing in it says what a new image would look like, or how surprised you should be by one.

PPCA writes down a story instead. Draw z\mathbf{z} from a standard Gaussian; push it through an affine map; add noise. That story assigns a probability to every point in RD\mathbb{R}^D, which is what buys the eight items on the list — and it also commits you to claims that can be wrong.

diagram The generative direction, and the inference that reverses it mermaid
x=Bz+μ+ϵRD,ϵN(0,σ2I)(10.63)\mathbf{x} = \mathbf{B}\mathbf{z} + \boldsymbol\mu + \boldsymbol\epsilon \in \mathbb{R}^D, \qquad \boldsymbol\epsilon \sim \mathcal{N}(\mathbf{0}, \sigma^2\mathbf{I}) \qquad \text{(10.63)} znN(z0,I),xnznN(xBzn+μ,σ2I)(10.65), (10.66)\mathbf{z}_n \sim \mathcal{N}(\mathbf{z} \mid \mathbf{0}, \mathbf{I}), \qquad \mathbf{x}_n \mid \mathbf{z}_n \sim \mathcal{N}(\mathbf{x} \mid \mathbf{B}\mathbf{z}_n + \boldsymbol\mu, \sigma^2\mathbf{I}) \qquad \text{(10.65), (10.66)}

This is ancestral sampling: draw the parent, then the child.

figure Example 10.5: the latent space is somewhere you can go matplotlib
Top left, a scatter of two-dimensional codes with three dashed rings at one, two and four standard deviations and five marked query points. Top right, a rising curve of percentage of out-of-range pixels against distance from the mean. Middle, five generated eight-by-eight digit images, one per query point. Top left, a scatter of two-dimensional codes with three dashed rings at one, two and four standard deviations and five marked query points. Top right, a rising curve of percentage of out-of-range pixels against distance from the mean. Middle, five generated eight-by-eight digit images, one per query point.
Every point in the plane decodes to an image, not just the ones the data occupies. The right panel measures the book's remark that querying away from the data produces artifacts: at two standard deviations 6.2 percent of the generated pixels fall outside the range any real image can occupy, at four 28.1 percent, at eight 48.4 percent.

§10.7.2 The likelihood, and why it needs the integral

Section titled “§10.7.2 The likelihood, and why it needs the integral”

The conditional p(xz)p(\mathbf{x}\mid\mathbf{z}) cannot be maximised over parameters, because it still mentions z\mathbf{z}. Integrating it out:

p(xB,μ,σ2)=N(xBz+μ,σ2I)N(z0,I)dz(10.68b)p(\mathbf{x}\mid\mathbf{B},\boldsymbol\mu,\sigma^2) = \int \mathcal{N}(\mathbf{x}\mid\mathbf{B}\mathbf{z}+\boldsymbol\mu,\sigma^2\mathbf{I})\,\mathcal{N}(\mathbf{z}\mid\mathbf{0},\mathbf{I})\,\mathrm{d}\mathbf{z} \qquad \text{(10.68b)} E[x]=μ,V[x]=BB+σ2I(10.69), (10.70b)\mathbb{E}[\mathbf{x}] = \boldsymbol\mu, \qquad \mathbb{V}[\mathbf{x}] = \mathbf{B}\mathbf{B}^\top + \sigma^2\mathbf{I} \qquad \text{(10.69), (10.70b)}

Verified by running Equations 10.65 and 10.66 forward 400,000400{,}000 times with M=5M = 5, σ2=4\sigma^2 = 4:

value
\lVertempirical mean  μ-\ \boldsymbol\mu\rVert0.0370500.037050
max\max\lvertempirical covariance  (BB+σ2I)-\ (\mathbf{B}\mathbf{B}^\top+\sigma^2\mathbf{I})\rvert0.0654520.065452
the same, relative to the largest entry2.1×1032.1\times10^{-3}
Monte-Carlo floor, 1/K1/\sqrt{K}1.6×1031.6\times10^{-3}

The gap is sampling noise of the size you would predict, not a discrepancy.

The joint, using Cov[x,z]=BCovz[z,z]=B\mathrm{Cov}[\mathbf{x},\mathbf{z}] = \mathbf{B}\,\mathrm{Cov}_z[\mathbf{z},\mathbf{z}] = \mathbf{B} (Equation 10.71):

p(x,zB,μ,σ2)=N ⁣([xz]  [μ0], [BB+σ2IBBI])(10.72)p(\mathbf{x},\mathbf{z}\mid\mathbf{B},\boldsymbol\mu,\sigma^2) = \mathcal{N}\!\left(\begin{bmatrix}\mathbf{x}\\ \mathbf{z}\end{bmatrix}\ \Bigg|\ \begin{bmatrix}\boldsymbol\mu\\ \mathbf{0}\end{bmatrix},\ \begin{bmatrix}\mathbf{B}\mathbf{B}^\top+\sigma^2\mathbf{I} & \mathbf{B}\\ \mathbf{B}^\top & \mathbf{I}\end{bmatrix}\right) \qquad \text{(10.72)}

§10.7.3 The posterior, and the thing it does not look at

Section titled “§10.7.3 The posterior, and the thing it does not look at”

Gaussian conditioning (§6.5.1) gives

p(zx)=N(zm,C)(10.73)p(\mathbf{z}\mid\mathbf{x}) = \mathcal{N}(\mathbf{z}\mid\mathbf{m},\mathbf{C}) \qquad \text{(10.73)} m=B(BB+σ2I)1(xμ)(10.74)\mathbf{m} = \mathbf{B}^\top(\mathbf{B}\mathbf{B}^\top+\sigma^2\mathbf{I})^{-1}(\mathbf{x}-\boldsymbol\mu) \qquad \text{(10.74)} C=IB(BB+σ2I)1B(10.75)\mathbf{C} = \mathbf{I} - \mathbf{B}^\top(\mathbf{B}\mathbf{B}^\top+\sigma^2\mathbf{I})^{-1}\mathbf{B} \qquad \text{(10.75)}

Note that the posterior covariance does not depend on the observed data x\mathbf{x}.

figure The measured posterior covariance, and what it is made of matplotlib
Left, five pairs of bars that match exactly, rising from 0.026391 to 0.076317. Right, two traces over two hundred observations: a blue one fluctuating around ten, and a red one pinned flat at the bottom of a symmetric-log axis. Left, five pairs of bars that match exactly, rising from 0.026391 to 0.076317. Right, two traces over two hundred observations: a blue one fluctuating around ten, and a red one pinned flat at the bottom of a symmetric-log axis.
Left: the diagonal of C against sigma-squared over lambda-m, which is what the Woodbury form reduces to for the maximum-likelihood B. Right: over 200 different observations the posterior mean moves and the posterior covariance changes by exactly zero. Page 907 measured the same structure for the Bayesian linear-regression posterior.
μML=1Nn=1Nxn,BML=T(Λσ2I)12R,σML2=1DMj=M+1Dλj(10.77)–(10.79)\boldsymbol\mu_{\mathrm{ML}} = \frac{1}{N}\sum_{n=1}^{N}\mathbf{x}_n, \qquad \mathbf{B}_{\mathrm{ML}} = \mathbf{T}(\boldsymbol\Lambda-\sigma^2\mathbf{I})^{\frac12}\mathbf{R}, \qquad \sigma^2_{\mathrm{ML}} = \frac{1}{D-M}\sum_{j=M+1}^{D}\lambda_j \qquad \text{(10.77)–(10.79)}

Equation 10.79 is page 1004’s JMJ_M divided by the number of directions it is spread across — “the average leftover variance that we cannot capture with the first MM principal components is treated as observation noise.” Measured:

MMσML2\sigma^2_{\mathrm{ML}}JM/(DM)J_M/(D-M)
119.358578739.358578739.358578739.35857873
555.425819815.425819815.425819815.42581981
10103.077607463.077607463.077607463.07760746
20201.348904651.348904651.348904651.34890465
40400.120511660.120511660.120511660.12051166

Two consequences worth stating:

R\mathbf{R} is back. Equation 10.78 ends in “an arbitrary orthogonal matrix”, which page 1004 measured: rotating B\mathbf{B} leaves the reconstruction error at 320.123369320.123369 and the projector identical to 1.1×10161.1\times10^{-16}. Here it means the maximum-likelihood solution is a whole family, and “PCA can identify the best lower-dimensional subspace in which the signals live, but not the signals themselves” (§10.8). ICA exists to break that tie by making p(z)p(\mathbf{z}) non-Gaussian.

The margin note is a guarantee, not an observation. Λσ2I\boldsymbol\Lambda-\sigma^2\mathbf{I} is positive semi-definite because σML2\sigma^2_{\mathrm{ML}} is an average of the discarded eigenvalues, and the discarded ones are all below the kept ones by construction. The square root in Equation 10.78 is always real.

Substituting BML\mathbf{B}_{\mathrm{ML}} into Equation 10.74 and reconstructing gives, per axis,

(Bm)m(PCA projection)m=λmσ2λm\frac{(\mathbf{B}\mathbf{m})_m}{(\text{PCA projection})_m} = \frac{\lambda_m - \sigma^2}{\lambda_m}

Measured against the prediction, four noise levels, five axes, and every cell matches:

σ2\sigma^2axis 11axis 22axis 33axis 44axis 55
110.9934020.9934020.9885990.9885990.9867170.9867170.9815000.9815000.9809210.980921
440.9736090.9736090.9543970.9543970.9468690.9468690.9260010.9260010.9236830.923683
16160.8944370.8944370.8175890.8175890.7874740.7874740.7040060.7040060.6947330.694733
40400.7360930.7360930.5439710.5439710.4686850.4686850.2600150.2600150.2368340.236834
figure Every axis is pulled towards the mean, and the weakest ones hardest matplotlib
Left, five curves starting flat at one and bending down as sigma squared grows on a log axis, the lower-variance axes falling fastest. Right, a grouped bar chart of shrinkage factors with a dot sitting exactly on top of every bar. Left, five curves starting flat at one and bending down as sigma squared grows on a log axis, the lower-variance axes falling fastest. Right, a grouped bar chart of shrinkage factors with a dot sitting exactly on top of every bar.
The dots on the right are the predicted factor and the bars are the measured one; they coincide in all twenty cells. The noisier the model believes the observation is, the less it trusts the code — and the axes with small eigenvalues, which carry the least signal relative to the noise, shrink the most.
pch.quizTag Does the probabilistic view land?
  1. Why can't the conditional in Equation 10.64 be used for maximum likelihood?

    pch.quizShowAnswer

    B — It still depends on the latent variables z, which are not data and not parameters — Equation 10.68b integrates them out — The likelihood must be a function of the data and the parameters only. Integrating z out gives a Gaussian with mean mu and covariance B B-transpose plus sigma-squared I — verified by 400,000 ancestral samples, agreeing to 2.1e-03 relative, which is the Monte-Carlo floor of 1.6e-03.

  2. What is notable about the posterior covariance C in Equation 10.75?

    pch.quizShowAnswer

    B — It does not depend on the observed x at all — measured, exactly zero change across 200 observations — The same structural fact page 907 measured for the Bayesian linear-regression posterior. Woodbury gives C as sigma-squared times the inverse of B-transpose B plus sigma-squared I, which for the maximum-likelihood B is diagonal with entries sigma-squared over lambda-m — measured to 9.7e-16. Uncertainty in inverse proportion to the variance the axis carries.

  3. What is the maximum-likelihood noise variance of Equation 10.79?

    pch.quizShowAnswer

    B — The average of the D minus M discarded eigenvalues — page 1004's J_M divided by D minus M — Matched to eight decimals at M = 1, 5, 10, 20 and 40. It also guarantees the square root in Equation 10.78 is real: Lambda minus sigma-squared I is positive semi-definite because sigma-squared is an average of eigenvalues all smaller than the kept ones.

  4. How does PPCA's reconstruction differ from PCA's?

    pch.quizShowAnswer

    B — It is PCA's, shrunk on each axis by (lambda_m - sigma^2)/lambda_m — measured to six decimals — Twenty cells measured across four noise levels and five axes, all matching. The axes with the smallest eigenvalues shrink most, because they carry the least signal relative to the assumed noise. As sigma goes to zero the factors go to one and PPCA becomes PCA — though below about 1e-08 the required inverse is numerically singular and the limit stops being computable.

Exercise 1 – Run the generative process forward

Section titled “Exercise 1 – Run the generative process forward”

Exercise 2 – The posterior covariance sees no data

Section titled “Exercise 2 – The posterior covariance sees no data”

Exercise 3 – Woodbury, and why C is diagonal

Section titled “Exercise 3 – Woodbury, and why C is diagonal”

Exercise 4 – Equation 10.79 is a leftover average

Section titled “Exercise 4 – Equation 10.79 is a leftover average”
  • Section 10.7 puts a probabilistic model behind PCA, which buys a likelihood, model comparison, a generative story, missing-data handling and a notion of novelty — the same list Chapter 9 bought by going Bayesian.
  • The arrow points from the code to the data. PPCA asserts a low-dimensional cause and then inverts it with Bayes’ theorem, where plain PCA simply computed the code as a function of the data.
  • Integrating the latent variable out gives a Gaussian with the sample mean and covariance B B-transpose plus sigma-squared I, confirmed by 400,000 ancestral samples to within the Monte-Carlo floor.
  • The cross-covariance between the data and the code is exactly B, which is what makes the joint in Equation 10.72 write down so cleanly.
  • The posterior covariance does not depend on the observed data at all — measured, exactly zero change over 200 observations, the same structure page 907 found in Bayesian linear regression.
  • Woodbury turns Equation 10.75 into an M-by-M inverse, and then the structure is visible: for the maximum-likelihood B it is diagonal with entries sigma-squared over lambda-m.
  • So the posterior is uncertain in inverse proportion to the variance each axis carries, and you know that before seeing any data.
  • Equation 10.79’s noise variance is the average of the discarded eigenvalues — page 1004’s reconstruction error divided by the number of directions it is spread over.
  • Which is also why Equation 10.78’s square root is always real: an average of eigenvalues all below the kept ones is itself below them.
  • PPCA is PCA with shrinkage. Each axis is scaled by lambda minus sigma-squared, over lambda — measured to six decimals across four noise levels, and hardest on the weakest axes.
  • As sigma goes to zero the two coincide, but below about 1e-08 the matrix Equation 10.74 inverts is numerically singular. The limit is a statement, not a recipe.
  • The arbitrary orthogonal R in Equation 10.78 is page 1004’s ambiguity again — PCA finds the subspace, not the signals, which is why ICA changes the prior on the code instead.

Next: Chapter 10 Worked Problems — eight problems built from claims the chapter makes, this module’s own.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading