Foundations to Frontier
Tests
A. Mathematical Foundations › A5 Statistics › Bayesian statistics

Priors, Likelihoods and Posteriors

Bayesian inference treats unknown parameters as uncertain quantities and updates beliefs with data: posterior ∝ likelihood × prior. You will compute posteriors on a grid for any prior (not just conjugate ones), summarize them with means, MAP points and credible intervals (equal-tailed and highest-density), see how prior influence fades with data, understand what a credible interval means compared with a confidence interval, and meet multimodal posteriors in robot localization, where the posterior mean can be a place the robot cannot possibly be.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Updating what you believe

A new gripper arrives. From experience with similar grippers, you think it probably works well, but there’s some chance it’s a dud. That’s your prior. You test it 10 times and it succeeds 6 times. That’s the evidence. Combining the two gives your posterior: what you should believe now. With more tests, the evidence matters more and your starting belief matters less.

Bayesian statistics is just this, done with probabilities: posterior = (how well each explanation predicts the data) × (how plausible it was before), then rescaled to add up to 1.

Belief before, evidence, belief after: Bayes on a grid
prior:
posterior mean 0.602 · MAP 0.843 · 95% HPD region [0.237, 0.936] (not one interval: two separate pieces) · Wilson 95% CI (frequentist) [0.313, 0.832]
Grey dashed: prior. Blue: likelihood of k successes in n trials. Orange: posterior ∝ prior × likelihood (all scaled to share an axis). Shaded: the 95% highest-posterior-density region. Green bar: the frequentist Wilson interval. With the mixture prior and ambiguous data, the posterior keeps two bumps ("works" vs "broken"), which a single interval misdescribes. With lots of data every prior gives nearly the same posterior.
Why engineers care

Robots localize themselves, filters fuse sensors, and engineers estimate failure rates from few tests by combining prior knowledge with data in exactly this way. Bayesian answers come as full distributions, so you can say “there’s a 90% chance the gripper’s success rate is above 70%”.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Your belief before seeing data is the…
  2. 2. With lots of data, the prior matters…
  3. 3. Posterior ∝ …

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Bayes’ rule for parameters

p(θ∣x)=p(x∣θ)p(θ)p(x),p(x)=∫p(x∣θ)p(θ) dθp(\theta\mid x) = \frac{p(x\mid\theta)p(\theta)}{p(x)}, \qquad p(x) = \int p(x\mid\theta)p(\theta)\,d\theta
  • The likelihood p(x∣θ)p(x\mid\theta) is the same function used by MLE (A5.1-4).
  • The prior p(θ)p(\theta) encodes knowledge before the data.
  • The evidence p(x)p(x) is a normalizing constant here. It matters for model comparison (A5.2-5).

Conjugate shortcut (A4.2-5)

A Beta(a,b)\text{Beta}(a, b) prior plus kk successes in nn trials gives a Beta(a+k,b+n−k)\text{Beta}(a + k, b + n - k) posterior. The prior acts like a+ba + b pseudo-trials. The posterior mean a+ka+b+n\frac{a + k}{a + b + n} is a weighted average of the prior mean and k/nk/n, with prior weight a+ba+b+n\frac{a + b}{a + b + n}.

Summaries

  • Posterior mean: minimizes expected squared error.
  • Posterior median: minimizes expected absolute error.
  • MAP: the posterior mode (A5.2-2).
  • Credible interval: an interval with 95% posterior probability. Equal-tailed, or HPD (highest posterior density, the shortest).
📝 Quick check (Level 1)
0/3 answered
  1. 1. Beta(2, 2) prior + 7/10 successes gives…
  2. 2. A Beta(a, b) prior is worth how many pseudo-trials?
  3. 3. The HPD interval is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Any prior: grid and beyond

For one or two parameters, evaluate log⁡p(θ)+log⁡p(x∣θ)\log p(\theta) + \log p(x\mid\theta) on a grid, subtract the maximum (to avoid underflow), exponentiate and normalize. This handles any prior: mixtures, truncations, priors built from expert opinion. For more parameters, grids explode (100d100^d points), and we need Laplace approximation, Monte Carlo, MCMC or variational inference (A5.2-6 to A5.2-9).

Sequential updating

Today’s posterior is tomorrow’s prior: p(θ∣x1,x2)∝p(x2∣θ)p(θ∣x1)p(\theta\mid x_1, x_2)\propto p(x_2\mid\theta)p(\theta\mid x_1) when the data are conditionally independent. Batch and sequential updates agree exactly. This is the logic of recursive Bayesian filters (Kalman, particle filters).

Credible vs confidence intervals

  • A 95% credible interval says: given the model and prior, P(θ∈I∣x)=0.95P(\theta\in I\mid x) = 0.95. That’s the statement people usually want.
  • A 95% confidence interval says: the procedure covers the fixed θ\theta 95% of the time (A5.1-6).
  • They often nearly coincide with lots of data (Bernstein–von Mises). They can differ a lot with little data, strong priors or boundary parameters. If the prior really describes how θ\theta varies across cases, credible intervals are also calibrated in the frequentist sense (Exercise 2).

Choosing priors

  • Informative: from past data or physics.
  • Weakly informative: rule out absurd values, e.g. “a motor constant is within a factor of 10 of the datasheet”.
  • Reference / Jeffreys: p(θ)∝I(θ)p(\theta)\propto\sqrt{I(\theta)}, invariant to reparameterization. For a proportion that’s Beta(12,12)\text{Beta}(\frac12, \frac12).
  • Check prior sensitivity: refit with a different reasonable prior. If the conclusions change, the data alone don’t settle the question.
🐍 Exercise 1: grid posteriors, credible intervals and prior sensitivity
Compute grid posteriors for a success probability. Check the flat-prior case against Beta(8, 4), compare equal-tailed and HPD intervals, verify that sequential updating equals batch updating, and show that a confident wrong prior dominates at n = 10 but not at n = 1000.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Updating on batch 1 and then batch 2 vs both at once gives…
  2. 2. The Jeffreys prior for a Bernoulli p is…
  3. 3. A grid posterior becomes impractical when…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Posterior concentration: Bernstein–von Mises

Under regularity conditions, with a prior that is positive and continuous at the true θ0\theta_0,

p(θ∣x1:n)≈N(θ^MLE,1nI(θ0)−1)p(\theta\mid x_{1:n})\approx\mathcal N\big(\hat\theta_{\text{MLE}}, \tfrac1nI(\theta_0)^{-1}\big)

in total variation as n→∞n\to\infty (van der Vaart, 1998, Ch. 10). The prior washes out, and Bayesian credible intervals become asymptotic confidence intervals. It fails for non-identifiable models, parameters on the boundary, and high-dimensional models where the prior keeps mattering.

Why the posterior mean minimizes expected squared loss

For any estimate aa, E[(θ−a)2∣x]=Var⁡(θ∣x)+(E[θ∣x]−a)2\mathbb E[(\theta - a)^2\mid x] = \operatorname{Var}(\theta\mid x) + (\mathbb E[\theta\mid x] - a)^2, minimized at a=E[θ∣x]a = \mathbb E[\theta\mid x]. Likewise, the posterior median minimizes expected absolute loss, and the mode approximately minimizes 0–1 loss. The best summary depends on the loss. For multimodal posteriors, the mean can sit in a low-probability valley.

Calibration when the prior is right

If θ∼p(θ)\theta\sim p(\theta) and x∼p(x∣θ)x\sim p(x\mid\theta), then for any credible set with P(θ∈C(x)∣x)=0.9P(\theta\in C(x)\mid x) = 0.9, averaging over xx gives P(θ∈C(x))=0.9P(\theta\in C(x)) = 0.9: exact coverage over the joint distribution. This is the basis of simulation-based calibration checks for Bayesian software (Talts et al., 2018).

Exercise 3.1: Show the Beta posterior mean is a weighted average

a+ka+b+n=a+ba+b+n⋅aa+b+na+b+n⋅kn\frac{a + k}{a + b + n} = \frac{a + b}{a + b + n}\cdot\frac a{a + b} + \frac n{a + b + n}\cdot\frac kn.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Bernstein–von Mises says the posterior becomes approximately…
  2. 2. The posterior median minimizes the expected…
  3. 3. If the prior is the true generating distribution, credible intervals are…

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

A beacon seen from a straight drive

A robot drives along a straight line and measures ranges to an unknown beacon. Ranges from points on a line can’t tell which side of the line the beacon is on, so the posterior has two mirror-image modes. The posterior mean lands on the line between them, a place the beacon cannot be. A Gaussian (EKF) summary would be confidently wrong. One range from off the line breaks the symmetry. This is the core difficulty of range-only SLAM, wireless localization and acoustic positioning, and why multi-hypothesis filters, particle filters and grid methods exist (Thrun, Burgard and Fox, 2005; Djugash et al., 2006).

🐍 Exercise 2 (research): multimodal beacon posterior and credible-interval calibration
Compute a 2-D grid posterior for a beacon from range measurements taken along a line. Show the two mirror modes and the useless posterior mean, then add one off-axis range to break the symmetry. Finally, verify that 90% credible intervals cover 90% of the time when the prior is the true generating distribution.

Bayesian inference in AI, robotics and aerospace

  • Recursive state estimation. Kalman, unscented and particle filters are sequential Bayes’ rule (Thrun, Burgard and Fox, 2005). Grid (histogram) filters do this exercise at scale for localization.
  • Reliability from few tests. Beta and gamma priors from heritage hardware combine with a handful of qualification tests to estimate failure rates (Hamada et al., 2008).
  • Bayesian deep learning. Posteriors over network weights, approximated by ensembles, MC dropout or variational methods, give predictive uncertainty for perception and planning (Gal and Ghahramani, 2016; Wilson and Izmailov, 2020).
  • Mission design under uncertainty. Bayesian updating of meteoroid flux, soil properties or atmospheric density as instruments return data.
  • Search and rescue / lost objects. Bayesian search theory updates a probability map after each unsuccessful search (Stone, 1975; used for AF447’s flight recorders).

References

  1. A. Gelman, J. Carlin, H. Stern, D. Dunson, A. Vehtari, D. Rubin (2013). Bayesian Data Analysis, 3rd ed. CRC Press.
  2. E. T. Jaynes (2003). Probability Theory: The Logic of Science. Cambridge University Press.
  3. H. Jeffreys (1946). “An invariant form for the prior probability in estimation problems.” Proc. R. Soc. A, 186.
  4. A. van der Vaart (1998). Asymptotic Statistics, Ch. 10 (Bernstein–von Mises). Cambridge University Press.
  5. S. Talts, M. Betancourt, D. Simpson, A. Vehtari, A. Gelman (2018). “Validating Bayesian inference algorithms with simulation-based calibration.” arXiv:1804.06788.
  6. S. Thrun, W. Burgard, D. Fox (2005). Probabilistic Robotics. MIT Press.
  7. J. Djugash, S. Singh, G. Kantor, W. Zhang (2006). “Range-only SLAM for robots operating cooperatively with sensor networks.” ICRA.
  8. M. Hamada, A. Wilson, C. S. Reese, H. Martz (2008). Bayesian Reliability. Springer.
  9. Y. Gal, Z. Ghahramani (2016). “Dropout as a Bayesian approximation.” ICML.
  10. L. Stone (1975). Theory of Optimal Search. Academic Press; L. Stone et al. (2014), “Search for the wreckage of Air France flight AF 447,” Statistical Science, 29(1).