Tutorials › Statistical Learning (Graduate) › PAC-Bayes Guarantees for Approximate Posteriors

PAC-Bayesian Generalization · Tutorial 370 of 989

PAC-Bayes Guarantees for Approximate Posteriors

Learn to separate statistical generalization error from posterior approximation error, with proved bounds and finite-class calculations.

Advanced 10 min read

What You'll Learn

  • State a fixed-temperature PAC-Bayes bound that holds uniformly over data-dependent posteriors.
  • Bound risk changes using total variation between an approximate and target posterior.
  • Relate total variation to the directed KL divergence from the approximation to the target.
  • Identify when approximation KL can also control prior complexity.
  • Calculate finite-class PAC-Bayes guarantees, including their approximation penalties.

Why Posterior Approximation Needs Its Own Error Term

A PAC-Bayes guarantee applies to a distribution over predictors, not only to a single predictor. In practice, the distribution a method can compute may be an approximation to a target posterior: for example, it may come from a numerical procedure or a restricted representation. A guarantee for the target posterior does not automatically become a guarantee for the approximation. The difference in their risks must be controlled, and the PAC-Bayes complexity term may also change.

This tutorial separates these effects. We first give a uniform PAC-Bayes bound for bounded losses, then compare an approximate posterior with a target posterior using total variation. A KL bound can control that discrepancy, but it is important to use the correct direction of KL and not to assume that KL divergence satisfies a triangle inequality.

Setup and a Uniform PAC-Bayes Bound

Let \(\mathcal H\) be a finite hypothesis class, let \(P\) be a prior distribution on \(\mathcal H\) fixed independently of the sample, and let \(Z_1,\ldots,Z_n\) be independent observations from a distribution \(D\). For each \(h\in\mathcal H\), assume the loss \(\ell(h,z)\) is measurable and lies in \([0,1]\). Define the population and empirical risks by

$$ R(h)=E_{Z\sim D}[\ell(h,Z)], \qquad \widehat R_S(h)=\frac{1}{n}\sum_{i=1}^n \ell(h,Z_i). $$

For any distribution \(Q\) on \(\mathcal H\), write \(R(Q)=E_{h\sim Q}[R(h)]\) and \(\widehat R_S(Q)=E_{h\sim Q}[\widehat R_S(h)]\). The KL divergence is \(\operatorname{KL}(Q\|P)=\sum_h Q(h)\log(Q(h)/P(h))\), with zero-mass terms omitted; it is infinite if \(Q\) assigns positive mass where \(P\) is zero.

Theorem: Fix \(\lambda>0\) and \(0<\delta<1\). With probability at least \(1-\delta\) over the sample, simultaneously for every distribution \(Q\) with \(\operatorname{KL}(Q\|P)<\infty\), $$ R(Q)\leq \widehat R_S(Q)+ \frac{\operatorname{KL}(Q\|P)+\log(1/\delta)}{\lambda} +\frac{\lambda}{8n}. $$

The fixed \(\lambda\) matters: the same high-probability event works for every \(Q\), including posteriors chosen after observing the sample. Choosing \(\lambda\) separately from the observed KL of each posterior requires an additional argument. If a family of posteriors is known in advance to satisfy \(\operatorname{KL}(Q\|P)\leq K\), one may choose \(\lambda=\sqrt{8n(K+\log(1/\delta))}\). The resulting bound holds simultaneously over that family, with the two penalty terms summing to \(\sqrt{(K+\log(1/\delta))/(2n)}\).

Proof of the Uniform Bound

For a fixed \(h\), Hoeffding's lemma applied to the independent bounded losses gives

$$ E_S\!\left[\exp\{\lambda(R(h)-\widehat R_S(h))\}\right] \leq \exp\!\left(\frac{\lambda^2}{8n}\right). $$

Indeed, \(R(h)-\widehat R_S(h)\) is the average of \(n\) independent centered variables, each with range length at most one; their moment-generating-function bounds multiply. Define \(Z_S=\sum_h P(h)\exp\{\lambda(R(h)-\widehat R_S(h))\}\). Averaging the preceding inequality over \(P\) gives \(E_S[Z_S]\leq \exp(\lambda^2/(8n))\). Markov's inequality therefore implies that, with probability at least \(1-\delta\),

$$ \log Z_S\leq \frac{\lambda^2}{8n}+\log(1/\delta). $$

On this event, take any \(Q\) with finite KL divergence. On the support of \(Q\), Jensen's inequality gives the change-of-measure inequality

$$ \log\sum_h P(h)e^{\phi(h)} \geq \log E_Q\!\left[e^{\phi(h)}\frac{P(h)}{Q(h)}\right] \geq E_Q[\phi(h)]-\operatorname{KL}(Q\|P). $$

The first inequality holds because the sum over the support of \(Q\) is only part of the full sum over \(P\); it does not require \(Q\) and \(P\) to have identical supports. Apply this inequality with \(\phi(h)=\lambda(R(h)-\widehat R_S(h))\). Combining it with the bound on \(\log Z_S\), then dividing by \(\lambda\), proves the theorem. The event was defined using \(Z_S\), independently of \(Q\), so the conclusion holds simultaneously for every such \(Q\). \(\square\)

Comparing an Approximate Posterior with Its Target

Let \(\rho\) denote a target posterior and \(Q\) an approximate posterior. Their total variation distance is

$$ \operatorname{TV}(Q,\rho)=\frac12\sum_{h\in\mathcal H}|Q(h)-\rho(h)|. $$

For any function \(g:\mathcal H\to[0,1]\), its expectations under these distributions differ by at most this distance. In particular, this holds both for the population risk \(R(h)\) and for the sample-specific empirical risk \(\widehat R_S(h)\).

Theorem: On the event in the uniform PAC-Bayes theorem, for any target posterior \(\rho\) and approximate posterior \(Q\) with finite KL divergence to \(P\), $$ R(Q)\leq \widehat R_S(\rho)+\operatorname{TV}(Q,\rho) +\frac{\operatorname{KL}(\rho\|P)+\log(1/\delta)}{\lambda} +\frac{\lambda}{8n}. $$ Consequently, replacing the target empirical risk by the approximate empirical risk gives the valid, generally looser bound $$ R(Q)\leq \widehat R_S(Q)+2\operatorname{TV}(Q,\rho) +\frac{\operatorname{KL}(\rho\|P)+\log(1/\delta)}{\lambda} +\frac{\lambda}{8n}. $$

To see the first inequality, apply the PAC-Bayes theorem to \(\rho\), then use \(R(Q)\leq R(\rho)+\operatorname{TV}(Q,\rho)\). For the second, also use \(\widehat R_S(\rho)\leq\widehat R_S(Q)+\operatorname{TV}(Q,\rho)\). Both applications are permitted even when the posteriors depend on the sample, because the event is uniform over distributions on \(\mathcal H\).

Controlling Risk Discrepancy with KL Divergence

For finite distributions, Pinsker's inequality states that

$$ \operatorname{TV}(Q,\rho)\leq \sqrt{\frac{\operatorname{KL}(Q\|\rho)}{2}}. $$

Here the direction is \(Q\|\rho\): a small \(\operatorname{KL}(Q\|\rho)\) controls the change from the target to the approximation. If \(Q\) puts mass outside the support of \(\rho\), this KL divergence is infinite and gives no such control.

For completeness, let \(A=\{h:Q(h)>\rho(h)\}\). Then \(\operatorname{TV}(Q,\rho)=Q(A)-\rho(A)\). Grouping the terms of the KL sum over \(A\) and its complement gives

$$ \operatorname{KL}(Q\|\rho)\geq q\log\frac{q}{r}+(1-q)\log\frac{1-q}{1-r}, \qquad q=Q(A),\quad r=\rho(A). $$

This grouping inequality follows by applying Jensen's inequality to the terms in each group; boundary cases follow by continuity or give infinite KL. For fixed \(r\in(0,1)\), the binary expression as a function of \(q\) has value and first derivative zero at \(q=r\), and second derivative \(1/[q(1-q)]\geq4\). Integrating this second-derivative bound between \(r\) and \(q\) yields a lower bound \(2(q-r)^2\). Thus \(\operatorname{KL}(Q\|\rho)\geq2\operatorname{TV}(Q,\rho)^2\), proving the stated inequality.

Substituting Pinsker's inequality into the comparison theorem turns an approximation guarantee in KL into an explicit risk penalty. In the bound using the approximate empirical risk, that penalty is at most \(\sqrt{2\operatorname{KL}(Q\|\rho)}\). Using the target empirical risk instead costs only \(\sqrt{\operatorname{KL}(Q\|\rho)/2}\).

Worked Example: Computing a Posterior's Prior Complexity

Consider a two-hypothesis class with uniform prior \(P=(0.5,0.5)\), and let \(Q=(0.7,0.3)\). Its KL complexity is

$$ \begin{aligned} \operatorname{KL}(Q\|P) &=0.7\log(0.7/0.5)+0.3\log(0.3/0.5)\\ &=0.7\log(1.4)+0.3\log(0.6)\\ &\approx 0.2355306-0.1532477\\ &\approx 0.0822829. \end{aligned} $$

For \(n=100\), \(\delta=0.05\), and fixed \(\lambda=20\), the theorem's excess-risk penalty is

$$ \frac{0.0822829+\log(20)}{20}+\frac{20}{8(100)} \approx \frac{3.078015}{20}+0.025 \approx 0.17890. $$

Thus, on the theorem's event, \(R(Q)\leq\widehat R_S(Q)+0.17890\). This calculation concerns the PAC-Bayes complexity relative to the prior; it is distinct from the extra error incurred when approximating some other target posterior.

Worked Example: Translating Approximation KL into Risk Error

Let the target posterior be \(\rho=(0.8,0.2)\) and the approximation be \(Q=(0.7,0.3)\) on two hypotheses. Their total variation distance is

$$ \operatorname{TV}(Q,\rho) =\frac12(|0.7-0.8|+|0.3-0.2|)=0.1. $$

The directed KL divergence is

$$ \begin{aligned} \operatorname{KL}(Q\|\rho) &=0.7\log(0.7/0.8)+0.3\log(0.3/0.2)\\ &=0.7\log(0.875)+0.3\log(1.5)\\ &\approx -0.093472+0.121640=0.028168. \end{aligned} $$

Pinsker's bound gives \(\operatorname{TV}(Q,\rho)\leq\sqrt{0.028168/2}\approx0.1187\), which is valid but looser than the exact value \(0.1\). If the two hypotheses have empirical risks \(0.10\) and \(0.30\), then \(\widehat R_S(\rho)=0.8(0.10)+0.2(0.30)=0.14\), while \(\widehat R_S(Q)=0.7(0.10)+0.3(0.30)=0.16\). The observed difference \(0.02\) is below the general bound \(0.1\), as it must be for risks in \([0,1]\).

Worked Example: A Finite-Class Approximate-Posterior Guarantee

Take three hypotheses with uniform prior \(P=(1/3,1/3,1/3)\), target posterior \(\rho=(0.6,0.3,0.1)\), and approximation \(Q=(0.5,0.4,0.1)\). Suppose their empirical risks are \(0.05,0.20,0.60\), respectively. Then

$$ \widehat R_S(\rho)=0.6(0.05)+0.3(0.20)+0.1(0.60)=0.15, \qquad \widehat R_S(Q)=0.5(0.05)+0.4(0.20)+0.1(0.60)=0.165. $$

The target's prior complexity and the posterior discrepancy are

$$ \begin{aligned} \operatorname{KL}(\rho\|P) &=0.6\log(1.8)+0.3\log(0.9)+0.1\log(0.3) \approx0.20067,\\ \operatorname{TV}(Q,\rho) &=\tfrac12(0.1+0.1+0)=0.1. \end{aligned} $$

Set \(n=500\), \(\delta=0.05\), and \(\lambda=40\). The common PAC-Bayes penalty is

$$ \frac{0.20067+\log(20)}{40}+\frac{40}{8(500)} \approx\frac{3.19640}{40}+0.01 \approx0.08991. $$

The target-risk comparison therefore gives \(R(Q)\leq0.15+0.1+0.08991=0.33991\). If the bound is written using the approximate empirical risk instead, it gives \(R(Q)\leq0.165+0.2+0.08991=0.45491\). Both hold on the same event of probability at least \(0.95\); the second pays twice for the empirical-risk discrepancy because it changes from the target empirical risk to the approximate one as well as from target to approximate population risk.

When Approximation Also Changes Complexity

The comparison just proved uses the target's KL complexity and pays explicitly for risk discrepancy. One can instead apply the PAC-Bayes theorem directly to \(Q\), but then the complexity is \(\operatorname{KL}(Q\|P)\). These two complexities cannot generally be interchanged using a triangle inequality: KL is not a metric.

A useful exact identity, when \(Q\ll\rho\ll P\), is

$$ \operatorname{KL}(Q\|P) =\operatorname{KL}(Q\|\rho)+E_Q\!\left[\log\frac{\rho(h)}{P(h)}\right]. $$

It follows by splitting \(\log(Q/P)=\log(Q/\rho)+\log(\rho/P)\) on the support of \(Q\). If \(\log(\rho(h)/P(h))\leq M\) everywhere that \(Q(h)>0\), then \(\operatorname{KL}(Q\|P)\leq\operatorname{KL}(Q\|\rho)+M\), and this can be substituted into the direct PAC-Bayes bound for \(Q\). Without a condition of this kind, a small KL divergence from \(Q\) to \(\rho\) alone does not ensure that \(Q\)'s prior complexity is close to \(\rho\)'s.

Common Pitfall

A common mistake is to claim that a small \(\operatorname{KL}(Q\|\rho)\) makes the PAC-Bayes bound for \(Q\) nearly identical to the bound for \(\rho\). That conclusion confuses two different quantities: the risk discrepancy, controlled by total variation, and the prior complexity, which is \(\operatorname{KL}(Q\|P)\). The correction is to state which route is being used. Either compare risks and retain the target complexity, or use \(Q\)'s complexity and justify its relationship to the target's. Also, when replacing the target empirical risk with the approximate empirical risk, include the second total-variation term.

Key takeaway: Approximation error can be separated from generalization error. For bounded losses, total variation controls the risk change; directed KL from the approximation to the target can bound that total variation. The PAC-Bayes complexity must still be evaluated against the prior or controlled by an additional assumption.

Check Your Understanding

Use the definitions and bounds above to answer these questions.

  1. Why does the uniform PAC-Bayes event permit the target posterior to depend on the observed sample?
  2. For losses in \([0,1]\), what bound controls the difference between the empirical risks under \(Q\) and \(\rho\)?
  3. Which direction of KL divergence is used with Pinsker's inequality to control \(\operatorname{TV}(Q,\rho)\), and what happens if \(Q\) assigns mass outside the support of \(\rho\)?
  4. Why does replacing \(\widehat R_S(\rho)\) by \(\widehat R_S(Q)\) add a second total-variation term?
  5. What additional condition would let you bound \(\operatorname{KL}(Q\|P)\) using \(\operatorname{KL}(Q\|\rho)\) and the target-to-prior density ratio?
Clinical Biostats