Expectation Maximization
Maximum likelihood asks which parameter values make the measurements most probable. Expectation–maximization is a way to answer that question when the model uses information—such as a group identity—that the dataset never recorded.
Maximum likelihood becomes harder when the model depends on unrecorded information
Begin with the job that maximum likelihood already performs. The observed measurements stay fixed, a chosen model family supplies candidate probability distributions, and each parameter value receives a likelihood according to how strongly its distribution supports those measurements. Maximum-likelihood estimation chooses a parameter value at a peak of that observed-data likelihood. Expectation–maximization keeps this destination.
This difficulty appears when the model describes more than the dataset records. A model may say that every measurement came from one of several groups, that a noisy reading arose from an unobserved signal, or that some category was missing. These unrecorded quantities affect how the measurements should contribute to the fit. If their values were available, ordinary maximum-likelihood calculations would often be straightforward. Without them, the parameters and the missing quantities have to be learned together.
Expectation–maximization, abbreviated EM, resolves this coupled problem by refusing to solve both unknowns at once. It holds the current parameters fixed while estimating probabilities for the missing quantities, then holds those probabilities fixed while updating the parameters. Repeating those two easier calculations produces the complete algorithm below.
EM repeats four stages around one maximum-likelihood objective
Stage 2 is called the expectation step, or E-step, because it averages over the possible values of the missing information using the current model. Stage 3 is called the maximization step, or M-step, because it chooses parameter values that maximize the objective formed by that expected completion. These names describe the two calculations inside the loop; initialization and the stopping check complete the four-stage procedure.
A delivery time can be observed even when the route that produced it is missing
A courier service uses three routes between the same distribution center and neighborhood. The routes differ in their typical travel times, but traffic makes their time ranges overlap. The dispatch system retained eighteen delivery times while losing the route field. The service wants to estimate how often each route was used, its typical time, and its variability from the times that remain.
A 29-minute delivery is compatible with all three provisional route patterns
The observable result comes before any algorithm: a time near the overlap cannot identify its route. A hard label would claim information the record does not contain. Yet a fitted route pattern could say how plausible each route is for that time. This is the coupling EM will break: route patterns would determine route probabilities, while route probabilities are needed to fit the route patterns.
Represent each route's time pattern by a probability distribution and call that distribution a component. For delivery , the measured time is observed while the route choice is its unobserved component assignment. A model quantity such as that is not directly observed is a latent variable. Component has weight , its probability of being used, and parameter , which controls its travel-time pattern. Collect all adjustable parameters in .
Every missing route forces the observed likelihood to combine several explanations
For one recorded time , the missing route could be any component. The probability of observing that time therefore adds the mutually exclusive route explanations. Route contributes its usage probability multiplied by the probability density its travel-time pattern assigns to :
Independent delivery records multiply these summed densities. Taking a logarithm converts the product across deliveries into a sum, but the addition across possible routes remains inside each logarithm. The parameters for all components are consequently coupled inside one observed-data objective:
Every delivery combines all possible route explanations before its logarithm is taken.
Each delivery contributes directly to the component named by its recorded route.
The easier form becomes visible by writing a route indicator. Let when delivery used component , and let it be zero otherwise. If these indicators were recorded alongside the times, would be the complete data. Its log-likelihood separates the route contributions:
The missing indicators cannot be replaced by unsupported hard labels. Stage 1 of EM instead supplies provisional component parameters. Those parameters make it possible to calculate a probability for every missing indicator—the expectation required by stage 2.
One EM cycle turns possible routes into fractional counts, then refits the route patterns
Begin a cycle with provisional parameters . They specify how frequently each component is used and which delivery times it supports. For delivery , compare the support supplied by component with the total support supplied by all components. Normalizing these alternatives produces the current conditional probability of every route assignment:
The value is the responsibility of component for delivery . The responsibilities for one delivery are nonnegative and sum to one. They are the conditional expectations of the missing indicators. Replacing those indicators in the complete-data log-likelihood produces the expected complete-data objective conventionally named :
The E-step has now formed an average complete-data log-likelihood over every possible route completion. Keep these responsibilities fixed and choose parameters that maximize this expected objective. That weighted refit is the M-step:
The provisional route patterns shown earlier were symmetric bell shapes with a center and spread. A component with this behavior, mean , and variance is a Gaussian component. A weighted collection of Gaussian components is a Gaussian mixture model, abbreviated GMM:
The laboratory begins with the same provisional three-component model displayed in the earlier figure. Perform the E-step to expose fractional route assignments without moving a curve. Then perform the M-step to refit the component weights, centers, and spreads without moving an observation. The reported observed-data log-likelihood changes only after a complete cycle.
Alternate one expectation step with one maximization step
| component | current weight | current center | current spread | next center after M-step |
|---|---|---|---|---|
| 1 | 0.340 | 20.50 | 5.80 | perform E-step |
| 2 | 0.330 | 29.00 | 6.30 | perform E-step |
| 3 | 0.330 | 37.50 | 5.90 | perform E-step |
For Gaussian components, the M-step reduces to familiar weighted maximum-likelihood calculations. Define the effective component count by adding the fractional deliveries assigned to component . That count determines the new component weight, weighted mean, and weighted variance:
Add the responsibilities to obtain the effective number of observations assigned to component j.
The component’s new weight is its fractional share of all observations.
The component center is the responsibility-weighted sample mean.
The component variance is the responsibility-weighted mean squared residual around the new center.
A zero mismatch gap makes each exact cycle climb
The GMM laboratory reports that its observed-data log-likelihood rises after each complete cycle, even though the M-step maximizes rather than the observed log-likelihood directly. To see why, consider any proposed probability distribution over the missing assignments. Two terms combine into an objective that sits at or below the observed log-likelihood: the average complete-data log-likelihood under and the uncertainty of itself.
The uncertainty term is the entropy . Their sum is the evidence lower bound, abbreviated ELBO and written :
The gap between the observed log-likelihood and this lower objective measures how differently and the model's current assignment posterior distribute probability across the same possible completions. This nonnegative mismatch is the Kullback–Leibler divergence, or KL divergence:
One move closes the gap; the other raises the objective it touches
In the E-step, set . The two assignment distributions then match, their KL divergence is zero, and the ELBO touches the observed log-likelihood at the current model. In the M-step, keep fixed and raise the ELBO by changing . Because the observed log-likelihood equals that raised ELBO plus another nonnegative gap, it cannot finish below the previous likelihood.
A climbing guarantee does not choose the highest peak
EM's exact cycle guarantees that the observed likelihood does not decrease. A surface can nevertheless contain several peaks, flat ridges, boundary singularities, and saddle points. The initial parameters determine which region of that surface the first responsibilities describe, so different initializations can lead to different stationary points.
Each completed cycle preserves or raises the observed-data objective.
Under suitable regularity conditions, limit points are stationary; they need not be global maxima.
Initialization, constraints, held-out fit, and scientific interpretation remain separate responsibilities.
A Gaussian mixture has an additional boundary problem. One component can center itself on one observation while its variance shrinks toward zero, making that observation's density grow without bound. Practical fitting therefore uses multiple initializations and may constrain component variances or add prior information. These choices modify the allowed parameter space or objective; they are not supplied by the bare EM recurrence.
If the parameters themselves have a prior distribution , the M-step can add its log-density to the expected complete-data objective. The resulting algorithm seeks a maximum a posteriori estimate, orMAP estimate, rather than an unpenalized maximum-likelihood estimate:
The missing explanation can be function values or a growing collection of components
Component labels are only one kind of latent variable. In another model, the observations may be noisy measurements of an unknown function, so its values at the observed inputs are latent. In a third model, the unknown object may be a probability distribution whose atoms supply a growing collection of component parameters. EM applies when these hidden quantities produce a useful expected complete-data objective and the resulting expectation and maximization calculations can be performed exactly or approximated honestly.
Infer ; refit .
Infer ; refit kernel and noise hyperparameters.
Approximate a posterior over a countably unbounded collection.
Finite mixtures and distributions over functions randomize different objects
A GMM is one probability distribution for an observation such as a delivery time. It first chooses one of finitely many components and then draws the observation from that component's Gaussian distribution. A Gaussian process, or GP, assigns probability to a complete function so that the function values at every finite input list have a multivariate Gaussian joint distribution. The word “Gaussian” therefore operates at different levels.
one component, then one observation
one complete function
the component assignment
function values such as
inside finitely many component densities
in every finite joint distribution of function values
weights, component means, and component spreads
kernel, mean-function, and observation-noise hyperparameters
A finite list of GP values gives EM a finite doorway
Let and observe noisy outputs . Although the random function spans a complete input domain, the likelihood of the measured dataset depends on the finite latent vector . Kernel and noise hyperparameters collected in can be fitted by integrating over this latent vector:
An EM formulation uses the current posterior distribution over the finite latent function values as its E-step.
Its M-step refits the kernel or noise hyperparameters using expected sufficient information from those function values.
For ordinary GP regression with Gaussian observation noise, both the latent posterior and marginal likelihood are available in closed form, so directly optimizing the log marginal likelihood is usually the standard route. EM is valid but not automatically the most efficient organization of the same calculation. With non-Gaussian observations, such as class labels, the latent function posterior is generally intractable; an approximate E-step based on expectation propagation, Laplace approximation, or variational inference produces an approximate EM-type method.
A growing mixture changes exact EM into approximate posterior inference
A Dirichlet process, or DP, assigns probability to complete probability measures over component parameters. In a Dirichlet-process mixture, draw one such measure, draw a component parameter for each observation from it, and then draw the observation from that component:
Repeated values of form clusters, while the number of occupied clusters can grow with the data. The hidden structure now includes assignments and a countably unbounded collection of possible atoms and weights. An exact finite responsibility table is therefore unavailable without another representation or approximation.
One deterministic route truncates a stick-breaking representation at a large finite level and chooses a tractable probability distribution over assignments, stick weights, and component parameters. Coordinate updates alternate between expected assignment probabilities and updated variational factors. This is often described as variational EM, but its target is an ELBO that approximates the posterior evidence, not the exact observed-data likelihood used by ordinary finite-mixture EM. Markov chain Monte Carlo supplies a different route by sampling the latent partitions and component parameters instead of optimizing a variational approximation.
A reusable expectation–maximization checklist
The courier problem gave every stage of EM a visible role: recorded times remained fixed, route assignments were latent, the E-step computed route probabilities, and the M-step used them as fractional counts. The same organization applies to another model only after its observed quantities, latent variables, parameters, and fitting objective have been specified. EM cannot decide which latent structure is scientifically meaningful; it optimizes the likelihood or posterior implied by that choice.
- 1Separate observed and latent quantities
Write the fixed observations , latent variables or , and adjustable parameters .
- 2Write both likelihoods
Identify the observed likelihood after marginalizing the latent variables and the complete-data likelihood before marginalization.
- 3Derive the exact conditional expectation
Find and the expected complete-data objective it produces.
- 4Maximize the stated objective
Distinguish an exact M-step, a generalized step that merely raises , and a MAP step that adds a parameter prior.
- 5Track the actual target
Monitor the observed likelihood, posterior objective, or variational bound that the derivation truly guarantees.
- 6Compare stationary points and check the model
Use multiple initializations where appropriate, inspect boundary behavior, and test whether the fitted family describes the observations adequately.
Continue through the connected tutorials
Sources and further reading
- A. P. Dempster, N. M. Laird, and D. B. Rubin (1977), “Maximum Likelihood from Incomplete Data via the EM Algorithm.” The general EM construction, monotone-likelihood argument, and finite-mixture example.
- C. F. Jeff Wu (1983), “On the Convergence Properties of the EM Algorithm.” Conditions connecting EM sequences to stationary points and unique maxima.
- R. A. Redner and H. F. Walker (1984), “Mixture Densities, Maximum Likelihood and the EM Algorithm.” A detailed treatment of mixture likelihoods and EM fitting.
- C. E. Rasmussen and C. K. I. Williams (2006), Gaussian Processes for Machine Learning. GP latent functions, marginal likelihood, kernels, hyperparameter learning, and mixture extensions.
- H.-C. Kim and Z. Ghahramani (2006), “Bayesian Gaussian Process Classification with the EM-EP Algorithm.” An approximate E-step over latent function values for GP hyperparameter learning.
- D. M. Blei and M. I. Jordan (2006), “Variational Inference for Dirichlet Process Mixtures.” Truncated stick-breaking variational inference for DP mixtures.
- R. M. Neal (2000), “Markov Chain Sampling Methods for Dirichlet Process Mixture Models.” Posterior-sampling alternatives for the unbounded latent mixture structure.
