Skip to content

The Gaussian Mixture Model

Chapter 9 fitted a function. Chapter 10 found a subspace. Chapter 11 fits a density — the third pillar — and it starts from an admission:

In practice, the Gaussian (or similarly all other distributions we encountered so far) have limited modeling capabilities.

The fix is one line of algebra. The consequences take a chapter, and the chapter warns you at the outset: “unlike other applications we discussed earlier (linear regression or PCA), we will not find a closed-form maximum likelihood solution.”

  • Equations 11.1–11.4: what a mixture model is, and why both halves of Equation 11.2 are needed — measured, dropping either one breaks the density in a different way.
  • Equation 11.5, the book’s own three-component mixture, checked: it integrates to 1.0000000000001.000000000000.
  • The mean of a mixture is a weighted mean; the variance is not a weighted variance. Measured on Equation 11.5: V[x]=7.79\mathbb{V}[x] = 7.79, of which the component variances supply 0.950.95 and the spread of the means supplies 6.846.8487.80%87.80\% of the total.
  • How far a mixture is from any single Gaussian: skewness 0.4271850.427185, excess kurtosis 1.294278-1.294278, and 0.3305850.330585 nats of KL from the closest one.
  • KK components do not mean KK modes. Two equal unit-variance Gaussians show one bump until their means are more than 2σ2\sigma apart — the transition measured at d=1.0000000d = 1.0000000.
  • K=1K = 1 recovers a single Gaussian exactly, to 0.00.0.
  • What the extra flexibility is worth: 1.3886101.388610 nats per data point on Figure 11.1’s kind of data, for 1717 parameters against 55.

Intuition: averaging densities, not averaging data

Section titled “Intuition: averaging densities, not averaging data”

There is a move here that is easy to read past. A mixture does not average the random variables — it averages the densities. Those are different operations and they give different answers.

Average two Gaussian random variables and you get a Gaussian, narrower than either. Average their densities and you get something that is not Gaussian at all, and wider than either — because the disagreement between the components is itself a form of spread.

That one distinction is the whole of §11.1, and the measurement below puts a number on it: 87.80%87.80\% of Equation 11.5’s variance comes from the components disagreeing about where the data is, not from any component’s own width.

diagram Where the flexibility comes from, and what it costs mermaid

A mixture model describes p(x)p(\mathbf{x}) as a convex combination of KK base distributions:

p(x)=k=1Kπkpk(x)(11.1)p(\mathbf{x}) = \sum_{k=1}^{K}\pi_k p_k(\mathbf{x}) \qquad \text{(11.1)} 0πk1,k=1Kπk=1(11.2)0 \leq \pi_k \leq 1, \qquad \sum_{k=1}^{K}\pi_k = 1 \qquad \text{(11.2)}

With Gaussian components, this is the Gaussian mixture model:

p(xθ)=k=1KπkN(xμk,Σk)(11.3)p(\mathbf{x}\mid\boldsymbol\theta) = \sum_{k=1}^{K}\pi_k\,\mathcal{N}(\mathbf{x}\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k) \qquad \text{(11.3)}

with θ:={μk,Σk,πk:k=1,,K}\boldsymbol\theta := \{\boldsymbol\mu_k, \boldsymbol\Sigma_k, \pi_k : k = 1,\ldots,K\}. The book’s worked instance:

p(xθ)=0.5N(x2,12)+0.2N(x1,2)+0.3N(x4,1)(11.5)p(x\mid\boldsymbol\theta) = 0.5\,\mathcal{N}(x\mid-2, \tfrac12) + 0.2\,\mathcal{N}(x\mid1, 2) + 0.3\,\mathcal{N}(x\mid4, 1) \qquad \text{(11.5)}
figure Figure 11.2, and what no single Gaussian can do about it matplotlib
Left, three dashed weighted Gaussian curves and a thick solid curve above them with three bumps, shaded underneath. Right, the same solid curve against a single dashed bell curve that is far too wide and misses both outer bumps, with the difference shaded. Left, three dashed weighted Gaussian curves and a thick solid curve above them with three bumps, shaded underneath. Right, the same solid curve against a single dashed bell curve that is far too wide and misses both outer bumps, with the difference shaded.
The solid curve is the sum of the three dashed ones and integrates to 1.000000000000. On the right it is compared against the Gaussian with the same mean and variance — the closest single Gaussian in KL — which is still 0.330585 nats away and puts its peak where the mixture has a trough.

For a mixture, E[x]=kπkμk\mathbb{E}[x] = \sum_k\pi_k\mu_k — the operation you would guess. The variance is not kπkσk2\sum_k\pi_k\sigma_k^2. By the law of total variance, conditioning on which component was used:

V[x]=kπkσk2within components+kπk(μkE[x])2between components\mathbb{V}[x] = \underbrace{\sum_k \pi_k\sigma_k^2}_{\text{within components}} + \underbrace{\sum_k \pi_k(\mu_k - \mathbb{E}[x])^2}_{\text{between components}}

On Equation 11.5, by numerical quadrature against the closed form:

quantityvalue
E[x]\mathbb{E}[x] by quadrature0.40000000000.4000000000
kπkμk\sum_k\pi_k\mu_k0.40000000000.4000000000
V[x]\mathbb{V}[x] by quadrature7.7900000000\mathbf{7.7900000000}
within-component part, kπkσk2\sum_k\pi_k\sigma_k^20.95000000000.9500000000
between-component part6.8400000000\mathbf{6.8400000000}
their sum7.79000000007.7900000000 (gap 8.9×10168.9\times10^{-16})
figure Eighty-eight percent of this mixture's variance is the components disagreeing matplotlib
Left, the mixture density with a dashed vertical line at 0.4 and three triangular markers on the axis showing the component means with their one-standard-deviation spans. Right, three bars: 0.95, 6.84 and 7.79. Left, the mixture density with a dashed vertical line at 0.4 and three triangular markers on the axis showing the component means with their one-standard-deviation spans. Right, three bars: 0.95, 6.84 and 7.79.
The three one-standard-deviation bars on the left are short; the gaps between the triangles are not. Averaging the component variances would report 0.95 against a true 7.79 — an understatement of 87.80 percent — because it ignores every unit of spread that comes from the means being in different places.

K components, and somewhere between 1 and K bumps

Section titled “K components, and somewhere between 1 and K bumps”

The book motivates mixtures by “multimodal data representations, i.e., they can describe datasets with multiple ‘clusters’”. True — but the count does not transfer. Two equal-weight unit-variance Gaussians at ±d\pm d:

ddseparation of the meansmodes
0.600.601.20σ1.20\sigma11
0.900.901.80σ1.80\sigma11
0.990.991.98σ1.98\sigma11
1.011.012.02σ2.02\sigma2\mathbf{2}
1.501.503.00σ3.00\sigma22

Bisected, the transition sits at d=1.0000000d = 1.0000000the means must be more than exactly 2σ2\sigma apart before a second bump appears at all. (The eighth decimal moves with the grid; the value itself is exactly 11.)

figure Two components, and the second bump only appears past two sigma matplotlib
Left, four mixture densities: two are single rounded humps, one is flat-topped and one has two clear peaks. Right, a step function of mode count against d, jumping from one to two at a dashed vertical line at d equals one. Left, four mixture densities: two are single rounded humps, one is flat-topped and one has two clear peaks. Right, a step function of mode count against d, jumping from one to two at a dashed vertical line at d equals one.
Below the threshold the two components are still there and still distinct as parameters; the density simply has one maximum. Counting bumps in a histogram is therefore a lower bound on K and never an estimate of it — which is why Section 11.5 sends you to cross-validation for choosing K.

And it moves with the weights. The more lopsided the mixture, the further apart the means must be:

π1\pi_1dd at which the second mode appears
0.50.51.0000001.000000
0.60.61.2213271.221327
0.70.71.3572941.357294
0.80.81.4903381.490338
0.90.91.657251\mathbf{1.657251}

What the flexibility buys, and what it costs

Section titled “What the flexibility buys, and what it costs”

On 10001000 points drawn from a three-component mixture in R2\mathbb{R}^2 — Figure 11.1’s kind of data:

modelparameterslog-likelihood
one fitted Gaussian555111.2117-5111.2117
the true mixture17173722.6020\mathbf{-3722.6020}
difference1388.60971388.6097 nats, or 1.388610\mathbf{1.388610} per point

1.391.39 nats per point is a factor of e1.394.0e^{1.39} \approx 4.0 in likelihood, per observation. That is the case for the chapter. And the price is stated in the same paragraph that makes the case:

logp(Xθ)=n=1Nlogk=1KπkN(xnμk,Σk)(11.10)\log p(\mathcal{X}\mid\boldsymbol\theta) = \sum_{n=1}^{N}\log\sum_{k=1}^{K}\pi_k\,\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k) \qquad \text{(11.10)}

The logarithm cannot get inside the sum. For K=1K = 1 it can — Equation 11.11 — and that is exactly why Chapters 9 and 10 had closed forms and this chapter does not. Page 1102 measures what that costs.

pch.quizTag Is the model clear?
  1. Equation 11.2 asks for weights in [0, 1] that sum to 1. Why not just the sum?

    pch.quizShowAnswer

    B — Because a weight vector can sum to 1 and still produce a function that goes negative — measured at -2.7e-02 — Using weights [0.8, -0.1, 0.3] the result still integrates to exactly 1.000000 and is still not a density. Summing to one buys normalisation; non-negativity buys the rest. A convex combination is required, not an affine one.

  2. How does a mixture's variance relate to its components' variances?

    pch.quizShowAnswer

    B — It is that, plus the weighted spread of the component means about the overall mean — Measured on Equation 11.5: the total is 7.79, the weighted component variances supply 0.95 and the spread of the means supplies 6.84 — 87.80 percent of the total. Averaging the component variances would understate the spread by that much. The mean, by contrast, really is the weighted mean.

  3. A GMM has K = 5 components. How many modes does its density have?

    pch.quizShowAnswer

    B — Anywhere from 1 to 5 — two equal unit-variance components show one bump until their means are more than 2 sigma apart — Measured by bisection, the transition for two equal-weight unit-variance Gaussians is at d = 1.0000000, i.e. means exactly two standard deviations apart. Unequal weights push it further: at a weight of 0.9 the threshold is 1.657251. Counting bumps in a histogram is a lower bound on K, never an estimate of it.

  4. Why does Equation 11.10 not admit a closed-form maximum likelihood solution?

    pch.quizShowAnswer

    B — Because the logarithm sits outside a sum over components and cannot be moved inside it — For K = 1 the sum vanishes and the log applies directly to the Gaussian — Equation 11.11 — which is what gave Chapters 9 and 10 their closed forms. With K greater than 1 the log of a sum has no such simplification, and Sections 11.2 and 11.3 are the consequence.

Exercise 1 – Break Equation 11.2, two ways

Section titled “Exercise 1 – Break Equation 11.2, two ways”

Exercise 2 – The law of total variance, on Equation 11.5

Section titled “Exercise 2 – The law of total variance, on Equation 11.5”

Exercise 4 – Find the threshold where the second bump appears

Section titled “Exercise 4 – Find the threshold where the second bump appears”

Exercise 5 – What the extra parameters are worth

Section titled “Exercise 5 – What the extra parameters are worth”
  • Chapter 11 estimates a density, the third of the book’s pillars, and starts by admitting that a single Gaussian is often a poor model.
  • A mixture is a convex combination of simple densities, and both halves of Equation 11.2 are needed: weights that sum to one but go negative still integrate to one and are still not a density.
  • The mean of a mixture is the weighted mean of the component means. The variance is not the weighted average of the component variances.
  • On the book’s own Equation 11.5 the total variance is 7.79, of which the component widths supply 0.95 and the spread of the means supplies 6.84 — 87.80 percent.
  • That decomposition is the law of total variance, and it comes back in Section 11.2 when a component’s width shrinks as its mean moves.
  • A mixture is not a Gaussian: measured skewness 0.427185 and excess kurtosis minus 1.294278, both exactly zero for any Gaussian.
  • The closest single Gaussian is still 0.330585 nats away in KL, and puts its peak where the mixture has a trough.
  • K components give between one and K modes. Two equal unit-variance Gaussians show one bump until their means are more than two standard deviations apart.
  • Measured by bisection, that transition is at d = 1.0000000, and unequal weights push it out to 1.657251 at a weight of nine tenths.
  • So counting bumps in a histogram is a lower bound on K and never an estimate of it.
  • The flexibility is worth 1.388610 nats per data point on the kind of data Figure 11.1 shows — a factor of four in likelihood — for twelve extra parameters.
  • And it costs the closed form. In Equation 11.10 the logarithm sits outside a sum over components and cannot be moved inside, which is the whole reason Sections 11.2 and 11.3 exist.

Next: Maximum Likelihood and Its Obstacle — §11.2’s opening, and exactly what the log-of-a-sum costs.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading