45.08.07 · mathematical-statistics / 08-learning-methods

The EM Algorithm and Gaussian-Mixture / Latent-Variable Models

shipped3 tiersLean: none

Anchor (Master): McLachlan & Krishnan 2008 The EM Algorithm and Extensions 2e (Wiley) Ch. 1-3 (the incomplete-data formulation, the E- and M-steps, the monotonicity theorem and the role of , and convergence to a stationary point); Dempster, Laird & Rubin 1977 J. Roy. Statist. Soc. B 39:1-38 (the original general formulation, the GEM generalisation, and the monotone-ascent proof); Wu 1983 Ann. Statist. 11:95-103 (the corrected convergence theory and the conditions for convergence to a stationary point)

Intuition Beginner

Suppose you have a pile of measurements that came from two different sources mixed together — say, the heights of fish from two species netted in one haul — but the labels are gone. You want the average height of each species, yet to compute those averages you would need to know which fish belongs to which species, and to guess the species you would need the averages. Each piece of knowledge depends on the other. This chicken-and-egg loop is the situation the EM algorithm is built to break.

EM breaks it by guessing, then refining. Start with a rough guess for the two averages. Now, for every fish, ask: given these guessed averages, how likely is it that this fish came from species one versus species two? A short fish near the first average gets assigned mostly to species one; a fish sitting between the two averages gets split, say sixty percent to one and forty percent to the other. These soft, fractional memberships are called responsibilities. That is the first half of the cycle.

The second half: now that every fish carries a fractional vote for each species, recompute each average as a weighted average, where each fish counts according to its vote. The new averages are better than the guesses you started with. Feed them back in, recompute the votes, recompute the averages, and repeat. Each pass improves the fit, and the numbers settle down. You alternate between guessing the hidden labels and re-estimating the parameters, and the loop converges.

Visual Beginner

Picture a number line with a cloud of dots — the fish heights. Two bell curves sit on the line, one centred on each guessed average. For a given dot, the two bell curves report how tall they are at that spot; the taller curve at that point wins more of the dot's vote. A dot directly under the left bell goes almost entirely to the left species; a dot in the overlap zone between the bells splits its vote.

step what you do what comes out
E-step with the bells fixed, score each dot's vote for each bell a soft membership (responsibility) per dot
M-step with the votes fixed, slide and reshape each bell updated averages, spreads, and mixing fractions

The takeaway: EM is two alternating moves. One move fills in the missing labels softly using the current parameters; the other re-estimates the parameters using those soft labels. Repeating the pair drives the fit uphill until it stops improving.

Worked example Beginner

Take four measurements on a line: . You believe they come from two clusters and you want each cluster's centre. Start with guessed centres and .

Step 1, score the votes (E-step). For each point, give more vote to the nearer centre. A simple scoring is to make the vote for a centre larger when the point is closer. Point is near (distance ) and far from (distance ), so almost all of its vote goes to cluster one; say to cluster one and to cluster two. By symmetry point also votes about for cluster one. Points and are near , so each votes about for cluster two and for cluster one.

Step 2, recompute the centres (M-step). Each new centre is the vote-weighted average of all four points. For cluster one, the weights are on the points :

For cluster two the weights flip to , giving .

Step 3, repeat. The centres moved from and to and — much closer to the two natural clumps near and . Feeding and back in sharpens the votes (points now vote even more strongly for cluster one), and the next M-step pulls the centres to roughly and , where they stop moving.

What this tells us: starting from a crude guess, one E-step plus one M-step already produced sensible centres, and a second pass nearly finishes the job. The fractional votes are what let the two unknowns be estimated together instead of waiting on each other.

Check your understanding Beginner

Formal definition Intermediate+

Let denote the observed data with density for , and suppose this density arises by marginalising a latent (unobserved) variable from a complete-data density :

The incomplete-data log-likelihood is and the complete-data log-likelihood is ; the latter cannot be evaluated because is not observed. Write for the posterior of the latent variable.

Definition (Q-function). For a current parameter value , the expected complete-data log-likelihood, or Q-function, is the conditional expectation 37.04.01

The averaging is over the latent posterior at the current parameter , while the argument inside the logarithm is the free variable to be optimised.

Definition (the EM iteration). Given an initial , the EM algorithm produces a sequence by alternating:

  • E-step. Using the current , form the function (in practice: compute the latent posterior and the expectations it induces).
  • M-step. Maximise the surrogate, .

A generalised EM (GEM) algorithm relaxes the M-step to any update with .

Definition (the evidence lower bound). For any probability density over the latent space, the evidence lower bound (ELBO) is

where is the Kullback-Leibler divergence. Because the KL term is non-negative and vanishes exactly when , the ELBO is a lower bound on that is tight at the latent posterior.

Definition (Gaussian mixture model). A -component Gaussian mixture in has density , with mixing weights , , component means , covariances , and the multivariate normal density. The latent is the component label, and . The responsibility of component for observation at parameter is the posterior class probability

The new symbols are recorded in _meta/NOTATION.md: (Q-function), (incomplete-data log-likelihood), (complete-data log-likelihood), (ELBO), (Kullback-Leibler divergence), (responsibility).

Counterexamples to common slips Intermediate+

  • "EM maximises the Q-function, so it maximises the likelihood." The M-step maximises , a surrogate tangent to at , not itself. Each step increases , but a single M-step lands at the surrogate's peak, which is generally not 's peak; the guarantee is monotone ascent, not one-shot maximisation.

  • "EM converges to the global maximum likelihood estimate." The mixture log-likelihood is non-concave and multimodal. EM ascends to a stationary point — a local maximum or a saddle — determined by the starting value. Different initialisations reach different solutions, which is why multiple random restarts (or k-means initialisation) are standard.

  • "The responsibilities are hard 0/1 labels." They are posterior probabilities in summing to one across components. A point exactly between two equal-variance components splits its responsibility evenly; hard assignment is the degenerate limit recovered only as the component variances shrink to zero.

  • "The mixture likelihood has a well-defined global maximum to find." For Gaussian mixtures with free covariances the likelihood is unbounded: placing one component's mean on a single data point and shrinking its variance to zero sends the likelihood to . The meaningful target is a sensible interior local maximum, not the (degenerate) global supremum.

Key theorem with proof Intermediate+

The signature result is the monotonicity theorem: each EM iteration never decreases the observed-data log-likelihood. The proof exhibits as the variable part of a lower bound on and isolates the gap as a Kullback-Leibler divergence, which the conditional form of Jensen's inequality 37.04.01 forces to move the right way [Dempster, A. P., Laird, N. M. & Rubin, D. B. — Maximum Likelihood from Incomplete Data via the EM Algorithm].

Theorem (EM ascent / monotonicity). Let satisfy (in particular if ). Then the observed-data log-likelihood does not decrease,

with equality only if and almost everywhere.

Proof. Take logarithms of the identity and rearrange:

The left side is free of . Take the expectation of both sides over ; the left side passes through unchanged, giving the decomposition

Evaluate this at and at and subtract:

It remains to show , i.e. is maximised in its first argument at . Write and . Then

where the inequality is the Gibbs inequality, itself the conditional Jensen inequality 37.04.01 applied to the concave logarithm: . Therefore both bracketed terms in the difference push upward, so . Equality forces both the -difference to vanish and , i.e. almost everywhere.

Bridge. This monotonicity is the foundational reason EM is a usable algorithm despite the latent-variable likelihood having no closed-form maximiser, and it builds toward the variational reformulation: the decomposition is exactly the ELBO identity read with , so EM is coordinate ascent on — the E-step maximises over (setting the KL gap to zero) and the M-step maximises over . This is dual to the Newton/Fisher-scoring route of direct maximum likelihood 44.03.03, which climbs directly using its gradient and curvature; EM trades that curvature information for a sequence of easy complete-data maximisations. The central insight is that the awkward marginal likelihood is replaced by a surrogate that touches it from below and is maximised separately, and this is exactly the minorize-maximize principle, of which EM is the canonical probabilistic instance. Putting these together, the same identity reappears in the Gaussian-mixture M-step, where maximising becomes responsibility-weighted moment matching, the latent-data echo of the exponential-family likelihood equation from 45.01.04; the convergence behaviour this guarantees — ascent to a stationary point, not the global optimum — appears again in the analysis of the algorithm's fixed points and rate in the Advanced results.

Exercises Intermediate+

Advanced results Master

The results below organise the EM algorithm around the variational identity of the Key theorem, the fixed-point and convergence theory that the monotonicity guarantee only opens, the rate of convergence governed by missing information, and the canonical instances — Gaussian mixtures, the soft/hard k-means limit, and the hidden-Markov Baum-Welch recursion. Direct gradient and Newton maximisation of remain the contrast class throughout 44.03.03, 45.01.04.

Theorem 1 (EM as coordinate ascent on the ELBO). Define . The E-step is the exact maximisation , attaining ; the M-step is , which (dropping the -free entropy of ) equals . EM is therefore alternating maximisation of a single objective over two coordinate blocks, and monotone ascent of is the immediate corollary . This is the foundation of the variational generalisations in which the E-step is restricted to a tractable family , giving variational EM with an inexact but still monotone bound [Hastie, T., Tibshirani, R. & Friedman, J. — The Elements of Statistical Learning (2nd ed.)].

Theorem 2 (Wu's convergence theorem). Suppose is continuous on and the Q-function is continuous in both arguments. If the EM map is closed and the level set is compact, then all limit points of the EM sequence are stationary points of , and increases monotonically to a value for some stationary point . Convergence of the parameter sequence itself (not merely of its limit-point set or of ) requires the additional condition that the stationary points achieving are isolated; without it the iterates can in principle drift along a ridge of equal likelihood. Dempster, Laird, and Rubin's original convergence assertion overstated the conclusion; Wu's analysis supplied the correct hypotheses [McLachlan, G. J. & Krishnan, T. — The EM Algorithm and Extensions (2nd ed.)].

Theorem 3 (linear rate and the fraction of missing information). Near a fixed point the EM map has Jacobian , where is the expected complete-data information, the observed-data information, and the missing information. Consequently , so EM converges linearly (geometrically) with rate equal to the largest eigenvalue of — the largest fraction of missing information. When little information is missing the rate is fast; when the latent structure is highly informative (heavily overlapping mixture components) EM crawls, which motivates acceleration via Aitken extrapolation, ECME, or switching to a Newton step on near the optimum [McLachlan, G. J. & Krishnan, T. — The EM Algorithm and Extensions (2nd ed.)].

Theorem 4 (Gaussian mixtures: closed-form M-step and the k-means limit). For the -component Gaussian mixture the M-step has the closed form , , with , i.e. responsibility-weighted means and covariances, the soft analogue of the cluster statistics in 45.08.08. Constrain all covariances to and let : the responsibilities converge to the hard indicator , the M-step means become unweighted cluster averages, and EM degenerates exactly into Lloyd's k-means algorithm. Soft k-means is EM for the spherical-Gaussian mixture at finite ; hard k-means is its zero-temperature limit [Hastie, T., Tibshirani, R. & Friedman, J. — The Elements of Statistical Learning (2nd ed.)].

Theorem 5 (Baum-Welch as EM for hidden Markov models). For a hidden Markov model with latent state path , observations , initial distribution , transition matrix , and emission densities , the complete-data log-likelihood is additive over time, . The E-step requires only the single-state posteriors and pairwise posteriors , computed in by the forward-backward recursion; the M-step then updates , , and the emission parameters as posterior-expected-count frequencies. The resulting algorithm is the Baum-Welch algorithm, which predates and is a special case of the general EM formulation [McLachlan, G. J. & Krishnan, T. — The EM Algorithm and Extensions (2nd ed.)].

Synthesis. The EM algorithm is one identity worked in several settings: the decomposition , equivalently , is the foundational reason monotone ascent holds and the reason EM is exactly coordinate ascent on the ELBO. The central insight is that an intractable marginal likelihood is replaced by a surrogate that touches it from below at the current iterate and is maximised separately — the minorize-maximize principle — so the latent integral is handled once, in the E-step, and the M-step is an ordinary complete-data fit. This is exactly the latent-data generalisation of 45.01.04: for exponential-family complete data the M-step is moment matching with the conditional expectation of the sufficient statistic in place of the unobserved statistic, so EM and maximum likelihood share one stationarity condition. The construction is dual to direct gradient/Newton maximisation of 44.03.03: EM buys stable, constraint-respecting, derivative-free ascent at the price of only linear convergence, the rate set by the fraction of missing information of Theorem 3, while Newton converges quadratically but must contend with the non-concave, possibly unbounded mixture surface. Putting these together, the Gaussian-mixture responsibilities specialise to hard k-means 45.08.08 in the vanishing-variance limit, and the forward-backward E-step specialises EM to Baum-Welch; the same surrogate-ascent skeleton recurs each time, and the bridge forward is that restricting the E-step to a tractable family is precisely the variational-inference programme that scales EM to models where the latent posterior is itself intractable.

Full proof set Master

Proposition 1 (the H-function inequality). For any and fixed , , with equality iff almost everywhere, where .

Proof. Write and , both probability densities in . Then

the inequality being the Gibbs inequality. It is the conditional Jensen inequality 37.04.01 for the strictly concave : , with equality iff is constant -almost-surely, i.e. a.e. since both integrate to one.

Proposition 2 (monotonicity / GEM ascent). If then .

Proof. The identity holds for every (take the conditional expectation under of , whose left side is -free). Subtracting the instances at and ,

The first bracket is by hypothesis; the second is by Proposition 1.

Proposition 3 (Gaussian-mixture M-step). Maximising over and yields , , , .

Proof. The objective separates: the -part is and the -part splits across . For , form the Lagrangian ; stationarity gives , and with forces , so . For component , the relevant terms are . Differentiating in : gives . Differentiating in using and with : , so at . Each is the weighted Gaussian maximum-likelihood estimate.

Proposition 4 (hard k-means as the limit). For the spherical mixture with , as the responsibility where (assuming a unique nearest centre), and the M-step mean updates converge to the unweighted cluster means of k-means.

Proof. With equal weights and ,

Let and , unique by assumption. For every exponent and the term is , while every term has , so its exponent and the term ; hence . For the term with contributes in the denominator, so . The responsibilities become hard indicators; the M-step mean becomes the average of the points assigned to centre , which is the Lloyd update.

Proposition 5 (linear convergence rate of EM). Let be the EM map with fixed point , , and suppose is differentiable near . Then , and the iteration converges linearly with rate when is an isolated local maximum.

Proof (structure). Differentiating the self-consistency relation that defines the M-step, (the gradient of in its first argument vanishes at the maximiser), with respect to gives where the subscripts denote the order of differentiation in the first and second arguments. At one identifies (the complete-data information) and (the missing information, from differentiating the H-function relation and using ). Hence . Because at an isolated local maximum, the eigenvalues of lie in , and the linearisation gives geometric convergence at rate .

Connections Master

  • Maximum likelihood and the method of moments 45.01.04 is the parent estimation theory: EM is the device that computes the maximum likelihood estimate when the likelihood marginalises a latent variable and the score equations have no closed form. The exponential-family M-step is exactly that unit's likelihood equation with the unobserved sufficient statistic replaced by its conditional expectation, so EM inherits the moment-matching characterisation and the strict-concavity-of-the-complete-data-likelihood structure that makes each M-step well posed, while the observed-data likelihood it ascends is in general non-concave.

  • Newton's method for optimization 44.03.03 is the contrast and the accelerator: direct maximisation of the observed-data log-likelihood by Newton or Fisher scoring converges quadratically but must handle the non-concave, possibly unbounded mixture surface and supply the Hessian; EM trades that for derivative-free, monotone, linear-rate ascent. The two are routinely hybridised — EM from a crude start to enter a good basin, then a Newton step near the optimum where the fraction-of-missing-information rate of EM (Theorem 3) becomes the bottleneck.

  • k-means and prototype clustering 45.08.08 is the hard-assignment specialisation: k-means is EM for an equal-weight spherical-Gaussian mixture in the limit of vanishing component variance, where soft responsibilities collapse to nearest-centre indicators and the responsibility-weighted M-step means become plain cluster averages. The soft/hard duality explains both why k-means is fast (no probabilities to track) and why it is brittle to non-spherical or unequal-size clusters that the full mixture handles.

  • Conditional expectation and martingales 37.04.01 supplies the analytic engine: the Q-function is a conditional expectation of the complete-data log-likelihood, and the monotonicity proof rests on conditional Jensen / the non-negativity of Kullback-Leibler divergence applied to latent posteriors. The same conditional-expectation calculus reappears in the forward-backward E-step for hidden Markov models and in the variational-inference generalisations where the E-step is projected onto a tractable family.

Historical & philosophical context Master

Special cases of the alternate-and-fill-in idea long predate the general formulation: Hartley treated the discrete-count missing-data case in 1958 [Hartley 1958], Baum and colleagues developed the forward-backward re-estimation for probabilistic functions of Markov chains through the late 1960s and early 1970s [Baum 1970], and the same recursion arose independently in genetics and in factor analysis. The unifying recognition that these were one algorithm — and the name "EM" — is due to Arthur Dempster, Nan Laird, and Donald Rubin in their 1977 Journal of the Royal Statistical Society B paper, which gave the general incomplete-data formulation, the E- and M-steps, the GEM relaxation, and the monotone-ascent argument via the -function and Jensen's inequality [Dempster, A. P., Laird, N. M. & Rubin, D. B. — Maximum Likelihood from Incomplete Data via the EM Algorithm].

The 1977 convergence claim was incomplete: it asserted convergence to a maximiser where only convergence of the likelihood values and stationarity of limit points hold under regularity. C. F. Jeff Wu corrected the theory in 1983, separating convergence of from convergence of the parameter sequence and giving the conditions (closedness of the EM map, compact level sets, isolated stationary points) under which each holds [Wu 1983]. The book-length synthesis, including the missing-information rate, standard-error estimation by Louis's method and the supplemented-EM algorithm, and the catalogue of extensions (ECM, ECME, stochastic and Monte Carlo EM), is McLachlan and Krishnan's monograph [McLachlan, G. J. & Krishnan, T. — The EM Algorithm and Extensions (2nd ed.)]. The variational reading of EM as coordinate ascent on the evidence lower bound, which became central to scalable Bayesian computation, is articulated by Neal and Hinton in 1998 [Neal-Hinton 1998].

Bibliography Master

@article{dempsterlairdrubin1977,
  author  = {Dempster, Arthur P. and Laird, Nan M. and Rubin, Donald B.},
  title   = {Maximum Likelihood from Incomplete Data via the {EM} Algorithm},
  journal = {Journal of the Royal Statistical Society, Series B},
  volume  = {39},
  number  = {1},
  year    = {1977},
  pages   = {1--38}
}

@book{mclachlankrishnan2008,
  author    = {McLachlan, Geoffrey J. and Krishnan, Thriyambakam},
  title     = {The {EM} Algorithm and Extensions},
  edition   = {2},
  series    = {Wiley Series in Probability and Statistics},
  publisher = {Wiley},
  year      = {2008}
}

@book{hastietibshiranifriedman2009,
  author    = {Hastie, Trevor and Tibshirani, Robert and Friedman, Jerome},
  title     = {The Elements of Statistical Learning: Data Mining, Inference, and Prediction},
  edition   = {2},
  series    = {Springer Series in Statistics},
  publisher = {Springer},
  year      = {2009}
}

@article{wu1983,
  author  = {Wu, C. F. Jeff},
  title   = {On the Convergence Properties of the {EM} Algorithm},
  journal = {The Annals of Statistics},
  volume  = {11},
  number  = {1},
  year    = {1983},
  pages   = {95--103}
}

@article{baum1970,
  author  = {Baum, Leonard E. and Petrie, Ted and Soules, George and Weiss, Norman},
  title   = {A Maximization Technique Occurring in the Statistical Analysis of Probabilistic Functions of {Markov} Chains},
  journal = {The Annals of Mathematical Statistics},
  volume  = {41},
  number  = {1},
  year    = {1970},
  pages   = {164--171}
}

@article{hartley1958,
  author  = {Hartley, Herman O.},
  title   = {Maximum Likelihood Estimation from Incomplete Data},
  journal = {Biometrics},
  volume  = {14},
  number  = {2},
  year    = {1958},
  pages   = {174--194}
}

@incollection{nealhinton1998,
  author    = {Neal, Radford M. and Hinton, Geoffrey E.},
  title     = {A View of the {EM} Algorithm that Justifies Incremental, Sparse, and Other Variants},
  booktitle = {Learning in Graphical Models},
  editor    = {Jordan, Michael I.},
  publisher = {Kluwer Academic Publishers},
  year      = {1998},
  pages     = {355--368}
}

@book{bishop2006,
  author    = {Bishop, Christopher M.},
  title     = {Pattern Recognition and Machine Learning},
  series    = {Information Science and Statistics},
  publisher = {Springer},
  year      = {2006}
}