GaussianKLMeasure.lean
1module23public import Mathlib.InformationTheory.KullbackLeibler.Basic4public import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap56/-! Relative entropy for two real-valued probability densities over a common measure. -/78@[expose] public section910open MeasureTheory11open scoped ENNReal1213namespace SubentropyCertificates.GaussianPinching1415variable {α : Type*} [MeasurableSpace α] {μ : Measure α} {a b : α → ℝ}1617/-- The measure with real nonnegative density `a` relative to `μ`. -/18noncomputable def densityMeasure (μ : Measure α) (a : α → ℝ) : Measure α :=19 μ.withDensity (fun x ↦ ENNReal.ofReal (a x))2021/-- A density of mass one defines a probability measure. -/22theorem densityMeasure_isProbability (ha0 : ∀ x, 0 ≤ a x) (ha1 : ∫ x, a x ∂μ = 1) :23 IsProbabilityMeasure (densityMeasure μ a) := by24 have hi : Integrable a μ := Integrable.of_integral_ne_zero (by rw [ha1]; norm_num)25 constructor26 rw [densityMeasure, withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ,27 ← ofReal_integral_eq_lintegral_ofReal hi (ae_of_all _ ha0), ha1, ENNReal.ofReal_one]2829/-- Express the first density relative to the second, allowing both to vanish. -/30private theorem densityMeasure_factor (ha : Measurable a) (hb : Measurable b)31 (hb0 : ∀ x, 0 ≤ b x) (hsupp : ∀ x, b x = 0 → a x = 0) :32 densityMeasure μ a = densityMeasure (densityMeasure μ b) (fun x ↦ a x / b x) := by33 unfold densityMeasure34 have hr : Measurable (fun x ↦ ENNReal.ofReal (a x / b x)) := (ha.div hb).ennreal_ofReal35 rw [← withDensity_mul μ hb.ennreal_ofReal hr]36 congr 137 funext x38 change ENNReal.ofReal (a x) = ENNReal.ofReal (b x) * ENNReal.ofReal (a x / b x)39 rw [← ENNReal.ofReal_mul (hb0 x)]40 by_cases h : b x = 041 · simp [h, hsupp x h]42 · rw [mul_comm, div_mul_cancel₀ _ h]4344/-- The relative entropy of probability densities is the usual integral of the log ratio.45The support condition includes singular densities which vanish on a common set. -/46theorem klDiv_densityMeasure_eq_integral (ha : Measurable a) (hb : Measurable b)47 (ha0 : ∀ x, 0 ≤ a x) (hb0 : ∀ x, 0 ≤ b x)48 (ha1 : ∫ x, a x ∂μ = 1) (hb1 : ∫ x, b x ∂μ = 1)49 (hsupp : ∀ x, b x = 0 → a x = 0)50 (hint : Integrable (fun x ↦ a x * Real.log (a x / b x)) μ) :51 InformationTheory.klDiv (densityMeasure μ a) (densityMeasure μ b) =52 ENNReal.ofReal (∫ x, a x * Real.log (a x / b x) ∂μ) := by53 let _ := densityMeasure_isProbability ha0 ha154 let _ := densityMeasure_isProbability hb0 hb155 have hfactor := densityMeasure_factor (μ := μ) ha hb hb0 hsupp56 have hac : densityMeasure μ a ≪ densityMeasure μ b := by57 rw [hfactor]58 exact withDensity_absolutelyContinuous _ _59 have hr : Measurable (fun x ↦ ENNReal.ofReal (a x / b x)) := (ha.div hb).ennreal_ofReal60 have hrn := Measure.rnDeriv_withDensity (densityMeasure μ b) hr61 change (densityMeasure (densityMeasure μ b) (fun x ↦ a x / b x)).rnDeriv62 (densityMeasure μ b) =ᵐ[_] _ at hrn63 rw [← hfactor] at hrn64 have hllr : llr (densityMeasure μ a) (densityMeasure μ b) =ᵐ[densityMeasure μ a]65 fun x ↦ Real.log (a x / b x) := by66 filter_upwards [hac.ae_le hrn] with x hx67 simp [llr, hx, ENNReal.toReal_ofReal (div_nonneg (ha0 x) (hb0 x))]68 have htop : ∀ᵐ x ∂μ, ENNReal.ofReal (a x) < ∞ := ae_of_all _ fun _ ↦ ENNReal.ofReal_lt_top69 have hi : Integrable (llr (densityMeasure μ a) (densityMeasure μ b)) (densityMeasure μ a) := by70 rw [integrable_congr hllr, densityMeasure,71 integrable_withDensity_iff ha.ennreal_ofReal htop]72 simpa only [ENNReal.toReal_ofReal (ha0 _), mul_comm] using hint73 rw [InformationTheory.klDiv_of_ac_of_integrable hac hi, integral_congr_ae hllr]74 simp only [measureReal_def, measure_univ, ENNReal.toReal_one, add_sub_cancel_right]75 rw [densityMeasure, integral_withDensity_eq_integral_toReal_smul ha.ennreal_ofReal htop]76 simp only [ENNReal.toReal_ofReal (ha0 _), smul_eq_mul]7778/-- A bounded likelihood ratio has an integrable entropy density, including at zeros. -/79theorem integrable_mul_log_ratio_of_le_mul (ha : Measurable a) (hb : Measurable b)80 (ha0 : ∀ x, 0 ≤ a x) (hb0 : ∀ x, 0 ≤ b x) (hib : Integrable b μ)81 {C : ℝ} (hdom : ∀ x, a x ≤ C * b x) :82 Integrable (fun x ↦ a x * Real.log (a x / b x)) μ := by83 obtain ⟨M, hM⟩ := (isCompact_Icc (α := ℝ) (a := 0) (b := C)).bddAbove_image84 Real.continuous_mul_log.norm.continuousOn85 apply (hib.const_mul M).mono' (ha.mul (ha.div hb).log).aestronglyMeasurable86 apply ae_of_all87 intro x88 by_cases hx : b x = 089 · simp [hx]90 have hxpos := lt_of_le_of_ne (hb0 x) (Ne.symm hx)91 have hratio : a x / b x ∈ Set.Icc 0 C :=92 ⟨div_nonneg (ha0 x) (hb0 x), (div_le_iff₀ hxpos).2 (hdom x)⟩93 have hbound := hM (Set.mem_image_of_mem _ hratio)94 calc95 ‖a x * Real.log (a x / b x)‖ =96 ‖(a x / b x * Real.log (a x / b x)) * b x‖ := by97 congr 198 rw [mul_right_comm, div_mul_cancel₀ _ hx]99 _ ≤ M * b x := by100 rw [norm_mul, Real.norm_of_nonneg (hb0 x)]101 exact mul_le_mul_of_nonneg_right hbound (hb0 x)102103end SubentropyCertificates.GaussianPinching
Axioms used
Choose a statement to see which axioms its proof uses.