Skip to content
Ahmed Haroon
Machine Learning

Expectation Maximization and Mixture Models

Expectation Maximization

Suppose our model contains an observed variable xx and a latent variable zz that we do not observe directly. The joint distribution is:

p(x,z;θ) p(x,z;\theta)

To find the probability of the observed data xx, we sum over all possible values of zz:

p(x;θ)=zp(x,z;θ) p(x;\theta) = \sum_z p(x,z;\theta)

For a continuous latent variable, the sum is replaced by an integral:

p(x;θ)=p(x,z;θ)dz p(x;\theta) = \int p(x,z;\theta)\,dz

We use sums below for notational simplicity.

For a dataset of nn observations, the log-likelihood is:

(θ)=i=1nlogp(x(i);θ) \ell(\theta) = \sum_{i=1}^n \log p(x^{(i)};\theta) =i=1nlogz(i)p(x(i),z(i);θ) = \sum_{i=1}^n \log \sum_{z^{(i)}} p(x^{(i)},z^{(i)};\theta)

The difficulty is the sum over the latent variable inside the logarithm:

logzp(x,z;θ) \log \sum_z p(x,z;\theta)

This often makes the likelihood difficult to optimize directly. EM handles this by constructing a lower bound on the log-likelihood and optimizing that bound instead.

The Evidence Lower Bound

To construct this lower bound, introduce a distribution Q(z)Q(z) over the latent variable, where:

zQ(z)=1 \sum_z Q(z)=1

and Q(z)0Q(z)\geq0.

We assume Q(z)>0Q(z)>0 wherever p(x,z;θ)>0p(x,z;\theta)>0, so the ratio below is well defined.

Jensen's Inequality

Jensen's inequality states that for a convex function ff:

E[f(X)]f(E[X]) \mathbb{E}[f(X)] \geq f(\mathbb{E}[X])

For a concave function, the inequality is reversed:

E[f(X)]f(E[X]) \mathbb{E}[f(X)] \leq f(\mathbb{E}[X])

Also, if XX is constant, then:

X=E[X] X=\mathbb{E}[X]

and therefore:

E[f(X)]=f(E[X]) \mathbb{E}[f(X)] = f(\mathbb{E}[X])

Using Jensen's inequality:

logp(x;θ)=logzQ(z)p(x,z;θ)Q(z) \log p(x;\theta) = \log \sum_z Q(z) \frac{p(x,z;\theta)}{Q(z)} zQ(z)logp(x,z;θ)Q(z) \geq \sum_z Q(z) \log \frac{p(x,z;\theta)}{Q(z)}

The expression on the right is called the Evidence Lower Bound, or ELBO.

See derivation
logp(x;θ)=logzp(x,z;θ) \log p(x;\theta) = \log \sum_z p(x,z;\theta) =logzQ(z)p(x,z;θ)Q(z) = \log \sum_z Q(z) \frac{p(x,z;\theta)}{Q(z)}
=logEzQ[p(x,z;θ)Q(z)] = \log \mathbb{E}_{z\sim Q} \left[ \frac{p(x,z;\theta)}{Q(z)} \right]
EzQ[logp(x,z;θ)Q(z)] \geq \mathbb{E}_{z\sim Q} \left[ \log \frac{p(x,z;\theta)}{Q(z)} \right]
=zQ(z)logp(x,z;θ)Q(z) = \sum_z Q(z) \log \frac{p(x,z;\theta)}{Q(z)}

The bound becomes tight when the quantity inside the expectation is constant with respect to zz:

p(x,z;θ)Q(z)=c \frac{p(x,z;\theta)}{Q(z)} = c

Solving this condition for QQ gives:

Q(z)=p(zx;θ) Q(z) = p(z\mid x;\theta)
See derivation

Starting from:

p(x,z;θ)Q(z)=c \frac{p(x,z;\theta)}{Q(z)} = c

we get:

Q(z)=p(x,z;θ)c Q(z) = \frac{p(x,z;\theta)}{c}

Since:

zQ(z)=1 \sum_z Q(z)=1

the right-hand side must also sum to 11:

zp(x,z;θ)c=1 \sum_z \frac{p(x,z;\theta)}{c} = 1

Therefore:

c=zp(x,z;θ) c = \sum_z p(x,z;\theta) =p(x;θ) = p(x;\theta)

So:

Q(z)=p(x,z;θ)p(x;θ) Q(z) = \frac{p(x,z;\theta)} {p(x;\theta)} =p(zx;θ) = p(z\mid x;\theta)

We can verify that this makes the bound tight:

zQ(z)logp(x,z;θ)Q(z) \sum_z Q(z) \log \frac{p(x,z;\theta)}{Q(z)} =zp(zx;θ)logp(x,z;θ)p(zx;θ) = \sum_z p(z\mid x;\theta) \log \frac{ p(x,z;\theta) }{ p(z\mid x;\theta) } =zp(zx;θ)logp(zx;θ)p(x;θ)p(zx;θ) = \sum_z p(z\mid x;\theta) \log \frac{ p(z\mid x;\theta)p(x;\theta) }{ p(z\mid x;\theta) } =zp(zx;θ)logp(x;θ) = \sum_z p(z\mid x;\theta) \log p(x;\theta) =logp(x;θ)zp(zx;θ) = \log p(x;\theta) \sum_z p(z\mid x;\theta)
=logp(x;θ) = \log p(x;\theta)

Formally, we define:

ELBO(x;Q,θ)=EzQ[logp(x,z;θ)Q(z)] \text{ELBO}(x;Q,\theta) = \mathbb{E}_{z\sim Q} \left[ \log \frac{p(x,z;\theta)}{Q(z)} \right] =zQ(z)logp(x,z;θ)Q(z) = \sum_z Q(z) \log \frac{p(x,z;\theta)}{Q(z)}

Therefore:

logp(x;θ)ELBO(x;Q,θ) \log p(x;\theta) \geq \text{ELBO}(x;Q,\theta)

This gives the two steps of EM.

In the E-step, we choose QQ to make the bound tight at the current parameters. In the M-step, we keep QQ fixed and choose new parameters that maximize the bound.

Repeat until a stopping criterion is met { \text{Repeat until a stopping criterion is met \{} (E-step) For each i, set { \quad \text{(E-step) For each } i, \text{ set \{} Qi(t)(z(i))p(z(i)x(i);θ(t)) \quad\quad Q_i^{(t)}(z^{(i)}) \leftarrow p(z^{(i)}\mid x^{(i)};\theta^{(t)}) } \quad \text{\}} (M-step) Set { \quad \text{(M-step) Set \{} θ(t+1)argmaxθi=1nELBO(x(i);Qi(t),θ) \quad\quad \theta^{(t+1)} \leftarrow \arg\max_\theta \sum_{i=1}^n \text{ELBO} \left( x^{(i)}; Q_i^{(t)}, \theta \right) } \quad \text{\}} } \text{\}}

In the E-step, we compute the posterior distribution of the latent variable for each training example using the current parameters:

p(z(i)=jx(i);θ(t))=p(x(i)z(i)=j;θ(t))p(z(i)=j;θ(t))l=1kp(x(i)z(i)=l;θ(t))p(z(i)=l;θ(t)) p(z^{(i)}=j\mid x^{(i)};\theta^{(t)}) = \frac{ p(x^{(i)}\mid z^{(i)}=j;\theta^{(t)}) p(z^{(i)}=j;\theta^{(t)}) }{ \sum_{l=1}^k p(x^{(i)}\mid z^{(i)}=l;\theta^{(t)}) p(z^{(i)}=l;\theta^{(t)}) }

The E-step choice makes the bound tight at θ(t)\theta^{(t)}.

In the M-step, we hold Q(t)Q^{(t)} fixed and choose θ(t+1)\theta^{(t+1)} to maximize that bound. The bound does not need to remain tight at the new parameter value.

This is exact EM when the E-step computes the exact posterior and the M-step globally maximizes the fixed-Q(t)Q^{(t)} objective.

Generalized EM may instead use any M-step that increases that objective. With an exact E-step, either version makes the observed-data log-likelihood nondecreasing, although neither guarantees a global optimum.

Monotonicity and Convergence

Each exact EM iteration guarantees that the observed-data log-likelihood does not decrease:

(θ(t+1))(θ(t)) \ell(\theta^{(t+1)}) \geq \ell(\theta^{(t)})

This does not mean that EM finds the global maximum. It may converge to a local optimum or another stationary point.

For any parameter value θ\theta and any distribution over the latent variables, the dataset log-likelihood:

(θ)=ilogp(x(i);θ) \ell(\theta) = \sum_i \log p(x^{(i)};\theta)

is at least the sum of the per-example ELBOs.

The ELBO is tangent to the log-likelihood at theta-t; maximizing it reaches theta-(t+1), where the log-likelihood is higher still

For fixed QtQ^{t}, the ELBO\text{ELBO} touches \ell at θt\theta^{t} (A); the MM-step maximizes the bound over θ\theta to obtain θt+1\theta^{t+1} (B), and since ELBO\ell \geq \text{ELBO}, (θt+1)\ell(\theta^{t+1}) (C) is at least as high.

First:

(θ(t+1))i=1nELBO(x(i);Qi(t),θ(t+1)) \ell(\theta^{(t+1)}) \geq \sum_{i=1}^n \text{ELBO} \left( x^{(i)}; Q_i^{(t)}, \theta^{(t+1)} \right)

In the M-step, θ(t+1)\theta^{(t+1)} is chosen to maximize the fixed-Q(t)Q^{(t)} ELBO.

Therefore:

i=1nELBO(x(i);Qi(t),θ(t+1)) \sum_{i=1}^n \text{ELBO} \left( x^{(i)}; Q_i^{(t)}, \theta^{(t+1)} \right) i=1nELBO(x(i);Qi(t),θ(t)) \geq \sum_{i=1}^n \text{ELBO} \left( x^{(i)}; Q_i^{(t)}, \theta^{(t)} \right)

Finally, the E-step chooses QQ so that the bound is tight at the current parameter value:

i=1nELBO(x(i);Qi(t),θ(t))=(θ(t)) \sum_{i=1}^n \text{ELBO} \left( x^{(i)}; Q_i^{(t)}, \theta^{(t)} \right) = \ell(\theta^{(t)})

Putting these together:

(θ(t+1))(θ(t)) \ell(\theta^{(t+1)}) \geq \ell(\theta^{(t)})

Tightness at θ(t)\theta^{(t)} is what turns an increase in the fixed-Q(t)Q^{(t)} bound into a guaranteed non-decrease in the observed-data likelihood.

Additional assumptions are needed for stronger convergence claims.

Successive tangent lower bounds climbing the log-likelihood toward a local maximum, with shrinking steps

In this illustrative run, each fresh bound touches \ell at the current θk\theta^k and is maximized to obtain the next iterate. The likelihood climbs toward a local maximum, although EM's general guarantee is only non-decrease.

For an unconstrained Gaussian mixture model, the likelihood is not even bounded above: one component can collapse its covariance around a data point.

In practice, covariance constraints, regularization, or priors are used to prevent this degeneracy.

Other Interpretations

The evidence lower bound can also be written as:

ELBO(x;Q,θ)=EzQ[logp(x,z;θ)]+H(Q) \text{ELBO}(x;Q,\theta) = \mathbb{E}_{z\sim Q} \left[ \log p(x,z;\theta) \right] + H(Q)

where:

H(Q)=EzQ[logQ(z)] H(Q) = - \mathbb{E}_{z\sim Q} [\log Q(z)]

Factoring the joint distribution gives:

ELBO(x;Q,θ)=EzQ[logp(xz;θ)]DKL(Qp(z;θ)) \text{ELBO}(x;Q,\theta) = \mathbb{E}_{z\sim Q} \left[ \log p(x\mid z;\theta) \right] - D_{KL} \left( Q\parallel p(z;\theta) \right)

If the prior p(z;θ)p(z;\theta) is fixed and has no parameters in θ\theta, then the KL term is constant with respect to θ\theta during the M-step.

This is not true in general. For example, the GMM mixing weights parameterize the prior over component assignments.

See derivation

For two distributions over a random variable zz:

DKL(Qp)=zQ(z)logQ(z)p(z) D_{KL}(Q\parallel p) = \sum_z Q(z) \log \frac{Q(z)}{p(z)} =EzQ[logQ(z)p(z)] = \mathbb{E}_{z\sim Q} \left[ \log \frac{Q(z)}{p(z)} \right]
ELBO(x;Q,θ)=EzQ[logp(x,z;θ)Q(z)] \text{ELBO}(x;Q,\theta) = \mathbb{E}_{z\sim Q} \left[ \log \frac{p(x,z;\theta)}{Q(z)} \right] =EzQ[logp(xz;θ)p(z;θ)Q(z)] = \mathbb{E}_{z\sim Q} \left[ \log \frac{ p(x\mid z;\theta)p(z;\theta) }{ Q(z) } \right] =EzQ[logp(xz;θ)+logp(z;θ)logQ(z)] = \mathbb{E}_{z\sim Q} \left[ \log p(x\mid z;\theta) + \log p(z;\theta) - \log Q(z) \right] =EzQ[logp(xz;θ)logQ(z)p(z;θ)] = \mathbb{E}_{z\sim Q} \left[ \log p(x\mid z;\theta) - \log \frac{Q(z)}{p(z;\theta)} \right] =EzQ[logp(xz;θ)]EzQ[logQ(z)p(z;θ)] = \mathbb{E}_{z\sim Q} \left[ \log p(x\mid z;\theta) \right] - \mathbb{E}_{z\sim Q} \left[ \log \frac{Q(z)}{p(z;\theta)} \right] =EzQ[logp(xz;θ)]DKL(Qp(z;θ)) = \mathbb{E}_{z\sim Q} \left[ \log p(x\mid z;\theta) \right] - D_{KL} \left( Q\parallel p(z;\theta) \right)

A second useful form relates the ELBO directly to the log-likelihood:

ELBO(x;Q,θ)=logp(x;θ)DKL(Qp(zx;θ)) \text{ELBO}(x;Q,\theta) = \log p(x;\theta) - D_{KL} \left( Q \parallel p(z\mid x;\theta) \right)

This shows that for a fixed value of θ\theta, the ELBO is maximized when:

Q(z)=p(zx;θ) Q(z) = p(z\mid x;\theta)

because this makes the KL divergence equal to 00.

This is exactly the choice made in the E-step.

Log-likelihood split into the ELBO plus the KL gap; setting Q to the posterior closes the gap so the bound is tight

At a fixed θ\theta, logp(x;θ)\log p(x;\theta) splits into the ELBO\text{ELBO} and the gap DKL(Qp(zx;θ))D_{KL}(Q\parallel p(z\mid x;\theta)). The E-step sets Q=p(zx;θ)Q=p(z\mid x;\theta), closing the gap.

See derivation
ELBO(x;Q,θ)=EzQ[logp(x,z;θ)Q(z)] \text{ELBO}(x;Q,\theta) = \mathbb{E}_{z\sim Q} \left[ \log \frac{p(x,z;\theta)}{Q(z)} \right] =EzQ[logp(zx;θ)p(x;θ)Q(z)] = \mathbb{E}_{z\sim Q} \left[ \log \frac{ p(z\mid x;\theta)p(x;\theta) }{ Q(z) } \right] =EzQ[logp(zx;θ)+logp(x;θ)logQ(z)] = \mathbb{E}_{z\sim Q} \left[ \log p(z\mid x;\theta) + \log p(x;\theta) - \log Q(z) \right] =EzQ[logp(x;θ)logQ(z)p(zx;θ)] = \mathbb{E}_{z\sim Q} \left[ \log p(x;\theta) - \log \frac{Q(z)}{p(z\mid x;\theta)} \right] =EzQ[logp(x;θ)]EzQ[logQ(z)p(zx;θ)] = \mathbb{E}_{z\sim Q} \left[ \log p(x;\theta) \right] - \mathbb{E}_{z\sim Q} \left[ \log \frac{Q(z)}{p(z\mid x;\theta)} \right] =logp(x;θ)DKL(Qp(zx;θ)) = \log p(x;\theta) - D_{KL} \left( Q\parallel p(z\mid x;\theta) \right)

Gaussian Mixture Models

A Gaussian Mixture Model assumes that each observation comes from one of kk Gaussian components.

For each example x(i)x^{(i)}, there is a latent variable:

z(i){1,,k} z^{(i)} \in \{1,\ldots,k\}

indicating which Gaussian generated it.

First, a component is chosen according to:

p(z(i)=j)=ϕj p(z^{(i)}=j) = \phi_j

where:

ϕj>0,j=1kϕj=1 \phi_j>0, \qquad \sum_{j=1}^k \phi_j = 1

Then the observation is drawn from that component:

x(i)z(i)=jN(μj,Σj) x^{(i)} \mid z^{(i)}=j \sim \mathcal N(\mu_j,\Sigma_j)

where:

μjRd \mu_j\in\mathbb R^d

and:

ΣjRd×d \Sigma_j \in \mathbb R^{d\times d}

is a symmetric positive-definite covariance matrix.

Two panels over the same data: on the left only the unlabeled points are observed; on the right each point is colored by the latent z that chose one of two Gaussians, each drawn as covariance ellipses

All we observe is the unlabeled cloud x(i)x^{(i)} (left). The model explains it with a hidden z(i)z^{(i)} that chooses one of the Gaussians, which then generates the observation (right). If we knew the z(i)z^{(i)}'s, fitting each Gaussian would be straightforward.

The component labels themselves are arbitrary: permuting all component labels gives the same mixture distribution.

In practice, covariance regularization is also commonly used to prevent a component from collapsing around a single training example.

The log-likelihood is:

(ϕ,μ,Σ)=i=1nlogp(x(i);ϕ,μ,Σ) \ell(\phi,\mu,\Sigma) = \sum_{i=1}^n \log p(x^{(i)};\phi,\mu,\Sigma) =i=1nlogz(i)=1kp(x(i)z(i);μ,Σ)p(z(i);ϕ) = \sum_{i=1}^n \log \sum_{z^{(i)}=1}^k p(x^{(i)}\mid z^{(i)};\mu,\Sigma) p(z^{(i)};\phi)

The difficulty is that we do not know which component generated each observation.

If the z(i)z^{(i)}'s were known, we could simply group the observations by component and estimate each Gaussian directly, similar to Gaussian Discriminant Analysis.

EM handles the missing assignments by alternating between estimating them and updating the Gaussian parameters.

Responsibilities in the E-Step

In the E-step, instead of assigning each point to exactly one component, EM gives every component a probability of having generated that point.

This probability is called a responsibility:

wj(i)=p(z(i)=jx(i);ϕ,μ,Σ) w_j^{(i)} = p \left( z^{(i)}=j \mid x^{(i)}; \phi,\mu,\Sigma \right)

Using Bayes' rule:

wj(i)=p(x(i)z(i)=j;μ,Σ)p(z(i)=j;ϕ)l=1kp(x(i)z(i)=l;μ,Σ)p(z(i)=l;ϕ) w_j^{(i)} = \frac{ p(x^{(i)}\mid z^{(i)}=j;\mu,\Sigma) p(z^{(i)}=j;\phi) }{ \sum_{l=1}^k p(x^{(i)}\mid z^{(i)}=l;\mu,\Sigma) p(z^{(i)}=l;\phi) }

The responsibilities for one example sum to 11:

j=1kwj(i)=1 \sum_{j=1}^k w_j^{(i)} = 1

After substituting the Gaussian densities, the responsibilities can also be written in a softmax-like form.

Top: two weighted Gaussian components and the mixture density they sum to. Bottom: the two posterior responsibilities as smooth curves crossing at one half, with sampled points sitting on them

The mixture p(x)p(x) is the sum of the weighted components ϕjp(xz=j)\phi_j p(x\mid z=j) (top). The E-step assigns each point softly: the responsibilities wj(i)=p(z=jx(i))w_j^{(i)}=p(z=j\mid x^{(i)}) move between 00 and 11 and sum to one (bottom).

See derivation
p(z(i)=jx(i);ϕ,μ,Σ) p(z^{(i)}=j\mid x^{(i)};\phi,\mu,\Sigma) =p(x(i)z(i)=j;μ,Σ)p(z(i)=j;ϕ)l=1kp(x(i)z(i)=l;μ,Σ)p(z(i)=l;ϕ) = \frac{ p(x^{(i)}\mid z^{(i)}=j;\mu,\Sigma) p(z^{(i)}=j;\phi) }{ \sum_{l=1}^k p(x^{(i)}\mid z^{(i)}=l;\mu,\Sigma) p(z^{(i)}=l;\phi) }

Substituting the Gaussian densities:

=1(2π)d/2Σj1/2exp(12(x(i)μj)TΣj1(x(i)μj))ϕjl=1k[1(2π)d/2Σl1/2exp(12(x(i)μl)TΣl1(x(i)μl))ϕl] = \frac{ \frac{1}{(2\pi)^{d/2}|\Sigma_j|^{1/2}} \exp \left( -\frac12 (x^{(i)}-\mu_j)^T \Sigma_j^{-1} (x^{(i)}-\mu_j) \right) \phi_j }{ \sum_{l=1}^k \left[ \frac{1}{(2\pi)^{d/2}|\Sigma_l|^{1/2}} \exp \left( -\frac12 (x^{(i)}-\mu_l)^T \Sigma_l^{-1} (x^{(i)}-\mu_l) \right) \phi_l \right] }
=Σj1/2exp(12(x(i)μj)TΣj1(x(i)μj))ϕjl=1k[Σl1/2exp(12(x(i)μl)TΣl1(x(i)μl))ϕl] = \frac{ |\Sigma_j|^{-1/2} \exp \left( -\frac12 (x^{(i)}-\mu_j)^T \Sigma_j^{-1} (x^{(i)}-\mu_j) \right) \phi_j }{ \sum_{l=1}^k \left[ |\Sigma_l|^{-1/2} \exp \left( -\frac12 (x^{(i)}-\mu_l)^T \Sigma_l^{-1} (x^{(i)}-\mu_l) \right) \phi_l \right] }

Define the score:

αj(x(i))=logϕj12logΣj12(x(i)μj)TΣj1(x(i)μj) \alpha_j(x^{(i)}) = \log\phi_j - \frac12 \log|\Sigma_j| - \frac12 (x^{(i)}-\mu_j)^T \Sigma_j^{-1} (x^{(i)}-\mu_j)

Then:

p(z(i)=jx(i);ϕ,μ,Σ)=exp(αj(x(i)))l=1kexp(αl(x(i))) p(z^{(i)}=j\mid x^{(i)};\phi,\mu,\Sigma) = \frac{ \exp(\alpha_j(x^{(i)})) }{ \sum_{l=1}^k \exp(\alpha_l(x^{(i)})) }

To verify this:

exp(αj(x(i)))l=1kexp(αl(x(i))) \frac{ \exp(\alpha_j(x^{(i)})) }{ \sum_{l=1}^k \exp(\alpha_l(x^{(i)})) } =exp(logϕj12logΣj12(x(i)μj)TΣj1(x(i)μj))l=1kexp(logϕl12logΣl12(x(i)μl)TΣl1(x(i)μl)) = \frac{ \exp \left( \log\phi_j - \frac12\log|\Sigma_j| - \frac12 (x^{(i)}-\mu_j)^T \Sigma_j^{-1} (x^{(i)}-\mu_j) \right) }{ \sum_{l=1}^k \exp \left( \log\phi_l - \frac12\log|\Sigma_l| - \frac12 (x^{(i)}-\mu_l)^T \Sigma_l^{-1} (x^{(i)}-\mu_l) \right) } =ϕjexp(12logΣj12(x(i)μj)TΣj1(x(i)μj))l=1kϕlexp(12logΣl12(x(i)μl)TΣl1(x(i)μl)) = \frac{ \phi_j \exp \left( -\frac12\log|\Sigma_j| - \frac12 (x^{(i)}-\mu_j)^T \Sigma_j^{-1} (x^{(i)}-\mu_j) \right) }{ \sum_{l=1}^k \phi_l \exp \left( -\frac12\log|\Sigma_l| - \frac12 (x^{(i)}-\mu_l)^T \Sigma_l^{-1} (x^{(i)}-\mu_l) \right) }
=Σj1/2exp(12(x(i)μj)TΣj1(x(i)μj))ϕjl=1k[Σl1/2exp(12(x(i)μl)TΣl1(x(i)μl))ϕl] = \frac{ |\Sigma_j|^{-1/2} \exp \left( -\frac12 (x^{(i)}-\mu_j)^T \Sigma_j^{-1} (x^{(i)}-\mu_j) \right) \phi_j }{ \sum_{l=1}^k \left[ |\Sigma_l|^{-1/2} \exp \left( -\frac12 (x^{(i)}-\mu_l)^T \Sigma_l^{-1} (x^{(i)}-\mu_l) \right) \phi_l \right] }

Parameter Updates in the M-Step

In the M-step, the responsibilities wj(i)w_j^{(i)} are held fixed while we update the parameters of each component.

The resulting updates are responsibility-weighted versions of the usual sample estimates:

ϕl=1ni=1nwl(i) \phi_l = \frac1n \sum_{i=1}^n w_l^{(i)} μl=i=1nwl(i)x(i)i=1nwl(i) \mu_l = \frac{ \sum_{i=1}^n w_l^{(i)}x^{(i)} }{ \sum_{i=1}^n w_l^{(i)} } Σl=i=1nwl(i)(x(i)μl)(x(i)μl)Ti=1nwl(i) \Sigma_l = \frac{ \sum_{i=1}^n w_l^{(i)} (x^{(i)}-\mu_l) (x^{(i)}-\mu_l)^T }{ \sum_{i=1}^n w_l^{(i)} }

So each component is fitted as if every observation belonged to it partially, with weight wl(i)w_l^{(i)}.

These updates come from maximizing the fixed-responsibility ELBO:

i=1nj=1kwj(i)logp(x(i)z(i)=j;μ,Σ)p(z(i)=j;ϕ)wj(i) \sum_{i=1}^{n} \sum_{j=1}^{k} w_j^{(i)} \log \frac{ p(x^{(i)}\mid z^{(i)}=j;\mu,\Sigma) p(z^{(i)}=j;\phi) }{ w_j^{(i)} }
See derivation

Start with:

i=1nj=1kwj(i)logp(x(i)z(i)=j;μ,Σ)p(z(i)=j;ϕ)wj(i) \sum_{i=1}^{n} \sum_{j=1}^{k} w_j^{(i)} \log \frac{ p(x^{(i)}\mid z^{(i)}=j;\mu,\Sigma) p(z^{(i)}=j;\phi) }{ w_j^{(i)} }

Substituting the Gaussian density:

=i=1nj=1kwj(i)log(1(2π)d/2Σj1/2exp(12(x(i)μj)TΣj1(x(i)μj))ϕjwj(i)) = \sum_{i=1}^n \sum_{j=1}^k w_j^{(i)} \log \left( \frac{ \frac{1}{(2\pi)^{d/2}|\Sigma_j|^{1/2}} \exp \left( -\frac12 (x^{(i)}-\mu_j)^T \Sigma_j^{-1} (x^{(i)}-\mu_j) \right) \phi_j }{ w_j^{(i)} } \right) =i=1nj=1kwj(i)[log(1(2π)d/2Σj1/2)12(x(i)μj)TΣj1(x(i)μj)+logϕjlogwj(i)] = \sum_{i=1}^n \sum_{j=1}^k w_j^{(i)} \left[ \log \left( \frac{1}{(2\pi)^{d/2}|\Sigma_j|^{1/2}} \right) - \frac12 (x^{(i)}-\mu_j)^T \Sigma_j^{-1} (x^{(i)}-\mu_j) + \log\phi_j - \log w_j^{(i)} \right]

First, take the derivative with respect to μl\mu_l:

μli=1nj=1kwj(i)[12(x(i)μj)TΣj1(x(i)μj)] \nabla_{\mu_l} \sum_{i=1}^n \sum_{j=1}^k w_j^{(i)} \left[ -\frac12 (x^{(i)}-\mu_j)^T \Sigma_j^{-1} (x^{(i)}-\mu_j) \right]
=i=1nwl(i)μl[12(x(i)μl)TΣl1(x(i)μl)] = \sum_{i=1}^n w_l^{(i)} \nabla_{\mu_l} \left[ -\frac12 (x^{(i)}-\mu_l)^T \Sigma_l^{-1} (x^{(i)}-\mu_l) \right]

Expanding the quadratic term:

=i=1nwl(i)μl[12(x(i)TΣl1x(i)μlTΣl1x(i)x(i)TΣl1μl+μlTΣl1μl)] = \sum_{i=1}^n w_l^{(i)} \nabla_{\mu_l} \left[ -\frac12 \left( x^{(i)T}\Sigma_l^{-1}x^{(i)} - \mu_l^T\Sigma_l^{-1}x^{(i)} - x^{(i)T}\Sigma_l^{-1}\mu_l + \mu_l^T\Sigma_l^{-1}\mu_l \right) \right]
=i=1nwl(i)[12(Σl1x(i)ΣlTx(i)+2Σl1μl)] = \sum_{i=1}^n w_l^{(i)} \left[ -\frac12 \left( -\Sigma_l^{-1}x^{(i)} - \Sigma_l^{-T}x^{(i)} + 2\Sigma_l^{-1}\mu_l \right) \right]
=i=1nwl(i)[12(Σl1x(i)Σl1x(i)+2Σl1μl)] = \sum_{i=1}^n w_l^{(i)} \left[ -\frac12 \left( -\Sigma_l^{-1}x^{(i)} - \Sigma_l^{-1}x^{(i)} + 2\Sigma_l^{-1}\mu_l \right) \right]

Therefore:

=i=1nwl(i)(Σl1x(i)Σl1μl) = \sum_{i=1}^n w_l^{(i)} \left( \Sigma_l^{-1}x^{(i)} - \Sigma_l^{-1}\mu_l \right)

Setting this equal to 00:

i=1nwl(i)Σl1x(i)=i=1nwl(i)Σl1μl \sum_{i=1}^n w_l^{(i)} \Sigma_l^{-1}x^{(i)} = \sum_{i=1}^n w_l^{(i)} \Sigma_l^{-1}\mu_l
Σl1[i=1nwl(i)x(i)]=Σl1[i=1nwl(i)]μl \Sigma_l^{-1} \left[ \sum_{i=1}^n w_l^{(i)}x^{(i)} \right] = \Sigma_l^{-1} \left[ \sum_{i=1}^n w_l^{(i)} \right] \mu_l

Canceling Σl1\Sigma_l^{-1}:

i=1nwl(i)x(i)=[i=1nwl(i)]μl \sum_{i=1}^n w_l^{(i)}x^{(i)} = \left[ \sum_{i=1}^n w_l^{(i)} \right] \mu_l

Therefore:

μl=i=1nwl(i)x(i)i=1nwl(i) \mu_l = \frac{ \sum_{i=1}^n w_l^{(i)}x^{(i)} }{ \sum_{i=1}^n w_l^{(i)} }

Now take the derivative with respect to ϕl\phi_l.

Only the terms:

i=1nj=1kwj(i)logϕj \sum_{i=1}^n \sum_{j=1}^k w_j^{(i)} \log\phi_j

depend on ϕ\phi.

Because:

j=1kϕj=1 \sum_{j=1}^k \phi_j = 1

we use a Lagrange multiplier:

L(ϕ)=i=1nj=1kwj(i)logϕj+β(j=1kϕj1) \mathcal L(\phi) = \sum_{i=1}^n \sum_{j=1}^k w_j^{(i)} \log\phi_j + \beta \left( \sum_{j=1}^k \phi_j - 1 \right)

Taking the derivative:

ϕlL(ϕ)=i=1nwl(i)ϕl+β \frac{\partial}{\partial\phi_l} \mathcal L(\phi) = \sum_{i=1}^n \frac{w_l^{(i)}}{\phi_l} + \beta

Setting this equal to 00:

i=1nwl(i)ϕl+β=0 \sum_{i=1}^n \frac{w_l^{(i)}}{\phi_l} + \beta = 0 ϕl=i=1nwl(i)β \phi_l = \frac{ \sum_{i=1}^n w_l^{(i)} }{ -\beta }

Using the constraint:

j=1kϕj=1 \sum_{j=1}^k \phi_j = 1

gives:

j=1ki=1nwj(i)β=1 \sum_{j=1}^k \frac{ \sum_{i=1}^n w_j^{(i)} }{ -\beta } = 1 i=1nj=1kwj(i)=β \sum_{i=1}^n \sum_{j=1}^k w_j^{(i)} = -\beta
i=1n1=β \sum_{i=1}^n 1 = -\beta

Therefore:

β=n -\beta=n

and:

ϕl=1ni=1nwl(i) \phi_l = \frac1n \sum_{i=1}^n w_l^{(i)}

We use the following matrix derivatives:

AA=A(A1)T \nabla_A|A| = |A|(A^{-1})^T

and:

A(xTA1x)=ATxxTAT \nabla_A \left( x^TA^{-1}x \right) = -A^{-T}xx^TA^{-T}

When AA is symmetric:

AT=A1 A^{-T}=A^{-1}

Finally, take the derivative with respect to Σl\Sigma_l:

Σli=1nj=1kwj(i)[log1(2π)d/2Σj1/212(x(i)μj)TΣj1(x(i)μj)] \nabla_{\Sigma_l} \sum_{i=1}^n \sum_{j=1}^k w_j^{(i)} \left[ \log \frac{1}{(2\pi)^{d/2}|\Sigma_j|^{1/2}} - \frac12 (x^{(i)}-\mu_j)^T \Sigma_j^{-1} (x^{(i)}-\mu_j) \right]
=i=1nwl(i)Σl[logΣl1/212(x(i)μl)TΣl1(x(i)μl)] = \sum_{i=1}^n w_l^{(i)} \nabla_{\Sigma_l} \left[ -\log|\Sigma_l|^{1/2} - \frac12 (x^{(i)}-\mu_l)^T \Sigma_l^{-1} (x^{(i)}-\mu_l) \right]

We evaluate the two derivatives separately.

First:

ΣllogΣl1/2 \nabla_{\Sigma_l} \log|\Sigma_l|^{1/2} =1Σl1/2ΣlΣl1/2 = \frac{1}{|\Sigma_l|^{1/2}} \nabla_{\Sigma_l} |\Sigma_l|^{1/2} =1Σl1/2(12Σl1/2)ΣlΣl = \frac{1}{|\Sigma_l|^{1/2}} \left( \frac12 |\Sigma_l|^{-1/2} \right) \nabla_{\Sigma_l} |\Sigma_l|
=12(1ΣlΣl)Σl1 = \frac12 \left( \frac{1}{|\Sigma_l|} |\Sigma_l| \right) \Sigma_l^{-1}
=12Σl1 = \frac12 \Sigma_l^{-1}

For the quadratic term:

Σl[(x(i)μl)TΣl1(x(i)μl)] \nabla_{\Sigma_l} \left[ (x^{(i)}-\mu_l)^T \Sigma_l^{-1} (x^{(i)}-\mu_l) \right] =Σl1(x(i)μl)(x(i)μl)TΣl1 = - \Sigma_l^{-1} (x^{(i)}-\mu_l) (x^{(i)}-\mu_l)^T \Sigma_l^{-1}

Putting these together:

i=1nwl(i)[12(Σl1+Σl1(x(i)μl)(x(i)μl)TΣl1)] \sum_{i=1}^n w_l^{(i)} \left[ \frac12 \left( -\Sigma_l^{-1} + \Sigma_l^{-1} (x^{(i)}-\mu_l) (x^{(i)}-\mu_l)^T \Sigma_l^{-1} \right) \right]

Setting this equal to 00 gives:

i=1nwl(i)Σl1=i=1nwl(i)Σl1(x(i)μl)(x(i)μl)TΣl1 \sum_{i=1}^n w_l^{(i)} \Sigma_l^{-1} = \sum_{i=1}^n w_l^{(i)} \Sigma_l^{-1} (x^{(i)}-\mu_l) (x^{(i)}-\mu_l)^T \Sigma_l^{-1}
(i=1nwl(i))Σl1=Σl1[i=1nwl(i)(x(i)μl)(x(i)μl)T]Σl1 \left( \sum_{i=1}^n w_l^{(i)} \right) \Sigma_l^{-1} = \Sigma_l^{-1} \left[ \sum_{i=1}^n w_l^{(i)} (x^{(i)}-\mu_l) (x^{(i)}-\mu_l)^T \right] \Sigma_l^{-1}

Multiplying through by Σl\Sigma_l gives:

Σl(i=1nwl(i))=i=1nwl(i)(x(i)μl)(x(i)μl)T \Sigma_l \left( \sum_{i=1}^n w_l^{(i)} \right) = \sum_{i=1}^n w_l^{(i)} (x^{(i)}-\mu_l) (x^{(i)}-\mu_l)^T

Therefore:

Σl=i=1nwl(i)(x(i)μl)(x(i)μl)Ti=1nwl(i) \Sigma_l = \frac{ \sum_{i=1}^n w_l^{(i)} (x^{(i)}-\mu_l) (x^{(i)}-\mu_l)^T }{ \sum_{i=1}^n w_l^{(i)} }
Repeat until convergence { \text{Repeat until convergence \{} (E-step) For each i and j, set { \quad \text{(E-step) For each }i\text{ and }j,\text{ set \{} wj(i)p(z(i)=jx(i);ϕ,μ,Σ) \quad\quad w_j^{(i)} \leftarrow p \left( z^{(i)}=j \mid x^{(i)}; \phi,\mu,\Sigma \right) } \quad \text{\}} (M-step) For each j, set { \quad \text{(M-step) For each }j,\text{ set \{} ϕj1ni=1nwj(i) \quad\quad \phi_j \leftarrow \frac1n \sum_{i=1}^n w_j^{(i)} μji=1nwj(i)x(i)i=1nwj(i) \quad\quad \mu_j \leftarrow \frac{ \sum_{i=1}^n w_j^{(i)}x^{(i)} }{ \sum_{i=1}^n w_j^{(i)} } Σji=1nwj(i)(x(i)μj)(x(i)μj)Ti=1nwj(i) \quad\quad \Sigma_j \leftarrow \frac{ \sum_{i=1}^n w_j^{(i)} (x^{(i)}-\mu_j) (x^{(i)}-\mu_j)^T }{ \sum_{i=1}^n w_j^{(i)} } } \quad \text{\}} } \text{\}}

It is useful to define the effective number of examples assigned to component jj:

Nj=i=1nwj(i) N_j = \sum_{i=1}^n w_j^{(i)}

Because the assignments are soft, NjN_j can be fractional.

The M-step then sets:

ϕj=Njn \phi_j = \frac{N_j}{n}

and computes responsibility-weighted means and covariances.

The responsibilities stay fixed throughout the M-step.

The E-step makes the ELBO equal to logp(x;θ(t))\log p(x;\theta^{(t)}) at the old parameters. After updating to θ(t+1)\theta^{(t+1)}, the bound is generally no longer tight, although the observed-data log-likelihood cannot decrease under exact EM.