Unit 2 of 8 · about 5 hours · derive, implement
Maximum likelihood and MAP estimation
Likelihood connects probability models to fitting objectives. MAP adds a prior, but a posterior mode is neither a posterior mean nor a complete uncertainty statement.
You'll be able to
- Derive Bernoulli, categorical and univariate Gaussian MLEs, including boundary cases.
- Derive Bernoulli MAP with a beta prior and Gaussian-mean MAP with known observation variance and a normal prior.
- Implement the objectives and use a separate grid search to check the closed forms and prior sensitivity.
Covers
Read
In this order, only the parts listed
0 of 2 done
- 14.310x Lecture 12: likelihood as a function of parametersMIT 14.310x - Data Analysis for Social Scientists
Slides 33 to 53, maximum likelihood and the example
Use strictly increasing transformations such as log to preserve a maximizer. Stop before the second uniform example and the broad MLE-properties summary.
- Murphy: simple likelihood and posterior derivationsProbabilistic Machine Learning: An Introduction
April 18, 2025 online edition: Sections 4.2.3 to 4.2.5 (pp. 110 to 112), 4.5.1 (pp. 121 to 122), and 4.6.4.1 (pp. 141 to 143)
Use the univariate Gaussian-Gaussian case with known observation variance. Skip multivariate covariance priors and empirical Bayes.
Focus on
- For independent Bernoulli observations with successes in trials, . The interior stationary point is , with negative second derivative; all-zero or all-one samples maximize at a boundary.
- Categorical MLE maximizes on the probability simplex. A Lagrange multiplier gives ; zero-count categories need boundary treatment.
- For iid Gaussian data, differentiate in and to get and . A zero residual sum of squares has no finite maximum with positive variance.
- A prior adds and to the log-likelihood exponents. The interior MAP formula needs both posterior shape parameters greater than one. Gaussian-mean MAP combines prior precision and data precision ; that posterior is Gaussian, so its mode equals its mean, unlike the example (2/3 versus 5/8).
Common mistakes · 3
- Normalizing likelihood over parameters as though it were already a posterior. A posterior needs a prior and its normalizing integral.
- Using in a Gaussian variance MLE. That is an unbiased estimator, not the likelihood maximizer.
- Confusing beta-prior MAP pseudo-counts , with posterior-mean pseudo-counts , .
Try it yourself
Closed-book, before checking anything
[1, 0, 1, 1] and , obtain MLE 3/4, posterior , MAP 2/3 and posterior mean 5/8. With Gaussian data [1, 2, 3], obtain joint MLE , . In a separate known-variance model with and prior , obtain MAP 1.5. Check in NumPy float64 without random draws: g = numpy.linspace(0.0001, 0.9999, 9999); maximize 3*log(g) + log1p(-g), then 4*log(g) + 2*log1p(-g). Next h = numpy.linspace(-1, 4, 5001); maximize -0.5*sum((y - h)**2) over each grid value, then subtract 0.5*h**2 for MAP. Grid optima are 0.7500, 0.6667, 2.000 and 1.500. The infinity-norm difference from the four analytic optima is 3.34e-5 or less; accept below 1e-4. Widen the Gaussian prior variance and verify that its MAP approaches 2.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why does a stationary-point calculation fail for all-one Bernoulli data?Answer
The log likelihood is and is increasing on . Its maximum on is . Differentiation alone misses that boundary.
2.Derive the Gaussian-mean MAP and identify the assumptions used.Answer
Independence with common known makes the log likelihood plus a constant. A normal prior adds , with . Setting the derivative to zero gives . Positive precisions make the second derivative negative, so this is the unique mode.
3.Does a stronger prior always improve a held-out prediction?Answer
No. It reduces movement away from the prior mean but can introduce bias when the prior is poorly matched. Evaluate predictions on independent data and report sensitivity; optimizing the posterior objective is not a generalization guarantee.
Practice
- Murphy Exercises 4.1 and 4.2: Gaussian MLE and MAP
Section 4.8, p. 164 in the April 18, 2025 online edition: Exercise 4.1, MLE for the univariate Gaussian; Exercise 4.2, MAP estimation for 1D Gaussians, parts a to d
Attempt closed-book before comparing with Sections 4.2.5 and 4.6.4.1. The public solutions list only headings for these two exercises, so use the independent grid check as well. In 4.2(a), take the derivative rather than merely stating the answer; check growing and prior variance tending to zero or infinity.
You're done when
You derive the estimators without copying, pass the independent grid check, solve Exercises 4.1 and 4.2, and explain the Bernoulli and Gaussian boundary failures.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 6 more in the section
- MIT 14.310x - Data Analysis for Social ScientistsMIT OpenCourseWare · primary
Follow lectures 11-15, 17-20 and 22 with matching slides and problem sets for inference, regression, causality and experiment design.
- Probabilistic Machine Learning: An IntroductionKevin P. Murphy · reference
Use the April 18, 2025 online edition: Sections 4.2.3 to 4.2.5, 4.5.1 and 4.6.4.1 for Bernoulli and Gaussian MLE/MAP; the definition and central intervals in 4.6.6; 2.1.2 and 11.7.4 for predictive uncertainty. Exercises 4.1 and 4.2 supply derivation practice.
Also in this section
- MIT 18.05 - Inference practiceMIT OpenCourseWare · required
Use classes 17-20, 22-24 and 26 with their problem sets for tests, intervals, bootstrap and regression.
- Causal Inference: What IfHernán & Robins · required
Read Chapters 1-3 and 6-8 for causal effects, DAGs, confounding, selection bias and identification reasoning.
- Patterns of trustworthy experimentationMicrosoft ExP · required
Read after the course to connect health checks, guardrails and statistical interpretation to production launch decisions.
- Always Valid InferenceJohari, Pekelis & Walsh · depth
Use the introduction and worked motivation to understand optional-stopping failure. Reproducing the theory is outside this gate.
- Permutation nulls and false discovery controlSciPy · reference
Read
permutation_testNotes, Unpaired statistics, for exchangeability and exact partitions;false_discovery_controlNotes and the named thrombolysis example for Bonferroni and Benjamini-Hochberg. Use as an independent implementation oracle, not as a substitute for stating assumptions. - Probability calibration: the statistical propertyscikit-learn · reference
Read the opening calibration definition, the proper-scoring-rule note, and Section 1.16.1, Calibration curves. Stop before recalibration methods; the later Classical ML unit implements them.