Gaussian Mixture Models and Expectation-Maximization › Formula

Michael BrenndoerferOctober 29, 202615 min read
Machine Learning from ScratchAll chapters
Part 9 of 15Unsupervised Learning
Chapter 66Gaussian Mixture Models and Expectation-Maximization › Formula
Reading section 4 of 10 · Formula · 15 minSection 4 of 10 · 15 min

Section 4 of 10 · 15 min read

Gaussian Mixture Models and Expectation-Maximization › FormulaSection view · Sections in this chapter4 / 10 ↓
Reading tools Definitions, links & notes

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Notes & comments

This section derives the mixture density, introduces the latent-variable formulation, and develops the E- and M-step updates.

Mixture densities and latent assignments

The derivation starts with the smallest object we need: a single Gaussian bump. In one dimension, with mean μ\mu, positive standard deviation σ>0\sigma>0 and variance σ2\sigma^2, its density is

N(x∣μ,σ2)=1σ2πexp⁡ ⁣(−(x−μ)22σ2).\mathcal{N}(x \mid \mu, \sigma^2) = \frac{1}{\sigma\sqrt{2\pi}} \exp\!\left(-\frac{(x-\mu)^2}{2\sigma^2}\right).

The fraction in front is not decoration. It is the exact constant that makes the area under the curve equal one, so the result can be treated as a probability density. The exponent measures how far xx sits from μ\mu in units of standard deviations, then squares that distance; the negative sign turns distance into a penalty, so points near the mean get high density and points far away get low density. A single Gaussian therefore encodes one centre and one spread. That is useful, but it cannot describe data with two separated modes.

A mixture removes that limitation by averaging several Gaussian densities together:

p(x∣θ)=∑k=1Kπk N(x∣μk,σk2),p(x \mid \boldsymbol{\theta}) = \sum_{k=1}^{K} \pi_k \, \mathcal{N}(x \mid \mu_k, \sigma_k^2),

where:

  • θ\boldsymbol{\theta}: the full parameter set collecting all means μk\mu_k, variances σk2\sigma_k^2, and mixing weights πk\pi_k
  • πk\pi_k: the mixing weight of component kk, satisfying πk≥0\pi_k \ge 0 and ∑k=1Kπk=1\sum_{k=1}^K \pi_k = 1, so the weights behave like probabilities
  • μk\mu_k: the mean (centre) of component kk
  • σk2\sigma_k^2: the variance of component kk (one-dimensional case; the multivariate case replaces it with a covariance matrix Σk\boldsymbol{\Sigma}_k below)
  • N(x∣μk,σk2)\mathcal{N}(x \mid \mu_k, \sigma_k^2): the Gaussian density of component kk evaluated at xx

The mixing weights describe prior component membership within the model: before seeing an observation's features, πk\pi_k is its chance of coming from component kk. These are mixture probabilities, not a Bayesian prior on the fitted parameters. The sum says that the overall density at xx is a weighted average of the component densities at xx: each component contributes in proportion to how much prior mass it owns.

This weighted sum is also a generative recipe. To produce a point, first choose a component kk with probability πk\pi_k, then draw the point from that component's Gaussian. The recipe contains a hidden step, and naming that step is what makes inference possible. Let zi∈{1,…,K}z_i \in \{1, \dots, K\} record which component produced observation ii. We never observe ziz_i, which is why it is called a latent variable. Writing the model jointly over the observation and its hidden label gives

p(xi,zi=k∣θ)=πk N(xi∣μk,Σk),p(\mathbf{x}_i, z_i = k \mid \boldsymbol{\theta}) = \pi_k \, \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k),

and the law of total probability recovers the marginal density we use:

p(xi∣θ)=∑k=1Kp(xi,zi=k∣θ).p(\mathbf{x}_i \mid \boldsymbol{\theta}) = \sum_{k=1}^{K} p(\mathbf{x}_i, z_i = k \mid \boldsymbol{\theta}).

That identity is the reason the latent variable earns its place. The marginal likelihood contains a sum over hidden states, and that sum is exactly what blocks a direct closed-form maximum. If we could condition on ziz_i, the sum would disappear; the latent variable lets us separate the difficult marginal problem into a sequence of easier complete-data problems.

Bayes' rule then turns the generative model into an inference procedure. Given the current parameters, the posterior probability that observation ii belongs to component kk is

γik=p(zi=k∣xi,θ)=πk N(xi∣μk,Σk)∑j=1Kπj N(xi∣μj,Σj).\gamma_{ik} = p(z_i = k \mid \mathbf{x}_i, \boldsymbol{\theta}) = \frac{\pi_k \, \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k)}{\sum_{j=1}^{K} \pi_j \, \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_j, \boldsymbol{\Sigma}_j)}.

The denominator is the total density at xi\mathbf{x}_i contributed by all components, and the numerator is the piece of that total contributed by component kk. Their ratio is the share of the density that component kk explains, which is precisely a probability. These γik\gamma_{ik} are the soft assignments. They replace the missing labels with graded beliefs instead of forcing each point into one cluster.

Before generalizing, it is worth seeing why the obvious optimization strategy fails. The log-likelihood of nn independent observations is

ℓ(θ)=∑i=1nlog⁡ ⁣(∑k=1Kπk N(xi∣μk,Σk)).\ell(\boldsymbol{\theta}) = \sum_{i=1}^{n} \log\!\left( \sum_{k=1}^{K} \pi_k \, \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k) \right).

We take logs because the likelihood itself is a product of nn densities, and products of many small numbers underflow quickly on a computer; logs turn products into sums without moving the maximum, since log⁡\log is strictly increasing. The obstacle is the outer logarithm sitting on top of a sum. Differentiating with respect to μk\boldsymbol{\mu}_k and setting the result to zero produces

∑i=1nγik Σk−1(xi−μk)=0,\sum_{i=1}^{n} \gamma_{ik} \, \boldsymbol{\Sigma}_k^{-1} (\mathbf{x}_i - \boldsymbol{\mu}_k) = \mathbf{0},

because the ratio πkN(xi∣μk,Σk)/∑jπjN(xi∣μj,Σj)\pi_k \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k) / \sum_j \pi_j \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_j, \boldsymbol{\Sigma}_j) is precisely γik\gamma_{ik}. Solving for the mean gives

μk=∑i=1nγik xi∑i=1nγik.\boldsymbol{\mu}_k = \frac{\sum_{i=1}^{n} \gamma_{ik}\, \mathbf{x}_i}{\sum_{i=1}^{n} \gamma_{ik}}.

This looks like a closed-form answer, but it is not: the responsibilities γik\gamma_{ik} on the right-hand side are themselves functions of the whole parameter set θ\boldsymbol{\theta}, including μk\boldsymbol{\mu}_k. We have a fixed-point equation, not a formula. EM's insight is to freeze the right-hand side at its current value, recompute the left-hand side, and repeat. The E-step supplies the current beliefs about the hidden labels; the M-step turns those beliefs into new parameters.

Now the multivariate case, which is what we will implement. For an observation x∈Rd\mathbf{x} \in \mathbb{R}^d the component density is

N(x∣μ,Σ)=(2π)−d/2∣Σ∣−1/2exp⁡ ⁣(−12(x−μ)⊤Σ−1(x−μ)),\mathcal{N}(\mathbf{x} \mid \boldsymbol{\mu}, \boldsymbol{\Sigma}) = (2\pi)^{-d/2} \lvert \boldsymbol{\Sigma} \rvert^{-1/2} \exp\!\left(-\tfrac{1}{2} (\mathbf{x} - \boldsymbol{\mu})^{\top} \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu})\right),

where μ\boldsymbol{\mu} is a dd-vector, Σ\boldsymbol{\Sigma} is a d×dd \times d symmetric positive definite covariance matrix, the superscript ⊤\top means transpose (turn the column vector into a row vector so the matrix product is defined), Σ−1\boldsymbol{\Sigma}^{-1} is the matrix inverse, and ∣Σ∣\lvert \boldsymbol{\Sigma} \rvert is the determinant. The quadratic form (x−μ)⊤Σ−1(x−μ)(\mathbf{x}-\boldsymbol{\mu})^{\top}\boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu}) is the squared Mahalanobis distance: it rescales and de-rotates space so that distance is measured in units of the component's own spread. The factor ∣Σ∣−1/2\lvert \boldsymbol{\Sigma} \rvert^{-1/2} does the same job the 1/σ1/\sigma factor did in one dimension: it divides by the volume the Gaussian occupies, so the density integrates to one.

Expectation and maximization steps

EM alternates between two problems, each of which is easy on its own. The first problem is inference: given parameters, what do we believe about the hidden labels? The second is estimation: given beliefs about the labels, what parameters are most likely?

Both problems are phrased in terms of the complete-data log-likelihood, the quantity we would maximize if the labels were observed. With zikz_{ik} a one-hot indicator equal to one when observation ii comes from component kk,

ℓc(θ)=∑i=1n∑k=1Kzik[log⁡πk+log⁡N(xi∣μk,Σk)].\ell_c(\boldsymbol{\theta}) = \sum_{i=1}^{n} \sum_{k=1}^{K} z_{ik} \Big[ \log \pi_k + \log \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k) \Big].

where:

  • ℓc(θ)\ell_c(\boldsymbol{\theta}): the complete-data log-likelihood, the log-likelihood we would maximize if the latent labels were observed
  • zikz_{ik}: a one-hot indicator equal to 11 when observation ii came from component kk, and 00 otherwise
  • πk\pi_k: the mixing weight of component kk
  • N(xi∣μk,Σk)\mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k): the Gaussian density of component kk evaluated at xi\mathbf{x}_i
  • nn: the number of observations, KK: the number of components

Because the indicators select exactly one term per observation, each component's mean and covariance can be fitted from its assigned observations. The mixing weights still share their sum-to-one constraint and are estimated from the component counts. That is the structure the marginal likelihood destroyed.

Since zikz_{ik} is unknown, we replace it with its conditional expectation, which is the responsibility: E[zik∣xi,θ]=γik\mathbb{E}[z_{ik} \mid \mathbf{x}_i, \boldsymbol{\theta}] = \gamma_{ik}. This produces the auxiliary function

Q(θ∣θt)=∑i=1n∑k=1Kγik[log⁡πk+log⁡N(xi∣μk,Σk)],Q(\boldsymbol{\theta} \mid \boldsymbol{\theta}^{t}) = \sum_{i=1}^{n} \sum_{k=1}^{K} \gamma_{ik} \Big[ \log \pi_k + \log \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k) \Big],

where θt\boldsymbol{\theta}^{t} denotes the parameters at iteration tt. The E-step consists of computing the γik\gamma_{ik} from the current parameters using Bayes' rule above. Each γik\gamma_{ik} depends on all components through the denominator. Holding responsibilities fixed separates the mean and covariance estimation by component, while the mixing weights retain their shared normalization.

The M-step maximizes QQ over θ\boldsymbol{\theta}. For the means, only the quadratic term depends on μk\boldsymbol{\mu}_k:

log⁡N(xi∣μk,Σk)=−d2log⁡(2π)−12log⁡∣Σk∣−12(xi−μk)⊤Σk−1(xi−μk).\log \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k) = -\tfrac{d}{2}\log(2\pi) - \tfrac{1}{2}\log\lvert \boldsymbol{\Sigma}_k \rvert - \tfrac{1}{2}(\mathbf{x}_i - \boldsymbol{\mu}_k)^{\top} \boldsymbol{\Sigma}_k^{-1} (\mathbf{x}_i - \boldsymbol{\mu}_k).

Differentiating the quadratic form with respect to the vector μk\boldsymbol{\mu}_k uses the chain rule on the squared Mahalanobis distance,

∂∂μk(xi−μk)⊤Σk−1(xi−μk)=−2 Σk−1(xi−μk),\frac{\partial}{\partial \boldsymbol{\mu}_k} (\mathbf{x}_i - \boldsymbol{\mu}_k)^{\top} \boldsymbol{\Sigma}_k^{-1} (\mathbf{x}_i - \boldsymbol{\mu}_k) = -2\,\boldsymbol{\Sigma}_k^{-1}(\mathbf{x}_i - \boldsymbol{\mu}_k),

where the minus sign appears because μk\boldsymbol{\mu}_k enters with a negative sign inside the parenthesis. Setting ∂Q/∂μk=0\partial Q / \partial \boldsymbol{\mu}_k = \mathbf{0} gives

∑i=1nγik Σk−1(xi−μk)=0.\sum_{i=1}^{n} \gamma_{ik} \, \boldsymbol{\Sigma}_k^{-1} (\mathbf{x}_i - \boldsymbol{\mu}_k) = \mathbf{0}.

Because Σk−1\boldsymbol{\Sigma}_k^{-1} is invertible, we may multiply both sides on the left by Σk\boldsymbol{\Sigma}_k to remove it, leaving ∑iγik(xi−μk)=0\sum_i \gamma_{ik}(\mathbf{x}_i - \boldsymbol{\mu}_k) = \mathbf{0}. Splitting the sum and solving,

μk=1Nk∑i=1nγik xi,Nk=∑i=1nγik.\boldsymbol{\mu}_k = \frac{1}{N_k} \sum_{i=1}^{n} \gamma_{ik} \, \mathbf{x}_i, \qquad N_k = \sum_{i=1}^{n} \gamma_{ik}.

where:

  • Nk=∑i=1nγikN_k = \sum_{i=1}^{n} \gamma_{ik}: the effective number of observations assigned to component kk, formed by summing the responsibilities
  • γik\gamma_{ik}: the responsibility of component kk for observation ii, its posterior probability of membership
  • xi\mathbf{x}_i: the ii-th observation

The mean update requires Nk>0N_k>0. When a component has zero effective count, this weighted-mean formula is undefined. We can stop with an error, reinitialize or remove the component, or retain its parameters as an inactive zero-weight component and skip its update. Our implementation below stops with an error. The effective count need not be an integer, because responsibilities are fractional: a point with γik=0.3\gamma_{ik} = 0.3 contributes 0.3xi0.3\mathbf{x}_i to the weighted feature sum, then division by NkN_k converts that sum to the mean. This is the soft-count idea in its simplest form.

For the covariance, we need two matrix-calculus facts. First, ∂log⁡∣Σ∣/∂Σ=Σ−1\partial \log\lvert \boldsymbol{\Sigma} \rvert / \partial \boldsymbol{\Sigma} = \boldsymbol{\Sigma}^{-1} for a symmetric positive definite matrix, which is the matrix analogue of ∂log⁡σ2/∂σ2=1/σ2\partial \log \sigma^2 / \partial \sigma^2 = 1/\sigma^2. Second, ∂(a⊤Σ−1a)/∂Σ=−Σ−1aa⊤Σ−1\partial (\mathbf{a}^{\top}\boldsymbol{\Sigma}^{-1}\mathbf{a})/\partial \boldsymbol{\Sigma} = -\boldsymbol{\Sigma}^{-1}\mathbf{a}\mathbf{a}^{\top}\boldsymbol{\Sigma}^{-1}, which follows from differentiating the inverse. Applying both,

∂Q∂Σk=∑i=1nγik[−12Σk−1+12Σk−1(xi−μk)(xi−μk)⊤Σk−1]=0.\frac{\partial Q}{\partial \boldsymbol{\Sigma}_k} = \sum_{i=1}^{n} \gamma_{ik} \left[ -\tfrac{1}{2}\boldsymbol{\Sigma}_k^{-1} + \tfrac{1}{2}\boldsymbol{\Sigma}_k^{-1}(\mathbf{x}_i - \boldsymbol{\mu}_k)(\mathbf{x}_i - \boldsymbol{\mu}_k)^{\top}\boldsymbol{\Sigma}_k^{-1} \right] = \mathbf{0}.

Multiply on the left and right by Σk\boldsymbol{\Sigma}_k (which is legal since it is invertible) and use Nk=∑iγikN_k = \sum_i \gamma_{ik}:

−NkΣk+∑i=1nγik(xi−μk)(xi−μk)⊤=0⟹Σk=1Nk∑i=1nγik(xi−μk)(xi−μk)⊤.-N_k \boldsymbol{\Sigma}_k + \sum_{i=1}^{n} \gamma_{ik}(\mathbf{x}_i - \boldsymbol{\mu}_k)(\mathbf{x}_i - \boldsymbol{\mu}_k)^{\top} = \mathbf{0} \quad\Longrightarrow\quad \boldsymbol{\Sigma}_k = \frac{1}{N_k} \sum_{i=1}^{n} \gamma_{ik}(\mathbf{x}_i - \boldsymbol{\mu}_k)(\mathbf{x}_i - \boldsymbol{\mu}_k)^{\top}.

where:

  • Σk\boldsymbol{\Sigma}_k: the d×dd \times d covariance matrix of component kk
  • γik\gamma_{ik}: the responsibility of component kk for observation ii
  • xi−μk\mathbf{x}_i - \boldsymbol{\mu}_k: the centered observation, its deviation from component kk's mean
  • NkN_k: the effective count for component kk

For this to be a valid nondegenerate Gaussian covariance we need Nk>0N_k>0 and a positive-definite scatter. This is the weighted scatter matrix of component kk, with each observation's outer product (xi−μk)(xi−μk)⊤(\mathbf{x}_i - \boldsymbol{\mu}_k)(\mathbf{x}_i - \boldsymbol{\mu}_k)^{\top} counted γik\gamma_{ik} times. It is the same estimator we would use with known labels, except that the counts are fractional.

The mixing weights carry a constraint, ∑kπk=1\sum_k \pi_k = 1, so we cannot differentiate and set to zero naively; we add the constraint times a Lagrange multiplier λ\lambda and differentiate the augmented expression:

L=∑i=1n∑k=1Kγiklog⁡πk+λ(∑k=1Kπk−1),∂L∂πk=Nkπk+λ=0.\mathcal{L} = \sum_{i=1}^{n}\sum_{k=1}^{K} \gamma_{ik} \log \pi_k + \lambda\left(\sum_{k=1}^{K}\pi_k - 1\right), \qquad \frac{\partial \mathcal{L}}{\partial \pi_k} = \frac{N_k}{\pi_k} + \lambda = 0.

The first term's derivative is Nk/πkN_k/\pi_k because ∂log⁡πk/∂πk=1/πk\partial \log \pi_k/\partial \pi_k = 1/\pi_k, and the Lagrange multiplier λ\lambda is a constant; note that although γik\gamma_{ik} itself depends on πk\pi_k through the Bayes formula, in Q(θ∣θt)Q(\boldsymbol{\theta} \mid \boldsymbol{\theta}^t) the responsibilities are held fixed at their current E-step values, so within this maximization they act as constants on the πk\pi_k derivative. Rearranging gives πk=Nk/(−λ)\pi_k = N_k / (-\lambda). Summing both sides over kk and using ∑kπk=1\sum_k \pi_k = 1 and ∑kNk=∑i∑kγik=n\sum_k N_k = \sum_i \sum_k \gamma_{ik} = n (each observation's responsibilities sum to one),

1=∑k=1Kπk=∑k=1KNk−λ=n−λ⟹−λ=n⟹πk=Nkn.1 = \sum_{k=1}^{K}\pi_k = \frac{\sum_{k=1}^{K} N_k}{-\lambda} = \frac{n}{-\lambda} \quad\Longrightarrow\quad -\lambda = n \quad\Longrightarrow\quad \pi_k = \frac{N_k}{n}.

where:

  • πk\pi_k: the mixing weight of component kk
  • NkN_k: the effective count for component kk
  • nn: the number of observations
  • λ\lambda: the Lagrange multiplier enforcing the constraint ∑kπk=1\sum_k \pi_k = 1

So each mixing weight is just the share of the effective count that component kk holds.

Collecting everything, one full EM iteration is:

γik=πkN(xi∣μk,Σk)∑jπjN(xi∣μj,Σj)(E-step)\gamma_{ik} = \frac{\pi_k \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k)}{\sum_j \pi_j \mathcal{N}(\mathbf{x}_i \mid \boldsymbol{\mu}_j, \boldsymbol{\Sigma}_j)} \qquad\text{(E-step)} Nk=∑iγik,μk=1Nk∑iγikxi,Σk=1Nk∑iγik(xi−μk)(xi−μk)⊤,πk=Nkn(M-step)N_k = \sum_i \gamma_{ik}, \qquad \boldsymbol{\mu}_k = \frac{1}{N_k}\sum_i \gamma_{ik}\mathbf{x}_i, \qquad \boldsymbol{\Sigma}_k = \frac{1}{N_k}\sum_i \gamma_{ik}(\mathbf{x}_i - \boldsymbol{\mu}_k)(\mathbf{x}_i - \boldsymbol{\mu}_k)^{\top}, \qquad \pi_k = \frac{N_k}{n} \qquad\text{(M-step)}

The matrix form of the M-step makes the computation obvious. Gather the responsibilities into an n×Kn \times K matrix R\mathbf{R} whose entry (i,k)(i,k) is γik\gamma_{ik}, and the data into an n×dn \times d matrix X\mathbf{X} whose rows are the observations. Let 1n\mathbf{1}_n be a column vector of ones and n=R⊤1n\mathbf{n} = \mathbf{R}^{\top}\mathbf{1}_n the column vector of effective counts. Then

M=diag⁡(n)−1R⊤X,Σk=1nk(X−1nμk⊤)⊤diag⁡(rk)(X−1nμk⊤),\mathbf{M} = \operatorname{diag}(\mathbf{n})^{-1} \mathbf{R}^{\top}\mathbf{X}, \qquad \boldsymbol{\Sigma}_k = \frac{1}{n_k} (\mathbf{X} - \mathbf{1}_n \boldsymbol{\mu}_k^{\top})^{\top} \operatorname{diag}(\mathbf{r}_k) (\mathbf{X} - \mathbf{1}_n \boldsymbol{\mu}_k^{\top}),

where:

  • R\mathbf{R}: the n×Kn \times K responsibility matrix with entry (i,k)=γik(i,k) = \gamma_{ik}
  • X\mathbf{X}: the n×dn \times d data matrix whose rows are the observations
  • 1n\mathbf{1}_n: a column vector of ones of length nn
  • n=R⊤1n\mathbf{n} = \mathbf{R}^{\top}\mathbf{1}_n: the column vector of effective counts whose kk-th entry is NkN_k
  • nkn_k: the kk-th entry of n\mathbf{n} (same as NkN_k), the effective count of component kk
  • rk\mathbf{r}_k: the kk-th column of R\mathbf{R} (the responsibilities for component kk)
  • M\mathbf{M}: the K×dK \times d matrix whose kk-th row is μk⊤\boldsymbol{\mu}_k^{\top}
  • μk\boldsymbol{\mu}_k: the mean of component kk
  • diag⁡(⋅)\operatorname{diag}(\cdot): turns a vector into a diagonal matrix

Multiplying R⊤\mathbf{R}^{\top} by X\mathbf{X} sums the rows of X\mathbf{X} weighted by the responsibilities (each column accumulates a weighted sum), and dividing by n\mathbf{n} turns those weighted sums into weighted averages, giving the K×dK \times d matrix M\mathbf{M} whose kk-th row is μk⊤\boldsymbol{\mu}_k^{\top}. The covariance expression is the same operation applied to the centered data: subtracting 1nμk⊤\mathbf{1}_n\boldsymbol{\mu}_k^{\top} centers every row, the diagonal matrix reweights the rows, and the product A⊤WA\mathbf{A}^{\top}\mathbf{W}\mathbf{A} accumulates the weighted outer products. In code this is a handful of matrix multiplications rather than nn nested loops, which matters because the E-step is repeated until convergence.

The reason EM works at all is that it is coordinate ascent on a lower bound. For a probability distribution q(z)q(z) that is positive on the joint model's positive support, multiplying and dividing inside the log by q(z)q(z) and applying Jensen's inequality (which says that for a concave function like log⁡\log, the average of the function is at most the function of the average) gives

log⁡p(x∣θ)=log⁡∑zq(z)p(x,z∣θ)q(z)  ≥  ∑zq(z)log⁡p(x,z∣θ)q(z).\log p(\mathbf{x}\mid\boldsymbol{\theta}) = \log \sum_{z} q(z)\frac{p(\mathbf{x}, z \mid \boldsymbol{\theta})}{q(z)} \;\ge\; \sum_{z} q(z) \log \frac{p(\mathbf{x}, z \mid \boldsymbol{\theta})}{q(z)}.

The gap between the two sides is the Kullback-Leibler divergence from qq to the posterior p(z∣x,θ)p(z \mid \mathbf{x}, \boldsymbol{\theta}), which is non-negative and equals zero exactly when qq is the posterior. The E-step sets qq to that posterior, closing the gap so the bound touches the log-likelihood at the current parameters. The M-step then pushes the bound up by maximizing it over θ\boldsymbol{\theta}. Since the log-likelihood is at least the bound, and the bound has increased, the log-likelihood cannot decrease. This proves likelihood nondecrease for the exact bound-increasing updates. It does not prove parameter convergence, a finite maximum, or a global optimum, and it does not apply automatically after an arbitrary covariance modification.

Mathematical Properties

A few properties follow directly from the derivation and shape how the method is used.

  • Monotone under exact updates. With valid parameters and an exact E-step followed by a bound-increasing M-step, ℓ(θt+1)≥ℓ(θt)\ell(\boldsymbol{\theta}^{t+1}) \ge \ell(\boldsymbol{\theta}^{t}). The likelihood is non-concave; finite interior limits under suitable regularity are stationary, and they need not be global maxima. Singular boundary behaviour remains possible.
  • Unbounded above for unrestricted mixtures with K≥2K\ge2. A component can collapse onto one observation while another covers the remaining points, driving the sample likelihood to +∞+\infty. A single Gaussian whose empirical centered covariance is positive definite does have a finite maximum-likelihood fit; the collapse claim is not a statement about every Gaussian model.
  • Label switching. Any permutation of the component indices leaves the likelihood unchanged, so its component labels are arbitrary. Comparing parameter estimates across runs requires matching components first.
  • Affine transformation of full-covariance models. For x′=Ax+b\mathbf{x}'=A\mathbf{x}+\mathbf{b} with invertible AA, transform each mean to Aμk+bA\boldsymbol{\mu}_k+\mathbf{b} and covariance to AΣkA⊤A\boldsymbol{\Sigma}_k A^{\top}. The density divides by ∣det⁡A∣|\det A|, so responsibilities remain unchanged and total log-likelihood shifts by −nlog⁡∣det⁡A∣-n\log|\det A|. This relates corresponding unrestricted fits, not arbitrary numerical runs with fixed regularization. Diagonal models are closed under axis scaling but not general rotations; spherical models permit common uniform scaling and rotations, not arbitrary axis scaling.
  • Asymptotic relation to k-means. For fixed observations and centroids, suppose all components have equal fixed weights and common spherical covariance σ2I\sigma^2 \mathbf{I}. As the externally specified common variance tends to zero, responsibilities at observations with a unique nearest centroid approach nearest-centroid indicators. This varies a prescribed variance across models rather than estimating it in the M-step. For each component with a positive limiting hard-assignment count, its mean update approaches the k-means update. Empty limiting clusters require a separate handling rule. This is the small-variance connection between the mixture and k-means.
  • Parameter counts. A full-covariance mixture has K(d+d(d+1)/2)+(K−1)K\big(d + d(d+1)/2\big) + (K-1) free parameters: KdKd means, KK covariance matrices with d(d+1)/2d(d+1)/2 distinct entries each, and K−1K-1 free mixing weights. Diagonal covariances cost 2Kd+(K−1)2Kd + (K-1), spherical ones cost K(d+1)+(K−1)K(d+1) + (K-1), and a tied covariance uses Kd+d(d+1)/2+(K−1)Kd+d(d+1)/2+(K-1) parameters by sharing one covariance across components.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy