No history yet

EM Theoretical Foundations

The Challenge of Latent Variables

In many statistical problems, we aim to find the parameters θ\theta that maximize the log-likelihood of our observed data, XX. This is standard Maximum Likelihood Estimation (MLE). The problem becomes significantly more complex when our model includes latent variables, ZZ, which are unobserved.

Our goal is to maximize the marginal log-likelihood, often called the incomplete-data log-likelihood:

L(θ)=logp(Xθ)=logZp(X,Zθ)\mathcal{L}(\theta) = \log p(X | \theta) = \log \sum_{Z} p(X, Z | \theta)

This marginalization often introduces complex dependencies or results in a sum within the logarithm, making direct optimization intractable. If we somehow knew the values of the latent variables ZZ, our problem would simplify to maximizing the complete-data log-likelihood, logp(X,Zθ)\log p(X, Z | \theta), which is typically much easier to work with.

The Expectation-Maximization (EM) algorithm provides an iterative approach to handle this intractability. Instead of maximizing L(θ)\mathcal{L}(\theta) directly, it maximizes a more convenient lower bound on it.

Constructing the Lower Bound

To derive this lower bound, we introduce an arbitrary probability distribution q(Z)q(Z) over the latent variables. We can then rewrite the marginal log-likelihood and apply Jensen's inequality. Since the logarithm is a concave function, we know that logE[Y]E[logY]\log E[Y] \ge E[\log Y]. This single mathematical property is the key to the entire EM derivation.

logp(Xθ)=logZp(X,Zθ)=logZq(Z)p(X,Zθ)q(Z)Zq(Z)logp(X,Zθ)q(Z)\begin{aligned} \\ \log p(X | \theta) &= \log \sum_{Z} p(X, Z | \theta) \\ &= \log \sum_{Z} q(Z) \frac{p(X, Z | \theta)}{q(Z)} \\ &\ge \sum_{Z} q(Z) \log \frac{p(X, Z | \theta)}{q(Z)} \\ \end{aligned}

This result is the Evidence Lower Bound (ELBO), a foundational concept in variational inference and the EM algorithm. We denote it as F(q,θ)\mathcal{F}(q, \theta):

F(q,θ)=Zq(Z)logp(X,Zθ)q(Z)logp(Xθ)\mathcal{F}(q, \theta) = \sum_{Z} q(Z) \log \frac{p(X, Z | \theta)}{q(Z)} \le \log p(X | \theta)

The gap between the ELBO and the true log-likelihood can be expressed using the Kullback-Leibler (KL) divergence, a measure of how one probability distribution differs from a second.

logp(Xθ)=F(q,θ)+DKL(q(Z)p(ZX,θ))\log p(X | \theta) = \mathcal{F}(q, \theta) + D_{\text{KL}}(q(Z) \|\| p(Z | X, \theta))

This decomposition is powerful. To maximize the log-likelihood, we can instead iteratively maximize the ELBO. The EM algorithm does this by coordinating updates to q(Z)q(Z) and θ\theta.

The Two Steps of EM

The algorithm proceeds in two alternating steps: maximizing the ELBO with respect to qq (E-step) and then with respect to θ\theta (M-step).

The E-Step

In the E-step, we hold the parameters θ(t)\theta^{(t)} from the previous iteration constant and maximize F(q,θ(t))\mathcal{F}(q, \theta^{(t)}) with respect to the distribution q(Z)q(Z). Looking at our decomposition, we see that the ELBO is maximized when the KL divergence term is minimized. The KL divergence DKL(qp)D_{\text{KL}}(q \|\| p) is zero if and only if q=pq = p. Therefore, we set q(Z)q(Z) to be the true posterior distribution of the latent variables:

q(t+1)(Z)=p(ZX,θ(t))q^{(t+1)}(Z) = p(Z | X, \theta^{(t)})
θ(t+1)=argmaxθF(q(t+1),θ)\theta^{(t+1)} = \arg\max_{\theta} \mathcal{F}(q^{(t+1)}, \theta)

Let's expand the ELBO to see what we are actually maximizing. We can separate it into two terms:

F(q,θ)=Zq(Z)logp(X,Zθ)Zq(Z)logq(Z)=Q(θ,θ(t))+H(q)\begin{aligned} \\ \mathcal{F}(q, \theta) &= \sum_{Z} q(Z) \log p(X, Z | \theta) - \sum_{Z} q(Z) \log q(Z) \\ &= Q(\theta, \theta^{(t)}) + H(q) \\ \end{aligned}

Since the entropy term H(q)H(q) does not depend on θ\theta, maximizing the ELBO is equivalent to maximizing the QQ function. This is the origin of the M-step's name: maximizing the expectation.

Q(θ,θ(t))=EZX,θ(t)[logp(X,Zθ)]Q(\theta, \theta^{(t)}) = E_{Z|X,\theta^{(t)}}[\log p(X, Z | \theta)]

By alternating these two steps, we are guaranteed to increase the marginal log-likelihood logp(Xθ)\log p(X|\theta) at each iteration, or leave it unchanged, until a local maximum is reached. The E-step makes the lower bound tight, and the M-step pushes the value of that bound up, which in turn pushes the true likelihood up.

Quiz Questions 1/5

Why is the Expectation-Maximization (EM) algorithm particularly useful in statistical modeling?

Quiz Questions 2/5

Which mathematical principle is the key to deriving the Evidence Lower Bound (ELBO) in the context of the EM algorithm?