S142 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 σ/N.
  • 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?

Name it

Likelihood

For independent observations x1,…,xN from a density p(x|θ), the likelihood of the parameters is p(𝒟|θ)=∏np(xn|θ); its logarithm is a sum, easier to work with. For a Gaussian,

ln⁡p(𝒟|μ,σ2)=−N2ln⁡(2πσ2)−12σ2∑n(xn−μ)2

Maximum likelihood

Maximizing gives μML=1N∑xn and σML2=1N∑(xn−μML)2, whose expectation is N−1Nσ2. If targets are t=y(x,𝐰)+ϵ with Gaussian ε, maximizing the likelihood over w is minimizing the sum of squared errors.

Bayes' theorem

p(θ|𝒟)=p(𝒟|θ)p(θ)p(𝒟)

posterior ∝ likelihood × prior. The maximum a posteriori (MAP) estimate maximizes the posterior. With Gaussian noise of variance σ2 and a Gaussian prior 𝐰∼𝒩(0,σw2I), MAP is regularized least squares with λ=σ2/σw2.

Worked example

Find the log-likelihood of the data 2, 4, 4, 6 at the maximum-likelihood parameters.

Show the solution
  1. Maximum-likelihood parameters. μ=4,σ2=2
  2. Log-likelihood. ln⁡p=−2ln⁡(4π)−82×2=−5.062−2=−7.062
  3. 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
  1. Probability of a flag. p(flag)=0.99×0.01+0.05×0.99=0.0594
  2. Bayes' rule. p(fault|flag)=0.99×0.010.0594=0.00990.0594=0.167
  3. 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
  1. Each unit's share of the likelihood. A unit that fails at time t contributes λe−λt; one still running at time T contributes the probability of surviving, e−λT.
  2. Log-likelihood. ln⁡L=3ln⁡λ−λ∑ti where the sum is the total time on test: ∑ti=200+500+800+1000+1000=3500hours
  3. Maximize. Setting the derivative to zero gives λ=3/3500=8.57×10−4per hour a mean time to failure of 1167 hours.
  4. Ignoring the survivors. That would give 500 hours, badly pessimistic: censored data still carry information.

Answer the maximum-likelihood rate is 8.57×10−4 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°.

Explain why

Why does minimizing squared error amount to maximum likelihood?

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.