Topic 60 of 62 · Wider ML toolkit
MLE vs MAP vs full Bayesian inference
MediumHow do MLE, MAP, and Bayesian inference differ, and where does weight decay fit in?
1 · Start with the intuition
MLE picks the parameters that make the data most likely. MAP also multiplies by a prior and picks the peak of the posterior. Full Bayesian inference keeps the whole posterior and averages predictions over it. Regularizers like L2 are priors in disguise.
2 · How the mechanism works
Mechanism step 1 of 3 · no question to answer
Likelihood only
MLE: argmax p(D | θ).
Next, we will look at: Add a prior. Move on when this operation makes sense.
Visualizing the behavior
Prior Beta(2, 2) and posterior Beta(5, 2) after 3 heads
Derived- prior 6p(1 − p)
- posterior 30p⁴(1 − p)
3 · The governing equation
θ_MLE = argmax log p(D | θ) θ_MAP = argmax [log p(D | θ) + log p(θ)] Gaussian prior N(0, τ²I) → penalty ‖θ‖² / (2τ²)
Notation: For linear regression with noise variance σ², MAP under N(0, τ²I) is ridge regression with λ = σ²/τ².
With lots of data the likelihood dominates and all three agree. With little data, MLE overfits (a coin that landed heads 3 times gets p = 1), MAP pulls toward the prior, and the Bayesian predictive also accounts for remaining uncertainty. MAP is still a point estimate and depends on how θ is parameterized. For deep nets, exact posteriors are intractable; approximations include ensembles, Laplace approximations, and MC dropout.
4 · Put concrete numbers on it
Worked numbers (from stated assumptions)5 · Common misconception to avoid
“MAP is Bayesian inference.” It uses a prior but discards the posterior’s spread, so it gives no uncertainty and can land on a sharp spike that holds little probability mass.
In practice · implementation & engineering rule of thumb
When you need calibrated uncertainty from a deep network without intractable integrals, a 3- to 5-model deep ensemble (or temperature scaling on a held-out split) is usually the strongest practical baseline.
# Deep ensemble predictive probability and epistemic disagreement: probs = torch.stack([m(x).softmax(dim=-1) for m in ensemble_models], dim=0) mean_prob = probs.mean(dim=0) # Approximate Bayesian predictive disagreement = probs.var(dim=0).mean(dim=-1) # High when models disagree
Go one level deeper
Follow-ups that often come after a correct first answer.
- Deep ensembles as approximate Bayes
- Training several networks from different random initializations and averaging their predictions captures multiple modes of the posterior. Lakshminarayanan et al. found ensembles give strong uncertainty and calibration in practice, often better than single-model approximations.
- Conjugacy
- A Beta prior with a Bernoulli likelihood gives a Beta posterior: add heads to α and tails to β. Conjugate pairs (Gaussian–Gaussian, Dirichlet–categorical) give closed-form updates, which is why they appear in interviews and in practical systems such as bandits.
6 · Self-check & interview synthesis
Explain it in your own words first
Before revealing the reference answer, try answering the opening question aloud in four beats: what it is → how the math works → what trade-off it makes → a concrete number or failure mode.
Follow-up question interviewers often ask next
MediumIs AdamW’s decoupled weight decay still exactly a Gaussian prior?
Show follow-up reasoning
Not exactly. The prior equivalence holds for an L2 term added to the loss under plain gradient descent. AdamW applies decay outside the adaptive update, which is effective regularization but no longer the gradient of a fixed log-prior under Adam’s preconditioning.