TensorTau PathToAGI Probability and Uncertainty Level 03

Level 03 · Probability and Uncertainty · Chapter 034

Maximum A Posteriori Estimation

What changes when learning uses both observed data and a prior belief about plausible parameters?

1. From MLE to MAP

Maximum likelihood chooses

θ^MLE=arg⁡max⁡θp(D∣θ).\hat\theta_{MLE}=\arg\max_\theta p(D\mid\theta).

But sometimes parameter values are not equally plausible before seeing data. Bayes gives

p(θ∣D)∝p(D∣θ)p(θ).p(\theta\mid D)\propto p(D\mid\theta)p(\theta).

MAP chooses the most probable parameter after combining data with the prior:

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

Taking logs:

θ^MAP=arg⁡max⁡θ[log⁡p(D∣θ)+log⁡p(θ)].\hat\theta_{MAP}=\arg\max_\theta [\log p(D\mid\theta)+\log p(\theta)].

Or minimizing negatives:

−log⁡likelihood−log⁡prior.\boxed{-\log likelihood-\log prior}.

That second term will look very familiar: it becomes regularization.


2. Gaussian Prior → L2 Regularization

Assume weights have prior

w∼N(0,τ2).w\sim\mathcal N(0,\tau^2).

Then

−log⁡p(w)=constant+w22τ2.-\log p(w)=constant+\frac{w^2}{2\tau^2}.

For many weights:

−log⁡p(w)=constant+λ∥w∥22.-\log p(\mathbf w)=constant+\lambda\|\mathbf w\|_2^2.

Therefore MAP with a zero-centered Gaussian prior is equivalent to optimizing data loss plus an L2 penalty.

Regularization can be interpreted as a prior belief that very large weights are less plausible.


3. Laplace Prior → L1 Regularization

A Laplace prior has density proportional to

e−λ∣w∣.e^{-\lambda|w|}.

Its negative log prior contributes

λ∣w∣.\lambda|w|.

So MAP with a Laplace prior produces L1 regularization, which tends to encourage sparse parameters.


4. Tiny Coin Example

Observe 3 heads and 1 tail. MLE for head probability is

p^=3/4=0.75.\hat p=3/4=0.75.

With very little data, that estimate can be unstable. A prior centered near 0.5 pulls the MAP estimate toward 0.5. As data grows, likelihood usually dominates and prior influence weakens.

This is the core intuition:

little data  → prior matters more
lots of data → evidence dominates

5. MAP Is Still a Point Estimate

Bayesian inference gives a full posterior distribution p(θ∣D)p(\theta\mid D). MAP throws most of that information away and keeps only the highest point.

So MAP is not “fully Bayesian uncertainty.” It is a convenient point estimate informed by a prior.


6. Code Intuition

import torch

w = torch.tensor([3.0, -4.0], requires_grad=True)
data_loss = torch.tensor(2.0)
lambda_ = 0.1

negative_log_prior = lambda_ * (w**2).sum()
map_objective = data_loss + negative_log_prior
print(map_objective)

The penalty is not an arbitrary extra punishment; under a Gaussian prior it is the negative log prior.


7. Break It

A prior is not a license to force the answer you want. Strong priors can overwhelm small datasets. Bad priors can bias estimates. MAP also depends on parameterization and hides posterior uncertainty.


8. Real-World Connection

MAP connects Bayesian reasoning to regularized regression, weight decay intuition, sparse models and probabilistic estimation. It explains why “fit the data” and “prefer simpler/plausible parameters” can live in one objective.


Mastery Check

  1. How does MAP differ from MLE?
  2. Why does a Gaussian prior produce an L2 penalty?
  3. Why does a Laplace prior produce L1?
  4. When does a prior matter most?
  5. Why is MAP not the same as retaining a full posterior?

Bridge to Chapter 035

Likelihood and posterior tell us which outcomes or parameters are plausible. But we still need a number describing how uncertain an entire distribution is.

That number is entropy.

Six ways to work the chapter, climbing from explaining it in your own words to investigating it like a researcher. Reading is not enough — this is where the chapter lands.

Explain

Explain MLE vs MAP using “data evidence” and “prior belief.”

Calculate

Show that the negative log of a zero-mean Gaussian prior is a constant plus a squared-weight penalty.

Predict

With the same prior, compare a dataset of 5 observations with one of 500,000. In which should the prior influence MAP more?

Break

Construct an example where an extremely strong but wrong prior hurts estimation.

Build

Fit a one-parameter regression model with squared error plus L2 penalty. Vary lambda and plot the fitted weight.

Investigate

Compare L1 and L2 regularization on a sparse synthetic regression problem. Which produces more exact zeros?

Ready to Continue?

Continue when you can derive regularization from a prior rather than treating it as a mysterious extra term.