Week 12 · Estimating parameters, and EM
Read the words of the video
- Imagine a detective finding clues at a scene. Many stories could explain them, but only one story makes those clues seem least surprising. The best detective chooses that most likely story. This is like Maximum Likelihood Estimation. We pick the model that makes the data we actually saw most probable.
- Now, imagine jars of sweets, but their labels are hidden. You get handfuls, but don't know which jar they came from! You first guess which jar each handful probably came from. Then, you use those guesses to re-estimate the jar contents. Repeating this loop is the EM algorithm.
- Let's try an example. A coin is tossed 12 times, and it lands on heads 9 times. To find the most likely probability of getting heads, we simply divide the number of heads by total tosses. So, 9 heads out of 12 tosses gives us 0.75, or 75%.
- For exams, remember: the normal variance MLE divides by 'n', but the unbiased version divides by 'n minus 1'. It's important to know which one to use! So, we learned to find the most likely story using MLE, and how EM helps with hidden information. You've got this!
The one-minute story
A detective arrives at a scene and finds clues. Many different stories could explain them, but one story makes the clues the least surprising. A good detective picks that story. That is maximum likelihood estimation (MLE): among all possible settings of the model, pick the one under which the data you actually saw was most likely.
Now make the detective's job harder. Two jars of sweets are on a table, and a friend, with eyes closed, picks a jar each time and hands you a handful, but never tells you which jar. You want each jar's colour mix, but the labels are hidden. What do you do?
You guess which jar each handful probably came from (using your current idea of the jars), then re-estimate the jars using those guesses, and repeat. Each round your guesses and your jar recipes improve together. That loop is the EM algorithm (Expectation-Maximisation), and it lets us fit models with hidden pieces.
By the end of this week you can:
- write down a likelihood and find the MLE for common models by calculus;
- explain the bias of the Gaussian variance MLE;
- state the idea of MAP estimation;
- explain latent variables and run one step of EM by hand on the two-coin problem.
Words you need
- Likelihood - the probability (or density) of the observed data, viewed as a function of the parameter .
- Log-likelihood - easier to work with; its peak is in the same place.
- MLE - the parameter value that maximises the likelihood.
- Estimator - a recipe that turns data into a guess for a parameter. It is unbiased if its guesses average to the truth.
- Latent (hidden) variable - something the model needs but we never observe, like "which jar".
- Responsibility - the current probability that a data point came from a given hidden cause.
- Prior and posterior - what you believe about before and after seeing data.
Idea 1: Maximum likelihood estimation
Say are independent draws from a distribution with density or mass . The probability of the whole data set is the product:
The MLE recipe
- Write the likelihood .
- Take the log (products become sums, and the maximiser does not move because is increasing).
- Differentiate with respect to and set it to zero.
- Solve, and check it is a maximum.
Likelihood is not the probability that is true. It is how probable the data is if were true. We vary and keep the data fixed.
The MLEs worth knowing
| Model | MLE |
|---|---|
| Bernoulli() | (fraction of successes) |
| Poisson() | |
| Exponential() | |
| Normal, known variance | |
| Normal, both unknown | , |
| Uniform |
Two cautions. The Normal variance MLE divides by , and it is biased (it underestimates on average); dividing by gives the unbiased version. And for the uniform, the derivative method fails (the likelihood keeps falling as grows, but cannot go below the biggest observation), so you argue directly: the smallest allowed is the max.
Question. A variable on has density , . Two observations are and . Find the MLE of .
Solution.
- .
- .
- , . So .
Question. , , . The observations are . Find .
Solution. Counts: two 1's, two 2's, two 3's. . . . (Valid: .)
Question. (a) Five thickness measurements come from a normal distribution of known variance. Find the MLE of the mean. (b) For the data find the MLE of the variance and the unbiased estimate.
Solution. (a) . (b) . MLE: . Unbiased: .
MLE and MAP
If you also have a prior belief , the posterior is , and the MAP (maximum a posteriori) estimate maximises it. MLE is MAP with a "flat" prior. With lots of data, the two agree. MAP gives you regularisation (ridge and LASSO in MLT week 6).
Link to least squares. If with Gaussian noise, the log-likelihood is . Maximising it means minimising the squared error: so least squares is MLE under Gaussian noise (week 3 and MLT week 5).
Idea 2: When something is hidden
Fitting a mixture of distributions: a data point comes from one of components, but we do not see which. The density is
Now has a log of a sum, which does not simplify, and setting the derivative to zero gives no tidy formula. If we knew which component produced each point, MLE would be easy (just estimate each component from its own points). The EM algorithm exploits exactly this.
Idea 3: The EM algorithm
Start with a guess for the parameters, then repeat two steps:
E-step (Expectation): with the current parameters, compute for every data point the responsibility: the probability that it came from each hidden cause. These are soft, fractional guesses.
M-step (Maximisation): pretend those fractional guesses are real. Re-estimate every parameter by ordinary MLE, weighting each data point by its responsibility.
Facts to remember:
- Each full round never decreases the likelihood, so EM climbs steadily.
- It converges to a local maximum, not necessarily the global one, so the starting guess matters.
- It is k-means' soft cousin: k-means assigns each point to one cluster (a hard guess); EM gives each point a fractional membership.
Setup. Two coins A and B have unknown heads-probabilities and . In each of 5 sessions one coin was chosen at random (we do not know which) and tossed 10 times. Heads out of 10: . Start with , .
E-step. For a session with heads, coin A would produce that with likelihood and coin B with . The responsibility of A is (the coins are equally likely a priori).
| heads | ||||
|---|---|---|---|---|
| 5 | 0.45 | 0.55 | ||
| 9 | 0.80 | 0.20 | ||
| 8 | 0.73 | 0.27 | ||
| 4 | 0.35 | 0.65 | ||
| 7 | 0.65 | 0.35 |
M-step. Re-estimate each coin's bias as (expected heads) over (expected tosses), using the weights.
- Coin A: expected heads ; expected tosses . So .
- Coin B: expected heads ; expected tosses . So .
From the guess the round moved to : coin A's probable heavy-heads sessions pulled it up. Repeating converges to roughly . (We verified these numbers by computer.)
For a Gaussian mixture the E-step responsibility is , and the M-step updates are , and the weighted variance. MLT week 4 walks through that in detail with numbers.
Your turn
A coin is tossed 12 times and shows heads 9 times. What is ? Write the log-likelihood and confirm.
Need a hint?
.
Show the full solution
. .
Waiting times minutes are modelled as exponential. Find the MLE of and .
Need a hint?
.
Show the full solution
, so . .
Why do we sometimes divide by instead of when estimating a variance?
Need a hint?
The sample mean is itself estimated from the same data.
Show the full solution
Data points sit slightly closer to their own sample mean than to the true mean, so underestimates the true variance on average. Multiplying by corrects that, giving the unbiased estimator. The MLE (with ) is biased but consistent: the bias vanishes as grows.
A uniform distribution on gives the sample . What is the MLE of ?
Need a hint?
The likelihood is for and otherwise.
Show the full solution
. (It is biased low: is almost always slightly bigger than the biggest sample.)
Why is the E-step in the two-coin problem needed at all? What would be easy if the coin labels were known?
Need a hint?
Think about what MLE would do per coin.
Show the full solution
If the labels were known, each coin's bias would just be (heads with that coin) / (tosses with that coin). The E-step fills in the missing labels with probabilities (responsibilities), and the M-step does exactly that same ratio, but with weighted counts.
Exam radar
In the MLF End Term, MLE appears in 16 of the 42 summarised papers, typically as: "MLE of for a normal with known variance from 5 measurements", "MLE of for exponential service times", "MLE of an unknown constant in a discrete distribution", or "a density with a parameter, find the estimate from a sample". The EM algorithm is not examined in MLF papers on the practice site.
EM matters in MLT: it appears in 46 of 60 MLT Quiz 1 papers (with Gaussian mixtures). Learn it here for the idea, then do the numbers in MLT week 4.
- Maximise the log-likelihood but report the parameter, not the maximum value, unless asked.
- Normal variance MLE uses ; the unbiased version uses . Read which one the question asks for.
- For an exponential the MLE of the rate is , not .
- EM finds a local maximum and depends on the start.
- Responsibilities across components must add to 1 for each data point.
Quick quiz
The MLE of p for a Bernoulli sample with 7 successes out of 10 is...
- 0.3
- 0.5
- 0.7
- 7
The MLE of the variance of a normal distribution (mean unknown) divides by...
- n minus 1
- n
- n squared
- 2
In the EM algorithm, the E-step computes...
- the final parameters
- the responsibilities (soft assignments to hidden causes)
- the learning rate
- the covariance of the data
Select all TRUE statements about EM. (select all that apply)
- Each iteration does not decrease the likelihood.
- It can converge to a local maximum.
- It always finds the global maximum.
- It needs the hidden labels to be known.
Recap
- MLE: write , take , differentiate, set to zero. Bernoulli ; Poisson ; exponential ; normal mean , variance with (biased).
- MAP adds a prior; least squares is MLE under Gaussian noise.
- Latent variables make the likelihood a log of a sum.
- EM: E-step (responsibilities) then M-step (weighted MLE). Likelihood never decreases; converges to a local maximum; soft version of k-means.
- , ,
- Normal: , ; unbiased
- Uniform: ; Exponential:
- MAP:
- EM: ; ;
- MLT week 4 - MLE, Bayes, Gaussian mixtures and EM: The EM algorithm for Gaussian mixtures is taught in both courses.
- MLT week 5 - Regression: least squares and its Bayesian view: MLE and MAP give the probabilistic view of least squares and ridge.
Practise with real exam questions
These come straight from past papers (with the real figures and the official answer key). Open 6 real questions on this week All End Term papers