Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Bet on a crowd, not on one classifier
Instead of picking one classifier, imagine a whole cloud of slightly different ones and, at prediction time, asking a random member of the cloud. Before seeing any data, you write down a prior guess of where good classifiers live. After training, the cloud (the posterior) moves to where the data says. PAC-Bayes says the cloud’s true error is at most its training error plus a penalty for how far it moved from your prior. A wide cloud that didn’t have to move far, meaning a solution robust to perturbation, generalizes well.
PAC-Bayes gives some of the few non-vacuous generalization certificates for neural networks, and it formalizes the intuition that “flat minima generalize”. It also underlies the analysis of Bayesian and ensemble methods, which are used for uncertainty-aware perception and safe learning-based control.
- 1. PAC-Bayes bounds the error of…
- 2. The prior must be chosen…
- 3. The penalty measures…
Level 1: Beginner
★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.Gibbs risk
For a distribution Q over hypotheses, the Gibbs risk is and the empirical version is .
The McAllester bound
For any prior P fixed before the data, with probability at least 1 − δ, simultaneously for all posteriors Q:
Compare with the finite-class bound . A point mass on one of |H| hypotheses under a uniform prior has , so PAC-Bayes generalizes Occam’s razor to continuous classes.
Gaussians
For and , the KL is . Small moves from the prior and large posterior variance (flatness) are cheap.
- 1. KL(N(μ, I) ‖ N(0, I)) for μ = (3, 4):
- 2. The bound holds…
- 3. With a point-mass posterior and a uniform prior on a finite class, KL equals…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.The tighter kl form (Seeger, Maurer)
where kl is the binary KL divergence. Inverting it numerically gives a bound that is much tighter when the training error is small (it behaves like 1/m instead of 1/√m). Pinsker’s inequality recovers McAllester.
Linear classifiers with Gaussian posteriors
For , the stochastic classifier sign(w′·x) errs on (x, y) with probability exactly
a smoothed, margin-based loss. Scaling the mean up (larger r = ‖w‖/σ) lowers this loss but raises KL = r²/2. The bound picks the balance, and this is the origin of PAC-Bayes margin bounds.
Choosing the prior
The prior can be anything that doesn’t look at the evaluation sample. Use a grid of priors with a union bound, or learn the prior on a separate part of the data (a data-dependent prior). The second is the trick behind non-vacuous bounds for deep networks (Dziugaite and Roy, 2017).
- 1. The kl form is tighter mainly when…
- 2. Gibbs error of a Gaussian linear classifier is a…
- 3. A data-dependent prior is valid if…
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.The change of measure (Donsker–Varadhan)
For any measurable f and distributions Q ≪ P:
Proof of the kl bound
Take . Since P doesn’t depend on S, Maurer’s lemma gives , and Markov’s inequality makes with probability at least 1 − δ. On that event, for every Q, change of measure gives . Joint convexity of kl moves the expectation inside: . ∎
Because the high-probability event doesn’t involve Q, the bound holds for all posteriors at once, including the one chosen after looking at the data.
Connections
- Bayes: minimizing over Q gives the Gibbs posterior . With log-loss this is Bayesian inference, and the objective is the (negative) ELBO.
- Flat minima: a large σ with low Gibbs error means that loss stays low under weight noise.
- 1. Donsker–Varadhan bounds E_Q[f] by…
- 2. The bound holds for all Q because…
- 3. The optimal posterior for R̂ + KL/λ is…
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.PAC-Bayes, measured
Exercise 1 (logistic regression, d = 20, 5% label noise). With prior N(0, I), the best kl-form bound at m = 2000 is 0.278 (best r = 12, KL = 72), while the posterior’s true Gibbs error is 0.149. The bound is non-vacuous but about twice the truth. At m = 500 it is 0.367 against 0.200. The square-root (McAllester) form is always looser.
Exercise 2: data-dependent priors. Learn the prior’s direction on the first half of the data and evaluate the bound on the second half. The posterior barely moves from such a prior: KL falls from 32 to 4.4 at m = 500, and from 72 to 1.5 at m = 2000. The bound drops from 0.382 to 0.242 at m = 500, and from 0.253 to 0.121 at m = 2000, close to the true 0.098. Using half the data well is worth more than using all of it with an uninformed prior.
PAC-Bayes in AI, robotics and aerospace
- Deep learning: non-vacuous bounds for MNIST-scale networks (Dziugaite and Roy), and bounds via compression.
- Bayesian deep learning: variational inference as PAC-Bayes bound minimization; ensembles and dropout.
- Robotics: PAC-Bayes control (Majumdar et al.) certifies the success rate of learned policies on novel environments, such as obstacle avoidance for drones.
- Meta-learning: learning the prior across tasks (PAC-Bayes meta-learning).
References
- D. McAllester (1999). “PAC-Bayesian model averaging.” COLT.
- M. Seeger (2002). “PAC-Bayesian generalisation error bounds for Gaussian process classification.” JMLR, 3.
- A. Maurer (2004). “A note on the PAC Bayesian theorem.” arXiv:cs/0411099.
- G. K. Dziugaite, D. M. Roy (2017). “Computing nonvacuous generalization bounds for deep (stochastic) neural networks with many more parameters than training data.” UAI.
- A. Majumdar, A. Farid, A. Sonar (2021). “PAC-Bayes control: learning policies that provably generalize to novel environments.” IJRR, 40.
- P. Alquier (2024). “User-friendly introduction to PAC-Bayes bounds.” Foundations and Trends in Machine Learning, 17.