Settings

Theme
Lite Mode (saves mobile data)

In Lite Mode, animations and videos don't play until you tap them, and their size is shown first. Interactive widgets still work.

Text size

Back up or move your progress →

Part 1: Math FoundationsProbability and Statistics

MAP estimation and priors

P1.D1145 min●●○ IntermediateReviewed Dec 1, 2026

Why this matters for machine learning

Maximum likelihood trusts the training data completely, which goes wrong when the data are few or noisy. A prior adds what you believed before seeing the data. The most common regularizers in machine learning are priors in disguise.

  • L2 regularization (ridge regression) penalizes the squared length of the weights. It is MAP estimation with a Gaussian prior on the weights, and the penalty strength is λ=σ2/τ2\lambda=\sigma^2/\tau^2. L1 regularization is a Laplace prior and gives sparse weights. (P3.A6: Regularization: L1 and L2, coming soon)
  • Weight decay in a neural network pulls every weight toward 00 at each step. With plain gradient descent it is the gradient of the L2 penalty that a Gaussian prior on the weights gives. (P4.17: Regularization for neural nets, coming soon)
  • An n-gram language model never lets a word pair that was unseen in training have probability 00: add-one or add-kk smoothing adds imagined counts, the same step as the coin's prior. (P6.2: N-gram language models, coming soon)
  • A stronger prior lowers the variance of a fit and adds bias, which is the trade-off behind overfitting and underfitting. (P3.A5: The bias–variance trade-off, coming soon)
  • Naive Bayes needs a prior class probability and smoothed word counts, so that a word never seen in spam does not make spam impossible. (P3.B2: Naive Bayes, coming soon)

Before this: Common distributions, Expectation and variance, Bayes' theorem, Maximum Likelihood Estimation

After this lesson you can

  • Write the posterior as prior times likelihood divided by an evidence that does not depend on the parameters, and define the MAP estimate as arg⁡max⁡θ [LL(θ)+ln⁡p(θ)]\arg\max_\theta\,[\mathrm{LL}(\theta)+\ln p(\theta)], with maximum likelihood as the special case of a flat prior
  • For a coin with a Beta(a,b)\mathrm{Beta}(a,b) prior and kk heads in NN flips, give the posterior Beta(a+k, b+N−k)\mathrm{Beta}(a+k,\,b+N-k), the MAP a+k−1a+b+N−2\frac{a+k-1}{a+b+N-2} and the mean a+ka+b+N\frac{a+k}{a+b+N}, read the prior as imagined flips, and say how its influence fades as NN grows
  • Combine a Gaussian prior with Gaussian data as a precision-weighted average (shrinkage), and derive that a Gaussian prior on weights gives an L2 penalty with λ=σ2/τ2\lambda=\sigma^2/\tau^2 while a Laplace prior gives an L1 penalty that can set weights exactly to 00
  • Say what MAP leaves out compared with the full posterior (spread, skew, the mean), how priors are chosen, and name the pitfalls: a strong wrong prior, and a MAP that changes when the parameter is rewritten

A coin lands heads three times in three flips. Maximum likelihood (P1.D10) says the heads probability is θ^=1\hat\theta=1, so tails is impossible. Would you bet your savings that the next flip is heads? Probably not. You know something the three flips do not say: coins that come out of a pocket are nearly fair, and three flips is very little evidence.

That outside knowledge has a place in the mathematics. It is the prior from Bayes’ theorem (P1.D6). Maximum likelihood asks which parameters make the data most probable and ignores everything else. MAP estimation asks which parameters are most probable after the data and the prior are both taken into account. This lesson shows that the answer for the coin is a tidy formula, that the prior is the same as a few imagined flips, and that the most common trick against overfitting in machine learning, penalizing large weights, is a prior in disguise. P1.D6 and P1.D10 each promised this lesson, and both promises are kept here.

Bayes’ theorem for parameters

P1.D6 used Bayes’ theorem for hypotheses such as “this patient is sick”. A hypothesis can also be a value of a model’s parameter θ\theta, and the evidence the data. The three parts keep their names:

p(θ∣data)⏟posterior=p(data∣θ)⏞likelihood p(θ)⏞priorp(data)⏟evidence.\underbrace{p(\theta\mid\text{data})}_{\text{posterior}} =\frac{\overbrace{p(\text{data}\mid\theta)}^{\text{likelihood}}\ \overbrace{p(\theta)}^{\text{prior}}}{\underbrace{p(\text{data})}_{\text{evidence}}}.

The prior p(θ)p(\theta) says which parameter values were plausible before the data. The likelihood p(data∣θ)=Lik(θ)p(\text{data}\mid\theta)=\mathrm{Lik}(\theta) is the function of P1.D10. The posterior is what you believe after. The evidence p(data)=∫Lik(θ) p(θ) dθp(\text{data})=\int \mathrm{Lik}(\theta)\,p(\theta)\,d\theta is a single number. It has no θ\theta in it, because θ\theta was integrated out, so it only rescales the posterior until its area is 11. When you only want to compare parameter values, it can be ignored:

p(θ∣data) ∝ Lik(θ)  p(θ).p(\theta\mid\text{data})\ \propto\ \mathrm{Lik}(\theta)\;p(\theta).

A small example. For 33 heads in 33 flips the likelihood is Lik(θ)=θ3\mathrm{Lik}(\theta)=\theta^3. Suppose the prior is flat, p(θ)=1p(\theta)=1 on [0,1][0,1]. Then the evidence is ∫01θ3 dθ=14\int_0^1\theta^3\,d\theta=\frac14, and the posterior is θ3/14=4θ3\theta^3/\tfrac14=4\theta^3, which has area 11. Suppose the prior instead is p(θ)=6θ(1−θ)p(\theta)=6\theta(1-\theta), which prefers biases near 12\frac12. The product is 6θ4(1−θ)6\theta^4(1-\theta), the evidence is ∫016θ4(1−θ) dθ=15\int_0^1 6\theta^4(1-\theta)\,d\theta=\frac15, and the posterior is 30 θ4(1−θ)30\,\theta^4(1-\theta). The two priors give different evidence, but only the shape of likelihood times prior decides where the peak is, and with the second prior it is at θ=0.8\theta=0.8, not at 11. The next sections explain why.

From maximum likelihood to MAP

The MAP estimate (maximum a posteriori) is the parameter value at the highest point of the posterior:

θ^MAP=arg⁡max⁡θ p(θ∣data).\hat\theta_{\text{MAP}}=\arg\max_\theta\ p(\theta\mid\text{data}).

Dividing by the evidence changes no ratio between parameter values, so it cannot move the maximum. Taking the log is allowed for the same reason as in P1.D10 (the log is increasing). Using LL(θ)=ln⁡Lik(θ)\mathrm{LL}(\theta)=\ln\mathrm{Lik}(\theta):

θ^MAP=arg⁡max⁡θ [LL(θ)+ln⁡p(θ)]=arg⁡min⁡θ [NLL(θ)−ln⁡p(θ)].\begin{aligned} \hat\theta_{\text{MAP}}&=\arg\max_\theta\ \bigl[\mathrm{LL}(\theta)+\ln p(\theta)\bigr]\\ &=\arg\min_\theta\ \bigl[\mathrm{NLL}(\theta)-\ln p(\theta)\bigr]. \end{aligned}

So MAP is maximum likelihood with an extra term, the log prior. In loss language, −ln⁡p(θ)-\ln p(\theta) is a penalty added to the negative log-likelihood. A parameter value that the prior finds implausible gets a big penalty. A flat prior has ln⁡p(θ)\ln p(\theta) equal to a constant, which adds nothing to the argmax, so maximum likelihood is MAP with a flat prior. For NN i.i.d. examples the recipe of P1.D10 is unchanged: write LL=∑iln⁡p(xi∣θ)\mathrm{LL}=\sum_i\ln p(x_i\mid\theta), add ln⁡p(θ)\ln p(\theta), and maximize.

Maximum likelihoodMAP
MaximizesLL(θ)\mathrm{LL}(\theta)LL(θ)+ln⁡p(θ)\mathrm{LL}(\theta)+\ln p(\theta)
Equals the posterior’s highest point whenthe prior is flatalways
Needsa model of the dataa model of the data and a prior
Small datacan give 00 or 11, or a wild fitpulled toward the prior
Much datathe data decideabout the same as maximum likelihood
Go deeper Flat depends on how the parameter is written

“Flat” means equal density per unit of the parameter, so it depends on the parameter chosen. Write the coin’s bias as θ\theta and take a flat prior on [0,1][0,1]. Rewrite the same coin by its log-odds φ=ln⁡θ1−θ\varphi=\ln\frac{\theta}{1-\theta}. The prior on φ\varphi is then not flat: its density is θ(1−θ)\theta(1-\theta), which is 0.250.25 at φ=0\varphi=0 and 0.0180.018 at φ=4\varphi=4. A flat prior on φ\varphi would be a different belief about the coin.

Maximum likelihood does not care: the MLE of φ\varphi is the log-odds of the MLE of θ\theta, because the log-odds is a one-to-one function of θ\theta. The MAP does care, because a density changes shape when the variable is changed. The pitfalls section works one example. The lesson is that a prior is only fully described together with the parameter it is placed on, and that a MAP value should be read with that parametrization named.

A coin with a Beta prior

For a coin, θ\theta is a number between 00 and 11, so the prior must be a distribution on [0,1][0,1]. A convenient family is the Beta distribution Beta(a,b)\mathrm{Beta}(a,b) with two positive parameters. Its density is proportional to

p(θ) ∝ θa−1(1−θ)b−1.p(\theta)\ \propto\ \theta^{a-1}(1-\theta)^{b-1}.

For a=b=1a=b=1 this is flat. For a=b=2a=b=2 it is a gentle hill centred on 12\frac12. For a=b=20a=b=20 it is a narrow hill. For a=2, b=20a=2,\ b=20 it is a narrow hill near 0.050.05: a strong belief that the coin rarely lands heads. This lesson uses a,b≥1a,b\ge1, which keeps every density finite. Why this family? Look at the likelihood, θk(1−θ)N−k\theta^k(1-\theta)^{N-k} for kk heads in NN flips. It has the same form, powers of θ\theta and 1−θ1-\theta. Multiplying prior by likelihood just adds the exponents:

p(θ∣data)∝θa−1+k×(1−θ)b−1+N−k,\begin{aligned} p(\theta\mid\text{data})&\propto\theta^{a-1+k}\\ &\quad\times(1-\theta)^{b-1+N-k}, \end{aligned}

and that is the density of Beta(a+k, b+N−k)\mathrm{Beta}(a+k,\ b+N-k). The posterior is again a Beta: updating only adds the counts. A prior with this property is called a conjugate prior for that likelihood. Three consequences follow, all for a,b≥1a,b\ge1.

The MAP. The highest point of θA−1(1−θ)B−1\theta^{A-1}(1-\theta)^{B-1} is at A−1A+B−2\frac{A-1}{A+B-2} (set the derivative of the log to zero, as in P1.D10). With A=a+kA=a+k and B=b+N−kB=b+N-k:

θ^MAP=a+k−1a+b+N−2.\hat\theta_{\text{MAP}}=\frac{a+k-1}{a+b+N-2}.

The posterior mean of Beta(A,B)\mathrm{Beta}(A,B) is AA+B\frac{A}{A+B}, which is a+ka+b+N\dfrac{a+k}{a+b+N}.

Imagined flips. Compare with the MLE kN\frac kN. The MAP is the same fraction with a−1a-1 imaginary heads and b−1b-1 imaginary tails added to the real counts. These are called pseudo-counts. For the MAP, the prior acts like a−1a-1 imagined heads and b−1b-1 imagined tails seen before the experiment starts. For the posterior mean it acts like aa heads and bb tails instead, which is why the mean has a+ba+b in its denominator.

For 33 heads in 33 flips:

priorposteriorMAPmean
Beta(1,1)\mathrm{Beta}(1,1)Beta(4,1)\mathrm{Beta}(4,1)110.80.8
Beta(2,2)\mathrm{Beta}(2,2)Beta(5,2)\mathrm{Beta}(5,2)0.80.80.7140.714

With the flat prior the MAP is 33=1\frac33=1, the same as the MLE, and the mean is 45\frac45. With Beta(2,2)\mathrm{Beta}(2,2) the MAP is 45\frac45 and the mean is 57\frac57.

The prior Beta(2,2)\mathrm{Beta}(2,2) is one imaginary head and one imaginary tail: 3+13+2=0.8\frac{3+1}{3+2}=0.8. This is add-one smoothing, also called Laplace smoothing. P1.D10 pointed to it with the same numbers, and P1.D6 gave the version for the mean: from a flat prior, hh heads in nn flips give h+1n+2\frac{h+1}{n+2}, Laplace’s rule of succession. The two 0.80.8 values have different meanings but the same formula, k+1N+2\frac{k+1}{N+2}: the posterior mean under the flat Beta(1,1)\mathrm{Beta}(1,1), and the posterior mode under Beta(2,2)\mathrm{Beta}(2,2). For 22 heads in 22 flips both give 34=0.75\frac34=0.75, the number from P1.D10.

Now try it. The three curves share one vertical axis, because the likelihood is drawn rescaled to have area 11 (the rescaling only changes its height, not its shape, and it is the posterior you would get from a flat prior).

Prior × likelihood → posterior for a coin

Prior
Data
A compromise: both count. The prior counts as 2 imagined flips (1 heads, 1 tails) against 10 real ones, so it has 17% of the weight: MAP = (10 × 0.8 + 2 × 0.5) / 12 = 0.75.
012300.250.50.751heads probability θ

prior likelihood, scaled to area 1 posterior

MLE k/N MAP (posterior mode) posterior mean

prior = Beta(2, 2), mode 0.5, mean 0.5 data: 8 heads in 10, MLE 0.8 posterior = Beta(10, 4) MAP = 0.75 posterior mean = 0.7143 posterior sd = 0.117
A coin's heads probability θ. Pink: the prior Beta(a, b). Blue dashed: the likelihood of k heads in N flips, rescaled to area 1. Green: the posterior Beta(a + k, b + N − k), which is the product of the other two, rescaled to area 1. Markers at the top, with dotted lines down to the axis: the maximum-likelihood estimate k/N (diamond), the MAP (circle, the highest point of the posterior) and the posterior mean (square). Presets: flat, weak, strong fair, and strong but wrong priors, and four data sets. The status line says whether the prior or the data dominate, and the readouts give the exact values.

Things to try:

  • Flat prior, 3 of 3. The posterior has the shape of the likelihood. The MAP equals the MLE and sits at the edge, θ=1\theta=1, while the mean is 0.80.8. A flat prior repairs nothing for the MAP.
  • Weak prior, 3 of 3. Choose Beta(2,2)\mathrm{Beta}(2,2): the MAP moves to 0.80.8, off the edge.
  • Strong fair prior, 8 of 10. The data say 0.80.8 but the MAP is 0.56250.5625, near the prior’s 0.50.5. Move NN to 100100 with 8080 heads: 0.71740.7174. The table below goes on to 10001000 flips and 0.78900.7890.
  • Strong wrong prior. Beta(2,20)\mathrm{Beta}(2,20) believes the coin is mostly tails (mode 0.050.05). After 88 heads in 1010 flips the MAP is 0.30.3 and after 8080 in 100100 it is 0.6750.675: the data pull it far, but slowly.
  • Edges. Set a=1a=1 with k=0k=0: the MAP is 00 whatever bb is, and the status line warns. A flat prior and no data gives a flat posterior with no highest point, so the MAP is undefined.

The prior fades as data arrive

The MAP can be rewritten as a weighted average. Write m=a+b−2m=a+b-2 for the number of imagined flips and θ0=a−1m\theta_0=\frac{a-1}{m} for the prior’s highest point (its mode). Then

θ^MAP=N⋅kN+m⋅θ0N+m.\hat\theta_{\text{MAP}}=\frac{N\cdot\frac kN+m\cdot\theta_0}{N+m}.

The data’s estimate kN\frac kN has weight NN and the prior’s mode has weight mm. The prior’s share is mm+N\frac{m}{m+N}, which shrinks like 1N\frac1N. Here is the strong fair prior Beta(20,20)\mathrm{Beta}(20,20) (m=38m=38, θ0=0.5\theta_0=0.5) against data that are 80%80\% heads:

flips NNheads kkMLEMAPprior’s share of the weight
55440.80.80.53490.534988%88\%
1010880.80.80.56250.562579%79\%
505040400.80.80.67050.670543%43\%
10010080800.80.80.71740.717428%28\%
100010008008000.80.80.78900.78904%4\%

This is the general pattern. With little data the prior decides, with lots of data the data decide, and the MAP and the MLE converge. The prior is not wrong to be strong, it just needs enough evidence to be overruled. A prior that gives zero density to the truth can never be overruled, which is why priors usually leave every plausible value possible, even if unlikely.

A point, and a picture

The MAP is one number. The posterior is the whole distribution, and it also says how sure you are. After 33 heads and 11 tail from a flat prior, the posterior is Beta(4,2)\mathrm{Beta}(4,2):

  • the MAP (mode) is 34=0.75\frac{3}{4}=0.75, equal to the MLE;
  • the mean is 46=0.667\frac46=0.667, and the median is 0.6860.686;
  • the standard deviation is 0.1780.178, and a central 95%95\% range is 0.280.28 to 0.950.95;
  • the probability that the coin favours heads (θ>0.5\theta>0.5) is 0.810.81.

The mode, median and mean differ because the posterior is skewed (it leans against the edge at 11). The mode is the single most probable value, the mean is the best guess to minimize squared error, and the posterior mean is also what you should use to predict the next flip: with a Beta\mathrm{Beta} posterior, the probability of heads on the next flip is exactly a+ka+b+N\frac{a+k}{a+b+N}. MAP throws away the spread, which is why a lot of Bayesian machine learning keeps the whole posterior when it can afford it, and why MAP is the cheap, common point summary when it cannot.

A Gaussian mean with a Gaussian prior

The same idea works for continuous parameters. Suppose NN measurements x1,…,xNx_1,\dots,x_N come from a Gaussian N(μ,σ2)N(\mu,\sigma^2) with a known spread σ\sigma and an unknown mean μ\mu (P1.D3), and the prior says μ∼N(μ0,τ2)\mu\sim N(\mu_0,\tau^2): a best guess μ0\mu_0, with uncertainty τ\tau. The log posterior, up to constants, is

LL(μ)+ln⁡p(μ)=−∑i(xi−μ)22σ2−(μ−μ0)22τ2.\begin{aligned} \mathrm{LL}(\mu)+\ln p(\mu)={}&-\frac{\sum_i(x_i-\mu)^2}{2\sigma^2}\\ &-\frac{(\mu-\mu_0)^2}{2\tau^2}. \end{aligned}

Set the derivative with respect to μ\mu to zero: N(xˉ−μ)σ2=μ−μ0τ2\frac{N(\bar x-\mu)}{\sigma^2}=\frac{\mu-\mu_0}{\tau^2}. Solving for μ\mu gives

μ^MAP=Nσ2 xˉ+1τ2 μ0Nσ2+1τ2.\hat\mu_{\text{MAP}}=\frac{\frac{N}{\sigma^2}\,\bar x+\frac{1}{\tau^2}\,\mu_0}{\frac{N}{\sigma^2}+\frac1{\tau^2}}.

This is a weighted average of the sample mean xˉ\bar x and the prior mean μ0\mu_0. The weights are precisions: precision is 1/variance1/\text{variance} (variance: P1.D4), so a sharper source gets more weight. The data’s precision is Nσ2\frac N{\sigma^2} (it grows with NN) and the prior’s is 1τ2\frac{1}{\tau^2}. The posterior is again Gaussian, with precision equal to the sum Nσ2+1τ2\frac N{\sigma^2}+\frac1{\tau^2}, so it is always narrower than both sources. A Gaussian is symmetric, so its mean and mode coincide and the MAP is also the posterior mean.

Take σ=2\sigma=2, a prior N(0,12)N(0,1^2), and xˉ=3\bar x=3:

NNdata precision N/σ2N/\sigma^2prior’s shareMAP of μ\musd
0000100%100\%0011
110.250.2580%80\%0.60.60.8940.894
441150%50\%1.51.50.7070.707
16164420%20\%2.42.40.4470.447
10010025253.8%3.8\%2.8852.8850.1960.196

The MLE is always 33, and the MAP starts at 00 and creeps toward 33. The pull toward the prior mean μ0\mu_0 is called shrinkage: estimates are shrunk toward a central value. A wider prior (large τ\tau) shrinks less. As τ→∞\tau\to\infty the prior becomes flat and the MAP tends to xˉ\bar x, the maximum-likelihood answer.

Priors on weights are regularizers

Here is the connection that makes this lesson matter for machine learning. Take a linear model with Gaussian noise: yi=w⊤xi+εiy_i=\mathbf{w}^\top\mathbf{x}_i+\varepsilon_i, εi∼N(0,σ2)\varepsilon_i\sim N(0,\sigma^2), with a Gaussian prior on each weight, wj∼N(0,τ2)w_j\sim N(0,\tau^2), independent (a prior centred on 00 that says “weights are probably small”; as a vector, w∼N(0,τ2I)\mathbf{w}\sim N(\mathbf{0},\tau^2\mathbf{I}), the multivariate Gaussian of P1.D7 with no correlation between weights). From P1.D10 the negative log-likelihood is 12σ2∑i(yi−w⊤xi)2\frac1{2\sigma^2}\sum_i(y_i-\mathbf{w}^\top\mathbf{x}_i)^2 plus a constant. The negative log prior is

−ln⁡p(w)=12τ2∑jwj2+constant=∥w∥22τ2+constant.\begin{aligned} -\ln p(\mathbf{w})&=\frac{1}{2\tau^2}\sum_j w_j^2+\text{constant}\\ &=\frac{\lVert\mathbf{w}\rVert^2}{2\tau^2}+\text{constant}. \end{aligned}

Add the two and multiply everything by the positive number 2σ22\sigma^2. The MAP weights minimize

∑i=1N(yi−w⊤xi)2+λ∥w∥2,\sum_{i=1}^N(y_i-\mathbf{w}^\top\mathbf{x}_i)^2+\lambda\lVert\mathbf{w}\rVert^2,

with

λ=σ2τ2.\lambda=\frac{\sigma^2}{\tau^2}.

This is ridge regression (L2 regularization): squared error plus λ\lambda times the squared length of the weights. A Gaussian prior is an L2 penalty. The correspondence tells you what λ\lambda means: a larger noise level σ\sigma means the data are less trustworthy, so shrink more, and a narrower prior (small τ\tau) also shrinks more. If the loss is the average squared error 1N∑i(⋅)2\frac1N\sum_i(\cdot)^2, divide the whole expression by NN: the penalty is then λN∥w∥2\frac{\lambda}{N}\lVert\mathbf{w}\rVert^2, which again shows the prior fading as NN grows. The closed form is w^=(X⊤X+λI)−1X⊤y\hat{\mathbf{w}}=(\mathbf{X}^\top\mathbf{X}+\lambda\mathbf{I})^{-1}\mathbf{X}^\top\mathbf{y}, which exists for every λ>0\lambda>0 even when X⊤X\mathbf{X}^\top\mathbf{X} has no inverse (P1.B12 and P3.A6 explain why adding λI\lambda\mathbf{I} fixes that).

Weight decay. In gradient descent (P1.F3) on the loss plus λ2∥w∥2\frac\lambda2\lVert\mathbf{w}\rVert^2, the penalty’s gradient is λw\lambda\mathbf{w}, so each step first multiplies the weights by (1−ηλ)(1-\eta\lambda) and then takes the usual step. The weights decay toward 00 unless the data pull them away. This is weight decay. Adding the penalty λ2∥w∥2\frac\lambda2\lVert\mathbf{w}\rVert^2 to the loss, an L2 penalty, is a MAP objective with a Gaussian prior (P4.17). With plain gradient descent the two views give the same update. With adaptive optimizers such as Adam, adding the penalty to the loss and decaying the weights directly are no longer the same thing, which is why a separate “decoupled” weight decay (AdamW) exists, and it no longer matches the Gaussian-prior MAP exactly.

A Laplace prior gives an L1 penalty. Suppose each weight instead has a Laplace prior with scale β\beta, density 12βe−∣w∣/β\frac1{2\beta}e^{-\lvert w\rvert/\beta}, a sharp peak at 00 with heavier tails than a Gaussian. Then −ln⁡p(w)=∣w∣β+constant-\ln p(w)=\frac{\lvert w\rvert}{\beta}+\text{constant}, and the same steps give

∑i=1N(yi−w⊤xi)2+λ1∑j∣wj∣,\sum_{i=1}^N(y_i-\mathbf{w}^\top\mathbf{x}_i)^2+\lambda_1\sum_j\lvert w_j\rvert,

with

λ1=2σ2β.\lambda_1=\frac{2\sigma^2}{\beta}.

This is lasso (L1 regularization). It behaves differently from L2, and the next widget shows how. (The Laplace distribution and Laplace’s add-one smoothing are different things that share a name.)

One weight: L2 shrinks, L1 can switch off

Look at a single weight. Measured in units of the data’s own uncertainty, the data alone give the cost (w−z)22\frac{(w-z)^2}{2}, lowest at the maximum-likelihood weight zz. The prior adds its penalty, and the MAP is the lowest point of the sum. Here σ=1\sigma=1, so the penalty strength λ\lambda in the cost (w−z)22+λ2w2\frac{(w-z)^2}2+\frac\lambda2w^2 (L2) or (w−z)22+λ∣w∣\frac{(w-z)^2}2+\lambda\lvert w\rvert (L1) relates to the earlier formulas like this: for L2, λ=σ2/τ2=1/τ2\lambda=\sigma^2/\tau^2=1/\tau^2, the same as before; for L1, λ=λ1/2=1/β\lambda=\lambda_1/2=1/\beta, half of λ1\lambda_1. Both cases have a closed form:

  • Gaussian prior (L2): w^=z⋅τ2τ2+1\hat w=z\cdot\dfrac{\tau^2}{\tau^2+1}. It is a fixed fraction of zz. For z=3z=3 and τ=1\tau=1 it is 1.51.5. It reaches 00 only if z=0z=0.
  • Laplace prior (L1): w^=sign⁡(z)max⁡(∣z∣−1β, 0)\hat w=\operatorname{sign}(z)\max\bigl(\lvert z\rvert-\tfrac1\beta,\ 0\bigr). It subtracts a fixed amount 1β\frac1\beta and stops at exactly 00. For z=3z=3 and β=1\beta=1 it is 22, and for z=0.8z=0.8 it is 00. This is called soft thresholding.

One weight: the data pull one way, the prior pulls to zero

Prior
Gaussian prior (L2 penalty, λ = 1/τ² = 1): MAP = 3 × τ²/(τ² + 1) = 1.5, which is 50% of the data's weight. It shrinks the weight, but it is not exactly 0 for any finite τ.
0246810−4−2024weight w

data: negative log-likelihood prior: its penalty (negative log prior) sum

MLE (lowest point of the data curve) MAP (lowest point of the sum)

MLE weight = 3 MAP weight = 1.5 λ in ½(w − z)² + λ × penalty = 1 kept from the data = 50%
One weight w. Blue dashed: the cost from the data alone (the negative log-likelihood), lowest at the maximum-likelihood weight (diamond). Pink: the penalty from the prior, the negative log prior, with a smooth bowl for the Gaussian prior and a V shape for the Laplace prior. Green: their sum, whose lowest point is the MAP weight (circle). Choose the kind of prior, the data's best weight and the prior's spread. The cost is (w − z)²/2 plus λw²/2 (Gaussian) or λ|w| (Laplace), in units where σ = 1. The readouts show λ, the MAP weight and how much of the data's weight is kept.

Try the Laplace prior with the data’s best weight at 0.80.8. A moderate prior makes the MAP exactly 00, and the Gaussian prior with the same strength only halves it. Then raise the best weight to 33 and see that L1 keeps most of it. The reason is the shape of the penalty at 00: the V has a corner, with slope 1β\frac1\beta on each side, so a weight stays at 00 as long as the data’s pull is weaker than that slope. The bowl is flat at 00, so any pull, however small, moves the weight a little. With many weights, an L1 penalty therefore switches off the weak ones and leaves a sparse solution (many weights exactly 00). P3.A6 shows why this gives feature selection and draws the geometry.

Practical notes on weights. The bias term is usually not penalized, which corresponds to a flat prior on it. A single τ\tau for all weights is a statement that every weight has the same typical size, which is only sensible when the features are on similar scales (P3.A11 covers scaling). And λ\lambda (or τ\tau) is a hyperparameter you choose, usually with a validation set (P3.A4, P4.23), not something that falls out of the data.

Choosing a prior

Where does a prior come from? There is no single answer, and the choices are modelling decisions:

  • Informative priors put real knowledge in: a physical constant, an earlier study, or the knowledge that coins are nearly fair. If the knowledge is right, the estimate improves a lot for small data.
  • Weak priors just rule out absurd values, such as Beta(2,2)\mathrm{Beta}(2,2) for a coin or N(0,102)N(0,10^2) for a weight. They stabilize the fit and give way to the data quickly.
  • Flat priors try to say nothing, but as the Go-deeper box showed, “flat” depends on the parametrization, and a flat prior on a weight with an unbounded range cannot even be a proper distribution (it has no area to normalize).
  • Conjugate priors are chosen for convenience: the posterior has the same form as the prior, as with Beta for a coin, Gaussian for a Gaussian mean, and Dirichlet for category counts. They make the algebra, and the imagined-count reading, work. Many models have no conjugate prior, and MAP is then found by numerical optimization (P1.F3).
  • Regularization strength as a prior is often tuned on held-out data instead of being justified by belief. Both views are useful: you can read λ\lambda as a belief (σ2/τ2\sigma^2/\tau^2) or as a knob.
Go deeper Counts for many categories: add-k smoothing and the Dirichlet prior

The coin’s two outcomes generalize to VV categories, such as the next word out of a vocabulary of size VV (P6.2). The conjugate prior of the categorical distribution is the Dirichlet with one pseudo-count parameter αi\alpha_i per category. After seeing category ii exactly nin_i times in NN draws with all αi=α\alpha_i=\alpha:

  • the posterior mean for category ii is ni+αN+Vα\dfrac{n_i+\alpha}{N+V\alpha};
  • the MAP, for α≥1\alpha\ge1, is ni+α−1N+Vα−V\dfrac{n_i+\alpha-1}{N+V\alpha-V}.

So add-one smoothing ni+1N+V\frac{n_i+1}{N+V} is the posterior mean for α=1\alpha=1, and also the MAP for α=2\alpha=2, the same pair as for the coin (V=2V=2). Add-kk smoothing uses ni+kN+Vk\frac{n_i+k}{N+Vk} with a smaller kk such as 0.10.1. With N=10N=10 and V=5V=5, a category never seen gets 0+110+5=0.067\frac{0+1}{10+5}=0.067 and not 00. This matters because a probability of 00 makes the log-loss infinite, as P1.D10 showed. Better smoothing methods exist for language models (P6.2). Label smoothing (P4.17) also softens targets, but it changes the training targets and is not derived from a prior on the parameters.

What can go wrong

Each pitfall has a condition:

  • A strong wrong prior. A prior that says the coin is mostly tails, Beta(2,20)\mathrm{Beta}(2,20), needs about 130130 flips at 80%80\% heads before the MAP even reaches 0.70.7 (the formula gives exactly 0.70.7 at N=130N=130). The prior’s pseudo-counts are real weight. Check the prior against the data you have, and prefer weaker priors when unsure.
  • MAP can still sit at an edge. Beta(1,b)\mathrm{Beta}(1,b) adds no imaginary heads. After 00 heads in any number of flips the MAP is 00. The prior must give a little room on both sides, as Beta(2,2)\mathrm{Beta}(2,2) does.
  • MAP is not invariant to reparametrization. The posterior Beta(4,2)\mathrm{Beta}(4,2) has its mode at θ=34\theta=\frac34. If the same posterior is written as a density over the log-odds φ\varphi, its highest point is at φ=ln⁡2\varphi=\ln 2, which is θ=23\theta=\frac23. In general the mode in log-odds sits at θ=AA+B\theta=\frac{A}{A+B}, which is the posterior mean, so the two parametrizations disagree about where the MAP is. The MLE does not have this problem. A MAP is therefore always a MAP in some parametrization, and two people who parametrize differently can report different values.
  • MAP is not the whole posterior. It ignores spread and skew. A very tall narrow spike can be the mode while holding almost no probability, which can mislead in high dimension.
  • The prior can look like cheating. Choosing a prior after seeing the data, to get a nicer answer, is a way to fool yourself. Fix the prior, or the way λ\lambda is chosen, before looking at the test set (P3.A4).
  • Regularization has a price. A stronger prior lowers variance and raises bias (P3.A5). An L2 penalty also shrinks useful weights, so too large a λ\lambda underfits.
Go deeper Keeping the whole posterior

The full Bayesian answer does not pick a single θ\theta. It averages predictions over the posterior: p(ynew∣data)=∫p(ynew∣θ) p(θ∣data) dθp(y_{\text{new}}\mid\text{data})=\int p(y_{\text{new}}\mid\theta)\,p(\theta\mid\text{data})\,d\theta. For the coin this gives the posterior mean a+ka+b+N\frac{a+k}{a+b+N} as the probability of heads on the next flip, and its spread says how unsure the estimate is. For a neural network the integral over millions of weights cannot be done exactly, so practical methods approximate it, and the MAP weights (the weights minimizing the loss plus weight decay) are the cheapest summary. This course mentions the idea but does not teach Bayesian neural networks. Confidence intervals and the frequentist alternative are in P1.D13.

Where this shows up in machine learning

  • Regularized regression. Ridge and lasso are the formulas above (P3.A6). The best λ\lambda is chosen by validation (P3.A4).
  • Weight decay in deep learning. Many large networks are trained with some form of it (P4.17). The Gaussian-prior reading explains why each weight is shrunk toward 00.
  • Smoothing counts. Naive Bayes and n-gram language models add pseudo-counts so unseen events keep a small probability (P3.B2, P6.2).
  • Language model pretraining. The loss of P1.D10 is a negative log-likelihood. Adding an L2 penalty to it gives a MAP objective, though the prior is rarely discussed (decoupled weight decay, AdamW, matches that only for plain gradient descent).
  • Bayesian uncertainty. The full posterior over weights gives error bars on predictions, at a high cost for big models.

Intuition

MAP is a tug-of-war. The data pull the estimate toward what they say, k/Nk/N for a coin or xˉ\bar x for a mean. The prior pulls toward what you believed before. Each side pulls with a strength equal to how much information it carries: NN real flips against a+b−2a+b-2 imagined ones, or precision Nσ2\frac{N}{\sigma^2} against 1τ2\frac1{\tau^2}. The knot ends at the weighted average. With more data the data’s team gets bigger and the knot moves toward it.

The analogy breaks in two places. It holds exactly for the coin and the Gaussian, but for other priors the pull is not a fixed weighted average (an L1 prior removes a fixed amount, and can stop at 00). And a tug-of-war has a winner, while MAP is a compromise: with a wrong prior and few data it can be worse than the data alone.

Math

Posterior. p(θ∣D)=Lik(θ) p(θ)/p(D)p(\theta\mid D)=\mathrm{Lik}(\theta)\,p(\theta)/p(D) and p(D)=∫Lik p dθp(D)=\int\mathrm{Lik}\,p\,d\theta, so arg⁡max⁡p(θ∣D)=arg⁡max⁡[LL(θ)+ln⁡p(θ)]\arg\max p(\theta\mid D)=\arg\max[\mathrm{LL}(\theta)+\ln p(\theta)].

Beta–Bernoulli. Prior ∝θa−1(1−θ)b−1\propto\theta^{a-1}(1-\theta)^{b-1}, data kk of NN, posterior Beta(a+k, b+N−k)\mathrm{Beta}(a+k,\,b+N-k). Mode A−1A+B−2\frac{A-1}{A+B-2} for A,B≥1A,B\ge1 (the posterior is flat when A=B=1A=B=1), mean AA+B\frac{A}{A+B}, variance AB(A+B)2(A+B+1)\frac{AB}{(A+B)^2(A+B+1)}. Weighted form: Nθ^MLE+mθ0N+m\frac{N\hat\theta_{\text{MLE}}+m\theta_0}{N+m} with m=a+b−2m=a+b-2.

Gaussian. With μ∼N(μ0,τ2)\mu\sim N(\mu_0,\tau^2) and data N(μ,σ2)N(\mu,\sigma^2): posterior precision Nσ2+1τ2\frac{N}{\sigma^2}+\frac1{\tau^2} and mean Nσ2xˉ+1τ2μ0Nσ2+1τ2\dfrac{\frac N{\sigma^2}\bar x+\frac1{\tau^2}\mu_0}{\frac N{\sigma^2}+\frac1{\tau^2}}.

Weights. NLL=12σ2∑(yi−w⊤xi)2\mathrm{NLL}=\frac1{2\sigma^2}\sum(y_i-\mathbf{w}^\top\mathbf{x}_i)^2. Gaussian prior: λ=σ2/τ2\lambda=\sigma^2/\tau^2 in ∑(⋅)2+λ∥w∥2\sum(\cdot)^2+\lambda\lVert\mathbf{w}\rVert^2, solution (X⊤X+λI)−1X⊤y(\mathbf{X}^\top\mathbf{X}+\lambda\mathbf{I})^{-1}\mathbf{X}^\top\mathbf{y}. Laplace prior: λ1=2σ2/β\lambda_1=2\sigma^2/\beta in ∑(⋅)2+λ1∑∣wj∣\sum(\cdot)^2+\lambda_1\sum\lvert w_j\rvert. One weight, in units of the data’s own uncertainty (σ=1\sigma=1): cost (w−z)22+λ2w2\frac{(w-z)^2}2+\frac\lambda2w^2 (L2) or (w−z)22+λ∣w∣\frac{(w-z)^2}2+\lambda\lvert w\rvert (L1), where zz is the maximum-likelihood weight. L2 gives z1+λ\frac{z}{1+\lambda} with λ=1/τ2\lambda=1/\tau^2, the same λ\lambda as above. L1 gives sign⁡(z)max⁡(∣z∣−λ,0)\operatorname{sign}(z)\max(\lvert z\rvert-\lambda,0) with λ=1/β\lambda=1/\beta, which is half of λ1\lambda_1.

Code

A MAP estimate by maximizing the log posterior on a grid, then by the closed form, and ridge regression with NumPy.

import numpy as np

# coin: 3 heads in 3 flips, Beta(2, 2) prior
theta = np.linspace(0.0005, 0.9995, 1999)
log_post = 3 * np.log(theta) + (2 - 1) * np.log(theta) + (2 - 1) * np.log(1 - theta)
print(theta[np.argmax(log_post)], (2 + 3 - 1) / (2 + 2 + 3 - 2))   # 0.8 and 0.8

# ridge: minimize ||y - Xw||^2 + lam ||w||^2 with lam = sigma^2 / tau^2
X = np.random.default_rng(0).normal(size=(20, 3))
y = X @ np.array([1.0, 0.0, -2.0]) + np.random.default_rng(1).normal(size=20)
lam = 1.0
w_map = np.linalg.solve(X.T @ X + lam * np.eye(3), X.T @ y)

In PyTorch the same L2 penalty is the weight_decay argument of an optimizer such as torch.optim.SGD.

Try it: MAP in code

The first cell finds the MAP for several coins by maximizing the log posterior on a fine grid, compares it with the formula, and prints how the prior fades. The second cell fits a regression with two nearly identical features: the maximum-likelihood weights are large and of opposite signs, and the MAP weights are similar in size and both positive. It checks the ridge formula against gradient descent on the negative log posterior, varies τ\tau, and compares L2 with L1 on one weight.

Try it: the coin's MAP on a grid, and the prior fading

Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).

The first line of output shows the flat prior: the MAP by the formula is 1.00001.0000, the same as the MLE (the grid stops at its last point, 0.99950.9995, because the true peak is the edge). Next comes Beta(2,2)\mathrm{Beta}(2,2) with 0.80000.8000. Strong priors give 0.56250.5625 (Beta(20,20)\mathrm{Beta}(20,20), 88 of 1010), 0.30000.3000 (Beta(2,20)\mathrm{Beta}(2,20), 88 of 1010) and 0.67500.6750 (Beta(2,20)\mathrm{Beta}(2,20), 8080 of 100100). For the other four coins the grid MAP and the formula agree to four decimals. The second table shows the prior’s share falling from 0.8840.884 to 0.0370.037 while the MAP rises from 0.53490.5349 to 0.78900.7890.

Try it: ridge as MAP, and L2 versus L1

Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).

The unpenalized fit is (2.843, −0.849)(2.843,\,-0.849): with two nearly equal features, a large positive weight and a negative one almost cancel, and a small change in the data would change them a lot. The ridge fit is (1.093, 0.900)(1.093,\,0.900), and gradient descent on the negative log posterior reaches the same weights. As τ\tau shrinks from 1010 to 0.10.1 the weights shrink, and their length falls from 2.6082.608 to 0.7420.742. In the last lines, L1 sets the weight 0.80.8 to exactly 00 while L2 halves it to 0.40.4.

Common mistakes

Check your understanding

  1. A coin has a flat prior on its heads probability, and you see 77 heads in 1010 flips. Which statement about the MAP estimate is correct?

  2. A coin gives 33 heads in 33 flips. With a Beta(2,2)\mathrm{Beta}(2,2) prior, what is the MAP estimate?

  3. You fit y=w⊤x+y=\mathbf{w}^\top\mathbf{x}+ noise, with noise spread σ\sigma and a Gaussian prior N(0,τ2)N(0,\tau^2) on each weight, and minimize ∑i(yi−w⊤xi)2+λ∥w∥2\sum_i(y_i-\mathbf{w}^\top\mathbf{x}_i)^2+\lambda\lVert\mathbf{w}\rVert^2. Which λ\lambda gives the MAP estimate?

  4. One weight has maximum-likelihood value 0.80.8. Which prior, with a strong enough penalty, makes the MAP weight exactly 00?

  5. Data: xˉ=3\bar x=3 from N=16N=16 measurements with σ=2\sigma=2. Prior: μ∼N(0,12)\mu\sim N(0,1^2). What is the MAP estimate of μ\mu?

Exercises

  1. A coin has a Beta(3,3)\mathrm{Beta}(3,3) prior and gives 66 heads in 88 flips. Find the posterior, the MAP, the posterior mean and the MLE.
    Show answerThe posterior is Beta(9,5)\mathrm{Beta}(9,5). The MAP is 3+6−13+3+8−2=812=0.667\frac{3+6-1}{3+3+8-2}=\frac8{12}=0.667, the mean is 914=0.643\frac9{14}=0.643 and the MLE is 68=0.75\frac68=0.75. The prior pulls the estimate toward 12\frac12.
  2. After 00 heads in 55 flips, give the MLE, the MAP under Beta(1,1)\mathrm{Beta}(1,1), the MAP under Beta(2,2)\mathrm{Beta}(2,2) and the posterior mean under Beta(1,1)\mathrm{Beta}(1,1).
    Show answerThe MLE is 00. The MAP under Beta(1,1)\mathrm{Beta}(1,1) is also 00 (the flat prior changes nothing). The MAP under Beta(2,2)\mathrm{Beta}(2,2) is 17=0.143\frac{1}{7}=0.143, and so is the posterior mean under Beta(1,1)\mathrm{Beta}(1,1), 17\frac{1}{7}.
  3. How many real flips balance the imagined flips of a Beta(11,11)\mathrm{Beta}(11,11) prior, so that the data and the prior have the same weight in the MAP?
    Show answerThe prior counts as a+b−2=20a+b-2=20 imagined flips, so N=20N=20 real flips give equal weight.
  4. Data have σ=1\sigma=1, N=4N=4 and xˉ=2\bar x=2. The prior is μ∼N(0,0.52)\mu\sim N(0,0.5^2). Find the MAP of μ\mu.
    Show answerThe data precision is 41=4\frac{4}{1}=4 and the prior precision is 10.25=4\frac1{0.25}=4. Equal weights give 4⋅2+4⋅08=1\frac{4\cdot2+4\cdot0}{8}=1.
  5. A regression has noise spread σ=2\sigma=2 and a prior N(0,0.52)N(0,0.5^2) on each weight. What penalty λ\lambda is it in ∑(y−w⊤x)2+λ∥w∥2\sum(y-\mathbf{w}^\top\mathbf{x})^2+\lambda\lVert\mathbf{w}\rVert^2? What if the loss is instead the mean over N=100N=100 examples?
    Show answerλ=σ2τ2=40.25=16\lambda=\frac{\sigma^2}{\tau^2}=\frac{4}{0.25}=16. For the average loss the penalty coefficient becomes λN=0.16\frac{\lambda}{N}=0.16.
  6. A single weight has data-only value z=2z=2 and penalty strength λ=0.5\lambda=0.5, in the cost (w−2)22+λ2w2\frac{(w-2)^2}2+\frac\lambda2w^2 (L2) or (w−2)22+λ∣w∣\frac{(w-2)^2}2+\lambda\lvert w\rvert (L1). Give the L2 and the L1 answers.
    Show answerL2: 21+0.5=1.333\frac{2}{1+0.5}=1.333. L1: 2−0.5=1.52-0.5=1.5. L1 removed a fixed amount, and L2 a fixed fraction.
  7. Compute the standard deviation of the posterior Beta(7,3)\mathrm{Beta}(7,3) from the P1.D6 exercise (Beta(2,2)\mathrm{Beta}(2,2) prior, 55 heads, 11 tail), and say what it tells you about the mean 0.70.7.
    Show answer7⋅3102⋅11=0.138\sqrt{\frac{7\cdot3}{10^2\cdot11}}=0.138. The coin’s bias is only known to about ±0.14\pm0.14 (one standard deviation), so a single number such as 0.70.7 hides how uncertain the estimate is.
  8. A prior Beta(2,20)\mathrm{Beta}(2,20) meets data with 80%80\% heads. How many flips NN are needed for the MAP to reach 0.70.7?
    Show answerSolve 2+0.8N−122+N−2=0.7\frac{2+0.8N-1}{22+N-2}=0.7, so 1+0.8N=14+0.7N1+0.8N=14+0.7N and N=130N=130 (with 104104 heads). Check: 105150=0.7\frac{105}{150}=0.7.
  9. An n-gram model has seen the current word 1010 times, and 55 different words are possible next. Under add-one smoothing, what probability does a never-seen next word get?
    Show answer0+110+5=115=0.067\frac{0+1}{10+5}=\frac1{15}=0.067. Without smoothing it would be 00, with infinite loss.
  10. Why is the bias term usually left out of the L2 penalty?
    Show answerPenalizing it would shrink the model’s baseline toward 00 (for example, the average output), which has no reason to be small. Not penalizing it is the same as a flat prior on the bias.
  11. Why does a Laplace prior give sparse solutions but a Gaussian prior does not?
    Show answerThe negative log Laplace density ∣w∣/β\lvert w\rvert/\beta has a corner at 00, with a slope of 1β\frac1\beta on each side, so a weight whose data pull is weaker than 1β\frac1\beta stays at exactly 00. The Gaussian’s w2/(2τ2)w^2/(2\tau^2) has zero slope at 00, so every non-zero pull gives a non-zero weight.
  12. The posterior Beta(4,2)\mathrm{Beta}(4,2) has mode 0.750.75 and mean 0.6670.667. Which one do you use to predict the next flip, and why?
    Show answerThe mean: the predictive probability of heads is the posterior mean a+ka+b+N=46\frac{a+k}{a+b+N}=\frac46, because it averages over the uncertain θ\theta. The mode is the single most probable θ\theta, not the best predictive probability.

Next: P1.D12 summarizes data without a model (mean, median, percentiles). P1.D13 asks how far results can be trusted when the data are a random sample, and P1.E1 to P1.E4 turn the negative log probabilities used here into information, entropy and cross-entropy. P3.A6 develops L1 and L2 regularization in practice, P4.17 puts weight decay in neural networks, and P6.2 smooths n-gram counts.

Key takeaways

  • Bayes for parameters: p(θ∣data)=p(data∣θ) p(θ)p(data)p(\theta\mid\text{data})=\dfrac{p(\text{data}\mid\theta)\,p(\theta)}{p(\text{data})}. The evidence p(data)p(\text{data}) is the same for every θ\theta, so the posterior is proportional to likelihood times prior. The MAP estimate (maximum a posteriori) is the highest point of the posterior, arg⁡max⁡θ[LL(θ)+ln⁡p(θ)]\arg\max_\theta[\mathrm{LL}(\theta)+\ln p(\theta)]. Maximum likelihood is MAP with a flat prior.
  • Coin with a Beta prior: Beta(a,b)\mathrm{Beta}(a,b) acts like a−1a-1 imagined heads and b−1b-1 imagined tails. After kk heads in NN flips the posterior is Beta(a+k, b+N−k)\mathrm{Beta}(a+k,\,b+N-k), the MAP is a+k−1a+b+N−2\frac{a+k-1}{a+b+N-2} (for a,b≥1a,b\ge1) and the posterior mean is a+ka+b+N\frac{a+k}{a+b+N}. With 33 heads in 33 flips, Beta(2,2)\mathrm{Beta}(2,2) gives the MAP 0.80.8 and Beta(1,1)\mathrm{Beta}(1,1) gives the mean 0.80.8: both are add-one smoothing, k+1N+2\frac{k+1}{N+2}.
  • The prior fades. The MAP is a weighted average of the data's k/Nk/N and the prior's mode, with weights NN and a+b−2a+b-2. With more data the prior's share shrinks like 1/N1/N. A strong prior needs much data to be overruled, and a strong wrong prior can mislead for a long time.
  • Gaussian data, Gaussian prior: the posterior mean is a precision-weighted average of the prior mean and the sample mean, with precision 1/variance1/\text{variance}. The estimate is pulled toward the prior mean, which is called shrinkage.
  • Priors are regularizers. For y=w⊤x+y=\mathbf{w}^\top\mathbf{x}+ Gaussian noise of spread σ\sigma, a Gaussian prior N(0,τ2)N(0,\tau^2) on each weight gives the ridge penalty λ∥w∥2\lambda\lVert\mathbf{w}\rVert^2 with λ=σ2/τ2\lambda=\sigma^2/\tau^2 (weight decay), and a Laplace prior gives an L1 penalty λ1∑∣wj∣\lambda_1\sum\lvert w_j\rvert that can make weights exactly 00.
  • Limits of MAP. It is a single point: the full posterior also gives spread and skew, and its mean and mode differ when it is skewed (Beta(4,2)\mathrm{Beta}(4,2): mode 0.750.75, mean 0.6670.667). MAP depends on how the parameter is written, unlike maximum likelihood. A prior is a modelling choice and can be wrong.
Found a mistake? Tell us