MathalyseResearch

Learn AI · Chapter 13 · Linear Factor Models

Probabilistic PCA and Factor Analysis

Describe data as a few hidden factors plus noise, read the covariance WWᵀ + ψ off a factor model, and see how probabilistic PCA turns into PCA as the noise shrinks.

Book §13.1, pages 490–491Equations 13.1–13.6About 30 minutes
Section 0

The big picture

How to use this page

Click the colored symbols. Clicking a symbol explains it and lights up the same symbol in the other equations.

Move the controls before you read on. Each demo is built so that the sentence below it describes something you have just seen.

x observed data h latent factors W loadings σ noise spread

A linear factor model describes data in two steps. First, a short list of hidden causes is drawn. Second, each observed measurement is a fixed linear mix of those causes plus a little noise. Think of a mixing desk. A few hidden knobs, the factors, set the level of every channel. Each channel is one observed measurement, and the hiss on each channel is its noise.

The first step draws the factors from a factorial distribution. Factorial means each factor is drawn independently of the others, so the joint distribution is a product of one-factor distributions:

(13.1)
Click any coloured symbol to see what it means.

The second step computes the observations. Each observation is a weighted sum of the factors plus an offset and noise:

(13.2)
Click any coloured symbol to see what it means.

Here is the list of latent factors (latent means hidden), one number per factor, and is the list of observed values, one per measurement. The matrix is the loading matrix. Its entry in row and column says how strongly factor pushes measurement . The vector is an offset. The noise is typically Gaussian and diagonal, which means each measurement gets its own independent noise.

The book draws this as a graph with arrows from factors to observations (its Figure 13.1). The demo below rebuilds that picture. Type the loadings, move the factors and watch the observations change.

Figure 13.1, rebuilt: build the loading matrix yourself

x1
x2
x3
Challenge +8 XP

Set the factors to h = (1, 0, 0) and the noise to 0. Then type the first column of W so that the output is x = (2, 0, 1).

Section 1

Factor analysis

Probabilistic PCA, factor analysis and other linear factor models are special cases of Equations 13.1 and 13.2. They differ only in the noise distribution and in the prior, which is the distribution of the factors fixed before any data are seen.

In factor analysis, the factors get the simplest possible prior, the unit-variance Gaussian of Equation 13.3. The observations then get conditionally independent noise. Conditional independence given means that once the factors are known, the noise on one measurement tells you nothing about the noise on another.

(13.3)
Click any coloured symbol to see what it means.

The noise covariance is diagonal, , so each measurement has its own variance. The entries of are the per-variable variances, one for each observed value.

To marginalise the factors means to remove them by summing, or for continuous factors integrating, over every value that can take. The result is a Gaussian for the observations, with a covariance that combines a factor part and a noise part. The factors are the reason the observations are correlated with one another. All correlation travels through , and the noise adds only to the diagonal:

(13.4)
Click any coloured symbol to see what it means.

Read the covariance as two parts. The matrix carries the shared structure that the factors create. The diagonal carries each measurement’s private noise. The covariance of the observations is the sum of the two.

Predict first. Set the factor strengths to 1 and 1, the angle to 0 degrees, the noise on x1 to 0.1, and the noise on x2 to 1. Which observed variable has the larger spread?

Factor analysis: the covariance is WWᵀ + ψ

samples1-sigma covariance ellipse
Challenge +8 XP

Make the cloud a circle. Make the variance along x1 and the variance along x2 within 0.05 of each other, with correlation below 0.02. Keep the angle at 0.

The demo draws the covariance as an ellipse. Its size and tilt come from . The diagonal noise adds to the two diagonal entries, so it changes the width along each measurement axis but cannot create correlation on its own. A tilted factor creates a tilted ellipse, which means correlation between the two measurements.

Section 2

Probabilistic PCA

Probabilistic PCA makes one change to factor analysis. It gives every measurement the same noise variance, so becomes a multiple of the identity, . The noise is then the same in every direction, a property called isotropic noise:

(13.5)
Click any coloured symbol to see what it means.

Equivalently, the model is written as a single line with one new noise term, where is a standard Gaussian noise vector:

(13.6)
Click any coloured symbol to see what it means.

The book cites Tipping and Bishop (1999), who give an iterative EM algorithm for estimating and from data. This page does not train the model. It shows what the model says about data once and are known.

The motivation is that most variation in the data is captured by the latent variables , up to a small residual reconstruction error of size . The residual is the part of that the factors do not explain.

As Tipping and Bishop (1999) show, probabilistic PCA becomes PCA as goes to zero. This is the most important result of this section. The cloud collapses onto the span of the columns of , meaning every weighted sum of those columns (a line when there is one column), and the thin direction disappears. The demo lets you watch this happen.

Probabilistic PCA: a flat cloud around a line

samplescovariance ellipse
Challenge +8 XP

Shrink the noise until the thin spread, which equals sigma, is below 0.05. The model is then almost exactly PCA.

In the demo the cloud is stretched along the loading direction by and across it by . The loading vector has length , fixed at 1.5 here. Watch the thin direction as falls.

Section 3

The sharp limit and the projection

The book makes two statements about the limit. As goes to zero, the density becomes very sharp around the span of the columns of . Also, the conditional expected value of given becomes an orthogonal projection of minus onto that span. An orthogonal projection is the point on the span closest to the data point. It is found by dropping a perpendicular from the point onto the span.

The book states the projection without a formula. The formula below is added here and is not printed in the book. It follows from Gaussian conditioning on Equations 13.5 and 13.6:

Click any coloured symbol to see what it means.

Each entry of is a coordinate, one per factor, of the point on the span that best explains . As goes to zero, the term that damps the matrix vanishes, and the coordinates become the ordinary least-squares coordinates. Least squares picks the orthogonal projection, so the limit is the projection the book names.

The second statement is a warning. A sharp density gives very low likelihood to points that are not near the span. The log-likelihood is the logarithm of the probability density, so a larger value means a more likely point. The log-likelihood of a point under Equation 13.5 is

Click any coloured symbol to see what it means.

Here is the covariance from Equation 13.5. This formula is added here for the demo and is not printed in the book.

Predict first. Set to 0.5, then drag the point to a place about 0.5 units off the line. As falls to 0.05, what happens to the log-likelihood of that point?

Drag the point: projection and likelihood

line span of Wreconstruction W E[h | x]
Challenge +8 XP

Set sigma to 0.05 or less, then drag the point until its log-likelihood is below −20.

Summary

  • The factors are drawn from a factorial prior. The observations are a linear mix of them plus noise, Equations 13.1 and 13.2.
  • Factor analysis gives the observations the covariance , where is diagonal and holds each measurement’s private noise.
  • Probabilistic PCA sets all noise variances equal to , which makes the noise isotropic.
  • As goes to zero, the model becomes PCA, and the conditional mean of becomes an orthogonal projection. A point far from the span then has very low likelihood.
Final quiz

Check yourself

Questions that mix the whole module. Each one is scored, and the score feeds your mastery of this module.

Source: Ian Goodfellow, Yoshua Bengio and Aaron Courville, Deep Learning, MIT Press, 2016, Section 13.1 (pages 490–491), free to read at deeplearningbook.org. Where the book prints equation numbers, the numbers here follow the book. The order of ideas follows the book. The explanations and all demos were written for this page.