S14 · Lesson 2 · Likelihood and Bayes' theorem for learning
The likelihood of a data set, maximum-likelihood estimates of a Gaussian's mean and variance and the bias of the variance, the log-likelihood, Bayes' theorem with priors and posteriors, and how a Gaussian prior on the weights turns least squares into regularized least squares
Lesson 1 chose parameters by minimizing squared error, which seems arbitrary. Probability gives it a reason: if the targets are the model's prediction plus Gaussian noise, least squares is exactly the choice that makes the observed data most probable, the maximum-likelihood fit. Treating the parameters themselves as uncertain, with a prior, then gives regularization a reason too. A11 built probability; this lesson puts it to work estimating parameters.
- The likelihood of the mean μ of a Gaussian (known σ = 1) given N observations averaging x̄ = 2, normalized to a peak of 1.
- The maximum sits at the sample mean, and the curve's width, the uncertainty in μ, shrinks as .
- With 100 observations the mean is pinned down ten times more tightly than with one.
Predict
Four measurements read 2, 4, 4 and 6. What's the maximum-likelihood estimate of their Gaussian variance?
The maximum-likelihood mean is the sample mean, 4, and the maximum-likelihood variance is the average squared deviation, (4 + 0 + 0 + 4)/4 = 2. It's biased low: on average it equals , because the mean was fitted to the same data. Dividing by N − 1 instead gives the unbiased 2.67.
Name it
Likelihood
For independent observations from a density , the likelihood of the parameters is ; its logarithm is a sum, easier to work with. For a Gaussian,
Maximum likelihood
Maximizing gives and , whose expectation is . If targets are with Gaussian ε, maximizing the likelihood over w is minimizing the sum of squared errors.
Bayes' theorem
posterior ∝ likelihood × prior. The maximum a posteriori (MAP) estimate maximizes the posterior. With Gaussian noise of variance and a Gaussian prior , MAP is regularized least squares with .
Worked example
Find the log-likelihood of the data 2, 4, 4, 6 at the maximum-likelihood parameters.
Show the solution
- Maximum-likelihood parameters.
- Log-likelihood.
- Compare other parameters. Any other μ or σ² gives a lower value; with σ² = 8/3 (the unbiased estimate), for example, it's −7.14.
Answer the log-likelihood at the maximum-likelihood parameters is −7.062.
Worked example
A fault detector flags 99% of faulty units and 5% of good ones; 1% of units are faulty. Given a flag, what's the chance the unit is faulty?
Show the solution
- Probability of a flag.
- Bayes' rule.
- Why it's so low. Most flags are false alarms because good units vastly outnumber faulty ones: the prior matters as much as the detector.
Answer given a flag, the unit is faulty with probability 0.167.
Worked example
Five units run a life test for 1000 hours. Three fail, at 200, 500 and 800 hours; two are still running at the end. Assuming a constant failure rate, what's the maximum-likelihood rate and mean time to failure?
Show the solution
- Each unit's share of the likelihood. A unit that fails at time t contributes ; one still running at time T contributes the probability of surviving, .
- Log-likelihood. where the sum is the total time on test:
- Maximize. Setting the derivative to zero gives a mean time to failure of 1167 hours.
- Ignoring the survivors. That would give 500 hours, badly pessimistic: censored data still carry information.
Answer the maximum-likelihood rate is per hour, a mean time to failure of 1167 hours.
Check
Four measurements read 1, 2, 9 and 10. What's the maximum-likelihood estimate of the Gaussian variance?
Check
The maximum-likelihood variance of 3 samples is 4. What's the unbiased estimate?
Check
A test detects a condition with probability 0.9 and falsely flags 0.05 of negatives. The condition's prevalence is 0.01. Given a positive, what's the probability of the condition?
Check
4 Gaussian observations have squared deviations from μ summing to 20. With σ² = 1, what's the log-likelihood?
Check
Targets have Gaussian noise of variance 0.1, and the weights a Gaussian prior with standard deviation 0.5. What regularization constant does MAP estimation correspond to?
Check
Samples of size 2 come from a Gaussian of variance 4. What's the expected value of the maximum-likelihood variance estimate?
Check
A photon counter records 3, 1, 5 and 8 counts in four equal intervals, assumed Poisson.
(a)
What is the maximum-likelihood count rate per interval?
(b)
At that rate, what's the probability of an interval with no counts?
Check
A life test sees F failures in a total time on test T, with a constant failure rate assumed.
Step 1
What is the maximum-likelihood failure rate?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What mean time to failure does it imply?
Step 3
What probability does it give that a unit survives a time t?
Explain why
Why does minimizing squared error amount to maximum likelihood?
Suppose each target is the model's output plus independent Gaussian noise of fixed variance. The probability density of observing a target t given the model's prediction y is proportional to , so the likelihood of the whole data set is the product of these, and its logarithm is a constant minus the sum of squared errors divided by . The parameters that maximize the log-likelihood are therefore exactly those that minimize the sum of squared errors. The connection also says when least squares is the wrong choice: if the noise has heavy tails or depends on the input, a different likelihood, and a different error function, fits better.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.