7 Gaussian Mixture Models
Real-world data is seldom generated by a single, simple distribution. Heights in a population mixing adults and children are bimodal. Pixel intensities in a natural image form multiple clusters. Gene expression levels across cell types follow distinct modes. Whenever the data-generating process has multiple regimes, a single Gaussian is a poor model.
The Gaussian mixture model (GMM) is the simplest and most instructive way to handle multimodality: model the density as a weighted sum of several Gaussian components. Despite its simplicity, the GMM already exhibits many of the phenomena that recur in modern generative modelling: latent variables, intractable likelihoods, the EM algorithm, and the tension between model capacity and computational tractability.
Historical Note.
The idea of finite mixtures dates back to Karl Pearson's 1894 paper [1], in which he decomposed the distribution of crab forehead-to-body ratios into two Gaussian components, inventing the method of moments along the way. The modern EM algorithm for fitting mixtures was formalised by Dempster, Laird, and Rubin in their landmark 1977 paper [2], which unified a wide variety of iterative procedures under a single framework. The EM algorithm remains the standard tool for fitting mixture models and is the conceptual ancestor of the variational methods used in VAEs and diffusion models.
Why Mixtures?
Example 1 (Old Faithful Geyser).
The Old Faithful geyser in Yellowstone erupts at intervals that are clearly bimodal: sometimes around 55 minutes, sometimes around 80 minutes. A single Gaussian centred near 68 minutes would place high density where no data exists and miss both modes. A mixture of two Gaussians captures each mode separately and assigns low density to the gap between them.
More generally, a single Gaussian can only represent a unimodal, ellipsoidal density. It cannot capture:
Multiple modes (clusters, subpopulations).
Skewness or heavy tails.
Complex shapes (banana-shaped, ring-shaped densities).
A mixture of Gaussians can, in principle, approximate any continuous density to arbitrary accuracy, given enough components (Theorem Theorem 3).
The Gaussian Mixture Model
Definition 1 (Gaussian Mixture Model).
A Gaussian mixture model with components in is a probability density of the form (GMM) where:
are the mixing weights (or mixing coefficients), satisfying .
is the mean of the -th component.
is the (symmetric, positive-definite) covariance matrix of the -th component.
is the multivariate Gaussian density.
The full parameter set is .
The Latent Variable Interpretation
A GMM has an elegant interpretation as a latent variable model, connecting it directly to the PGM framework of Chapter 6.
Definition 2 (GMM as a Latent Variable Model).
Key Idea.
The GMM is a generative model: it specifies a complete probabilistic story for how data is generated. To sample a new data point, we:
Draw a component index .
Draw .
This two-step procedure is the simplest instance of the ancestral sampling pattern that recurs in VAEs (), autoregressive models (), and diffusion models ().
Geometry of Gaussian Mixtures
To build intuition, let us visualise what GMMs look like.
Example 2 (Reading the 1D Mixture).
In Figure fig:gmm:1d, the three components have:
| Component | |||
| 1 (green) | 0.3 | 1.0 | |
| 2 (blue) | 0.5 | 3 | 0.5 |
| 3 (red) | 0.2 | 6 | 1.5 |
Remark 1 (Effect of Covariance Structure in 2D).
In two or more dimensions, each component's covariance matrix controls the shape of its density contours:
Spherical (): circular contours. Fewest parameters ( scalars).
Diagonal (): axis-aligned ellipses. parameters.
Full ( unconstrained): arbitrarily oriented ellipses. parameters.
Choosing the covariance type is a biasβvariance trade-off: more flexible shapes fit data better but require more parameters and are more prone to overfitting.
Maximum Likelihood Estimation
Given i.i.d. observations , we want to find the parameters that best explain the data. The log-likelihood is
(LL)
Caution.
The log-likelihood contains a log of a sum, which prevents it from decomposing into per-component terms. This is fundamentally different from the βcomplete-dataβ log-likelihood where each is known (Proposition Proposition 2). Direct gradient-based optimisation is possible but awkward; the EM algorithm provides an elegant alternative.
The Singularity Problem
Proposition 1 (MLE Singularity).
Proof.
For the -th term in the log-likelihood: As , this diverges to .
Example 3 (Singularity in Practice).
Imagine fitting components to data . If we set (exactly on a data point) and , the likelihood shoots to infinity. This is a degenerate solution: the component has βcollapsedβ onto a single point. In practice, this is avoided by:
Adding a regularisation term (e.g. ).
Using Bayesian priors (e.g. an inverse-Wishart prior on ).
Monitoring for near-singular components and resetting them.
The EM Algorithm for GMMs
The EM algorithm, introduced in Chapter 6 (Definition Definition 9), has a particularly clean closed-form instantiation for GMMs.
Complete-Data Log-Likelihood
If we knew the latent assignments , the log-likelihood would decompose:
Proposition 2 (Complete-Data Log-Likelihood).
With observed pairs, the complete-data log-likelihood is (LL) which decomposes over components: each , , can be estimated independently.
Insight.
The fundamental trick of EM is: since we don't know , we replace the hard indicator with its soft expectation , the responsibility of component for data point . This turns the intractable problem (log-of-sum) into a tractable one (sum-of-logs, weighted by responsibilities).
E-Step: Computing Responsibilities
Definition 3 (Responsibility).
The responsibility of component for observation is the posterior probability: (Responsibility)
This is simply Bayes' theorem: the prior is updated by the likelihood to give the posterior.
Example 4 (Computing Responsibilities by Hand).
Consider components in 1D with current parameters: , , , . For a data point : So the responsibilities are: Component 1 βclaimsβ 98.2% of the responsibility for ; it is much more likely that this point came from the component centred at than the one centred at .
M-Step: Updating Parameters
Given the responsibilities, we update each parameter by maximising the expected complete-data log-likelihood .
Theorem 1 (M-Step Updates for GMMs).
Define the effective count . The M-step updates are: (PI)
Proof.
We derive each update by differentiating the expected complete-data log-likelihood.
Mean. Differentiating with respect to :
Covariance. Similarly, differentiating with respect to and using the identity yields .
Mixing weights. We maximise subject to using a Lagrange multiplier:
Remark 2 (Intuition for the M-Step).
Each update has a beautiful interpretation:
: the mixing weight is the fraction of data softly assigned to component .
: the mean is the responsibility-weighted average of the data.
: the covariance is the responsibility-weighted scatter around the new mean.
Compare with the hard-assignment case (plain averaging over cluster members): EM simply replaces βmember of cluster β with βhas responsibility for cluster β.
The Complete EM Algorithm
Algorithm 1 (EM for Gaussian Mixture Models).
A Worked Numerical Example
Example 5 (One Iteration of EM in 1D).
Consider with data and initial parameters: , , , .
E-step. Compute the Gaussian density at each point for each component, then responsibilities:
| 0.2420 | 0.0001 | 0.9996 | 0.0004 | |
| 0.3989 | 0.0044 | 0.9891 | 0.0109 | |
| 0.0001 | 0.2420 | 0.0004 | 0.9996 | |
| 0.0000 | 0.0540 | 0.0000 | 1.0000 |
M-step. Effective counts: , . The means have moved toward the two natural clusters and . Further iterations would converge to and .
Convergence Properties
Theorem 2 (Monotone Convergence of EM).
Each EM iteration increases (or leaves unchanged) the observed-data log-likelihood:
Proof.
By Jensen's inequality, the E-step constructs a lower bound on that is tight at . The M-step maximises this bound, so . See Chapter 6, Proposition Proposition 3 for the general statement.
Caution.
EM converges to a local maximum, not a global one. The solution depends on initialisation. Practical strategies include:
-means initialisation: run -means first and use the cluster centroids as initial means.
-means++: a smarter seeding that spreads initial centres apart.
Multiple restarts: run EM several times and keep the solution with the highest log-likelihood.
EM as Coordinate Ascent on the ELBO
The EM algorithm has a beautiful interpretation as coordinate ascent on the evidence lower bound (ELBO), which provides the bridge to variational inference (Chapter 8).
Proposition 3 (Log-Likelihood Decomposition).
For any distribution over latent variables: (Decompose) Since the KL divergence is non-negative, the ELBO is a lower bound on the log-likelihood.
Insight.
The two EM steps correspond to alternating maximisation of the ELBO:
E-step: fix , maximise ELBO over . The optimum is (the responsibilities), which makes the KL term zero and the ELBO equal to the log-likelihood.
M-step: fix , maximise ELBO over . This is equivalent to maximising the expected complete-data log-likelihood .
For GMMs, the E-step is tractable (closed-form responsibilities). For more complex models like VAEs, the E-step is intractable, so we restrict to a parametric family and optimise with gradient descent; this is variational inference.
Relationship to -Means
The popular -means clustering algorithm is a special case of GMM-EM.
Proposition 4 (-Means as a Limiting Case).
Consider a GMM with components sharing the same isotropic covariance for all . In the limit :
The responsibilities become hard assignments: .
The M-step mean update becomes the centroid: .
This is exactly the -means algorithm.
Remark 3 (Soft vs. Hard Assignments).
Points near a cluster boundary get split responsibility in GMM-EM (e.g. , ), whereas -means assigns them entirely to the nearest centroid. This soft assignment makes GMMs more robust to overlapping clusters, at the cost of slower convergence and a more complex model.
Model Selection: Choosing
How do we choose the number of components ? Increasing always increases the log-likelihood (more parameters means better fit), so we need a regularised criterion.
Definition 4 (Information Criteria).
Two common model selection criteria are: (BIC) where is the maximised log-likelihood, is the number of free parameters, and is the number of data points. Lower is better: these criteria trade off goodness-of-fit against model complexity.
Example 6 (Parameter Count for a GMM).
For a GMM with components in and full covariance matrices, the number of free parameters is: For and : parameters. This grows quadratically in , a foretaste of the curse of dimensionality.
Remark 4 (BIC vs. AIC).
The BIC penalises complexity more heavily (penalty ) and tends to select simpler models. It is consistent: as , it selects the true with probability 1 (assuming the data truly comes from a finite mixture). The AIC penalises less (penalty ) and tends to select more complex models, which can give better predictive performance. In practice, the BIC is the more common choice for selecting the number of mixture components.
GMMs as Generative Models
GMMs are not just a clustering tool; they are fully specified generative models. Once we have estimated , we can generate new data by ancestral sampling (see the Key Idea box in Section The Latent Variable Interpretation).
Algorithm 2 (Sampling from a GMM).
Input: Fitted parameters , number of samples .
for :
Draw .
Compute Cholesky factor .
Draw .
Set .
return .
Example 7 (GMM as Image Generator?).
Suppose we have images of handwritten digits (MNIST), each flattened to dimensions. We fit a GMM with components. Sampling from this GMM produces new 784-dimensional vectors that we can reshape into images.
The results are blurry and noisy. Each component mean typically looks like a blurred average of similar digits, and samples from that component add Gaussian noise to this average. The model cannot produce sharp, realistic digits because:
It models individual pixel statistics, not spatial structure.
The Gaussian assumption produces βfuzzyβ samples, since real images have sharp edges and discrete intensities.
Modelling -dimensional full covariances requires parameters per component.
Universal Density Approximation
Despite these practical limitations, GMMs have a remarkable theoretical property:
Theorem 3 (GMM as Universal Approximator).
Any continuous probability density on can be approximated arbitrarily well (in the sense of convergence) by a Gaussian mixture with sufficiently many components .
Proof sketch.
Cover the support of the target density with small hypercubes. In each hypercube, approximate by a Gaussian whose mean is the centre of the cube and whose covariance is proportional to the cube volume. As the cubes shrink, the approximation converges to in .
Remark 5 (Theory vs. Practice).
The universal approximation theorem tells us GMMs are theoretically expressive enough. But the required may be astronomically large (exponential in ), and fitting that many components from finite data is hopeless. This is the familiar curse of dimensionality, the same gap between existence and practicality that motivates deep generative models.
Challenges of GMMs for Generation
| Challenge | GMM Limitation | Deep Model Solution |
| Curse of dimensionality | parameters in total | Learned low-dim. manifold (VAE) |
| No spatial structure | Flat vector, no pixel locality | CNNs, U-Nets |
| Blurry samples | Gaussian noise in pixel space | Adversarial loss (GAN), score matching |
| Mode coverage | Needs per mode; fixed | Continuous latent space |
| Scalability | per EM iteration | SGD on mini-batches |
| Discrete structure | Cannot model sharp edges | Nonlinear decoders |
Key Idea.
The GMM is the simplest generative model: latent variable selects a mode, and then is drawn from that mode. Every subsequent generative model we study can be seen as addressing one or more of the GMM's limitations:
VAEs replace the discrete with a continuous latent and use a neural network decoder instead of a fixed Gaussian.
Normalising flows make the mapping invertible so the density is tractable.
GANs abandon the explicit density entirely and directly learn a mapping .
Diffusion models use a hierarchy of latent variables (a long chain) instead of a single .
In this sense, the GMM is the ancestor of all deep generative models.
When GMMs Are the Right Choice
Despite their limitations for high-dimensional generation, GMMs remain an excellent choice in many settings:
Example 8 (Good Use Cases for GMMs).
Density estimation in low-to-moderate dimensions (): financial returns, sensor data, scientific measurements.
Clustering with uncertainty: unlike -means, GMMs give soft assignments and cluster shapes (ellipses, not spheres).
Anomaly detection: a point with is flagged as anomalous.
Speaker verification: the βi-vector + GMM-UBMβ pipeline was the standard in automatic speaker recognition for decades.
Initialisation for deep models: GMM clustering of latent codes is used in some VAE variants.
Mixture density networks (Section Mixture Density Networks): neural networks that output GMM parameters, combining the expressiveness of deep models with the interpretability of mixtures.
Beyond Basic GMMs
Bayesian GMMs and the Dirichlet Process
A key limitation of standard GMMs is that must be chosen in advance. Bayesian nonparametric methods address this.
Definition 5 (Dirichlet Process Mixture Model).
A Dirichlet process mixture model (DPMM) places a Dirichlet process prior on the mixing distribution, where is the concentration parameter and is the base measure. This allows the number of active components to grow with the data:
Small : few components (data is simple).
Large : many components (data is complex).
The βChinese restaurant processβ provides an intuitive construction: the -th customer joins existing table with probability , or starts a new table with probability .
Remark 6 (Practical Use).
DPMMs avoid the model selection problem entirely but are more expensive to fit (typically via Gibbs sampling or variational inference). They are useful when the number of clusters is unknown and may grow with data size, e.g. in topic modelling, population genetics, or astronomical source detection.
Mixture Density Networks
A powerful extension combines GMMs with neural networks:
Definition 6 (Mixture Density Network).
A mixture density network (MDN) [3] is a neural network that takes input and outputs the parameters of a conditional GMM: where , , are all output by the network (with appropriate constraints: softmax for , positive-definiteness for ).
Insight.
MDNs are a bridge between classical GMMs and modern deep generative models. In fact, the decoder of a VAE with a mixture-of-Gaussians output can be viewed as an MDN conditioned on the latent code . MDNs are particularly useful for modelling multi-valued functions, e.g. inverse kinematics (multiple joint configurations for one end-effector position) or probabilistic weather forecasting (multiple plausible trajectories).
Chapter Summary
A Gaussian mixture model represents a density as , a weighted sum of Gaussian components.
The latent variable interpretation () connects GMMs to the PGM framework and ancestral sampling.
The EM algorithm alternates between computing responsibilities (E-step) and updating parameters (M-step); it monotonically increases the log-likelihood and converges to a local optimum.
EM can be understood as coordinate ascent on the ELBO, bridging to variational inference.
-means is a special case of GMM-EM in the hard-assignment limit.
The BIC/AIC provide principled model selection for choosing .
GMMs are fully specified generative models, but struggle in high dimensions due to the curse of dimensionality and lack of spatial structure. They are the conceptual ancestor of all deep generative models.
Extensions include Bayesian nonparametrics (DPMM) and mixture density networks (MDNs).
In the next chapter, we study variational inference, the framework that generalises the EM algorithm to models where the E-step is intractable, enabling VAEs and modern deep generative models.
Exercises
Exercise 1 (EM by Hand).
Consider a 1D GMM with , initial parameters , , , , and data .
- (a)
Perform one E-step: compute for each data point and component.
- (b)
Perform one M-step: compute updated , , .
- (c)
Compute the log-likelihood before and after this iteration and verify it increased.
Exercise 2 (Deriving the M-Step).
Starting from the expected complete-data log-likelihood
- (a)
Derive the M-step update for by setting .
- (b)
Derive the M-step update for .
- (c)
Use Lagrange multipliers to derive the update for subject to .
Exercise 3 (Monotonicity of EM).
Prove that EM never decreases the observed-data log-likelihood. Hint: Use Jensen's inequality and the decomposition .
Exercise 4 (-Means as GMM Limit).
Consider a GMM with shared isotropic covariance for all .
- (a)
Show that as , the responsibilities become hard assignments.
- (b)
Show the M-step mean update reduces to the -means centroid rule.
- (c)
Give a dataset where soft EM assignments produce qualitatively different clusters than -means.
Exercise 5 (Initialisation and Local Optima).
- (a)
Construct a 1D example where poor EM initialisation converges to a suboptimal local maximum.
- (b)
Explain why multiple random restarts help.
- (c)
Describe -means++ and explain why it provides good initialisation for EM.
Exercise 6 (Singularity Analysis).
- (a)
Show that setting and causes .
- (b)
Why doesn't this happen in practice with reasonable initialisation?
- (c)
Propose two regularisation strategies and explain their effect.
Exercise 7 (BIC Model Selection).
Generate samples from a 2D GMM with components.
- (a)
Fit GMMs with and compute BIC for each.
- (b)
Plot BIC vs. . Does the minimum occur at ?
- (c)
Repeat with . Is model selection harder with less data?
Exercise 8 (GMM Sampling and Evaluation).
Fit a GMM with components (full covariance) to the MNIST training set (flattened to ).
- (a)
Sample 100 images and visualise them. Describe the quality.
- (b)
Compute the log-likelihood on the test set.
- (c)
Repeat with and . Does the log-likelihood improve? Do the samples improve visually?
- (d)
Discuss why increasing eventually fails to improve sample quality despite improving likelihood.
Exercise 9 (ELBO Decomposition).
Starting from the identity :
- (a)
Derive this decomposition from first principles.
- (b)
Show that the E-step sets the KL term to zero.
- (c)
Show that the M-step increases the ELBO by maximising over .
- (d)
Explain in your own words why this means EM can only increase (or maintain) the log-likelihood.
Exercise 10 (Curse of Dimensionality for GMMs).
- (a)
Compute the number of free parameters for a GMM with and full covariance in .
- (b)
How many data points would you need for reliable estimation? (A common rule of thumb is .)
- (c)
Suggest two strategies to reduce the parameter count (e.g. diagonal covariances, PCA preprocessing) and discuss their trade-offs.
- (d)
Explain why deep generative models like VAEs handle or while GMMs cannot.
Exercise 11 (GMM as Universal Approximator).
- (a)
Construct a GMM that approximates a Uniform density using equally-weighted, equally-spaced components with variance . Plot the approximation for .
- (b)
How does the approximation error scale with ?
- (c)
Repeat for a bimodal density. How does the required grow with the distance between modes?
Exercise 12 (Mixture Density Network).
Consider predicting from where the true relationship is with (bimodal noise).
- (a)
Why would a standard neural network with MSE loss fail to capture the bimodal conditional ?
- (b)
Design an MDN with Gaussian components. What are the output dimensions of the network?
- (c)
Write the negative log-likelihood loss for training.
- (d)
After training, how would you sample from for a given ?
Exercise 13 (GMM for Anomaly Detection).
Fit a GMM with to a dataset of βnormalβ 2D data points.
- (a)
Explain how to use as an anomaly score.
- (b)
What threshold would you choose, and how?
- (c)
A new data point has for all but is not extremely low. How is this possible? (Hint: consider the tails of the Gaussian.)
- (d)
Suggest a modification to make GMM-based anomaly detection more robust.
Exercise 14 (From GMM to VAE).
Trace the conceptual path from GMM to VAE:
- (a)
In a GMM, the latent variable is discrete. What happens if we replace it with a continuous ?
- (b)
The GMM decoder is . What does the VAE replace this with?
- (c)
The GMM E-step computes exactly. Why can't we do this for the continuous-latent model, and what does the VAE do instead?
- (d)
Summarise: what are the three key changes from GMM to VAE?
References
-
Contributions to the Mathematical Theory of Evolution
BibTeX
@article{pearson1894contributions, title={Contributions to the Mathematical Theory of Evolution}, author={Pearson, Karl}, journal={Philosophical Transactions of the Royal Society of London A}, volume={185}, pages={71--110}, year={1894} }Journal article
-
Maximum Likelihood from Incomplete Data via the EM Algorithm
BibTeX
@article{dempster1977maximum, title={Maximum Likelihood from Incomplete Data via the {EM} Algorithm}, author={Dempster, Arthur P and Laird, Nan M and Rubin, Donald B}, journal={Journal of the Royal Statistical Society: Series B}, volume={39}, number={1}, pages={1--38}, year={1977} }Journal article
-
Mixture Density Networks
BibTeX
@article{bishop1994mixture, title={Mixture Density Networks}, author={Bishop, Christopher M}, journal={Aston University Technical Report NCRG/94/004}, year={1994} }Journal article