Tutorials › Statistical Learning (Graduate) › Hierarchical Priors and Hyper-Posterior Bounds

PAC-Bayesian Generalization · Tutorial 367 of 989

Hierarchical Priors and Hyper-Posterior Bounds

Learn how model-selection complexity and within-model predictor complexity combine in one PAC-Bayes risk guarantee.

Advanced 10 min read

What You'll Learn

  • Define a hierarchical prior and the corresponding hyperposterior and conditional posteriors
  • Decompose joint Kullback–Leibler divergence into model-level and within-model costs
  • Derive a simultaneous PAC-Bayes risk bound for bounded losses
  • Calculate both divergence terms in finite hierarchical examples
  • Recognize why a hyperposterior penalty alone can understate complexity

Why Put a Prior on Models and Predictors?

A predictor may be chosen in two stages: first select a model or predictor class, then select a predictor within that class. A single flat prior over all predictors can represent this arrangement, but it can hide which part of the complexity comes from selecting a model and which comes from selecting a predictor inside it. A hierarchical prior keeps those costs visible.

The resulting guarantee controls the risk averaged over both stages of the posterior. Its central feature is that the divergence penalty has two parts: one for moving the model distribution away from its prior, and one for moving each within-model predictor distribution away from its own prior.

Hierarchical Prior and Posterior

Let \(m\) denote a model index, taking values in a measurable space \(\mathcal M\). For each \(m\), let \(\mathcal H_m\) be its predictor space. The loss \(\ell(h,z)\) is assumed measurable and bounded between 0 and 1. The data \(S=(Z_1,\ldots,Z_n)\) are independent and identically distributed from a distribution \(D\).

Definition: A hierarchical prior consists of a prior \(\pi\) on model indices and, for each model \(m\), a prior \(P_m\) on predictors in \(\mathcal H_m\). Together they define a joint prior \(\Pi(dm,dh)=\pi(dm)P_m(dh)\). A hierarchical posterior consists of a distribution \(\rho\) on models and conditional distributions \(Q_m\) on predictors. Its joint distribution is \(Q(dm,dh)=\rho(dm)Q_m(dh)\). The posterior-averaged population and empirical risks are $$ R(Q)=\mathbb E_{m\sim\rho,\,h\sim Q_m}R(h),\qquad \widehat R_S(Q)=\mathbb E_{m\sim\rho,\,h\sim Q_m}\widehat R_S(h), $$ where \(R(h)=\mathbb E_{Z\sim D}[\ell(h,Z)]\) and \(\widehat R_S(h)=n^{-1}\sum_{i=1}^n\ell(h,Z_i)\).

The prior \(\pi\) and the conditional priors \(P_m\) must be fixed independently of the sample for the result below. The posterior may depend on the sample. More generally, a prior constructed by a valid data-splitting or other information-control procedure can be used when its required independence conditions hold.

Theorem (Hierarchical PAC-Bayes bound): Under the assumptions above, fix \(\lambda>0\) and \(0<\delta<1\). With probability at least \(1-\delta\) over the sample, every hierarchical posterior satisfying \(\rho\ll\pi\) and \(Q_m\ll P_m\) for \(\rho\)-almost every \(m\) obeys $$ R(Q)\leq \widehat R_S(Q) +\frac{\operatorname{KL}(\rho\|\pi)+\mathbb E_{m\sim\rho}\operatorname{KL}(Q_m\|P_m)+\log(1/\delta)}{\lambda} +\frac{\lambda}{8n}. $$ If the relevant divergence is infinite, the bound is vacuous. The same event works for all such posteriors, including posteriors chosen after observing the sample.

Why the Divergence Has Two Terms

The model-level cost is \(\operatorname{KL}(\rho\|\pi)\). The conditional cost is the average, under the selected model distribution, of \(\operatorname{KL}(Q_m\|P_m)\). Together they are exactly the divergence of the joint posterior from the joint prior.

Result (Chain rule for hierarchical KL): If \(\rho\ll\pi\) and \(Q_m\ll P_m\) for \(\rho\)-almost every \(m\), then $$ \operatorname{KL}(Q\|\Pi) = \operatorname{KL}(\rho\|\pi) +\mathbb E_{m\sim\rho}\operatorname{KL}(Q_m\|P_m). $$

To verify the identity, write \(r(m)=d\rho/d\pi(m)\) and \(q_m(h)=dQ_m/dP_m(h)\). The joint density ratio is \(dQ/d\Pi(m,h)=r(m)q_m(h)\). Integrating its logarithm under \(Q\) gives

$$ \begin{aligned} \operatorname{KL}(Q\|\Pi) &=\mathbb E_{m\sim\rho,\,h\sim Q_m} \left[\log r(m)+\log q_m(h)\right]\\ &=\mathbb E_{m\sim\rho}\log r(m) +\mathbb E_{m\sim\rho}\mathbb E_{h\sim Q_m}\log q_m(h)\\ &=\operatorname{KL}(\rho\|\pi) +\mathbb E_{m\sim\rho}\operatorname{KL}(Q_m\|P_m). \end{aligned} $$

The first expectation depends only on how much the posterior reweights models. The second measures the additional reweighting of predictors within each selected model. This decomposition is not an approximation: it is the joint KL divergence written in hierarchical form. If a posterior puts mass where the corresponding prior has none, absolute continuity fails and the associated divergence is infinite.

Proof of the Hierarchical Bound

The proof first controls an exponential moment under the joint prior, then transfers that control to every posterior using the KL divergence. For a fixed predictor \(h\), Hoeffding’s lemma applies because each loss lies in \([0,1]\). Independence of the observations therefore gives

$$ \mathbb E_S\exp\left\{\lambda\sum_{i=1}^n \bigl(R(h)-\ell(h,Z_i)\bigr)\right\} \leq \exp\left(\frac{n\lambda^2}{8}\right). $$

Integrate this inequality with respect to the fixed joint prior \(\Pi\), and define \(Z(S)=\mathbb E_{(m,h)\sim\Pi}\exp\{\lambda\sum_i(R(h)-\ell(h,Z_i))\}\). Tonelli’s theorem applies to the nonnegative integrand, so \(\mathbb E_S Z(S)\leq\exp(n\lambda^2/8)\). Markov’s inequality then implies that, with probability at least \(1-\delta\),

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

Fix any posterior \(Q\) on this event. For \(Q\ll\Pi\), Jensen’s inequality yields

$$ \lambda n\bigl(R(Q)-\widehat R_S(Q)\bigr) \leq \operatorname{KL}(Q\|\Pi)+\log Z(S). $$

Indeed, writing \(q=dQ/d\Pi\), the left side is \(\mathbb E_Q[g]\), where \(g(m,h)=\lambda\sum_i(R(h)-\ell(h,Z_i))\). Jensen’s inequality gives \(\mathbb E_Q[g-\log q]\leq\log\mathbb E_Q[\exp(g)/q]=\log\mathbb E_\Pi[\exp(g)]\), which is the displayed inequality after adding \(\operatorname{KL}(Q\|\Pi)=\mathbb E_Q\log q\). Substituting the event bound for \(\log Z(S)\), dividing by \(\lambda n\), and applying the KL chain rule proves the theorem. The event depends on the prior and sample, not on \(Q\), so the conclusion holds simultaneously for all posteriors. \(\square\)

Worked Calculations

Worked Example: A Bound with Two Complexity Costs

There are two models, \(A\) and \(B\), with \(\pi(A)=\pi(B)=1/2\). The posterior assigns \(\rho(A)=3/4\) and \(\rho(B)=1/4\). In model \(A\), the prior assigns probability \(1/2\) to each of two predictors; \(Q_A\) assigns probabilities \(0.9\) and \(0.1\). In model \(B\), let \(Q_B=P_B\). Suppose their empirical risks are respectively \(0.05\), \(0.45\), and \(0.20\).

The model-level divergence is

$$ \operatorname{KL}(\rho\|\pi) =\frac34\log(1.5)+\frac14\log(0.5) \approx 0.1308. $$

The conditional divergence in model \(A\) is

$$ \operatorname{KL}(Q_A\|P_A) =0.9\log(1.8)+0.1\log(0.2) \approx 0.3681. $$

Model \(B\)'s conditional divergence is zero, so the posterior-averaged conditional cost is \((3/4)(0.3681)+(1/4)(0)\approx0.2760\). The total divergence is therefore about \(0.4069\). The posterior empirical risk is \( (3/4)[0.9(0.05)+0.1(0.45)]+(1/4)(0.20)=0.1175\). For \(n=100\), \(\delta=0.05\), and the fixed choice \(\lambda=50\), the theorem gives

$$ R(Q)\leq0.1175+\frac{0.4069+\log(20)}{50}+\frac{50}{800} \approx 0.2481. $$

Both divergence terms affect the guarantee: the first charges for favoring model \(A\), and the second for favoring one predictor within \(A\).

Worked Example: Checking the Chain Rule Directly

Let \(\pi(A)=\pi(B)=1/2\). In model \(A\), let \(P_A=(0.9,0.1)\) and \(Q_A=(0.75,0.25)\); in model \(B\), set \(Q_B=P_B=(0.2,0.8)\). Set \(\rho(A)=0.8\) and \(\rho(B)=0.2\).

The model divergence is \(0.8\log(1.6)+0.2\log(0.4)\approx0.1927\). For model \(A\), the conditional divergence is \(0.75\log(0.75/0.9)+0.25\log(0.25/0.1)\approx0.0923\); for \(B\), it is zero. Thus the hierarchical expression is \(0.1927+0.8(0.0923)\approx0.2666\).

To check it as a single joint divergence, list the four prior masses as \((0.45,0.05,0.10,0.40)\) and the posterior masses as \((0.60,0.20,0.04,0.16)\). Hence

$$ \begin{aligned} \operatorname{KL}(Q\|\Pi) &=0.60\log(0.60/0.45)+0.20\log(0.20/0.05)\\ &\quad+0.04\log(0.04/0.10)+0.16\log(0.16/0.40)\\ &\approx0.1726+0.2773-0.0367-0.1466=0.2666. \end{aligned} $$

The direct joint calculation agrees with the two-level decomposition, including the negative contributions from joint atoms that the posterior downweights.

Worked Example: The Cost of Concentrating Within a Model

Suppose there are two models with equal prior probabilities. In model \(A\), one predictor \(g\) has prior probability \(0.1\); all remaining predictors together have probability \(0.9\). Consider the posterior that selects \(A\) with probability one and selects \(g\) with probability one conditional on \(A\). The model-level divergence is \(\log 2\), while the within-model divergence is \(\log 10\). The total is \(\log 20\approx2.9957\).

Suppose \(g\)'s empirical risk is \(0.04\), \(n=400\), and \(\delta=0.05\). With the fixed choice \(\lambda=100\), the valid bound is

$$ R(g)\leq0.04+\frac{\log 20+\log 20}{100}+\frac{100}{3200} \approx0.1312. $$

If one incorrectly charged only the model-level divergence, the calculated upper bound would be \(0.04+(\log 2+\log 20)/100+100/3200\approx0.1081\). That smaller number is not justified: the posterior has concentrated on a predictor whose within-model prior probability was only \(0.1\), and that change costs \(\log 10\).

Common Pitfall and Practical Meaning

  • Wrong: “The posterior selected a model, so the model-level KL is the complete complexity penalty.” This overlooks how much the posterior has changed the predictor distribution inside that model.
  • Correction: Include \(\mathbb E_{m\sim\rho}\operatorname{KL}(Q_m\|P_m)\) as well as \(\operatorname{KL}(\rho\|\pi)\). If the posterior keeps \(Q_m=P_m\), the conditional cost is zero; otherwise it must be calculated.
  • Wrong: “A convenient prior can be chosen after seeing the same sample without changing the argument.” The proof uses the prior before observing the sample. A data-dependent prior requires a valid independence or information-control justification.

The two-level form is useful when model classes have different structures or natural predictor priors. It allows the analysis to distinguish the price of selecting a class from the price of adapting within that class, while remaining exactly equivalent to a joint-prior PAC-Bayes bound. The temperature \(\lambda\) trades off the divergence penalty against the bounded-loss concentration term; it must be fixed for the stated guarantee unless a separate argument justifies data-dependent or simultaneous choices.

Check Your Understanding

Use the definitions and bound to answer the following.

  1. In the hierarchical KL identity, what does each of the two terms measure?
  2. If \(Q_m=P_m\) for every model with positive posterior mass, which complexity term vanishes?
  3. Why does the theorem apply to a sample-dependent posterior even though the prior must be fixed independently of the sample?
  4. For a posterior concentrated on one model and one predictor, explain why the two divergence costs need not be equal.
  5. What must be checked before using a prior constructed from the observed sample?
Clinical Biostats