Week 4 · MLE, Bayes, Gaussian mixtures and EM
Read the words of the video
- You find a coin and flip it 10 times: 7 heads. What is the chance of heads? A quick answer is '70%'. But what if it looked like a perfectly ordinary coin? You would probably say 'it is surely close to 50%'. The data and your prior feeling should both count.
- Bayesian estimation is the maths of mixing these two: start with a belief, update it with data, and end with a better belief. With lots of data, evidence wins; with little data, the prior still has a voice. Another idea: GMM learns hidden groups by alternately guessing groups and refitting curves.
- Imagine you start with a mild belief in a fair coin. Then you see 7 heads and 3 tails in ten flips. Your belief updates! Instead of just 70% heads, your new estimate might be closer to 64% or 67%. Your initial feeling still has a small say.
- For exams, remember the Beta posterior update formula: add heads to alpha, tails to beta! Also, know that EM climbs to a local maximum, not always the best one. And always check if the question asks for the mean or the most likely value. You got this!
The one-minute story
Part 1, one coin. You find a coin and flip it 10 times: 7 heads. What is the chance of heads? A quick answer is "70%". But what if it looked like a perfectly ordinary coin? You would probably say "it is surely close to 50%, 7 out of 10 is just luck". The data and your prior feeling should both count. Bayesian estimation is the maths of mixing the two: start with a belief, update it with data, and end with a better belief. With lots of data the evidence wins; with little data the prior still has a voice.
Part 2, mixed groups. Measure the heights of 1000 people at a school gathering, but forget to write down who is a child and who is an adult. The heights form two overlapping bumps. A Gaussian mixture model (GMM) says: "each person comes from one of two hidden groups, and each group has its own bell curve". EM (expectation-maximisation) learns the two bell curves without ever being told the groups, by alternately guessing the groups and refitting the curves.
By the end of this week you can:
- compute MLE for common distributions and explain its bias;
- do Bayesian estimation with a Beta prior and a Bernoulli likelihood, and tell MLE, MAP and posterior mean apart;
- write the GMM model and compute its log-likelihood;
- carry out the E-step and M-step by hand and count GMM parameters.
Words you need
- Prior - belief about the parameter before seeing data.
- Likelihood - how well each parameter value explains the data.
- Posterior - updated belief after seeing data.
- Conjugate prior - a prior chosen so that the posterior has the same family. Beta prior with Bernoulli data gives a Beta posterior.
- MAP - the mode (peak) of the posterior.
- Mixture component - one of the hidden groups, with weight , mean and covariance .
- Responsibility - the probability that point came from component .
Idea 1: Recap of MLE
For data and a model , MLE picks the that makes the data most probable: write the log-likelihood , differentiate, set to zero.
| Model | MLE |
|---|---|
| Bernoulli() with heads in tosses | |
| Gaussian mean | |
| Gaussian variance | (biased low) |
| Exponential | |
| Poisson | |
| Uniform |
MLE is the pure "let the data speak" answer. With 3 tosses and 3 heads it says : "this coin never shows tails", which is silly. That is where a prior helps.
Idea 2: Bayesian estimation
Treat the unknown parameter as a random variable with a distribution. Bayes' rule (MLF week 10) says
The Beta-Bernoulli model: the most-asked calculation of this quiz
The unknown is a coin's heads-probability . A natural prior is the Beta distribution:
with mean . You see heads and tails (). The likelihood is , so
That is conjugacy: the posterior is the same kind of curve as the prior, with the counts simply added.
Read and as pretend flips you already saw: pretend heads and pretend tails. Beta(2,2) means "I have a hunch from 2 heads and 2 tails". Then real data just adds real flips to the pile. After the update you have a pile of heads and tails, and the Beta curve for that pile is your new belief.
For the posterior Beta with and :
| Summary | Formula |
|---|---|
| Posterior mean | |
| MAP (posterior mode) | (when ) |
| MLE (ignores the prior) | |
| Posterior variance |
Observations:
- The posterior mean is a blend: lies between the prior mean and the MLE, and moves towards the MLE as grows.
- A uniform prior is Beta: its posterior mean is , Laplace's rule of succession (never gives probability 0 or 1).
- The probability that the next toss is heads equals the posterior mean.
- As the prior washes out: MAP, posterior mean and MLE all converge.
Question. Prior Beta(2,2). You see 7 heads and 3 tails. Give the posterior, its mean, the MAP estimate and the MLE. What is the probability the next toss is heads?
Solution.
- Posterior: Beta Beta(9,5).
- Posterior mean: .
- MAP (mode): .
- MLE: .
- The next toss is heads with probability the posterior mean, .
The prior (centred on ) has pulled the estimate from down towards : MLE MAP mean .
Posterior mean and posterior mode (MAP) are different numbers: versus . Re-read whether the question asks for "expected value / mean" or "most likely value / MAP / mode".
Idea 3: Gaussian mixture models
A GMM says each data point is generated in two stages:
- Pick a component with probability (the mixing weights, ).
- Draw from .
The density of a point is the weighted sum
and for independent points the log-likelihood is
The log of a sum blocks a neat formula for the best parameters, so we use EM.
The EM algorithm for a GMM
E-step. For every point and every component, the responsibility
(Each point's responsibilities add to 1 across components.)
M-step. With (the "effective number of points" in component ):
These are exactly the ordinary MLE formulas for a Gaussian, but every point is weighted by its responsibility.
Properties worth knowing:
- Each EM iteration never decreases the log-likelihood; the algorithm climbs to a local maximum (it can depend on the start, which is often set by k-means).
- If one component collapses onto a single point, its variance and the likelihood : a singularity that must be avoided (add a small floor to the variance).
- k-means is the hard version: shrink every to and let ; the responsibilities become 0 or 1 and EM becomes Lloyd's algorithm.
Question. Data: . A 2-component GMM in 1-D with both standard deviations fixed at 1, equal weights , initial means and . Do one E-step and one M-step.
Solution. Use . The common factor and the equal weights cancel in the ratio.
E-step.
| 1 | ||||
| 4 | ||||
| 6 |
(For example .) The point sits exactly between the two means, so it is a coin flip.
M-step. Effective counts: and .
The means moved from to : the left component moved towards its point , the right one towards . The log-likelihood improved from to , as EM promises.
Counting GMM parameters
For components in dimensions:
| Covariance type | Parameters per component | Total |
|---|---|---|
| Full | (mean) (covariance) | |
| Diagonal | ||
| Spherical () |
The final counts the mixing weights (the last weight is forced by ).
Question. A GMM with components in dimensions. Count the parameters for full, diagonal and spherical covariances.
Solution. Full: . Diagonal: . Spherical: .
Your turn
Prior Beta(1,1) (uniform). You see 4 heads and 1 tail. Give the posterior, posterior mean, MAP and MLE.
Need a hint?
Add the counts to .
Show the full solution
Beta(5,2). Mean . MAP . MLE (with a uniform prior the MAP equals the MLE).
Prior Beta(20,20) (a strong belief the coin is fair). You see 3 heads in 3 tosses. What is the posterior mean? What would MLE say?
Need a hint?
.
Show the full solution
Beta(23,20), mean . The MLE says . The strong prior barely moves: three tosses are tiny evidence against forty pretend ones.
A two-component model gives a point likelihoods and . Find , .
Need a hint?
Normalise.
Show the full solution
Total . , .
Three points have responsibilities for component 1 of , and values . Compute , and .
Need a hint?
.
Show the full solution
. . .
(a) EM increases the log-likelihood each step. (b) EM always finds the global maximum. (c) A point's responsibilities across components add to 1. (d) The mixing weights are .
Need a hint?
Review the concept box.
Show the full solution
(a) True. (b) False, only a local maximum. (c) True. (d) True.
Exam radar
MLT Quiz 1 is where this week lives. Concept summaries mention EM / expectation-maximisation in 46 of 60 papers, Gaussian mixture models in 52, MLE in 39, Bayes in 32, Bernoulli in 28, Beta distribution in 16, Beta posterior mean in 15, GMM likelihood in 12, E-step in 11, M-step in 11, posterior mean in 11, Bernoulli distribution in 16.
The standard questions: Beta posterior mean after some heads and tails; MLE vs MAP vs posterior mean; compute a responsibility from given likelihoods; a mixing weight or mean after the M-step; "is the log-likelihood non-decreasing under EM?"; GMM parameter count.
- Mean vs mode of the posterior; the mode has the and .
- Prior pseudo-counts are and (not ) when you compute the posterior mean.
- The Beta prior is for the heads-probability, so adding data adds heads to and tails to .
- Responsibilities are per point, summing over components, not over points.
- EM gives a local maximum. It does not guarantee the best fit.
- The Gaussian-variance MLE divides by .
Quick quiz
Prior Beta(3,2), then 2 heads and 1 tail. The posterior is...
- Beta(2,1)
- Beta(5,3)
- Beta(6,2)
- Beta(3,2)
For Beta(5,3), the posterior mean is...
- 5/3
- 5/8
- 4/6
- 3/8
In the E-step of EM for a GMM, we compute...
- new means
- responsibilities
- the learning rate
- the number of clusters
Select all TRUE statements. (select all that apply)
- MLE ignores the prior.
- With a uniform Beta(1,1) prior, MAP equals MLE for Bernoulli data.
- The posterior mean is always equal to the MLE.
- EM can decrease the log-likelihood in some iteration.
Recap
- MLE: for Bernoulli. Bayes: posterior likelihood prior.
- Beta() prior + heads, tails Beta(); mean , mode .
- GMM: ; log-likelihood has a log of a sum.
- EM: E-step responsibilities ; M-step weighted MLE (, weighted means and covariances). Likelihood never decreases; local maximum; k-means is the hard limit.
- Beta posterior: ; mean ; MAP ; MLE
- Beta mean ; variance
- GMM:
- ; ; ; ;
- Parameters: full ; diagonal ; spherical
- MLF week 2 - Slopes, change and the steepest way up: Maximum likelihood means 'set the derivative to zero', which is MLF week 2 in action.
- MLF week 12 - Estimating parameters, and EM: The EM algorithm for Gaussian mixtures is taught in both courses.
- MLP week 12 - Unsupervised learning in sklearn: Gaussian mixtures in scikit-learn.
Practise with real exam questions
These come straight from past papers (with the real figures and the official answer key). Open 33 real questions on this week All Quiz 1 papers