Skip to content
AIAI Wranglers

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 K components in ℝd⁑ is a probability density of the form (GMM)p(𝒙)=βˆ‘k=1KΟ€k𝒩(𝒙|𝝁k,𝚺k), where:

  • Ο€kβ‰₯0 are the mixing weights (or mixing coefficients), satisfying βˆ‘k=1KΟ€k=1.

  • 𝝁kβˆˆβ„d⁑ is the mean of the k-th component.

  • 𝚺kβˆˆβ„dΓ—d⁑ is the (symmetric, positive-definite) covariance matrix of the k-th component.

  • 𝒩(𝒙|𝝁,𝚺)=(2Ο€)βˆ’d/2|𝚺|βˆ’1/2exp⁑(βˆ’12(π’™βˆ’π)π–³πšΊβˆ’1(π’™βˆ’π)) is the multivariate Gaussian density.

The full parameter set is ΞΈ={Ο€k,𝝁k,𝚺k}k=1K.

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).

Introduce a discrete latent variable z∈{1,…,K} indicating which component generated a given observation: (GEN)z∼Categorical⁑(Ο€1,…,Ο€K),𝒙|z=kβˆΌπ’©(𝝁k,𝚺k). Marginalising over z recovers the mixture density : p(𝒙)=βˆ‘k=1KP(z=k)p(𝒙|z=k)=βˆ‘k=1KΟ€k𝒩(𝒙|𝝁k,𝚺k).

Plate diagram for the Gaussian mixture model (cf. Chapter 6). Each data point 𝒙i depends on its latent assignment zi and the component parameters (𝝁k,𝚺k). Shaded nodes are observed.

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:

  1. Draw a component index z∼Categorical⁑(𝝅).

  2. Draw π’™βˆΌπ’©(𝝁z,𝚺z).

This two-step procedure is the simplest instance of the ancestral sampling pattern that recurs in VAEs (𝒛→𝒙), autoregressive models (x1β†’x2β†’β‹―), and diffusion models (𝒙T→𝒙Tβˆ’1→⋯→𝒙0).

Geometry of Gaussian Mixtures

To build intuition, let us visualise what GMMs look like.

A 1D Gaussian mixture with K=3 components. Dashed curves show the weighted components Ο€k𝒩(x|ΞΌk,Οƒk2); the solid black curve is their sum, the mixture density. The mixture captures three distinct modes.

Example 2 (Reading the 1D Mixture).

In Figure fig:gmm:1d, the three components have:

Componentπkμkσk2
1 (green)0.3βˆ’11.0
2 (blue)0.530.5
3 (red)0.261.5
The blue component is the tallest and narrowest (large Ο€, small Οƒ2). The red component is the broadest (large Οƒ2) but has the smallest weight. The mixture density has three modes, a shoulder between the green and blue peaks, and a long right tail contributed by the red component.

Remark 1 (Effect of Covariance Structure in 2D).

In two or more dimensions, each component's covariance matrix 𝚺k controls the shape of its density contours:

  • Spherical (𝚺k=Οƒk2I⁑): circular contours. Fewest parameters (K scalars).

  • Diagonal (𝚺k=diag⁑(Οƒk12,…,Οƒkd2)): axis-aligned ellipses. Kd parameters.

  • Full (𝚺k unconstrained): arbitrarily oriented ellipses. Kd(d+1)/2 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 N i.i.d. observations π’Ÿ={𝒙1,…,𝒙N}, we want to find the parameters ΞΈ that best explain the data. The log-likelihood is

(LL)β„“(ΞΈ)=βˆ‘i=1Nlog⁑p(𝒙i;ΞΈ)=βˆ‘i=1Nlogβ‘βˆ‘k=1KΟ€k𝒩(𝒙i|𝝁k,𝚺k).

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 zi 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).

The GMM log-likelihood is unbounded above. Specifically, if we set 𝝁k=𝒙j for some data point 𝒙j and let 𝚺kβ†’πŸŽ, then 𝒩(𝒙j|𝝁k,𝚺k)β†’βˆž, so β„“(ΞΈ)β†’+∞.

Proof.

For the j-th term in the log-likelihood: log⁑p(𝒙j)β‰₯log⁑[Ο€k𝒩(𝒙j|𝒙j,Οƒ2I⁑)]=log⁑πkβˆ’d2log⁑(2πσ2). As Οƒ2β†’0, this diverges to +∞.

Example 3 (Singularity in Practice).

Imagine fitting K=2 components to data {1,2,3,4,5}. If we set ΞΌ1=3 (exactly on a data point) and Οƒ12β†’0, the likelihood shoots to infinity. This is a degenerate solution: the component has β€œcollapsed” onto a single point. In practice, this is avoided by:

  1. Adding a regularisation term (e.g. 𝚺k+ϡI⁑).

  2. Using Bayesian priors (e.g. an inverse-Wishart prior on 𝚺k).

  3. 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 z1,…,zN, the log-likelihood would decompose:

Proposition 2 (Complete-Data Log-Likelihood).

With observed (𝒙i,zi) pairs, the complete-data log-likelihood is (LL)β„“c(ΞΈ)=βˆ‘i=1Nβˆ‘k=1KπŸ™[zi=k][log⁑πk+log⁑𝒩(𝒙i|𝝁k,𝚺k)], which decomposes over components: each Ο€k, 𝝁k, 𝚺k can be estimated independently.

Insight.

The fundamental trick of EM is: since we don't know zi, we replace the hard indicator πŸ™[zi=k] with its soft expectation Ξ³ik=P(zi=k|𝒙i;ΞΈ(t)), the responsibility of component k for data point i. 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 k for observation 𝒙i is the posterior probability: (Responsibility)Ξ³ik=defP(zi=k|𝒙i;ΞΈ(t))=Ο€k(t)𝒩(𝒙i|𝝁k(t),𝚺k(t))βˆ‘j=1KΟ€j(t)𝒩(𝒙i|𝝁j(t),𝚺j(t)).

This is simply Bayes' theorem: the prior P(zi=k)=Ο€k is updated by the likelihood p(𝒙i|zi=k) to give the posterior.

Example 4 (Computing Responsibilities by Hand).

Consider K=2 components in 1D with current parameters: Ο€1=Ο€2=0.5, ΞΌ1=0, ΞΌ2=4, Οƒ12=Οƒ22=1. For a data point x=1: 𝒩(1|0,1)=12Ο€eβˆ’1/2β‰ˆ0.2420,𝒩(1|4,1)=12Ο€eβˆ’9/2β‰ˆ0.0044. So the responsibilities are: Ξ³1=0.5Γ—0.24200.5Γ—0.2420+0.5Γ—0.0044=0.12100.1232β‰ˆ0.982,Ξ³2β‰ˆ0.018. Component 1 β€œclaims” 98.2% of the responsibility for x=1; it is much more likely that this point came from the component centred at 0 than the one centred at 4.

M-Step: Updating Parameters

Given the responsibilities, we update each parameter by maximising the expected complete-data log-likelihood Q(ΞΈ,ΞΈ(t))=𝔼z|𝒙;ΞΈ(t)[β„“c(ΞΈ)].

Theorem 1 (M-Step Updates for GMMs).

Define the effective count Nk=βˆ‘i=1NΞ³ik. The M-step updates are: (PI)Ο€k(t+1)=NkN,𝝁k(t+1)=1Nkβˆ‘i=1NΞ³ik𝒙i,𝚺k(t+1)=1Nkβˆ‘i=1NΞ³ik(𝒙iβˆ’πk(t+1))(𝒙iβˆ’πk(t+1))𝖳.

Proof.

We derive each update by differentiating the expected complete-data log-likelihood.

Mean. Differentiating Q with respect to 𝝁k: βˆ‚Qβˆ‚πk=βˆ‘i=1NΞ³ik𝚺kβˆ’1(𝒙iβˆ’πk)=𝟎⟹𝝁k=βˆ‘iΞ³ik𝒙iβˆ‘iΞ³ik.

Covariance. Similarly, differentiating Q with respect to 𝚺kβˆ’1 and using the identity βˆ‚βˆ‚πšΊβˆ’1log⁑|πšΊβˆ’1|=𝚺 yields .

Mixing weights. We maximise Q subject to βˆ‘kΟ€k=1 using a Lagrange multiplier: βˆ‚βˆ‚Ο€k[βˆ‘iβˆ‘jΞ³ijlog⁑πj+Ξ»(1βˆ’βˆ‘jΟ€j)]=0⟹NkΟ€k=Ξ»βŸΉΟ€k=NkN.

Remark 2 (Intuition for the M-Step).

Each update has a beautiful interpretation:

  • Ο€k=Nk/N: the mixing weight is the fraction of data softly assigned to component k.

  • 𝝁k: the mean is the responsibility-weighted average of the data.

  • 𝚺k: 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 k” with β€œhas responsibility Ξ³ik for cluster k”.

The Complete EM Algorithm

Algorithm 1 (EM for Gaussian Mixture Models).

Input: Data {𝒙1,…,𝒙N}, number of components K, convergence threshold Ο΅.

Initialise Ο€k(0),𝝁k(0),𝚺k(0) for k=1,…,K.

repeat

  1. E-step: For each i,k, compute responsibility Ξ³ik via .

  2. M-step: Update Ο€k,𝝁k,𝚺k via –.

  3. Evaluate: Compute log-likelihood β„“(ΞΈ) via .

until |β„“(ΞΈ(t+1))βˆ’β„“(ΞΈ(t))|<Ο΅.

Output: Fitted parameters ΞΈβˆ—={Ο€k,𝝁k,𝚺k}k=1K.

A Worked Numerical Example

Example 5 (One Iteration of EM in 1D).

Consider K=2 with data {βˆ’1,0,4,5} and initial parameters: Ο€1=Ο€2=0.5, ΞΌ1=0, ΞΌ2=3, Οƒ12=Οƒ22=1.

E-step. Compute the Gaussian density at each point for each component, then responsibilities:

xi𝒩(xi|0,1)𝒩(xi|3,1)Ξ³i1Ξ³i2
βˆ’10.24200.00010.99960.0004
βˆ’00.39890.00440.98910.0109
βˆ’40.00010.24200.00040.9996
βˆ’50.00000.05400.00001.0000

M-step. Effective counts: N1β‰ˆ1.989, N2β‰ˆ2.011. Ο€1(1)β‰ˆ0.497,Ο€2(1)β‰ˆ0.503,ΞΌ1(1)=0.9996β‹…(βˆ’1)+0.9891β‹…0+0.0004β‹…4+0.0000β‹…51.989β‰ˆβˆ’0.502,ΞΌ2(1)β‰ˆ0.0004β‹…(βˆ’1)+0.0109β‹…0+0.9996β‹…4+1.0000β‹…52.011β‰ˆ4.487. The means have moved toward the two natural clusters {βˆ’1,0} and {4,5}. Further iterations would converge to ΞΌ1β‰ˆβˆ’0.5 and ΞΌ2β‰ˆ4.5.

Convergence Properties

Theorem 2 (Monotone Convergence of EM).

Each EM iteration increases (or leaves unchanged) the observed-data log-likelihood: β„“(ΞΈ(t+1))β‰₯β„“(ΞΈ(t)).

Proof.

By Jensen's inequality, the E-step constructs a lower bound Q(ΞΈ,ΞΈ(t))+const on β„“(ΞΈ) that is tight at ΞΈ=ΞΈ(t). The M-step maximises this bound, so β„“(ΞΈ(t+1))β‰₯Q(ΞΈ(t+1),ΞΈ(t))+constβ‰₯Q(ΞΈ(t),ΞΈ(t))+const=β„“(ΞΈ(t)). 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:

  • k-means initialisation: run k-means first and use the cluster centroids as initial means.

  • k-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 q(zi) over latent variables: (Decompose)log⁑p(𝒙i;ΞΈ)=βˆ‘k=1Kq(zi=k)log⁑p(𝒙i,zi=k;ΞΈ)q(zi=k)⏟ELBO(ΞΈ,q)+𝖣KL⁑(q(zi)β€–p(zi|𝒙i;ΞΈ))⏟β‰₯0. 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 q. The optimum is qβˆ—(zi)=p(zi|𝒙i;ΞΈ) (the responsibilities), which makes the KL term zero and the ELBO equal to the log-likelihood.

  • M-step: fix q, maximise ELBO over ΞΈ. This is equivalent to maximising the expected complete-data log-likelihood Q(ΞΈ,ΞΈ(t)).

For GMMs, the E-step is tractable (closed-form responsibilities). For more complex models like VAEs, the E-step is intractable, so we restrict q to a parametric family and optimise with gradient descent; this is variational inference.

Relationship to k-Means

The popular k-means clustering algorithm is a special case of GMM-EM.

Proposition 4 (k-Means as a Limiting Case).

Consider a GMM with K components sharing the same isotropic covariance 𝚺k=Οƒ2I⁑ for all k. In the limit Οƒ2β†’0:

  1. The responsibilities become hard assignments: Ξ³ikβ†’πŸ™[k=arg minj⁑‖𝒙iβˆ’πjβ€–2].

  2. The M-step mean update becomes the centroid: 𝝁k=1|Ck|βˆ‘i∈Ck𝒙i.

This is exactly the k-means algorithm.

Remark 3 (Soft vs. Hard Assignments).

Points near a cluster boundary get split responsibility in GMM-EM (e.g. Ξ³i1=0.6, Ξ³i2=0.4), whereas k-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 K

How do we choose the number of components K? Increasing K 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)BIC=βˆ’2β„“(ΞΈ^)+plog⁑N,AIC=βˆ’2β„“(ΞΈ^)+2p, where β„“(ΞΈ^) is the maximised log-likelihood, p is the number of free parameters, and N 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 K components in ℝd⁑ and full covariance matrices, the number of free parameters is: p=(Kβˆ’1)⏟mixingΒ weights+Kd⏟means+Kβ‹…d(d+1)2⏟covariances=K(d(d+1)2+d+1)βˆ’1. For d=10 and K=5: p=5(55+10+1)βˆ’1=329 parameters. This grows quadratically in d, a foretaste of the curse of dimensionality.

Remark 4 (BIC vs. AIC).

The BIC penalises complexity more heavily (penalty ∝log⁑N) and tends to select simpler models. It is consistent: as Nβ†’βˆž, it selects the true K with probability 1 (assuming the data truly comes from a finite mixture). The AIC penalises less (penalty ∝2) 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 {Ο€k,𝝁k,𝚺k}k=1K, number of samples M.

for m=1,…,M:

  1. Draw z(m)∼Categorical⁑(Ο€1,…,Ο€K).

  2. Compute Cholesky factor 𝐋k=chol⁑(𝚺z(m)).

  3. Draw 𝝐(m)βˆΌπ’©(0,I⁑).

  4. Set 𝒙(m)=𝝁z(m)+𝐋z(m)𝝐(m).

return {𝒙(1),…,𝒙(M)}.

Example 7 (GMM as Image Generator?).

Suppose we have N=60,000 images of handwritten digits (MNIST), each flattened to d=784 dimensions. We fit a GMM with K=50 components. Sampling from this GMM produces new 784-dimensional vectors that we can reshape into 28Γ—28 images.

The results are blurry and noisy. Each component mean 𝝁k 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:

  1. It models individual pixel statistics, not spatial structure.

  2. The Gaussian assumption produces β€œfuzzy” samples, since real images have sharp edges and discrete intensities.

  3. Modelling 784-dimensional full covariances requires ∼300,000 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 ℝd⁑ can be approximated arbitrarily well (in the sense of L1 convergence) by a Gaussian mixture with sufficiently many components K.

Proof sketch.

Cover the support of the target density pβˆ— with small hypercubes. In each hypercube, approximate pβˆ— 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 pβˆ— in L1.

Remark 5 (Theory vs. Practice).

The universal approximation theorem tells us GMMs are theoretically expressive enough. But the required K may be astronomically large (exponential in d), 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

ChallengeGMM LimitationDeep Model Solution
Curse of dimensionalityO(Kd2) parameters in totalLearned low-dim. manifold (VAE)
No spatial structureFlat vector, no pixel localityCNNs, U-Nets
Blurry samplesGaussian noise in pixel spaceAdversarial loss (GAN), score matching
Mode coverageNeeds K per mode; K fixedContinuous latent space
ScalabilityO(NKd2) per EM iterationSGD on mini-batches
Discrete structureCannot model sharp edgesNonlinear decoders
Challenges of GMMs as generative models and how deep models address them.

Key Idea.

The GMM is the simplest generative model: latent variable z 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 z∈{1,…,K} with a continuous latent π’›βˆˆβ„m⁑ and use a neural network decoder instead of a fixed Gaussian.

  • Normalising flows make the mapping 𝒛→𝒙 invertible so the density p(𝒙) 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 z.

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 (d≲50): financial returns, sensor data, scientific measurements.

  • Clustering with uncertainty: unlike k-means, GMMs give soft assignments and cluster shapes (ellipses, not spheres).

  • Anomaly detection: a point 𝒙 with p(𝒙)<Ο„ 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 K 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 DP(Ξ±,G0) on the mixing distribution, where Ξ±>0 is the concentration parameter and G0 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 (N+1)-th customer joins existing table k with probability ∝Nk, 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: p(π’š|𝒙)=βˆ‘k=1KΟ€k(𝒙)𝒩(π’š|𝝁k(𝒙),𝚺k(𝒙)), where Ο€k(𝒙), 𝝁k(𝒙), 𝚺k(𝒙) are all output by the network (with appropriate constraints: softmax for Ο€k, positive-definiteness for 𝚺k).

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

  1. A Gaussian mixture model represents a density as p(𝒙)=βˆ‘kΟ€k𝒩(𝒙|𝝁k,𝚺k), a weighted sum of Gaussian components.

  2. The latent variable interpretation (z→𝒙) connects GMMs to the PGM framework and ancestral sampling.

  3. 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.

  4. EM can be understood as coordinate ascent on the ELBO, bridging to variational inference.

  5. k-means is a special case of GMM-EM in the hard-assignment limit.

  6. The BIC/AIC provide principled model selection for choosing K.

  7. 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.

  8. 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 K=2, initial parameters Ο€1=Ο€2=0.5, ΞΌ1=0, ΞΌ2=3, Οƒ12=Οƒ22=1, and data {βˆ’1,0,4,5}.

  1. (a)

    Perform one E-step: compute Ξ³ik for each data point and component.

  2. (b)

    Perform one M-step: compute updated Ο€k, ΞΌk, Οƒk2.

  3. (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 Q(ΞΈ,ΞΈ(t))=βˆ‘i=1Nβˆ‘k=1KΞ³ik[log⁑πk+log⁑𝒩(𝒙i|𝝁k,𝚺k)],

  1. (a)

    Derive the M-step update for 𝝁k by setting βˆ‚Q/βˆ‚πk=0.

  2. (b)

    Derive the M-step update for 𝚺k.

  3. (c)

    Use Lagrange multipliers to derive the update for Ο€k subject to βˆ‘kΟ€k=1.

Exercise 3 (Monotonicity of EM).

Prove that EM never decreases the observed-data log-likelihood. Hint: Use Jensen's inequality and the decomposition log⁑p(𝒙)=ELBO+𝖣KL⁑.

Exercise 4 (k-Means as GMM Limit).

Consider a GMM with shared isotropic covariance 𝚺k=Οƒ2I⁑ for all k.

  1. (a)

    Show that as Οƒ2β†’0, the responsibilities become hard assignments.

  2. (b)

    Show the M-step mean update reduces to the k-means centroid rule.

  3. (c)

    Give a dataset where soft EM assignments produce qualitatively different clusters than k-means.

Exercise 5 (Initialisation and Local Optima).

  1. (a)

    Construct a 1D example where poor EM initialisation converges to a suboptimal local maximum.

  2. (b)

    Explain why multiple random restarts help.

  3. (c)

    Describe k-means++ and explain why it provides good initialisation for EM.

Exercise 6 (Singularity Analysis).

  1. (a)

    Show that setting 𝝁k=𝒙j and 𝚺kβ†’πŸŽ causes β„“(ΞΈ)β†’+∞.

  2. (b)

    Why doesn't this happen in practice with reasonable initialisation?

  3. (c)

    Propose two regularisation strategies and explain their effect.

Exercise 7 (BIC Model Selection).

Generate N=500 samples from a 2D GMM with Kβˆ—=3 components.

  1. (a)

    Fit GMMs with K=1,2,…,8 and compute BIC for each.

  2. (b)

    Plot BIC vs. K. Does the minimum occur at K=3?

  3. (c)

    Repeat with N=50. Is model selection harder with less data?

Exercise 8 (GMM Sampling and Evaluation).

Fit a GMM with K=10 components (full covariance) to the MNIST training set (flattened to d=784).

  1. (a)

    Sample 100 images and visualise them. Describe the quality.

  2. (b)

    Compute the log-likelihood on the test set.

  3. (c)

    Repeat with K=50 and K=200. Does the log-likelihood improve? Do the samples improve visually?

  4. (d)

    Discuss why increasing K eventually fails to improve sample quality despite improving likelihood.

Exercise 9 (ELBO Decomposition).

Starting from the identity log⁑p(𝒙;ΞΈ)=ELBO(ΞΈ,q)+𝖣KL⁑(q(z)β€–p(z|𝒙;ΞΈ)):

  1. (a)

    Derive this decomposition from first principles.

  2. (b)

    Show that the E-step sets the KL term to zero.

  3. (c)

    Show that the M-step increases the ELBO by maximising over ΞΈ.

  4. (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).

  1. (a)

    Compute the number of free parameters for a GMM with K=20 and full covariance in d=100.

  2. (b)

    How many data points N would you need for reliable estimation? (A common rule of thumb is N≫p.)

  3. (c)

    Suggest two strategies to reduce the parameter count (e.g. diagonal covariances, PCA preprocessing) and discuss their trade-offs.

  4. (d)

    Explain why deep generative models like VAEs handle d=784 or d=3072 while GMMs cannot.

Exercise 11 (GMM as Universal Approximator).

  1. (a)

    Construct a GMM that approximates a Uniform[0,1] density using K equally-weighted, equally-spaced components with variance Οƒ2=1/(12K2). Plot the approximation for K=3,10,50.

  2. (b)

    How does the L1 approximation error scale with K?

  3. (c)

    Repeat for a bimodal density. How does the required K grow with the distance between modes?

Exercise 12 (Mixture Density Network).

Consider predicting yβˆˆβ„β‘ from xβˆˆβ„β‘ where the true relationship is y=x+0.3sin⁑(2Ο€x)+Ο΅ with ϡ∼0.5𝒩(βˆ’1,0.12)+0.5𝒩(1,0.12) (bimodal noise).

  1. (a)

    Why would a standard neural network with MSE loss fail to capture the bimodal conditional p(y|x)?

  2. (b)

    Design an MDN with K=2 Gaussian components. What are the output dimensions of the network?

  3. (c)

    Write the negative log-likelihood loss for training.

  4. (d)

    After training, how would you sample from p(y|x) for a given x?

Exercise 13 (GMM for Anomaly Detection).

Fit a GMM with K=5 to a dataset of β€œnormal” 2D data points.

  1. (a)

    Explain how to use p(𝒙) as an anomaly score.

  2. (b)

    What threshold Ο„ would you choose, and how?

  3. (c)

    A new data point π’™βˆ— has Ξ³ikβ‰ˆ0 for all k but p(π’™βˆ—) is not extremely low. How is this possible? (Hint: consider the tails of the Gaussian.)

  4. (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:

  1. (a)

    In a GMM, the latent variable z is discrete. What happens if we replace it with a continuous π’›βˆΌπ’©(0,I⁑)?

  2. (b)

    The GMM decoder is p(𝒙|z=k)=𝒩(𝝁k,𝚺k). What does the VAE replace this with?

  3. (c)

    The GMM E-step computes P(z|𝒙) exactly. Why can't we do this for the continuous-latent model, and what does the VAE do instead?

  4. (d)

    Summarise: what are the three key changes from GMM to VAE?

References

  1. Contributions to the Mathematical Theory of Evolution

    Karl Pearson

    Philosophical Transactions of the Royal Society of London A, vol. 185, pp. 71-110 Β· 1894

    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

  2. Maximum Likelihood from Incomplete Data via the EM Algorithm

    Arthur P Dempster, Nan M Laird, Donald B Rubin

    Journal of the Royal Statistical Society: Series B, vol. 39, no. 1, pp. 1-38 Β· 1977

    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

  3. Mixture Density Networks

    Christopher M Bishop

    Aston University Technical Report NCRG/94/004 Β· 1994

    BibTeX
    @article{bishop1994mixture,
      title={Mixture Density Networks},
      author={Bishop, Christopher M},
      journal={Aston University Technical Report NCRG/94/004},
      year={1994}
    }

    Journal article