Download data/lean/OAI/Probability/SKGap/Entropy/ScalarEntropyTarget.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SKGap/Entropy/ScalarEntropyTarget.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/SKGap/Entropy/ScalarEntropyTarget.lean
-
curl -L -o ScalarEntropyTarget.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SKGap/Entropy/ScalarEntropyTarget.lean
12.3 kB
| import Mathlib | |
| import OAI.Probability.SKGap.Entropy.EntropyTransport | |
| import OAI.Probability.SKGap.Entropy.EntropyEll | |
| namespace OAI | |
| section | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter | |
| open scoped NNReal ENNReal Topology | |
| noncomputable section | |
| open Real Set | |
| namespace SKGap | |
| theorem gaussian_tanh_integration_by_parts {d : β} {s : ββ₯0} (hs : s β 0) : | |
| (β« y, (y - d) * tanh y βgaussianReal d s) = | |
| (s : β) * (1 - β« y, tanh y ^ 2 βgaussianReal d s) := by | |
| have ht : Integrable tanh (gaussianReal d s) := Integrable.of_bound | |
| continuous_tanh.aestronglyMeasurable 1 (ae_of_all _ (fun y => (abs_tanh_lt_one y).le)) | |
| have h := gaussian_integration_by_parts hs hasDerivAt_tanh ht | |
| ((integrable_const 1).sub integrable_tanh_sq) | |
| (integrable_sub_mul_tanh IsGaussian.integrable_id d) | |
| rw [integral_sub (integrable_const 1) integrable_tanh_sq] at h | |
| simpa using h | |
| theorem scalar_entropy_finite {P : Measure β} [IsProbabilityMeasure P] | |
| (hP : Integrable (fun y : β => y ^ 2) P) | |
| {j d : β} {s : ββ₯0} (hj0 : 0 < j) (hj1 : j < 1) (hs : s β 0) | |
| (hcons : j * (β« y, tanh y ^ 2 βP) β€ (s : β)) | |
| (hD : klDiv P (gaussianReal d s) β β€) : | |
| let q := β« y, tanh y ^ 2 βP | |
| let a := β« y, (y - d) * tanh y βP | |
| let T := j * (a - (s : β) * (1 - q)) ^ 2 / (2 * (s : β) * ((s : β) + j * q)) | |
| T β€ (klDiv P (gaussianReal d s)).toReal β§ | |
| (a β (s : β) * (1 - q) β T < (klDiv P (gaussianReal d s)).toReal) := by | |
| dsimp only | |
| let q := β« y, tanh y ^ 2 βP | |
| let a := β« y, (y - d) * tanh y βP | |
| let k := j * q / (s : β) | |
| let B := j * (1 - q) | |
| let C := j * a / (s : β) | |
| let D := (klDiv P (gaussianReal d s)).toReal | |
| have hsp : 0 < (s : β) := NNReal.coe_pos.mpr (pos_iff_ne_zero.mpr hs) | |
| have hq0 : 0 < q := entropy_q_pos hs hD | |
| have hq1 : q < 1 := entropy_q_lt_one | |
| have hk0 : 0 < k := div_pos (mul_pos hj0 hq0) hsp | |
| have hk1 : k β€ 1 := (div_le_one hsp).mpr hcons | |
| have hB0 : 0 < B := mul_pos hj0 (sub_pos.mpr hq1) | |
| have hB1 : B < 1 := by dsimp [B]; nlinarith | |
| have htransport (u : β) (hu : u < 1) : | |
| u * (C - B) - k * u ^ 2 / 2 - B * entropyEll u β€ j * D := by | |
| have h := mul_le_mul_of_nonneg_left (entropy_transport_lower (secondMoment_integrable hP) hu hs hD) hj0.le | |
| change j * (u / (s : β) * a - u ^ 2 / (2 * (s : β)) * q + (1 - q) * log (1 - u)) β€ j * D at h | |
| convert h using 1 | |
| dsimp [k, B, C, entropyEll] | |
| field_simp | |
| ring | |
| have hvariance (hC : 1 < C) : C ^ 2 / k - 1 - log (C ^ 2 / k) β€ 2 * (j * D) := by | |
| let v := (β« y, (y - d) ^ 2 βP) / (s : β) | |
| have hcauchy := entropy_moment_cauchy hP d hq0 | |
| have hcv : C ^ 2 / (j * k) β€ v := by | |
| have heq : C ^ 2 / (j * k) * (s : β) = a ^ 2 / q := by | |
| dsimp [C, k] | |
| field_simp | |
| dsimp [v] | |
| rw [le_div_iffβ hsp, heq, div_le_iffβ hq0] | |
| simpa only [q, a, mul_comm] using hcauchy | |
| have hv : 0 < v := (div_pos (pow_pos (by linarith : 0 < C) 2) (mul_pos hj0 hk0)).trans_le hcv | |
| have hvar : (β« y, (y - d) ^ 2 βP) = (s : β) * v := by dsimp [v]; field_simp | |
| have hbound := entropy_variance_lower hs (centered_secondMoment_integrable hP d) hD hv hvar | |
| exact entropy_variance_scaled_lower hj0 hj1.le hk0 hk1 hC hcv hbound | |
| have hopt := entropy_scalar_optimization hk0 hk1 hB0 hB1 | |
| (mul_nonneg hj0.le ENNReal.toReal_nonneg) htransport hvariance | |
| have heq : (C - B) ^ 2 / (2 * (1 + k)) = | |
| j * (j * (a - (s : β) * (1 - q)) ^ 2 / (2 * (s : β) * ((s : β) + j * q))) := by | |
| dsimp [C, B, k] | |
| field_simp | |
| rw [heq] at hopt | |
| refine β¨le_of_mul_le_mul_left hopt.1 hj0, ?_β© | |
| intro ha | |
| have hCB : C β B := by | |
| intro h | |
| apply ha | |
| dsimp [C, B] at h | |
| have he := (div_eq_iff hsp.ne').mp h | |
| nlinarith | |
| exact lt_of_mul_lt_mul_left (hopt.2 hCB) hj0.le | |
| def scalarEntropyTarget (P : Measure β) (j d : β) (s : ββ₯0) : β := | |
| j * ((β« y, (y - d) * tanh y βP) - (s : β) * (1 - β« y, tanh y ^ 2 βP)) ^ 2 / | |
| (2 * (s : β) * ((s : β) + j * (β« y, tanh y ^ 2 βP))) | |
| theorem scalarEntropyTarget_nonneg {P : Measure β} {j d : β} {s : ββ₯0} (hj : 0 β€ j) : | |
| 0 β€ scalarEntropyTarget P j d s := by | |
| unfold scalarEntropyTarget | |
| apply div_nonneg (mul_nonneg hj (sq_nonneg _)) | |
| positivity | |
| theorem scalar_entropy_inequality {P : Measure β} [IsProbabilityMeasure P] | |
| (hP : Integrable (fun y : β => y ^ 2) P) | |
| {j d : β} {s : ββ₯0} (hj0 : 0 < j) (hj1 : j < 1) (hs : s β 0) | |
| (hcons : j * (β« y, tanh y ^ 2 βP) β€ (s : β)) : | |
| ENNReal.ofReal (scalarEntropyTarget P j d s) β€ klDiv P (gaussianReal d s) := by | |
| by_cases hD : klDiv P (gaussianReal d s) = β€ | |
| Β· simp [hD] | |
| Β· rw [ENNReal.ofReal_le_iff_le_toReal hD] | |
| exact (scalar_entropy_finite hP hj0 hj1 hs hcons hD).1 | |
| theorem scalar_entropy_equality_iff {P : Measure β} [IsProbabilityMeasure P] | |
| (hP : Integrable (fun y : β => y ^ 2) P) | |
| {j d : β} {s : ββ₯0} (hj0 : 0 < j) (hj1 : j < 1) (hs : s β 0) | |
| (hcons : j * (β« y, tanh y ^ 2 βP) β€ (s : β)) : | |
| klDiv P (gaussianReal d s) = ENNReal.ofReal (scalarEntropyTarget P j d s) β | |
| P = gaussianReal d s := by | |
| constructor | |
| Β· intro he | |
| have hD : klDiv P (gaussianReal d s) β β€ := by rw [he]; exact ENNReal.ofReal_ne_top | |
| have hreal : (klDiv P (gaussianReal d s)).toReal = scalarEntropyTarget P j d s := by | |
| rw [he, ENNReal.toReal_ofReal (scalarEntropyTarget_nonneg hj0.le)] | |
| have hm : (β« y, (y - d) * tanh y βP) = (s : β) * (1 - β« y, tanh y ^ 2 βP) := by | |
| by_contra h | |
| have hstrict := (scalar_entropy_finite hP hj0 hj1 hs hcons hD).2 h | |
| change scalarEntropyTarget P j d s < _ at hstrict | |
| rw [hreal] at hstrict | |
| exact lt_irrefl _ hstrict | |
| have hzero : klDiv P (gaussianReal d s) = 0 := by simpa [scalarEntropyTarget, hm] using he | |
| exact klDiv_eq_zero_iff.mp hzero | |
| Β· rintro rfl | |
| simp [scalarEntropyTarget, gaussian_tanh_integration_by_parts hs, klDiv_self] | |
| end SKGap | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory Real Set Filter | |
| open scoped Topology NNReal ENNReal BoundedContinuousFunction | |
| namespace SKGap | |
| def EntropyTestBound (P Q : Measure β) (D : β) : Prop := | |
| β f : β βα΅ β, (β« x, f x βP) - log (β« x, exp (f x) βQ) β€ D | |
| def realClip (n : β) (x : β) : β := max (-(n:β)) (min (n:β) x) | |
| lemma realClip_bounds (n : β) (x : β) : -(n:β) β€ realClip n x β§ realClip n x β€ n := by | |
| constructor | |
| Β· exact le_max_left _ _ | |
| Β· exact max_le (by linarith [Nat.cast_nonneg (Ξ± := β) n]) (min_le_left _ _) | |
| lemma realClip_abs (n : β) (x : β) : |realClip n x| β€ |x| := by | |
| rw [abs_le] | |
| constructor | |
| Β· exact le_sup_of_le_right (le_min (by linarith [abs_nonneg x]) (neg_abs_le x)) | |
| Β· exact sup_le (by linarith [abs_nonneg x]) ((min_le_right _ _).trans (le_abs_self x)) | |
| lemma realClip_le (n : β) (x : β) : realClip n x β€ max 0 x := | |
| max_le (by linarith [le_max_left (0:β) x]) ((min_le_right _ _).trans (le_max_right _ _)) | |
| lemma tendsto_realClip (x : β) : Tendsto (fun n : β => realClip n x) atTop (π x) := by | |
| have he : βαΆ n : β in atTop, realClip n x = x := by | |
| obtain β¨N, hNβ© := exists_nat_ge |x| | |
| filter_upwards [eventually_ge_atTop N] with n hn | |
| have hb : |x| β€ (n:β) := hN.trans (by exact_mod_cast hn) | |
| have hx := abs_le.mp hb | |
| simp only [realClip, min_eq_right hx.2, max_eq_right hx.1] | |
| exact (tendsto_congr' he).2 tendsto_const_nhds | |
| def clippedBC {f : β β β} (hf : Continuous f) (n : β) : β βα΅ β := | |
| BoundedContinuousFunction.ofNormedAddCommGroup (fun x => realClip n (f x)) | |
| (by unfold realClip; fun_prop) n (fun x => by | |
| rw [Real.norm_eq_abs, abs_le]; exact realClip_bounds n (f x)) | |
| lemma entropyTestBound_continuous {P Q : Measure β} [IsProbabilityMeasure P] | |
| [IsProbabilityMeasure Q] {D : β} (hD : EntropyTestBound P Q D) | |
| {f : β β β} (hf : Continuous f) (hi : Integrable f P) | |
| (he : Integrable (fun x => exp (f x)) Q) : | |
| (β« x, f x βP) - log (β« x, exp (f x) βQ) β€ D := by | |
| have hP : Tendsto (fun n => β« x, clippedBC hf n x βP) atTop (π (β« x, f x βP)) := by | |
| apply tendsto_integral_of_dominated_convergence (fun x => |f x|) | |
| Β· intro n; exact (clippedBC hf n).continuous.aestronglyMeasurable | |
| Β· exact hi.abs | |
| Β· intro n; exact ae_of_all _ (fun x => by | |
| change βrealClip n (f x)β β€ |f x| | |
| rw [Real.norm_eq_abs]; exact realClip_abs n (f x)) | |
| Β· exact ae_of_all _ (fun x => tendsto_realClip (f x)) | |
| have hQ : Tendsto (fun n => β« x, exp (clippedBC hf n x) βQ) atTop (π (β« x, exp (f x) βQ)) := by | |
| apply tendsto_integral_of_dominated_convergence (fun x => 1+exp (f x)) | |
| Β· intro n; exact (by fun_prop : Continuous (fun x => exp (clippedBC hf n x))).aestronglyMeasurable | |
| Β· exact (integrable_const 1).add he | |
| Β· intro n; exact ae_of_all _ (fun x => by | |
| rw [Real.norm_eq_abs, abs_of_pos (exp_pos _)] | |
| calc | |
| _ β€ exp (max 0 (f x)) := exp_le_exp.mpr (realClip_le n (f x)) | |
| _ β€ 1+exp (f x) := by | |
| by_cases hx : 0 β€ f x | |
| Β· rw [max_eq_right hx]; linarith | |
| Β· rw [max_eq_left (le_of_not_ge hx), exp_zero]; linarith [exp_pos (f x)]) | |
| Β· exact ae_of_all _ (fun x => continuous_exp.continuousAt.tendsto.comp (tendsto_realClip (f x))) | |
| have hpos : 0 < β« x, exp (f x) βQ := integral_pos_iff_support_of_nonneg | |
| (fun x => (exp_pos (f x)).le) he |>.mpr (by simp [Function.support, (exp_pos _).ne']) | |
| exact le_of_tendsto (hP.sub ((continuousAt_log hpos.ne').tendsto.comp hQ)) | |
| (Eventually.of_forall (fun n => hD (clippedBC hf n))) | |
| lemma entropyTestBound_normalized {P Q : Measure β} [IsProbabilityMeasure P] | |
| [IsProbabilityMeasure Q] {D : β} (hD : EntropyTestBound P Q D) | |
| {f : β β β} (hf : Continuous f) (hi : Integrable f P) | |
| (he : Integrable (fun x => exp (f x)) Q) (hZ : β« x, exp (f x) βQ = 1) : | |
| (β« x, f x βP) β€ D := by | |
| simpa only [hZ, log_one, sub_zero] using entropyTestBound_continuous hD hf hi he | |
| lemma integrable_exp_boundedContinuous {Q : Measure β} [IsFiniteMeasure Q] (f : β βα΅ β) (t : β) : | |
| Integrable (fun x => exp (t*f x)) Q := by | |
| apply Integrable.of_bound (by fun_prop) (exp (|t| * βfβ)) | |
| exact ae_of_all _ (fun x => by | |
| rw [Real.norm_eq_abs, abs_of_pos (exp_pos _)] | |
| apply exp_le_exp.mpr | |
| calc | |
| t*f x β€ |t*f x| := le_abs_self _ | |
| _ = |t| * |f x| := abs_mul _ _ | |
| _ β€ |t| * βfβ := mul_le_mul_of_nonneg_left (by simpa only [Real.norm_eq_abs] using f.norm_coe_le_norm x) (abs_nonneg _)) | |
| lemma boundedContinuous_mgf_deriv {Q : Measure β} [IsProbabilityMeasure Q] (f : β βα΅ β) : | |
| HasDerivAt (fun t : β => β« x, exp (t*f x) βQ) (β« x, f x βQ) 0 := by | |
| have hset : integrableExpSet (fun x => f x) Q = univ := by | |
| ext t; exact iff_true_intro (integrable_exp_boundedContinuous f t) | |
| have h := hasDerivAt_mgf (X := fun x => f x) (ΞΌ := Q) (t := 0) (by simp [hset]) | |
| convert! h using 1; simp | |
| lemma entropyTestBound_zero_eq {P Q : Measure β} [IsProbabilityMeasure P] | |
| [IsProbabilityMeasure Q] (hD : EntropyTestBound P Q 0) : P = Q := by | |
| apply ext_of_forall_integral_eq_of_IsFiniteMeasure | |
| intro f | |
| let g : β β β := fun t => log (β« x, exp (t*f x) βQ) - t*(β« x, f x βP) | |
| have hg0 : g 0 = 0 := by simp [g] | |
| have hmin : IsLocalMin g 0 := by | |
| apply Filter.Eventually.of_forall | |
| intro t | |
| have h := hD (t β’ f) | |
| simp only [BoundedContinuousFunction.smul_apply, smul_eq_mul, integral_const_mul] at h | |
| rw [hg0] | |
| dsimp [g] | |
| exact (show 0 β€ log (β« x, exp (t*f x) βQ)-t*(β« x, f x βP) by linarith) | |
| have hder : HasDerivAt g ((β« x, f x βQ)-(β« x, f x βP)) 0 := by | |
| have h := (boundedContinuous_mgf_deriv (Q := Q) f).log (by simp) | |
| convert! h.sub ((hasDerivAt_id (0:β)).mul_const (β« x, f x βP)) using 1; simp | |
| have hz := hmin.hasDerivAt_eq_zero hder | |
| linarith | |
| lemma entropyTestBound_nonneg {P Q : Measure β} [IsProbabilityMeasure P] | |
| [IsProbabilityMeasure Q] {D : β} (hD : EntropyTestBound P Q D) : 0 β€ D := by | |
| simpa using hD 0 | |
| end SKGap | |
| end | |
| end | |
| end | |
| end | |
| end OAI | |