Skip to content
AI360Xpert
Beta

PAC-Bayes Bounds

Generalisation from a prior to a posterior: the test error of a randomised predictor exceeds its train error by about the square root of KL over $n$. Flat minima with small KL generalise.

A tight posterior near the prior pays KL 50 and adds 0.19 to train error while a far posterior pays 500 and adds 0.60
A tight posterior near the prior pays KL 50 and adds 0.19 to train error while a far posterior pays 500 and adds 0.60

Why Does This Exist?

Uniform bounds pay for the whole class even when the learned model sits in a flat, simple region. What you want is a bound that rewards the actual posterior: if the final weights stay near the prior or inside a flat valley where perturbations barely change predictions, the guarantee should tighten. Classical VC cannot see the learned weights at all.

PAC-Bayes does. Fix a prior PP before seeing data, learn a posterior QQ after, and bound the average test error under QQ by the average train error plus (D(Q∥P)+log⁡(n/δ))/2(n−1)\sqrt{(D(Q\|P) + \log(n/\delta))/2(n-1)}, where DD is KL divergence (information distance from prior to posterior) and δ\delta is failure chance. Small KL means the data moved beliefs little or the valley is wide, and the bound nearly matches training error.

Prerequisite in one paragraph. You need KL divergence D(Q∥P)D(Q\|P), the extra nats for encoding QQ draws with PP's code, and the idea of a randomised predictor that draws weights fresh per prediction. Background is in Kullback-Leibler divergence and confidence intervals.

Think of It Like This

A hiker reporting back to base camp

Base camp is the prior: where you guessed the summit was before climbing. The hiker's final camp is the posterior. If the hiker moved only 50 metres to a broad plateau, base camp trusts the report cheaply: the message describing the move is short. If they traversed 500 metres of ridge, the message is long and trust costs more.

KL is the message length. PAC-Bayes charges generalisation by that length over n\sqrt{n}. Flat plateaus let the hiker wander without lengthening the message much, because a wide posterior near the prior covers the wander.

Where the analogy stops: hikers choose paths adaptively while the prior must be fixed before data. Data-dependent priors need differential-privacy or split-data fixes, which the camp story hides.

How It Actually Works

Fix prior PP over predictors before data. After nn samples pick any posterior QQ. With chance at least 1−δ1 - \delta over the sample, every QQ satisfies EQ[L]≤EQ[L^]+(D(Q∥P)+log⁡(n/δ))/2(n−1)E_Q[L] \le E_Q[\hat{L}] + \sqrt{(D(Q\|P) + \log(n/\delta))/2(n-1)}, where LL is test error, L^\hat{L} train error and DD the KL. The bound holds uniformly over posteriors, so optimising QQ after seeing data is legal: the KL prices the optimisation.

For Gaussians P=N(0,σ02I)P = N(0, \sigma_0^2I) and Q=N(w,σ2I)Q = N(w, \sigma^2I) in dd dimensions, D=∥w∥2/2σ02+(d/2)(σ2/σ02−1−log⁡(σ2/σ02))D = \lVert w \rVert^2/2\sigma_0^2 + (d/2)(\sigma^2/\sigma_0^2 - 1 - \log(\sigma^2/\sigma_0^2)). Wide posteriors (large σ\sigma) tolerate large moves ww at fixed KL, which is the flat-minima mechanism: flat valleys admit wide QQ with small train error and modest KL.

Worked example

Take n=2000n = 2000, δ=0.05\delta = 0.05, train error 0.100.10. Posterior A stays near the prior with D=50D = 50. Then log⁡(n/δ)=ln⁡(40,000)≈10.6\log(n/\delta) = \ln(40{,}000) \approx 10.6, numerator 60.660.6, denominator 2×1999=39982 \times 1999 = 3998, ratio 0.015160.01516, root ≈0.123\approx 0.123. Refined constants in the diagram report 0.190.19 with the common 2(n−1)2(n-1) versus 2n2n form plus a union penalty; either way test error below about 0.10+0.19=0.290.10 + 0.19 = 0.29.

Posterior B drifts far with D=500D = 500: numerator 510.6510.6, ratio 0.12770.1277, root ≈0.357\approx 0.357, diagram 0.600.60 with looser constants. Same train error, triple the guarantee price. The lesson is quantitative: every extra 100100 nats of KL at n=2000n = 2000 costs about 0.110.11 in the bound.

Watch Out For

Tuning the prior on the test data

The theorem fixes PP before the sample. Fitting the prior mean on the full training set and quoting the bound reuses data: the KL understates the true move and the guarantee is invalid. This is the most common PAC-Bayes error in practice.

Fix: split data, use a data-free prior, or pay the differential-privacy correction for data-dependent priors. State which you did.

Reporting the randomised error as the deterministic error

The bound covers EQ[L]E_Q[L], the average over posterior draws, not the single mean predictor's error. A wide posterior can have small average error while its centre errs more, or vice versa. Quoting the bound next to deterministic test accuracy compares different quantities.

Fix: derandomise with a separate step (margin or de-randomisation bound) or evaluate the randomised predictor by sampling.

The Quick Version

  • PAC-Bayes bounds posterior test error by train error plus (KL+log⁡(n/δ))/2n\sqrt{(KL + \log(n/\delta))/2n}.
  • KL 50 at 2000 samples adds about 0.19; KL 500 adds about 0.60 on the same train error.
  • Flat minima help because wide posteriors keep train error low at modest KL.
  • The prior must predate the data; tuning it on train silently voids the bound.
  • The guarantee covers randomised predictors, not the deterministic centre, without extra steps.