Expectation-Maximization (EM)
Source: Unit 3 §10
The problem EM solves
- Maximum Likelihood Estimation (MLE) searches over distributions and parameters to fit the data, but it requires complete data - every interacting variable must be observed.
- MLE becomes intractable the moment there are hidden or latent variables: unobserved variables that interact with the data you can see.
EM performs MLE in the presence of latent variables by alternating two steps that each assume the other's answer:
- E-step: estimate the values of the latent variables, given the current parameters.
- M-step: optimise the model parameters, assuming the estimated latent values are true.
- Repeat until convergence.
The loop converges to a local maximum. A different initial guess can land on a different answer, so EM in practice means EM with several random restarts, keeping the best likelihood.
Warm-up: K-means as a special case
K-means partitions data into K distinct, non-overlapping clusters. You must specify K in advance, and each observation is assigned to exactly one cluster.
With clusters C₁, …, Cₖ:
C₁ ∪ C₂ ∪ … ∪ Cₖ = {1, …, n}- every point belongs to some cluster.Cₖ ∩ Cₖ' = ∅fork ≠ k'- the clusters do not overlap.
Objective: minimise the within-cluster variation summed over all clusters, where intra-cluster distance is measured by Euclidean distance between pairs of points.
| EM step | K-means action |
|---|---|
| E-step | Assign each data point to the closest cluster: wᵢₖ = 1 if xᵢ is in cluster k, else 0. |
| M-step | Recompute the centroid (the mean) of each cluster. |
Convergence is guaranteed, but only to a local minimum, which is the same caveat as EM in general and the same fix: multiple random restarts.
EM in general
- E-step: the missing data are estimated, given the observed data and the current parameter estimates.
- M-step: the likelihood is maximised, assuming the missing data are known - the E-step's estimates are used in place of the actual missing data.
- Repeat, feeding each step's output into the other, until the parameters stop changing.
Worked example: two coins
Problem: estimate the biases and of two coins. The experiment: pick a coin at random, flip it 10 times, record the results. Do that 5 times.
Case 1: the coin identities are known
This is the easy case, and it is just counting.
Case 2: the coin identities are unknown
The coin identity is now a latent variable, and counting is no longer available. Use EM.
- Guess initial biases, say and . Each coin is equally likely to have been picked: .
- E-step. For each trial - take , which is 8 heads and 2 tails - compute how likely each coin is to have produced it: and .
- Apply Bayes. Because , the priors cancel: .
- Proportionally assign the head and tail counts of that trial to each coin, in the ratio of those responsibilities. The counts become fractional.
- M-step. Recompute and from the fractional assigned counts, exactly as in case 1 but with soft counts.
- Repeat. The iteration converges to a local maximum.
EM's M-step is the same counting formula as the known-identity case. The only difference is that the counts are fractional, weighted by the E-step's responsibilities. If the responsibilities ever became 0 or 1, EM would reduce exactly to case 1.
Gaussian Mixture Models
- A multivariate Gaussian is a vector of normally distributed variables where any linear combination is also normal. The univariate case is the familiar single bell.
- A GMM models the data as a mixture of several Gaussians, and we estimate their parameters - means, covariances and mixing weights - by Maximum Likelihood, which in practice means EM.
- EM for GMM is soft clustering: the E-step computes the responsibility of each Gaussian for each point, and the M-step updates each Gaussian's mean, covariance and weight.
- Estimating the parameters of a Gaussian Mixture Model.
- The Baum-Welch algorithm for Hidden Markov Models - see HMM Algorithms.
- Clustering generally.