Documentation

CslibFrontier.MachineLearning.PACBayes.KL

The PAC-Bayes-kl bound #

The PAC-Bayes-kl bound, [Seeger2002, Theorem 1] for losses in [0, 1]; Seeger states it for the zero-one loss and [Maurer2004, Lemma 3] extends it. Hypotheses are indexed by a countable type ι, ℓ i z ∈ [0, 1] is the loss of the hypothesis i on the example z, and P is a prior on ι fixed before the sample. Under m ≥ 1 i.i.d. examples S from D and for every δ > 0, with probability at least 1 - δ every probability measure Q on ι with KL(Q ‖ P) < ∞ satisfies

kl(𝔼_{i∼Q} L_S(i) ‖ 𝔼_{i∼Q} L_D(i)) ≤ (KL(Q ‖ P) + log ((m + 1) / δ)) / m,

where kl(q ‖ p) is the binary relative entropy Cslib.Probability.binaryKL q p. The bound is implicit in the true risk; inverting kl in its second argument bounds 𝔼_Q L_D, and the bound is tighter than McAllester's (CslibFrontier.MachineLearning.PACBayes.Basic) when the empirical risk is small.

The proof follows [Seeger2002, Appendix A] and [Maurer2004, Section 3]: the change-of-measure inequality applied to f(i) = m kl(L_S(i) ‖ L_D(i)), Jensen's inequality for kl (Cslib.Probability.binaryKL_integral_le_integral), Maurer's exponential moment 𝔼_S exp (m kl(L_S(i) ‖ L_D(i))) ≤ m + 1 (Cslib.Probability.lintegral_exp_mul_binaryKL_sum_div_le) and Markov's inequality over the prior (Cslib.MachineLearning.PACBayes.measure_ofReal_div_le_lintegral_le). The function f can be unbounded under Q; its Q-integrability follows from the change of measure (Cslib.Probability.integrable_of_lintegral_exp_ne_top). Jensen's inequality for kl needs L_S(i) = L_D(i) whenever L_D(i) ∈ {0, 1}, where the true divergence is otherwise infinite; this holds for every i on almost every sample.

Taking point-mass posteriors gives the Occam form: every hypothesis i with P {i} > 0 satisfies kl(L_S(i) ‖ L_D(i)) ≤ (log (1 / P {i}) + log ((m + 1) / δ)) / m.

Differences from the sources: the hypothesis space is countable with measurable singletons; δ < 1 is not needed; posteriors with infinite divergence are excluded; each ℓ i must be measurable. [Maurer2004, Theorem 5] proves the sharper log (2√m / δ) for m ≥ 8 from the exponential moment bound 2√m of its Theorem 1, which is not formalized here.

Main results #

References #

theorem Cslib.MachineLearning.PACBayes.ae_forall_empiricalRisk_eq {ι : Type u_1} {Z : Type u_2} [MeasurableSpace Z] {D : MeasureTheory.Measure Z} [MeasureTheory.IsProbabilityMeasure D] {ℓ : ι → Z → ℝ} [Countable ι] (hℓ : ∀ (i : ι), Measurable (ℓ i)) (hℓ01 : ∀ (i : ι) (z : Z), ℓ i z ∈ Set.Icc 0 1) {m : ℕ} (hm : 0 < m) :
∀ᵐ (S : Fin m → Z) ∂MeasureTheory.Measure.pi fun (x : Fin m) => D, ∀ (i : ι), (trueRisk ℓ D i = 0 → empiricalRisk ℓ S i = 0) ∧ (trueRisk ℓ D i = 1 → empiricalRisk ℓ S i = 1)

On almost every nonempty sample, every hypothesis whose true risk is 0 or 1 has the same empirical risk.

theorem Cslib.MachineLearning.PACBayes.measure_pi_exists_binaryKL_integral_risk_gt {ι : Type u_1} {Z : Type u_2} [MeasurableSpace Z] {D : MeasureTheory.Measure Z} [MeasureTheory.IsProbabilityMeasure D] {ℓ : ι → Z → ℝ} [MeasurableSpace ι] [Countable ι] [MeasurableSingletonClass ι] (hℓ : ∀ (i : ι), Measurable (ℓ i)) (hℓ01 : ∀ (i : ι) (z : Z), ℓ i z ∈ Set.Icc 0 1) {m : ℕ} (hm : 0 < m) (P : MeasureTheory.Measure ι) [MeasureTheory.IsProbabilityMeasure P] {δ : ℝ} (hδ : 0 < δ) :

The PAC-Bayes-kl bound [Seeger2002, Theorem 1] [Mau04]: for a prior P on a countable index, losses ℓ i z ∈ [0, 1], m ≥ 1 and δ > 0, the samples on which some posterior Q with KL(Q ‖ P) < ∞ has (KL(Q ‖ P) + log ((m + 1) / δ)) / m < kl(𝔼_Q L_S ‖ 𝔼_Q L_D) have probability at most δ.

theorem Cslib.MachineLearning.PACBayes.measure_pi_exists_binaryKL_risk_gt {ι : Type u_1} {Z : Type u_2} [MeasurableSpace Z] {D : MeasureTheory.Measure Z} [MeasureTheory.IsProbabilityMeasure D] {ℓ : ι → Z → ℝ} [MeasurableSpace ι] [Countable ι] [MeasurableSingletonClass ι] (hℓ : ∀ (i : ι), Measurable (ℓ i)) (hℓ01 : ∀ (i : ι) (z : Z), ℓ i z ∈ Set.Icc 0 1) {m : ℕ} (hm : 0 < m) (P : MeasureTheory.Measure ι) [MeasureTheory.IsProbabilityMeasure P] {δ : ℝ} (hδ : 0 < δ) :
(MeasureTheory.Measure.pi fun (x : Fin m) => D) {S : Fin m → Z | ∃ (i : ι), P {i} ≠ 0 ∧ (Real.log (1 / P.real {i}) + Real.log ((↑m + 1) / δ)) / ↑m < Probability.binaryKL (empiricalRisk ℓ S i) (trueRisk ℓ D i)} ≤ ENNReal.ofReal δ

The Occam form of the PAC-Bayes-kl bound: taking point-mass posteriors, with probability at least 1 - δ every index i with P {i} > 0 satisfies kl(L_S(i) ‖ L_D(i)) ≤ (log (1 / P {i}) + log ((m + 1) / δ)) / m.