Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Theorem 31.1 (PAC-Bayes): w.p. ≥ 1−δ over S ∼ D^m, every posterior Q with finite divergence has L_D(Q) ≤ L_S(Q) + √((D(Q‖P) + ln(m/δ))/(2(m−1)))

Proved
UnderstandingML.pac_bayes_bound

by naimengye · Sep 24, 2026 · Mathlib 0df444a (Lean v4.33.1)

generalization-boundgibbs-predictorkullback-leiblerpac-bayes

Theorem 31.1. Let DDD be an arbitrary distribution over an example domain ZZZ. Let HHH be a hypothesis class and let ℓ:H×Z→[0,1]\ell : H \times Z \to [0,1]ℓ:H×Z→[0,1] be a loss function. Let PPP be a prior distribution over HHH and let δ∈(0,1)\delta \in (0,1)δ∈(0,1). Then, with probability of at least 1−δ1 - \delta1−δ over the choice of an i.i.d. training set S={z1,…,zm}S = \{z_1, \dots, z_m\}S={z1​,…,zm​} sampled according to DDD, for all distributions QQQ over HHH (even such that depend on SSS), we have

LD(Q)≤LS(Q)+D(Q∥P)+ln⁡(m/δ)2(m−1),L_D(Q) \le L_S(Q) + \sqrt{\frac{D(Q\|P) + \ln(m/\delta)}{2(m-1)}},LD​(Q)≤LS​(Q)+2(m−1)D(Q∥P)+ln(m/δ)​​,

where D(Q∥P)=Eh∼Q[ln⁡(Q(h)/P(h))]D(Q\|P) = \mathbb{E}_{h \sim Q}[\ln(Q(h)/P(h))]D(Q∥P)=Eh∼Q​[ln(Q(h)/P(h))] is the Kullback–Leibler divergence.

Formally: HHH a measurable space, ℓ\ellℓ jointly measurable, m≥2m \ge 2m≥2, and QQQ ranging over the probability measures Q≪PQ \ll PQ≪P with QQQ-integrable log-density (the posteriors with a finite divergence; for the others the bound is vacuous).

Preamble
import Definitions.Def_UnderstandingML_PACBayes

open MeasureTheory
Formal statement
namespace UnderstandingML

/-- **Theorem 31.1** (p. 416). Let `D` be an arbitrary distribution over an example domain `Z`.
Let `H` be a hypothesis class and let `ℓ : H × Z → [0, 1]` be a loss function. Let `P` be a prior
distribution over `H` and let `δ ∈ (0, 1)`. Then, with probability of at least `1 − δ` over the
choice of an i.i.d. training set `S = {z₁, …, z_m}` sampled according to `D`, for all
distributions `Q` over `H` (even such that depend on `S`), we have
`L_D(Q) ≤ L_S(Q) + √((D(Q‖P) + ln(m/δ)) / (2(m − 1)))`.
The loss is jointly measurable, `m ≥ 2`, and `Q` ranges over the probability measures `Q ≪ P`
with `Q`-integrable log-density (those with a finite divergence). -/
theorem pac_bayes_bound {Z Hyp : Type*} [MeasurableSpace Z] [MeasurableSpace Hyp]
    (loss : Hyp → Z → ℝ) (hmeas : Measurable (Function.uncurry loss))
    (hloss : ∀ h z, loss h z ∈ Set.Icc (0 : ℝ) 1) (D : Measure Z) [IsProbabilityMeasure D]
    (P : Measure Hyp) [IsProbabilityMeasure P] (m : ℕ) (hm : 2 ≤ m) (δ : ℝ) (hδ : 0 < δ)
    (hδ1 : δ < 1) :
    iidLaw D m {S | ∃ Q : Measure Hyp, IsProbabilityMeasure Q ∧ Q ≪ P ∧
      Integrable (fun h ↦ Real.log (Q.rnDeriv P h).toReal) Q ∧
      gibbsEmpRisk loss S Q + Real.sqrt ((klDiv Q P + Real.log (m / δ)) / (2 * (m - 1))) <
        gibbsRisk loss D Q} ≤ ENNReal.ofReal δ := by sorry

end UnderstandingML
Source
Shalev-Shwartz and Ben-David, Understanding Machine Learning: From Theory to Algorithms, Cambridge University Press 2014, doi:10.1017/CBO9781107298019, §31.1 p. 416, Theorem 31.1 with its proof (pp. 416-417)
Human review
  • Endorsed by Shuze Chen · Sep 25, 2026

    Confirmed by the moderator at approval.

  • Endorsed by naimengye · Sep 25, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me