Exercises — Maximum a posteriori estimation (MAP)
A quick reminder of the one object everything below rests on, the log-posterior objective:
Level 1 — Recognition
Exercise 1.1
Which question does MAP answer, and which does Maximum Likelihood Estimation (MLE) answer?
Recall Solution
- MLE asks: "which makes the observed data most probable?" → maximises .
- MAP asks: "which is most probable given the data AND my prior belief?" → maximises the posterior . MAP adds the belief term on top of the MLE data term.
Exercise 1.2
Under what single condition does exactly?
Recall Solution
When the prior is uniform (flat), . Then is a constant that does not depend on , so it drops out of the and only the data term remains. MLE is thus MAP with "no opinion before the data."
Exercise 1.3
MAP returns the mode or the mean of the posterior? For a symmetric posterior, does the choice matter?
Recall Solution
MAP returns the mode — the peak (highest point) of the posterior. For a symmetric posterior (e.g. Gaussian) the peak sits at the centre, so mode = mean and it makes no difference. For skewed posteriors (Beta, Gamma) mode mean, so it matters.
Level 2 — Application
Exercise 2.1
Coin flipped times, heads. Prior on head-probability is Beta. Find .
Recall Solution
The posterior of a Binomial likelihood with a Beta prior is Beta (this is why Beta is the conjugate prior). The mode of Beta with is : Compare : the prior mean pulled the estimate down slightly.
Exercise 2.2
Derive the general Beta-mode formula by maximising the log-posterior. Show that for a Beta density the mode is , and confirm the critical point is a maximum.
Recall Solution
Take the log (products → sums, and log is monotonic so the peak location is unchanged): Differentiate w.r.t. and set to zero (flat slope at the top): Expand: , so WHY this is a maximum, not a min or a boundary point (for ):
- Interior second-derivative check. . With both terms are negative, so the log-posterior is concave everywhere on — the single critical point is a genuine maximum.
- Boundary check. As , ; as , . So the density vanishes at both ends and no larger value hides at a boundary. The interior peak wins.
Exercise 2.3
Gaussian data with known noise variance , prior with prior variance . Given observation , find .
Recall Solution
From the parent note, . With : The prior mean shrank the raw data mean down to .
Level 3 — Analysis
Figure 1 — Gaussian MAP: how data overtakes the prior. The figure below plots the Gaussian shrinkage coefficient (the weight placed on the data mean) against the number of observations . The horizontal axis is ; the vertical axis is the coefficient, running from to . The solid red curve is the coefficient itself; the orange dashed line at height marks the case (all weight on the prior mean ); the blue dashed line at height marks the MLE limit (all weight on the data). Watch the red curve climb from toward — that rising motion is the prior handing control to the data.

Exercise 3.1
Using the Gaussian result , describe the behaviour as (no data) and as (infinite data). What does each limit mean?
Recall Solution
- : . With no data the estimate collapses to the prior mean — belief is all we have. This is the left end of the red curve, sitting on the orange dashed line.
- : , so , the MLE. Data drowns out the prior. This is the red curve approaching the blue dashed line on the right. The smooth climb of the red curve from up to is the shrinkage story: evidence gradually overtakes belief.
Exercise 3.2
Rewrite the general Gaussian MAP as a precision-weighted average of the prior mean and the data mean . Show the weights are the precisions (of the prior) and (of the data). Here is the noise variance and the prior variance.
Recall Solution
Log-posterior (drop constants): Differentiate and set to zero: WHY we now group the terms this way: we want a single equation of the form "(coefficient) = (known stuff)", so we sweep every piece containing to one side and every constant to the other. Expand the sum using (there are identical terms, giving ): Now collect the two -terms (they share the unknown ) on the left and push the two known means to the right: Divide by the bracket to isolate : This is a precision-weighted average: each mean is weighted by its precision (1/variance) — how confident we are in it. More data () or a sharper prior () tips the balance accordingly. Plugging recovers .
Exercise 3.3
A prior Beta is placed on a coin's bias. You observe heads in flips. Show the MAP equals the MLE and explain why geometrically.
Recall Solution
Posterior is Beta. Mode , exactly the MLE. Why: Beta is the flat, uniform density on — a totally opinion-free prior. A flat prior adds a constant to the log-posterior, leaving the likelihood peak untouched. This is the L1 principle in action.
Level 4 — Synthesis
Figure 2 — Regularization is a MAP prior: L2 vs L1. The next figure shows why different priors give different regularizers. The horizontal axis is a single weight ; the vertical axis is the penalty (up to a constant). The blue curve is the L2 penalty coming from a Gaussian prior — a smooth bowl. The green curve is the L1 penalty coming from a Laplace prior — a V-shape with a sharp kink at . That kink is the whole point: it lets the optimum sit exactly at , producing the sparsity Lasso is famous for. (In this section denotes the variance of the Gaussian prior on the weights, not a data-noise variance.)

Exercise 4.1
Show that L2 regularization (ridge penalty) is exactly MAP with a zero-mean Gaussian prior. Identify in terms of the prior variance.
Recall Solution
MAP minimises the negative log-posterior: For a Gaussian prior (here is the prior variance on the weights), . So the objective becomes Matching this to the standard ridge form gives A tighter prior (small ) → larger → stronger shrinkage toward . This is why Ridge Regression and L2 regularization are Bayesian at heart. Convention caveat: the exact constant depends on how you write the penalty. If you use you get ; if instead you write the penalty as (many textbooks absorb the into ) you get . The proportionality — tighter prior means stronger penalty — is the invariant message; the leading factor is just bookkeeping.
Exercise 4.2
By analogy, which prior gives L1 regularization (Lasso), and what feature of that prior explains the sparsity Lasso produces?
Recall Solution
A Laplace (double-exponential) prior gives , i.e. the L1 penalty with . Why sparsity: The Laplace prior has a sharp spike at (its density is non-differentiable there). That kink — the green V in the figure above — means the MAP objective can have its optimum sit exactly at , driving many coefficients to precisely zero.
Exercise 4.3
Given ridge with (using the plain convention), what prior variance does this correspond to?
Recall Solution
From : A unit-variance Gaussian prior on the weights.
Level 5 — Mastery
Exercise 5.1 (Degenerate priors)
A student explores Beta priors with shape parameters . Handle three cases and state the honest MAP for each: (a) the symmetric (Jeffreys) prior with heads in flips; (b) the one-sided case ; (c) the one-sided case .
Recall Solution
The interior-mode formula is valid only when and ; otherwise the log-posterior is no longer concave and we must inspect the endpoints directly. Recall the log-density .
(a) Symmetric , no data (posterior = prior). The density blows up to at both endpoints. The formula gives , but that critical point is a minimum, not a maximum. Check the curvature: ; with both terms are positive, so the log-posterior is convex — the interior point is a valley bottom. As and the density , so the maxima sit at the boundaries. Honest MAP: non-unique — maximizers at both and ; the posterior mode is not a single point.
(b) One-sided . The term makes the density non-decreasing pressure toward (as , if , or stays finite if ), while pushes the density to at . The single maximum sits at the left boundary. Honest MAP: .
(c) One-sided . By the mirror-image argument, drives the density up toward while kills it at . The single maximum sits at the right boundary. Honest MAP: .
Take-away: always confirm and before trusting the interior formula; otherwise locate the maximum by checking the boundaries, and be ready to report a non-unique mode.
Exercise 5.2 (Prior fights the data)
Coin: flips, heads (all heads). Prior Beta (strong belief the coin is tails-biased). Compute and comment.
Recall Solution
Posterior Beta Beta. Both shapes , so mode is valid: The MLE is (would insist the coin never lands tails — a classic small-sample overfit). The strong prior drags the estimate all the way to , refusing the extreme claim. This is the safety-rail value of MAP with scarce data.
Exercise 5.3 (Precision limit)
In the Gaussian model, let the prior become infinitely vague, (prior precision ). Show and connect this to Fisher Information. (Here is the fixed noise variance, the prior variance.)
Recall Solution
From Exercise 3.2, prior weight is the prior precision . As this weight : An infinitely vague prior carries no information, so MAP → MLE. The data's weight is exactly the Fisher information of Gaussian samples about — the more information the data carries, the more it dominates a fixed prior.
Exercise 5.4 (Zero data, sharp prior)
observations, Gaussian prior . What is ?
Recall Solution
With no data the data term vanishes; the log-posterior is the log-prior, whose peak is the prior mean: The prior variance affects our confidence, but with zero observations the peak location is simply the prior mean.
Recall Checkpoints
Test yourself before reading the answers.
Recall What does MAP maximise — mode or mean?
The mode (peak) of the posterior , not its mean.
Recall MLE is MAP with which prior?
A uniform (flat) prior — the belief term becomes a constant and drops out of the .
Recall Mode of Beta
when ? (valid only when the log-posterior is concave, i.e. and ; otherwise the maximum sits on a boundary).
Recall Which prior gives the L2 / ridge penalty, and how is
related to it? A zero-mean Gaussian prior; with the convention, (so ).
Recall Which prior gives the L1 / Lasso penalty, and why the sparsity?
A Laplace prior; its sharp spike (kink) at lets the optimum sit exactly at .
Recall The Gaussian MAP mean is what kind of average?
A precision-weighted average of the prior mean and the data mean, each weighted by its precision (1/variance).
Recall What is
precision? Precision — high when you are certain (narrow bell), low when vague (wide bell).