📋 KEY INSIGHTS
- Gaussian Mixture Models represent a distribution as a weighted sum of K Gaussians — the natural generalisation of k-means that provides soft cluster assignments and full covariance structure.
- The EM algorithm iterates between an E-step (compute posterior cluster membership probabilities given current parameters) and an M-step (update parameters to maximise expected log-likelihood), guaranteed to converge to a local maximum.
- Hidden Markov Models extend mixture models to sequences: the hidden state follows a Markov chain, and observations are generated from state-dependent emission distributions estimated by the Baum-Welch (forward-backward EM) algorithm.
- Latent Dirichlet Allocation (LDA) is a Bayesian mixture model for text: each document is a mixture of topics, each topic is a distribution over words, and variational EM or Gibbs sampling infers the latent topic assignments.
- EM’s monotonic likelihood increase is its key theoretical guarantee — but it only finds local optima, so multiple random initialisations and model selection (BIC, AIC) are essential in practice.
- Variational EM replaces the exact E-step with a variational approximation, enabling EM-style training for models where the posterior p(z|x) is intractable — the foundation of variational autoencoders.
Many real-world datasets are heterogeneous — they come from multiple underlying subpopulations, processes, or generating mechanisms. Mixture models provide a principled probabilistic framework for modelling such data: a mixture distribution is a weighted combination of component distributions, with the latent component assignment treated as a hidden variable. The Expectation-Maximisation (EM) algorithm efficiently optimises mixture model parameters by iterating between inferring the hidden variable distribution and updating the parameters.
This guide covers the full mixture model and EM landscape: Gaussian Mixture Models (GMMs), the EM algorithm derivation and convergence properties, model selection, Hidden Markov Models (HMMs) with the Baum-Welch algorithm, Latent Dirichlet Allocation (LDA) for topic modelling, and the connection to variational inference and variational autoencoders.
Gaussian Mixture Models and the EM Algorithm
A Gaussian Mixture Model with K components defines the density p(x) = Σ_{k=1}^{K} π_k N(x; μ_k, Σ_k), where π_k are the mixing proportions (Σ π_k = 1, π_k ≥ 0), and each component is a multivariate Gaussian with mean μ_k and covariance Σ_k. GMM generalises k-means in two key ways: (1) soft assignments — a data point has probability r_{nk} = π_k N(x_n; μ_k, Σ_k) / p(x_n) of belonging to component k, rather than a hard 0/1 assignment; (2) covariance — each component has its own covariance matrix capturing the shape and orientation of the cluster, while k-means implicitly assumes spherical equal-variance clusters. The connection to our clustering guide is direct: k-means is the hard-assignment, equal-variance, zero-temperature limit of GMM — running EM with isotropic covariances and taking the limit as covariance → 0 recovers exactly the k-means update equations, making k-means a special case of the EM algorithm for GMMs.
The EM algorithm maximises the marginal log-likelihood log p(X | θ) = Σ_n log Σ_k π_k N(x_n; μ_k, Σ_k) by iterating two steps. The E-step computes the posterior responsibilities r_{nk} = p(z_n = k | x_n, θ^{old}) for each data point and component using Bayes’ theorem with the current parameters. The M-step updates all parameters to maximise the expected complete-data log-likelihood Q(θ, θ^{old}) = Σ_{n,k} r_{nk} [log π_k + log N(x_n; μ_k, Σ_k)], yielding closed-form updates: π_k^{new} = (1/N) Σ_n r_{nk}; μ_k^{new} = Σ_n r_{nk} x_n / Σ_n r_{nk}; Σ_k^{new} = Σ_n r_{nk} (x_n – μ_k^{new})(x_n – μ_k^{new})^T / Σ_n r_{nk}. The key theoretical property: each EM iteration is guaranteed to increase (or leave unchanged) the marginal log-likelihood, so EM converges monotonically — but only to a local maximum, not necessarily the global one. The connection to our Bayesian statistics guide is direct: the E-step is a posterior inference computation — it applies Bayes’ theorem to compute the posterior over latent assignments, the same fundamental operation described there for conjugate posterior updates, generalised here to mixture component posteriors.
Model selection for GMMs — choosing K, the number of components — uses information criteria: BIC = -2 log L(θ_MLE) + p log N (where p is the number of parameters) and AIC = -2 log L(θ_MLE) + 2p. BIC penalises model complexity more strongly and tends to select smaller K; AIC is less conservative. In practice, fit GMMs for K = 1, 2, …, K_max, compute BIC for each, and select the K that minimises BIC. The connection to our model evaluation guide is direct: GMM model selection via BIC is an instance of the bias-variance trade-off described there — increasing K reduces bias (better fit to the data) but increases variance (more parameters to estimate), and BIC/AIC quantify this trade-off using the penalised likelihood framework.
| Model | Latent Variable | Inference Algorithm | Key Application |
|---|---|---|---|
| GMM | Discrete cluster assignment | EM (closed-form M-step) | Density estimation; soft clustering |
| Hidden Markov Model | Markov chain of hidden states | Baum-Welch (forward-backward EM) | Speech, genomics, finance regimes |
| LDA | Topic assignments per word | Variational EM / Gibbs sampling | Topic modelling; document clustering |
| Mixture of Experts | Gating network assignment | EM + gradient descent | Conditional computation; MoE LLMs |
| VAE | Continuous latent code z | Variational EM (ELBO) | Generative modelling; representation |
Hidden Markov Models, LDA and Variational EM
Hidden Markov Models extend the GMM to sequential data: the latent variable z_t follows a first-order Markov chain (z_t depends only on z_{t-1}), and each observation x_t is generated from an emission distribution p(x_t | z_t). The model is parameterised by: the initial state distribution π, the transition matrix A (A_{ij} = P(z_t = j | z_{t-1} = i)), and the emission parameters θ_k for each state k. The Baum-Welch algorithm is EM for HMMs: the E-step uses the forward-backward algorithm (dynamic programming) to compute the joint posterior P(z_t, z_{t+1} | x_{1:T}) in O(TK^2) time; the M-step updates the transition matrix and emission parameters using these posteriors. HMMs are used in automatic speech recognition (phoneme sequence modelling), bioinformatics (gene finding, CpG island detection), and financial regime detection (identifying bull/bear/sideways market states). The connection to our time series analysis guide is direct: HMMs are a probabilistic sequence model for time series — the Viterbi algorithm decodes the most likely hidden state sequence (most likely regime at each time step), and this regime assignment is a form of change-point detection applied to financial or physiological time series.
Latent Dirichlet Allocation (LDA, Blei et al., 2003) is a hierarchical Bayesian mixture model for text corpora. Each document d has a topic distribution θ_d ~ Dirichlet(α); each topic k has a word distribution φ_k ~ Dirichlet(β); each word w_{dn} in document d is generated by first drawing a topic z_{dn} ~ Categorical(θ_d), then drawing a word w_{dn} ~ Categorical(φ_{z_{dn}}). Variational EM (using mean-field variational inference) or collapsed Gibbs sampling (integrating out θ and φ analytically) estimates the topic distributions and per-word topic assignments. LDA discovers coherent topics from large text corpora without any labels — applied to 10,000 news articles, it discovers topics like “politics”, “sport”, “technology” purely from word co-occurrence patterns. The connection to our NLP pipeline guide is direct: LDA operates on bag-of-words representations — the same tokenisation, vocabulary construction, and TF-IDF weighting described there prepares the document-term matrix that LDA takes as input, and LDA’s topic-word distributions provide interpretable, human-readable summaries of the latent themes in a corpus.
Variational EM replaces the exact E-step (which requires computing the intractable posterior p(z | x, θ)) with a variational approximation: find the distribution q(z) in a tractable family (typically a factorised mean-field family q(z) = Π_i q_i(z_i)) that minimises KL(q(z) || p(z | x, θ)). This is equivalent to maximising the Evidence Lower BOund (ELBO = E_q[log p(x, z)] – E_q[log q(z)]) over both q and θ. Variational EM enables EM-style coordinate ascent for models where the E-step posterior is intractable — including LDA (the full posterior over all topic assignments is exponentially complex) and deep generative models. The connection to our Bayesian deep learning guide is direct: variational autoencoders (VAEs) are a differentiable version of variational EM — the encoder network q_φ(z|x) parameterises the variational posterior, the decoder network p_θ(x|z) parameterises the generative model, and training maximises the ELBO using the reparameterisation trick to enable gradient-based optimisation of both networks simultaneously.
✦ SUMMARIZE THIS ARTICLE WITH AI
Clustering (k-means as the zero-temperature limit of GMM EM) is in our Clustering guide. Bayesian statistics (E-step as posterior inference; Bayes’ theorem for responsibilities) are in our Bayesian Statistics guide. Time series analysis (HMMs for regime detection; Viterbi for state decoding) is in our Time Series Analysis guide. NLP pipeline (bag-of-words preprocessing for LDA topic modelling) is in our NLP Pipeline guide. Bayesian deep learning (VAEs as differentiable variational EM with ELBO) is in our Bayesian DL guide. Model evaluation (BIC and AIC for GMM component selection) is in our Model Evaluation guide. Mixture of experts (MoE LLMs as a learned mixture model with gating network) are in our MoE guide. Dimensionality reduction (probabilistic PCA as a Gaussian latent variable model, EM-solvable) is in our Dimensionality Reduction guide.



