Download data/lean/OAI/Combinatorics/BooleanFunctions/MomentTransfer.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 13 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/BooleanFunctions/MomentTransfer.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/BooleanFunctions/MomentTransfer.lean
-
curl -L -o MomentTransfer.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/BooleanFunctions/MomentTransfer.lean
13 kB
| import OAI.Combinatorics.BooleanFunctions.GaussianGain | |
| namespace OAI | |
| open scoped BigOperators Topology NNReal ENNReal | |
| open MeasureTheory ProbabilityTheory Filter Real | |
| noncomputable section | |
| namespace SquareRootDegree | |
| namespace MomentTransfer | |
| open SmoothGaussian SmoothSelector GaussianGain | |
| /-- Only compact continuous test functions are passed through weak convergence. -/ | |
| theorem compact_test_tendsto {Ξ© : β β Type*} [β n, MeasurableSpace (Ξ© n)] | |
| (P : β n, Measure (Ξ© n)) [β n, IsProbabilityMeasure (P n)] | |
| (T : β n, Ξ© n β β) (hT : TendstoInDistribution T atTop (fun x : β => x) P (gaussianReal 0 1)) | |
| (f : β β β) (hf : Continuous f) (hc : HasCompactSupport f) : | |
| Tendsto (fun n => β« x, f (T n x) βP n) atTop (π (β« x, f x βgaussianReal 0 1)) := by | |
| have h := (ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mp hT.tendsto) | |
| (ofCompactSupport f hf hc) | |
| change Tendsto (fun n => β« x, f x β(P n).map (T n)) atTop | |
| (π (β« x, f x β(gaussianReal 0 1).map (fun x => x))) at h | |
| rw [Measure.map_id'] at h | |
| have he (n : β) : (β« x, f x β(P n).map (T n)) = | |
| β« x, f (T n x) βP n := by | |
| rw [integral_map (hT.forall_aemeasurable n) hf.aestronglyMeasurable] | |
| simpa only [he] using h | |
| def moments {Ξ© : Type*} [MeasurableSpace Ξ©] (P : Measure Ξ©) (T : Ξ© β β) | |
| {ΞΉ : Type*} (w : ΞΉ β β β β) (k : Fin 3) (i : ΞΉ) : β := | |
| β« x, w i (T x)*(T x)^(k:β) βP | |
| variable {ΞΉ : Type*} [Fintype ΞΉ] [DecidableEq ΞΉ] | |
| def means (l : Fin 3 β ΞΉ β β) (i : ΞΉ) : β := l 1 i / l 0 i | |
| def vars (l : Fin 3 β ΞΉ β β) (i : ΞΉ) : β := l 2 i / l 0 i - (means l i)^2 | |
| def gain (l s : Fin 3 β ΞΉ β β) : β := | |
| (β i, l 0 i) * (1 + β i, vars l i - | |
| β i, (s 2 i + 2*(1-means l i)*s 1 i + | |
| ((1-means l i)^2+β j β Finset.univ.erase i, vars l j)*s 0 i) / l 0 i) | |
| theorem gain_tendsto (l s : β β Fin 3 β ΞΉ β β) (lβ sβ : Fin 3 β ΞΉ β β) | |
| (hl : β k i, Tendsto (fun n => l n k i) atTop (π (lβ k i))) | |
| (hs : β k i, Tendsto (fun n => s n k i) atTop (π (sβ k i))) | |
| (hb : β i, lβ 0 i β 0) : | |
| Tendsto (fun n => gain (l n) (s n)) atTop (π (gain lβ sβ)) := by | |
| have hm (i : ΞΉ) : Tendsto (fun n => means (l n) i) atTop (π (means lβ i)) := | |
| (hl 1 i).div (hl 0 i) (hb i) | |
| have hv (i : ΞΉ) : Tendsto (fun n => vars (l n) i) atTop (π (vars lβ i)) := | |
| ((hl 2 i).div (hl 0 i) (hb i)).sub ((hm i).pow 2) | |
| have hvsum := tendsto_finsetSum Finset.univ (fun i _ => hv i) | |
| have hother (i : ΞΉ) := tendsto_finsetSum (Finset.univ.erase i) (fun j _ => hv j) | |
| have hj (i : ΞΉ) : Tendsto (fun n => (s n 2 i + 2*(1-means (l n) i)*s n 1 i + | |
| ((1-means (l n) i)^2+β j β Finset.univ.erase i, vars (l n) j)*s n 0 i) / l n 0 i) | |
| atTop (π ((sβ 2 i + 2*(1-means lβ i)*sβ 1 i + | |
| ((1-means lβ i)^2+β j β Finset.univ.erase i, vars lβ j)*sβ 0 i) / lβ 0 i)) := by | |
| exact (((hs 2 i).add ((tendsto_const_nhds.mul (tendsto_const_nhds.sub (hm i))).mul (hs 1 i))).add | |
| ((((tendsto_const_nhds.sub (hm i)).pow 2).add (hother i)).mul (hs 0 i))).div (hl 0 i) (hb i) | |
| exact (tendsto_finsetProd Finset.univ (fun i _ => hl 0 i)).mul | |
| ((tendsto_const_nhds.add hvsum).sub (tendsto_finsetSum Finset.univ (fun i _ => hj i))) | |
| theorem hat_le_one (N : β) (Ξ΄ : β) (i : Fin (2*N+1)) (t : β) : | |
| hat N Ξ΄ i t β€ 1 := by | |
| exact (Finset.single_le_sum (fun j _ => hat_nonneg N Ξ΄ j t) (Finset.mem_univ i)).trans | |
| (hats_sum_le_one N Ξ΄ t) | |
| theorem hat_moment_integrable {Ξ© : Type*} [MeasurableSpace Ξ©] {P : Measure Ξ©} | |
| (T : Ξ© β β) (hT : Measurable T) (N : β) (Ξ΄ : β) (i : Fin (2*N+1)) (k : β) | |
| (hi : Integrable (fun x => (T x)^k) P) : | |
| Integrable (fun x => hat N Ξ΄ i (T x)*(T x)^k) P := by | |
| apply hi.norm.mono' (by fun_prop) | |
| filter_upwards [] with x | |
| rw [Real.norm_eq_abs,abs_mul,abs_of_nonneg (hat_nonneg ..)] | |
| exact mul_le_of_le_one_left (abs_nonneg _) (hat_le_one ..) | |
| theorem weight_moment_eq {Ξ© : Type*} [MeasurableSpace Ξ©] {P : Measure Ξ©} | |
| (T : Ξ© β β) (hT : Measurable T) (N : β) (Ξ΄ : β) (i : Fin (2*N+1)) (k : β) | |
| (hi : Integrable (fun x => (T x)^k) P) : | |
| (β« x, weight N Ξ΄ i (T x)*(T x)^k βP) = | |
| (β« x, hat N Ξ΄ i (T x)*(T x)^k βP) + | |
| if i = middle N then (β« x, (T x)^k βP) - | |
| β j, β« x, hat N Ξ΄ j (T x)*(T x)^k βP else 0 := by | |
| have hh (j) := hat_moment_integrable T hT N Ξ΄ j k hi | |
| by_cases he : i = middle N | |
| Β· subst i | |
| simp only [weight,ite_true,add_mul,sub_mul,one_mul,Finset.sum_mul] | |
| rw [integral_add (f := fun x => hat N Ξ΄ (middle N) (T x)*(T x)^k) | |
| (g := fun x => (T x)^k-β j, hat N Ξ΄ j (T x)*(T x)^k) | |
| (hh (middle N)) (hi.sub (integrable_finsetSum Finset.univ (fun j _ => hh j))), | |
| integral_sub hi (integrable_finsetSum Finset.univ (fun j _ => hh j)), | |
| integral_finsetSum Finset.univ (fun j _ => hh j)] | |
| Β· simp only [weight,he,ite_false,add_zero] | |
| theorem gaussian_pow_integrable (k : Fin 3) : | |
| Integrable (fun x : β => x^(k:β)) (gaussianReal 0 1) := by | |
| fin_cases k | |
| Β· simp only [pow_zero]; exact integrable_const _ | |
| Β· change Integrable (fun x : β => x^1) (gaussianReal 0 1) | |
| simp only [pow_one] | |
| exact (memLp_id_gaussianReal (ΞΌ := 0) (v := 1) 1).integrable le_rfl | |
| Β· exact gaussian_sq_integrable 1 | |
| theorem leaf_moments_tendsto {Ξ© : β β Type*} [β n, MeasurableSpace (Ξ© n)] | |
| (P : β n, Measure (Ξ© n)) [β n, IsProbabilityMeasure (P n)] | |
| (T : β n, Ξ© n β β) (hT : TendstoInDistribution T atTop (fun x : β => x) P (gaussianReal 0 1)) | |
| (k : Fin 3) (i : Leaves) : | |
| Tendsto (fun n => moments (P n) (T n) leafTest k i) atTop | |
| (π (moments (gaussianReal 0 1) id leafTest k i)) := by | |
| apply compact_test_tendsto P T hT | |
| Β· exact (continuous_tent _ _).mul (continuous_id.pow _) | |
| Β· exact (tent_compactSupport width_pos).mul_right | |
| theorem selector_moments_tendsto {Ξ© : β β Type*} [β n, MeasurableSpace (Ξ© n)] | |
| (P : β n, Measure (Ξ© n)) [β n, IsProbabilityMeasure (P n)] | |
| (T : β n, Ξ© n β β) (hm : β n, Measurable (T n)) | |
| (hT : TendstoInDistribution T atTop (fun x : β => x) P (gaussianReal 0 1)) | |
| (hi : β n (k : Fin 3), Integrable (fun x => (T n x)^(k:β)) (P n)) | |
| (hM : β k : Fin 3, Tendsto (fun n => β« x, (T n x)^(k:β) βP n) atTop | |
| (π (β« x : β, x^(k:β) βgaussianReal 0 1))) (k : Fin 3) (i : Leaves) : | |
| Tendsto (fun n => moments (P n) (T n) selectorTest k i) atTop | |
| (π (moments (gaussianReal 0 1) id selectorTest k i)) := by | |
| have hh (j : Leaves) := compact_test_tendsto P T hT | |
| (fun x => hat gridN step j x*x^(k:β)) | |
| ((hat_continuous ..).mul (continuous_id.pow _)) ((hat_compactSupport step_pos j).mul_right) | |
| simp only [moments,selectorTest] | |
| simp_rw [weight_moment_eq (T _) (hm _) _ _ _ _ (hi _ k), | |
| weight_moment_eq id measurable_id _ _ _ _ (gaussian_pow_integrable k)] | |
| by_cases he : i = middle gridN | |
| Β· simp only [he,ite_true] | |
| exact (hh (middle gridN)).add ((hM k).sub (tendsto_finsetSum Finset.univ (fun j _ => hh j))) | |
| Β· simp only [he,ite_false,add_zero] | |
| exact hh i | |
| theorem weight_le_one (N : β) (Ξ΄ : β) (i : Fin (2*N+1)) (t : β) : | |
| weight N Ξ΄ i t β€ 1 := by | |
| calc weight N Ξ΄ i t β€ β j, weight N Ξ΄ j t := | |
| Finset.single_le_sum (fun j _ => weight_nonneg N Ξ΄ j t) (Finset.mem_univ i) | |
| _ = 1 := weight_sum .. | |
| theorem gaussian_selector_integrable (k : Fin 3) (i : Leaves) : | |
| Integrable (fun x : β => selectorTest i x*x^(k:β)) (gaussianReal 0 1) := by | |
| apply (gaussian_pow_integrable k).norm.mono' (by dsimp [selectorTest]; fun_prop) | |
| filter_upwards [] with x | |
| change |weight gridN step i x*x^(k:β)| β€ |x^(k:β)| | |
| rw [abs_mul,abs_of_nonneg (weight_nonneg ..)] | |
| exact mul_le_of_le_one_left (abs_nonneg _) (weight_le_one ..) | |
| theorem quadratic_moment_formula {P : Measure β} (w : β β β) | |
| (h0 : Integrable w P) (h1 : Integrable (fun x => w x*x) P) | |
| (h2 : Integrable (fun x => w x*x^2) P) (a v : β) : | |
| (β« x, w x*((1+x-a)^2+v) βP) = (β« x, w x*x^2 βP) + | |
| 2*(1-a)*(β« x, w x*x βP) + ((1-a)^2+v)*(β« x, w x βP) := by | |
| have he : (fun x => w x*((1+x-a)^2+v)) = fun x => | |
| w x*x^2 + (2*(1-a))*(w x*x) + ((1-a)^2+v)*w x := by funext x; ring | |
| rw [he,integral_add (f := fun x => w x*x^2+(2*(1-a))*(w x*x)) | |
| (g := fun x => ((1-a)^2+v)*w x) (h2.add (h1.const_mul _)) (h0.const_mul _), | |
| integral_add h2 (h1.const_mul _), integral_const_mul,integral_const_mul] | |
| def gaussianLeafMoments : Fin 3 β Leaves β β := moments (gaussianReal 0 1) id leafTest | |
| def gaussianSelectorMoments : Fin 3 β Leaves β β := moments (gaussianReal 0 1) id selectorTest | |
| @[simp] theorem gaussianLeaf_zero (i : Leaves) : gaussianLeafMoments 0 i = GaussianGain.beta i := by | |
| simp only [gaussianLeafMoments,moments,Fin.val_zero,pow_zero,mul_one,GaussianGain.beta,mass,id_eq] | |
| @[simp] theorem gaussianLeaf_mean (i : Leaves) : means gaussianLeafMoments i = mu i := by | |
| simp only [means,gaussianLeafMoments,moments,Fin.val_zero,Fin.val_one,pow_zero,pow_one,mul_one, | |
| mu,mean,mass,id_eq] | |
| @[simp] theorem gaussianLeaf_var (i : Leaves) : vars gaussianLeafMoments i = sigma i := by | |
| rw [vars,gaussianLeaf_mean] | |
| simp only [gaussianLeafMoments,moments,Fin.val_zero,pow_zero,mul_one, | |
| sigma,SmoothGaussian.variance,mass,id_eq,mu] | |
| rfl | |
| theorem gaussianGain_eq : gain gaussianLeafMoments gaussianSelectorMoments = | |
| (β i : Leaves, GaussianGain.beta i) * (1+totalVariance-J) := by | |
| have hi0 (i) : Integrable (selectorTest i) (gaussianReal 0 1) := by | |
| simpa only [Fin.val_zero,pow_zero,mul_one] using gaussian_selector_integrable 0 i | |
| have hi1 (i) : Integrable (fun x => selectorTest i x*x) (gaussianReal 0 1) := by | |
| simpa only [Fin.val_one,pow_one] using gaussian_selector_integrable 1 i | |
| have hi2 (i) : Integrable (fun x => selectorTest i x*x^2) (gaussianReal 0 1) := | |
| gaussian_selector_integrable 2 i | |
| have hik (i) : Integrable (fun x => selectorTest i x*((1+x-mu i)^2+otherVariance i)/GaussianGain.beta i) | |
| (gaussianReal 0 1) := by | |
| have he : (fun x => selectorTest i x*((1+x-mu i)^2+otherVariance i)) = fun x => | |
| selectorTest i x*x^2 + (2*(1-mu i))*(selectorTest i x*x) + | |
| ((1-mu i)^2+otherVariance i)*selectorTest i x := by funext x; ring | |
| apply Integrable.div_const | |
| rw [he] | |
| exact ((hi2 i).add ((hi1 i).const_mul _)).add ((hi0 i).const_mul _) | |
| have hJ : J = β i, (gaussianSelectorMoments 2 i + 2*(1-mu i)*gaussianSelectorMoments 1 i + | |
| ((1-mu i)^2+otherVariance i)*gaussianSelectorMoments 0 i) / GaussianGain.beta i := by | |
| change (β« t, β i, selectorTest i t*((1+t-mu i)^2+otherVariance i)/GaussianGain.beta i | |
| βgaussianReal 0 1) = _ | |
| rw [integral_finsetSum Finset.univ (fun i _ => hik i)] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| rw [integral_div,quadratic_moment_formula _ (hi0 i) (hi1 i) (hi2 i)] | |
| simp only [gaussianSelectorMoments,moments,Fin.val_zero,Fin.val_one,pow_zero,pow_one,mul_one,id_eq] | |
| rfl | |
| simp only [gain,gaussianLeaf_zero,gaussianLeaf_mean,gaussianLeaf_var,totalVariance,hJ,otherVariance] | |
| theorem gaussianGain_pos : 0 < gain gaussianLeafMoments gaussianSelectorMoments := by | |
| rw [gaussianGain_eq] | |
| exact positive_gaussian_deficit | |
| def eta : β := gain gaussianLeafMoments gaussianSelectorMoments / 2 | |
| theorem eta_pos : 0 < eta := div_pos gaussianGain_pos (by norm_num) | |
| theorem eventually_positive_gain {Ξ© : β β Type*} [β n, MeasurableSpace (Ξ© n)] | |
| (P : β n, Measure (Ξ© n)) [β n, IsProbabilityMeasure (P n)] | |
| (T : β n, Ξ© n β β) (hm : β n, Measurable (T n)) | |
| (hT : TendstoInDistribution T atTop (fun x : β => x) P (gaussianReal 0 1)) | |
| (hi : β n (k : Fin 3), Integrable (fun x => (T n x)^(k:β)) (P n)) | |
| (hM : β k : Fin 3, Tendsto (fun n => β« x, (T n x)^(k:β) βP n) atTop | |
| (π (β« x : β, x^(k:β) βgaussianReal 0 1))) : | |
| βαΆ n in atTop, (β i : Leaves, 0 < moments (P n) (T n) leafTest 0 i) β§ | |
| eta < gain (moments (P n) (T n) leafTest) (moments (P n) (T n) selectorTest) := by | |
| have hl := leaf_moments_tendsto P T hT | |
| have hs := selector_moments_tendsto P T hm hT hi hM | |
| have hg := gain_tendsto (fun n => moments (P n) (T n) leafTest) | |
| (fun n => moments (P n) (T n) selectorTest) gaussianLeafMoments gaussianSelectorMoments | |
| hl hs (fun i => by rw [gaussianLeaf_zero]; exact (beta_pos i).ne') | |
| have he : eta < gain gaussianLeafMoments gaussianSelectorMoments := by | |
| dsimp [eta]; linarith [gaussianGain_pos] | |
| have hge := (tendsto_order.mp hg).1 eta he | |
| have hp : βαΆ n in atTop, β i : Leaves, 0 < moments (P n) (T n) leafTest 0 i := by | |
| apply Filter.eventually_all.mpr | |
| intro i | |
| exact (hl 0 i).eventually (lt_mem_nhds (by | |
| change 0 < gaussianLeafMoments 0 i | |
| rw [gaussianLeaf_zero]; exact beta_pos i)) | |
| exact hp.and hge | |
| end MomentTransfer | |
| end SquareRootDegree | |
| end | |
| end OAI | |