mixle.experimental.pac_bayes module¶
PAC-Bayes certificates over an explicit finite hypothesis space.
The posterior and prior accepted here are probability distributions over fixed predictors/hypotheses—not
observation-density mixture components. The prior must be selected independently of the certified sample;
the posterior may depend on that sample. Callers provide one bounded loss per hypothesis and sample, and
an explicit PACBayesAssumptions receipt. The certificate uses the finite-space
KL(Q || P) and the McAllester bounded-loss inequality.
gaussian_kl remains available only as a mathematical primitive for genuine Gaussian distributions over
parameters. It is not used by certify_generalization() and does not convert fitted observation
distributions into a hypothesis posterior.
- class PACBayesAssumptions(hypothesis_space_id, prior_id, sample_iid, hypotheses_fixed_before_sample, prior_fixed_before_sample, loss_fixed_before_sample, loss_lower=0.0, loss_upper=1.0)[source]
Bases:
objectCaller-attested premises required by the theorem.
- class GeneralizationCertificate(empirical_loss, empirical_loss_by_hypothesis, kl, hypothesis_kl_terms, n, delta, raw_bound, bound, vacuous, posterior, prior, theorem, assumptions)[source]
Bases:
objectA theorem-matched finite-hypothesis PAC-Bayes certificate.
- Parameters:
- gaussian_kl(mu_q, s2_q, mu_p, s2_p)[source]
KL(N(mu_q, s2_q) || N(mu_p, s2_p))for genuine parameter laws.
- categorical_kl(posterior, prior)[source]
Finite-hypothesis
KL(Q || P)and its exact per-hypothesis summands.
- mcallester_bound(empirical_loss, kl, n, *, delta=0.05)[source]
Return the raw McAllester upper bound for a loss in
[0, 1].
- certify_generalization(losses, posterior, prior, *, assumptions, delta=0.05)[source]
Certify the Gibbs risk of
posteriorover a fixed finite hypothesis class.- Parameters:
losses (Any) – Matrix with shape
(n_hypotheses, n_samples)and values in[0, 1].posterior (Any) – Sample-dependent probability vector
Qover the hypothesis rows.prior (Any) – Data-independent probability vector
Pover the same rows.assumptions (PACBayesAssumptions) – Explicit theorem-premise receipt; any false premise fails closed.
delta (float) – Failure probability in
(0, 1).
- Return type:
GeneralizationCertificate