Alex Minnaar

The Gaussian Mixture Model and the EM Algorithm

22 May 2017

This post is about the Gaussian mixture model which is a generative probabilistic model with hidden variables and the EM algorithm which is the algorithm used to compute the maximum likelihood estimate of its parameters.

The Gaussian Mixture Model

As stated earlier the Gaussian mixture model is a probabilistic model that assumes that the observed data points can be expressed as a convex combination (mixture) of hidden Gaussian distributions. You can also look at it from a clustering perspective - all data points belong to clusters (expressed as Gaussian distributions) with different probabilities. However, all that is observed is the data points themselves and the underlying Gaussian distributions from which they are assumed to be generated are hidden/latent variables that we must infer. It is also important to note that we are NOT trying to infer the number of Gaussian distributions - we assume that that is known before hand and we call that .

So to express this more concretely, let’s assume we have i.i.d. datapoints

and also assume there are hidden Gaussian distributions.

Each with hidden mean and covariance . These are the hidden parameters that we are aiming to infer.

Let’s also introduce a hidden variable which governs the assignment of data points to Gaussian distributions. So the probability that a data point is assigned to the distribution is

and are called the mixing coefficients. Intuitively, these values say which Gaussian distribution the data point is closest to.

Now we can express the likelihood of a single data point as

From this you can see how we are expressing each data point as a convex combination of Gaussians.

Also, the joint distribution of a datapoint and it’s assignment can be expressed as

and it is important to note that is being used here rather than and is binary valued (it is either assigned to that Gaussian or it isn’t), so the Gaussians that aren’t assigned to that datapoint will just contribute a to the product.

So for the entire dataset, the likelihood is

The Goal

As stated earlier, the goal here is to compute the maximum likelihood estimate of the hidden Gaussian parameters , and for all . The typical procedure is to take the derivative of the log of the likelihood function with respect to the parameter, set it to zero, then try to solve for the parameter. If we do this we get the following expressions for , and .

As you can see, each expression contains the term . Using Bayes rule, this can be written as

So the problem is that , and are written in terms of the unknown and conversely is written in terms of the unknowns , and . So we cannot solve for anything because every unknown is written in terms of another unknown so we are stuck. In order to get unstuck we use the EM algorithm.

The EM Algorithm

The EM (Expectation-Maximization) algorithm proposes a solution to this problem. Starting from a random initialization of the parameters , and the EM algorithm iterates between the following steps until convergence.


        E-Step: Evaluate based on the latest values of , and .

        M-Step: Evaluate , and based on the latest value of .


Upon convergence you will get a maximum likelihood estimate of the parameters , and , but it is not guaranteed to be the global optimum. It is, however, guaranteed that the likelihood will increase at every step.

In this way the EM algoritham can be viewed as a kind of coordinate ascent algorithm - starting with a completely random guess, we are re-estimating an unknown parameter based on our best guess of the parameters it depends on and we iteratively move in the right direction.

Formally, the E-step is defined as evaluating the expected value of the log likelihood function (hence the name expectation-maximization) but in many cases such as ours, all that is really necessary is evaluating the simpler expression of . In general, the EM algorithm is applicable whenever you are trying to find the maximum likelihood estimate of the parameters within models with hidden variables and particularly those that involve distributions from the exponential family. Another well-known example of the EM algorithm is the Baum-Welch algorithm which is the EM algorithm applied to the hidden Markov model.

Thank you for reading.

References