Tutorials › Statistical Learning (Graduate) › Posterior-Averaged Risk and Gibbs Prediction

PAC-Bayesian Generalization · Tutorial 356 of 989

Posterior-Averaged Risk and Gibbs Prediction

Learn how posterior-averaged risk relates to the error of a randomized Gibbs prediction, and why an average-risk guarantee is not a guarantee for every predictor drawn.

Advanced 11 min read

What You'll Learn

  • Define population and empirical risk for a posterior distribution over predictors.
  • Relate posterior-averaged risk to the expected loss of a randomized Gibbs prediction.
  • Derive a high-probability PAC-Bayes bound for bounded losses.
  • Distinguish the risk averaged over posterior draws from the risk of one realized draw.
  • Identify why averaging predictions or taking a typical posterior draw changes the performance question.

Two Risks That Sound Similar

A PAC-Bayes guarantee often involves a posterior distribution \(Q\) over predictors. The risk in such a bound is averaged over that distribution: draw a predictor according to \(Q\), then average its population loss. A Gibbs prediction makes precisely such a random draw before predicting. This connects the PAC-Bayes quantity to a randomized prediction rule, but the connection is an expectation—not a guarantee that every predictor in the posterior performs well.

The distinction matters because the risk of a posterior draw is itself random. A posterior can put most of its mass on low-risk predictors and a small amount on high-risk ones, or it can spread its mass across predictors with similar risks. Both situations can have the same posterior-averaged risk but different probabilities of drawing a poor predictor. We will make these performance criteria precise and derive a bound for the average.

Posterior-Averaged Population and Empirical Risk

Let \(Z=(X,Y)\) be a test observation with distribution \(D\), and let \(h\) be a predictor from a measurable class \(\mathcal H\). Suppose the loss \(\ell(h,Z)\) is measurable and takes values in \([0,1]\). The population risk of a fixed predictor is its expected loss on a fresh observation. Given an independent training sample \(S=(Z_1,\ldots,Z_n)\) drawn identically from \(D\), its empirical risk is the average loss on that sample.

$$ 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). $$

A posterior \(Q\) is a probability distribution over \(\mathcal H\); it may depend on the observed sample. Its posterior-averaged population and empirical risks are

$$ R(Q)=E_{h\sim Q}[R(h)], \qquad \widehat R_S(Q)=E_{h\sim Q}[\widehat R_S(h)]. $$

These quantities average losses over predictors. In particular, \(R(Q)\) is an ordinary number once \(Q\) is fixed. By contrast, if \(H\sim Q\), then \(R(H)\) is a random variable: it is the population risk of the predictor actually drawn.

Definition: A Gibbs prediction draws \(H\sim Q\) and uses \(H\) to predict. Its risk is the expected loss over both a fresh test observation and the internal random draw: \(R_{\mathrm{Gibbs}}(Q)=E_{H\sim Q,\,Z\sim D}[\ell(H,Z)]\). The draw may be made once for a predictor used on future observations, or afresh for each prediction. For the expected loss on one fresh observation, both conventions have the same risk.

Why Gibbs Risk Equals Posterior-Averaged Risk

The equality follows from iterated expectation. The assumptions above ensure that the loss is measurable and bounded, so the expectations exist and the order of integration can be interchanged.

Proposition: For a measurable loss with \(E_{h\sim Q,Z\sim D}[|\ell(h,Z)|]<\infty\), \(R_{\mathrm{Gibbs}}(Q)=R(Q)\). If \(\ell\) is nonnegative, the equality also holds as an equality of extended expectations, even when the risk is infinite.

Proof. By the definition of the joint draw and Tonelli's theorem for a nonnegative loss (or Fubini's theorem when the loss is integrable),

$$ E_{H\sim Q,\,Z\sim D}[\ell(H,Z)] =E_{H\sim Q}\!\left[E_{Z\sim D}[\ell(H,Z)]\right] =E_{H\sim Q}[R(H)] =R(Q). $$

Thus the posterior-averaged risk is exactly the expected test loss of a randomized Gibbs prediction. The equality does not say that the random variable \(R(H)\) equals its expectation for each draw. \(\square\)

Worked Example: A Gibbs Classifier With Two Possible Risks

Suppose \(Q\) assigns probability \(0.8\) to classifier \(h_1\), whose population misclassification risk is \(0.25\), and probability \(0.2\) to classifier \(h_2\), whose risk is \(0.75\). Use zero-one loss, so risk is the probability of misclassification.

The posterior-averaged risk is

$$ R(Q)=0.8(0.25)+0.2(0.75)=0.20+0.15=0.35. $$

A single Gibbs draw has risk \(0.25\) with probability \(0.8\), and risk \(0.75\) with probability \(0.2\). Its expected risk is \(0.35\), as calculated. But the realized predictor does not have risk \(0.35\): its risk is either \(0.25\) or \(0.75\). In particular, the average alone does not promise that a drawn classifier has risk at most \(0.35\).

A High-Probability PAC-Bayes Guarantee

The PAC-Bayes bound below makes the controlled quantity explicit. Let \(P\) be a prior distribution on \(\mathcal H\), fixed independently of the training sample. For probability measures \(Q\) and \(P\), \(\mathrm{KL}(Q\|P)\) is their Kullback–Leibler divergence; it is infinite unless \(Q\) is absolutely continuous with respect to \(P\). The bound holds simultaneously for all posteriors, including posteriors selected after seeing the sample.

Theorem: Suppose \(Z_1,\ldots,Z_n\) are independent and identically distributed from \(D\), the loss is measurable and lies in \([0,1]\), and \(P\) is a fixed prior. For any fixed \(\lambda>0\) and \(\delta\in(0,1)\), with probability at least \(1-\delta\) over \(S\), every posterior \(Q\) satisfies
$$ R(Q)\leq \widehat R_S(Q) +\frac{\mathrm{KL}(Q\|P)+\log(1/\delta)}{\lambda} +\frac{\lambda}{8n}. $$

The temperature \(\lambda\) in this version is fixed before observing the sample. The terms on the right are empirical posterior-averaged risk, a complexity and confidence penalty, and a bounded-loss concentration penalty.

Proof. For each 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). $$

Integrate this inequality with respect to \(P\). Tonelli's theorem applies because the integrand is nonnegative, so

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

Markov's inequality therefore implies that, with probability at least \(1-\delta\), the integral inside the expectation is at most \(\exp\{\lambda^2/(8n)\}/\delta\). This is a single event depending on \(S\), not on \(Q\).

On that event, apply the change-of-measure inequality \(E_Q[g]\leq \mathrm{KL}(Q\|P)+\log E_P[e^g]\), valid for measurable \(g\) when the displayed expectations exist. With \(g(h)=\lambda(R(h)-\widehat R_S(h))\), this yields

$$ \lambda\{R(Q)-\widehat R_S(Q)\} \leq \mathrm{KL}(Q\|P)+\frac{\lambda^2}{8n}+\log(1/\delta). $$

If \(\mathrm{KL}(Q\|P)=\infty\), the stated bound is vacuous; otherwise divide by \(\lambda>0\). Since the event was uniform over \(Q\), the conclusion holds for every posterior on that event. \(\square\)

The theorem bounds \(R(Q)\), which the proposition identifies with the expected loss of a Gibbs prediction. It is not a bound on the risk of every predictor in the support of \(Q\), nor does it by itself bound the probability that one posterior draw has risk above a specified threshold.

Worked Example: Reading a PAC-Bayes Bound as a Gibbs Guarantee

Suppose \(n=100\), a posterior has empirical risk \(\widehat R_S(Q)=0.12\) and \(\mathrm{KL}(Q\|P)=2\), and we seek confidence \(1-\delta=0.95\). Use the theorem with the fixed choice \(\lambda=20\). Since \(\log(1/0.05)=\log(20)\approx 2.996\), the complexity and confidence penalty is

$$ \frac{2+2.996}{20}=0.2498, \qquad \frac{20}{8(100)}=0.025. $$

Consequently, on the theorem's event,

$$ R(Q)\leq 0.12+0.2498+0.025=0.3948. $$

This is a high-probability statement about the training sample: with probability at least \(0.95\), the posterior-averaged population risk is at most \(0.3948\). Equivalently, on that event it bounds the expected loss of a fresh Gibbs prediction, including its random draw from \(Q\). It does not state that \(95\%\) of predictors drawn from \(Q\) have risk at most \(0.3948\); that would be a different probability statement.

Different Randomization Conventions, Same One-Case Risk

There are two common ways to use the randomness in a Gibbs rule. One can draw \(H\sim Q\) once and use that same predictor for many future observations. Or one can draw a fresh \(H\) independently for each prediction. In either case, for one fresh observation, the expected loss is \(R(Q)\). The conventions need not give the same dependence across a sequence of predictions: with one draw, the same predictor's strengths and weaknesses persist; with fresh draws, the predictor can change from case to case.

Worked Example: One Prediction at a Fixed Input

At a particular input \(x\), suppose the true label is \(1\). Under \(Q\), a classifier predicting \(1\) is drawn with probability \(0.7\), and a classifier predicting \(0\) is drawn with probability \(0.3\). With zero-one loss, the random prediction is wrong with probability \(0.3\), so its expected loss at this input is \(0.3\).

This calculation is about the randomized action on this case. If the draw is retained as one classifier for an entire test population, that classifier has a population risk determined by its behavior on all possible inputs—not just by whether it is correct at \(x\). A bound on the posterior-averaged population risk averages those whole-population risks over draws.

Common Pitfall: Replacing an Average by a Typical Draw

A small average risk does not automatically imply that most posterior draws have small risk. A useful general fact is Markov's inequality: for nonnegative \(R(H)\) and any \(t>0\), \(P_{H\sim Q}(R(H)\geq t)\leq R(Q)/t\). This can give a probability statement about a draw, but it is a separate, usually weaker conclusion and requires choosing a threshold \(t\).

$$ P_{H\sim Q}\{R(H)\geq t\} \leq \frac{E_{H\sim Q}[R(H)]}{t} =\frac{R(Q)}{t}. $$

For the two-classifier example above, the inequality at \(t=0.75\) gives an upper bound \(0.35/0.75\approx0.467\), while the actual probability of drawing a classifier with risk at least \(0.75\) is \(0.2\). Neither this inequality nor the PAC-Bayes bound claims that each draw is close to the average.

Another tempting substitution is to average the prediction values first and then evaluate the loss. That generally changes the object being evaluated. For example, let the response be \(Y=1\), and let \(Q\) put probability \(1/2\) on each of two constant regression predictors, \(h_0=0\) and \(h_2=2\). Under squared-error loss, each predictor has loss \(1\), so \(R(Q)=1\). A prediction equal to the arithmetic average, \(1\), has squared loss \(0\). These are different procedures and different criteria: the Gibbs rule samples one predictor, whereas averaging predictions produces a new prediction. The PAC-Bayes guarantee for \(R(Q)\) directly concerns the former.

Key takeaway: A PAC-Bayes risk bound controls the posterior-averaged risk, which equals the expected loss of a Gibbs prediction. It does not certify each posterior draw, and it does not silently become a guarantee for a prediction formed by averaging predictors' outputs.

Check Your Understanding

Use the distinction between an average over predictors and the risk of one realized draw.

  1. If \(Q\) assigns probabilities \(0.6\) and \(0.4\) to predictors with risks \(0.1\) and \(0.6\), respectively, what is \(R(Q)\), and what values can \(R(H)\) take?
  2. State the two sources of randomness included in the risk of a Gibbs prediction.
  3. What does the high-probability PAC-Bayes theorem say is simultaneous over posteriors, and what is its probability taken over?
  4. Why does a bound on \(R(Q)\) not imply that every predictor in the support of \(Q\) has risk at most that bound?
  5. Under what condition does the Markov bound on \(P_{H\sim Q}\{R(H)\geq t\}\) apply, and what does it add to the posterior-averaged guarantee?
Clinical Biostats