Add lean source and binary files (part 128)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- lean/OAI/Probability/SKGap/Entropy/WeightedMomentComparison.leanAdded+78
- lean/OAI/Probability/SKGap/Entropy/WeightedRateAssembly.leanAdded+39
- lean/OAI/Probability/SKGap/Entropy/WeightedScalarMoments.leanAdded+69
- lean/OAI/Probability/SKGap/Entropy/WordUniformCost.leanAdded+106
- lean/OAI/Probability/SKGap/Gaussian/AdaptiveInnovationSquareTails.leanAdded+96
- lean/OAI/Probability/SKGap/Gaussian/ConditionalGramTail.leanAdded+94
- lean/OAI/Probability/SKGap/Gaussian/ConditionalUniformTail.leanAdded+122
- lean/OAI/Probability/SKGap/Gaussian/DiagonalNormTail.leanAdded+47
- lean/OAI/Probability/SKGap/Gaussian/FourierMoment.leanAdded+74
- lean/OAI/Probability/SKGap/Gaussian/GOEGaussian.leanAdded+64
- lean/OAI/Probability/SKGap/Gaussian/GOERowTail.leanAdded+98
- lean/OAI/Probability/SKGap/Gaussian/GOEScalarTail.leanAdded+158
- lean/OAI/Probability/SKGap/Gaussian/GaussMoment.leanAdded+511
- lean/OAI/Probability/SKGap/Gaussian/GaussianCompactTailRate.leanAdded+186
- lean/OAI/Probability/SKGap/Gaussian/GaussianCoordinateMemLp.leanAdded+109
- lean/OAI/Probability/SKGap/Gaussian/GaussianCoordinates.leanAdded+187
- lean/OAI/Probability/SKGap/Gaussian/GaussianDisintegration.leanAdded+56
- lean/OAI/Probability/SKGap/Gaussian/GaussianFiniteIBPError.leanAdded+43
- lean/OAI/Probability/SKGap/Gaussian/GaussianGramMomentsJoined.leanAdded+197
- lean/OAI/Probability/SKGap/Gaussian/GaussianLinearDensity.leanAdded+170
- lean/OAI/Probability/SKGap/Gaussian/GaussianMarginal.leanAdded+175
- lean/OAI/Probability/SKGap/Gaussian/GaussianMatrixChaining.leanAdded+82
- lean/OAI/Probability/SKGap/Gaussian/GaussianPDFMoment.leanAdded+172
- lean/OAI/Probability/SKGap/Gaussian/GaussianPartition.leanAdded+163
- lean/OAI/Probability/SKGap/Gaussian/GaussianProductIntegral.leanAdded+73
- lean/OAI/Probability/SKGap/Gaussian/GaussianProductPower.leanAdded+163
- lean/OAI/Probability/SKGap/Gaussian/GaussianProductUpperTailLipschitz.leanAdded+103
- lean/OAI/Probability/SKGap/Gaussian/GaussianQuadratic.leanAdded+202
- lean/OAI/Probability/SKGap/Gaussian/GaussianQuadraticSupComparison.leanAdded+147
- lean/OAI/Probability/SKGap/Gaussian/GaussianRankCorrection.leanAdded+429
- lean/OAI/Probability/SKGap/Gaussian/GaussianRecipeEvent.leanAdded+121
- lean/OAI/Probability/SKGap/Gaussian/GaussianReductionPointwise.leanAdded+73
- lean/OAI/Probability/SKGap/Gaussian/GaussianRegression.leanAdded+134
- lean/OAI/Probability/SKGap/Gaussian/GaussianSign.leanAdded+79
- lean/OAI/Probability/SKGap/Gaussian/GaussianSquareTail.leanAdded+153
- lean/OAI/Probability/SKGap/Gaussian/GaussianTailScale.leanAdded+179
- lean/OAI/Probability/SKGap/Gaussian/GaussianTiltIdentity.leanAdded+64
- lean/OAI/Probability/SKGap/Gaussian/GaussianTiltMass.leanAdded+171
- lean/OAI/Probability/SKGap/Gaussian/GaussianVectorMoments.leanAdded+63
- lean/OAI/Probability/SKGap/Gaussian/IndependentBoundedAverageTailLaw.leanAdded+234
- lean/OAI/Probability/SKGap/Gaussian/LiteralWeakTail.leanAdded+108
- lean/OAI/Probability/SKGap/Gaussian/LocalGaussianMoments.leanAdded+165
- lean/OAI/Probability/SKGap/Gaussian/MatrixNormTail.leanAdded+104
- lean/OAI/Probability/SKGap/Gaussian/MatrixWordMoments.leanAdded+93
- lean/OAI/Probability/SKGap/Gaussian/PartitionSecondMoment.leanAdded+144
- lean/OAI/Probability/SKGap/Gaussian/PhiMoments.leanAdded+138
- lean/OAI/Probability/SKGap/Gaussian/PhiStein.leanAdded+135
- lean/OAI/Probability/SKGap/Gaussian/ProductGaussianDensity.leanAdded+42
- lean/OAI/Probability/SKGap/Gaussian/RegressionMoments.leanAdded+63
- lean/OAI/Probability/SKGap/Gaussian/ReplicaTailWeight.leanAdded+318
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778import Mathlibimport OAI.Probability.SKGap.Model
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Realopen scoped BigOperators
variable {ι : Type*} [Fintype ι]
lemma sum_abs_le_sqrt_card_l2 (d : ι → ℝ) : (∑ i, |d i|) ≤ √(Fintype.card ι:ℝ)*√(∑ i,d i^2) := by simpa only [one_mul,one_pow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one, sq_abs] using Real.sum_mul_le_sqrt_mul_sqrt Finset.univ (fun _ : ι => (1:ℝ)) (fun i => |d i|)
theorem weighted_moment_comparison (a v y f : ι → ℝ) {H C D R : ℝ} (hH : 0 ≤ H) (hC : 0 ≤ C) (hD : 0 ≤ D) (hR : 1 ≤ R) (ha : ∀ i, |a i-v i| ≤ D) (hsmall : ∀ i, |y i| ≤ R → |f i| ≤ H) (hlarge : ∀ i, |f i| ≤ C*(1+y i^2)) : |∑ i,(a i-v i)*f i| ≤ H*√(Fintype.card ι:ℝ)*√(∑ i,(a i-v i)^2)+ 2*C*D*∑ i,if R < |y i| then y i^2 else 0 := by have hpoint (i : ι) : |(a i-v i)*f i| ≤ H*|a i-v i|+ 2*C*D*(if R < |y i| then y i^2 else 0) := by rw [abs_mul] by_cases hi : R < |y i| · rw [ite_eq_left hi] have hy : 1 ≤ y i^2 := by nlinarith [sq_abs (y i)] have hf : |f i| ≤ 2*C*y i^2 := (hlarge i).trans (by nlinarith) have hh := mul_le_mul (ha i) hf (abs_nonneg _) hD nlinarith [mul_nonneg hH (abs_nonneg (a i-v i))] · rw [ite_eq_right hi,mul_zero,add_zero] simpa only [mul_comm H] using mul_le_mul_of_nonneg_left (hsmall i (le_of_not_gt hi)) (abs_nonneg (a i-v i)) calc _ ≤ ∑ i, |(a i-v i)*f i| := Finset.abs_sum_le_sum_abs _ _ _ ≤ ∑ i,(H*|a i-v i|+2*C*D*(if R < |y i| then y i^2 else 0)) := Finset.sum_le_sum (fun i _ => hpoint i) _ = H*(∑ i,|a i-v i|)+2*C*D*∑ i,if R < |y i| then y i^2 else 0 := by rw [Finset.sum_add_distrib,← Finset.mul_sum,← Finset.mul_sum] _ ≤ _ := by rw [mul_assoc H] exact add_le_add (mul_le_mul_of_nonneg_left (sum_abs_le_sqrt_card_l2 _) hH) le_rfl
theorem normalized_weighted_moment_comparison {n : ℕ} (hn : 0 < n) (a v y f : Fin n → ℝ) {H C D R ε ν : ℝ} (hH : 0 ≤ H) (hC : 0 ≤ C) (hD : 0 ≤ D) (hR : 1 ≤ R) (hε : 0 ≤ ε) (ha : ∀ i, |a i-v i| ≤ D) (hsmall : ∀ i, |y i| ≤ R → |f i| ≤ H) (hlarge : ∀ i, |f i| ≤ C*(1+y i^2)) (hclose : ∑ i,(a i-v i)^2 ≤ ε^2*(n:ℝ)) (htail : (∑ i,if R < |y i| then y i^2 else 0) ≤ ν*(n:ℝ)) : |(∑ i,(a i-v i)*f i)/(n:ℝ)| ≤ H*ε+2*C*D*ν := by have hnR : 0 < (n:ℝ) := by exact_mod_cast hn have hnorm : √(∑ i,(a i-v i)^2) ≤ ε*√(n:ℝ) := by apply Real.sqrt_le_iff.mpr constructor · positivity · nlinarith [Real.sq_sqrt hnR.le] have h := weighted_moment_comparison a v y f hH hC hD hR ha hsmall hlarge simp only [Fintype.card_fin] at h have h' : |∑ i,(a i-v i)*f i| ≤ (H*ε+2*C*D*ν)*(n:ℝ) := by calc _ ≤ _ := h _ ≤ H*√(n:ℝ)*(ε*√(n:ℝ))+2*C*D*(ν*(n:ℝ)) := by exact add_le_add (mul_le_mul_of_nonneg_left hnorm (by positivity)) (mul_le_mul_of_nonneg_left htail (by positivity)) _ = H*ε*(√(n:ℝ))^2+2*C*D*ν*(n:ℝ) := by ring _ = _ := by rw [Real.sq_sqrt hnR.le]; ring rw [abs_div,abs_of_pos hnR] exact (div_le_iff₀ hnR).mpr h'end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839import Mathlibimport OAI.Probability.SKGap.Localization.ScalarEmpirical
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Real Setopen scoped ENNReal
lemma weighted_four_region_bound {α : Type*} [MeasurableSpace α] (μ : Measure α) (f g : α → ℝ≥0∞) (hg : Measurable g) (B F D : Set α) (hB : MeasurableSet B) (hF : MeasurableSet F) (hD : MeasurableSet D) (hfg : ∀ x, f x ≤ g x) (k : ℝ≥0∞) (hgood : ∀ x ∈ B ∩ Fᶜ ∩ Dᶜ, f x ≤ g x*k) : (∫⁻ x, f x ∂μ) ≤ (∫⁻ x in Bᶜ,g x ∂μ)+(∫⁻ x in B ∩ F,g x ∂μ)+ (∫⁻ x in D,g x ∂μ)+(∫⁻ x,g x ∂μ)*k := by have bound (E : Set α) : (∫⁻ x in E,f x ∂μ) ≤ (∫⁻ x in E,g x ∂μ) := lintegral_mono hfg have sub (E E' : Set α) (h : E ⊆ E') : (∫⁻ x in E,g x ∂μ) ≤ (∫⁻ x in E',g x ∂μ) := lintegral_mono_set h have hgood' : (∫⁻ x in B ∩ Fᶜ ∩ Dᶜ,f x ∂μ) ≤ (∫⁻ x,g x ∂μ)*k := by calc _ ≤ ∫⁻ x in B ∩ Fᶜ ∩ Dᶜ,g x*k ∂μ := lintegral_mono_ae (ae_restrict_of_forall_mem ((hB.inter hF.compl).inter hD.compl) hgood) _ = (∫⁻ x in B ∩ Fᶜ ∩ Dᶜ,g x ∂μ)*k := lintegral_mul_const _ hg _ ≤ (∫⁻ x,g x ∂μ)*k := mul_le_mul' (lintegral_mono' Measure.restrict_le_self le_rfl) le_rfl have h3 := (lintegral_split_le μ f (B ∩ Fᶜ) D).trans (add_le_add ((bound _).trans (sub _ _ (fun _ h=>h.2))) hgood') have h2 := (lintegral_split_le μ f B F).trans (add_le_add (bound _) h3) have h1 := (lintegral_split_le μ f univ B).trans (add_le_add (by simpa only [univ_inter] using h2) (by simpa only [univ_inter] using bound Bᶜ)) simpa only [Measure.restrict_univ,add_comm,add_left_comm,add_assoc] using h1
end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869import Mathlibimport OAI.Probability.SKGap.Model
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Real MeasureTheoryopen scoped BigOperators BoundedContinuousFunction
lemma scalarVariance_cosh (y : ℝ) : (1-tanh y^2)*cosh y^2=1 := by rw [tanh_eq_sinh_div_cosh] field_simp exact cosh_sq_sub_sinh_sq y
lemma square_le_sinh_square (y : ℝ) : y^2 ≤ sinh y^2 := by by_cases hy : 0 ≤ y · have h := (self_le_sinh_iff).2 hy have hs := (sinh_nonneg_iff).2 hy nlinarith · have h := (sinh_le_self_iff).2 (le_of_not_ge hy) have hs := (sinh_nonpos_iff).2 (le_of_not_ge hy) nlinarith
lemma scalarVariance_weight_bound (y : ℝ) : (1+y^2)*(1-tanh y^2) ≤ 1 := by have hv : 0 ≤ 1-tanh y^2 := sub_nonneg.mpr (tanh_sq_lt_one y).le have hb : 1+y^2 ≤ cosh y^2 := by linarith [square_le_sinh_square y,cosh_sq_sub_sinh_sq y] have h := mul_le_mul_of_nonneg_right hb hv rw [mul_comm (cosh y^2),scalarVariance_cosh] at h exact h
lemma weightedScalarMoment_bound (k l : Fin 3) (y : ℝ) : |y^(k:ℕ)*tanh y^(l:ℕ)*(1-tanh y^2)| ≤ 1 := by have hv : 0 ≤ 1-tanh y^2 := sub_nonneg.mpr (tanh_sq_lt_one y).le have ht : |tanh y|^(l:ℕ) ≤ 1 := pow_le_one₀ (abs_nonneg _) (abs_tanh_lt_one y).le have hy : |y|^(k:ℕ) ≤ 1+y^2 := by fin_cases k · simp only [pow_zero]; nlinarith [sq_nonneg y] · simp only [pow_one] nlinarith [sq_nonneg (|y|-1),sq_abs y] · simp only [pow_two,← sq_abs y]; nlinarith [sq_abs y] calc _ = (|y|^(k:ℕ)*|tanh y|^(l:ℕ))*(1-tanh y^2) := by rw [abs_mul,abs_mul,abs_pow,abs_pow,abs_of_nonneg hv] _ ≤ (1+y^2)*(1-tanh y^2) := by apply mul_le_mul_of_nonneg_right _ hv exact (mul_le_mul_of_nonneg_left ht (by positivity)).trans (by simpa using hy) _ ≤ 1 := scalarVariance_weight_bound y
def weightedScalarMoment (k l : Fin 3) : ℝ →ᵇ ℝ := BoundedContinuousFunction.ofNormedAddCommGroup (fun y => y^(k:ℕ)*tanh y^(l:ℕ)*(1-tanh y^2)) (by have ht : Continuous tanh := by change Continuous (fun y => tanh y) simp_rw [tanh_eq_sinh_div_cosh] exact continuous_sinh.div continuous_cosh (fun y => (cosh_pos y).ne') fun_prop) (1:ℝ) (fun y => by simpa only [Real.norm_eq_abs] using weightedScalarMoment_bound k l y)
lemma continuous_weightedScalarMoment_integral (k l : Fin 3) : Continuous (fun P : ProbabilityMeasure ℝ => ∫ y, weightedScalarMoment k l y ∂P) := ProbabilityMeasure.continuous_integral_boundedContinuousFunction _
end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106import Mathlibimport OAI.Probability.SKGap.Matrix.WordExpectedRecursion
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Matrix Real Setopen scoped BigOperators SchwartzMap
lemma finite_cost_bound (g : ℕ→ℕ→ℕ→ℝ) (L : ℕ) : ∃ C : ℝ,0≤C ∧ ∀ u≤L,∀ v≤L,∀ q≤L,g u v q≤C := by let C := ∑ u∈Finset.range (L+1),∑ v∈Finset.range (L+1),∑ q∈Finset.range (L+1),|g u v q| refine ⟨C,by dsimp [C];positivity,?_⟩ intro u hu v hv q hq calc g u v q ≤ |g u v q| := le_abs_self _ _ ≤ ∑ r∈Finset.range (L+1),|g u v r| := Finset.single_le_sum (f := fun r => |g u v r|) (fun _ _=>abs_nonneg _) (Finset.mem_range.mpr (Nat.lt_succ_of_le hq)) _ ≤ ∑ w∈Finset.range (L+1),∑ r∈Finset.range (L+1),|g u w r| := Finset.single_le_sum (f := fun w => ∑ r∈Finset.range (L+1),|g u w r|) (fun w _=>Finset.sum_nonneg (fun r _=>abs_nonneg (g u w r))) (Finset.mem_range.mpr (Nat.lt_succ_of_le hv)) _ ≤ C := by dsimp only [C] exact Finset.single_le_sum (f := fun w => ∑ v∈Finset.range (L+1),∑ r∈Finset.range (L+1),|g w v r|) (fun w _=>Finset.sum_nonneg (fun v _=>Finset.sum_nonneg (fun r _=>abs_nonneg (g w v r)))) (Finset.mem_range.mpr (Nat.lt_succ_of_le hu))
lemma continuous_wordMarkedCost (B : NNReal) (j R A c : ℝ) (p q : ℕ) : Continuous (fun z=>wordMarkedCost B j R A c z p q) := by unfold wordMarkedCost markedRateConstant wordDifferentialBound fun_prop
lemma wordMarkedCost_uniform (B : NNReal) (j R A c : ℝ) (L : ℕ) : ∃ C : ℝ,0≤C ∧ ∀ z∈Icc (0:ℝ) 1,∀ p≤L,∀ q≤L, wordMarkedCost B j R A c z p q≤C := by let H : ℝ→ℝ := fun z=>∑ p∈Finset.range (L+1),∑ q∈Finset.range (L+1),|wordMarkedCost B j R A c z p q| have hH : Continuous H := by unfold H exact continuous_finsetSum _ (fun p _=>continuous_finsetSum _ (fun q _=>(continuous_wordMarkedCost B j R A c p q).abs)) obtain ⟨C,hC⟩ := isCompact_Icc.exists_bound_of_continuousOn hH.continuousOn refine ⟨max 0 C,le_max_left _ _,?_⟩ intro z hz p hp q hq have hb : wordMarkedCost B j R A c z p q≤H z := by calc _ ≤ |wordMarkedCost B j R A c z p q| := le_abs_self _ _ ≤ ∑ r∈Finset.range (L+1),|wordMarkedCost B j R A c z p r| := Finset.single_le_sum (f := fun r=>|wordMarkedCost B j R A c z p r|) (fun _ _=>abs_nonneg _) (Finset.mem_range.mpr (Nat.lt_succ_of_le hq)) _ ≤ H z := by dsimp only [H] exact Finset.single_le_sum (f := fun w=>∑ r∈Finset.range (L+1),|wordMarkedCost B j R A c z w r|) (fun w _=>Finset.sum_nonneg (fun r _=>abs_nonneg (wordMarkedCost B j R A c z w r))) (Finset.mem_range.mpr (Nat.lt_succ_of_le hp)) have hbH : |H z|≤C := hC z hz exact hb.trans ((le_abs_self _).trans (hbH.trans (le_max_right _ _)))
variable {ι : Type*}lemma wordPartners_length_sides (a : ι→ℝ) (F : List (WordLetter ι)) (c : WordCut ι) (hc : c∈wordPartners a F) : c.left.length≤F.length+1 ∧ c.right.length≤F.length+1 := by have hh := wordPartners_lengths a F c hc cases hi : c.inversePartner · simp only [hi,Bool.false_eq_true,ite_false] at hh omega · have hs := wordPartners_inverse_sides a F c hc hi have hL : inverseCount c.left≤c.left.length := List.countP_le_length have hR : inverseCount c.right≤c.right.length := List.countP_le_length simp only [hi,ite_true] at hh omega
lemma wordRecursionAtCost_uniform {j B z C : ℝ} (hz : z∈Icc (0:ℝ) 1) (hC : 0≤C) (L : ℕ) (hc : ∀ u≤L,∀ v≤L,∀ q≤L,wordLeadingCost j B u v q≤C) (a : ι→ℝ) (P Q : List (WordLetter ι)) (hP : P.length+1+Q.length≤L) : wordRecursionAtCost j B z a P Q≤(L:ℝ)*C := by have hp : P.length≤L := by omega have hq : Q.length≤L := by omega have hz' (b : Bool) : |if b then z else 1|≤1 := by split · rw [abs_of_nonneg hz.1];exact hz.2 · simp have hl (c : WordCut ι) (h : c∈wordPartners a P) : |if c.inversePartner then z else 1| *wordLeadingCost j B c.left.length c.right.length Q.length≤C := by have hb := wordPartners_length_sides a P c h have hcost := hc c.left.length (by omega) c.right.length (by omega) Q.length hq have hh := mul_le_mul_of_nonneg_left hcost (abs_nonneg (if c.inversePartner then z else 1)) exact hh.trans ((mul_le_mul_of_nonneg_right (hz' _) hC).trans_eq (one_mul C)) have hr (c : WordCut ι) (h : c∈wordPartners a Q) : |if c.inversePartner then z else 1| *wordLeadingCost j B P.length c.left.length c.right.length≤C := by have hb := wordPartners_length_sides a Q c h have hcost := hc P.length hp c.left.length (by omega) c.right.length (by omega) exact (mul_le_mul_of_nonneg_left hcost (abs_nonneg (if c.inversePartner then z else 1))).trans ((mul_le_mul_of_nonneg_right (hz' _) hC).trans_eq (one_mul C)) have hb (X : List (WordCut ι)) (f : WordCut ι→ℝ) (hf : ∀ x∈X,f x≤C) : (X.map f).sum≤(X.length:ℝ)*C := by induction X with | nil => simp | cons x X ih => simp only [List.map_cons,List.sum_cons,List.length_cons,Nat.cast_add,Nat.cast_one] exact (add_le_add (hf x List.mem_cons_self) (ih (fun x hx=>hf x (List.mem_cons_of_mem _ hx)))).trans_eq (by ring) have hsum := add_le_add (hb _ _ hl) (hb _ _ hr) have hlen : ((wordPartners a P).length:ℝ)+(wordPartners a Q).length≤L := by exact_mod_cast (show (wordPartners a P).length+(wordPartners a Q).length≤L by have hh1 := wordPartners_card_bound a P have hh2 := wordPartners_card_bound a Q omega) apply hsum.trans nlinarith [mul_nonneg hC (sub_nonneg.mpr hlen)]end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596import Mathlibimport OAI.Probability.SKGap.Gaussian.SquareTail2
namespace OAI
sectionopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen scoped BigOperatorsopen scoped BigOperators NNReal ENNRealopen MeasureTheory Metric Setopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Setopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators ENNReal NNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Matrixopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators ENNReal NNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNRealopen scoped BigOperatorsopen Filter Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Topologynamespace SKGapCutoff.Regression
theorem adaptive_innovation_squareTails {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] (r : ℕ) (U : ∀ n, H n → Fin n → Fin r → ℝ) (q : ∀ n, H n → Fin n → ℝ) (hUm : ∀ n, Measurable (U n)) (hqm : ∀ n, Measurable (q n)) (hU : ∀ n h a, ∑ i, U n h i a^2 ≤ 1) (hq : ∀ n h, ∑ i, q n h i^2 ≤ 1) : ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) (fun n z i => Real.sqrt n * queryInnovation (residualProjection (U n z.1)) (q n z.1) z.2 i) := by have hs (n : ℕ) : HasLaw Prod.snd (standardArrayLaw (Fin n ⊕ Unit)) ((ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) := ⟨measurable_snd.aemeasurable, measurePreserving_snd.map_eq⟩ have ht : ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) (fun _ z i => z.2 (Sum.inl i)) := by refine iid_exponential_squareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) (fun _ z i => z.2 (Sum.inl i)) (fun _ _ => (measurable_pi_apply _).comp measurable_snd) ?_ (gaussianReal 0 1) ?_ ?_ · intro n apply iIndepFun_comp_hasLaw (hs n) (fun i g => g (Sum.inl i)) (fun _ => (measurable_pi_apply _).aemeasurable) exact coordinates_independent.precomp Sum.inl_injective · intro n i exact (coordinate_hasLaw (Sum.inl i)).fun_comp (hs n) · exact gaussian_integrable_exp_quarter_sq exact ht.l2_stability (adaptive_innovation_error_exponential ρ r U q hUm hqm hU hq)
end SKGapCutoff.Regression
open MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topology
end
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394import Mathlibimport OAI.Probability.SKGap.Localization.GramColumnBounds
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Matrix MeasureTheory ProbabilityTheory Real Setopen scoped BigOperators Matrix.Norms.Frobeniusvariable {ι : Type*} [Fintype ι] [DecidableEq ι]
omit [DecidableEq ι] inlemma matrixBilinear_eq_pair (M : Matrix ι ι ℝ) (x y : EuclideanSpace ℝ ι) : matrixBilinear M x y=matrixPair M x.ofLp y.ofLp := by simp only [matrixBilinear,matrixPair,dotProduct,Matrix.mulVec,Finset.mul_sum] congr 1; ext i; congr 1; ext k; ring
lemma exactG_transpose (j : ℝ) (a : ι → ℝ) {W : Matrix ι ι ℝ} (hW : Wᵀ=W) : (exactG j a W)ᵀ=exactG j a W := by simp only [exactG,Matrix.transpose_mul,Matrix.transpose_nonsing_inv, Matrix.transpose_sub,Matrix.transpose_one,Matrix.transpose_smul,hW, pathDiagonal,Matrix.diagonal_transpose,Matrix.mul_assoc]
def augmentedGramTolerance (B ε : ℝ) : ℝ := 4*(ε+(sqrt B)⁻¹*(1+B)*ε+B⁻¹*(1+2*B+B^2)*ε)
def actualAugmentedGram {n : ℕ} (j : ℝ) (a : Fin n → ℝ) (p : Fin 3 → EuclideanSpace ℝ (Fin n)) (u : EuclideanSpace ℝ (Fin n)) (g : MatrixCoordinates (Fin n) → ℝ) : Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ := let B := j/(n:ℝ)*∑ i,a i let W := goeMatrix (j/(n:ℝ)) g let V := extendColumns (fun r => (p r).ofLp) (residualGramVector B W u.ofLp) Vᵀ*exactG j a W*V
def diagonalAugmentedGram {n : ℕ} (a : Fin n → ℝ) (p : Fin 3 → EuclideanSpace ℝ (Fin n)) : Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ := fromBlocks (fun r s => matrixPair (diagonal a) (p r).ofLp (p s).ofLp) 0 0 1
theorem conditional_augmented_gram_tail {j A U ε : ℝ} (hj : 0 < j) (hA : 0 < A) (hs : sqrt j*A < 1) (hU : 0 ≤ U) (hε : 0 < ε) : ∃ (c : ℝ) (N : ℕ), 0 < c ∧ 0 < N ∧ ∀ n, N ≤ n → ∀ a : Fin n → ℝ, (∀ i,0 ≤ a i) → (∀ i,a i ≤ A) → 0 < j/(n:ℝ)*∑ i,a i → ∀ (p : Fin 3 → EuclideanSpace ℝ (Fin n)) (u : EuclideanSpace ℝ (Fin n)), (∀ r,‖p r‖ ≤ U) → ‖u‖ ≤ U → u.ofLp⬝ᵥu.ofLp=1 → (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real {g | ¬bilinearPathGood j A a g ∨ augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε < ‖actualAugmentedGram j a p u g-diagonalAugmentedGram a p‖} ≤ 99*Real.exp (-c*(n:ℝ)) := by obtain ⟨c,N,hc,hN,ht⟩ := bilinear_deterministic_equivalents hj hA hs hU hε 4 refine ⟨c,N,hc,hN,?_⟩ intro n hn a ha haA hB p u hp hu hunit let v : Fin 4 → EuclideanSpace ℝ (Fin n) := Fin.cons u p have hv : ∀ r,‖v r‖ ≤ U := by intro r refine Fin.cases hu (fun r => hp r) r have hh := ht n hn a ha haA v hv apply (measureReal_mono (s₂ := {g | ¬bilinearPathGood j A a g ∨ ∃ r s k, ε < |matrixBilinear (bilinearError k j a (goeMatrix (j/(n:ℝ)) g)) (v r) (v s)|}) ?_ (measure_ne_top _ _)).trans (by norm_num only [Nat.cast_ofNat,show (3:ℝ)+6*4^2=99 by norm_num] at hh; exact hh) intro g hg by_contra hbad change ¬(¬bilinearPathGood j A a g ∨ ∃ r s k, ε < |matrixBilinear (bilinearError k j a (goeMatrix (j/(n:ℝ)) g)) (v r) (v s)|) at hbad push Not at hbad rcases hbad with ⟨hpath,hpair⟩ have he (r s : Fin 4) (k : Fin 3) : |matrixPair (bilinearError k j a (goeMatrix (j/(n:ℝ)) g)) (v r).ofLp (v s).ofLp| ≤ ε := by rw [← matrixBilinear_eq_pair] exact hpair r s k have h00 (r s : Fin 3) := he r.succ s.succ 0 have h0u (r : Fin 3) := he r.succ 0 0 have h1u (r : Fin 3) := he r.succ 0 1 have h0 := he 0 0 0 have h1 := he 0 0 1 have h2 := he 0 0 2 simp only [v,Fin.cons_succ,Fin.cons_zero,bilinearError,ite_true,ite_false, Fin.reduceEq,Fintype.card_fin] at h00 h0u h1u h0 h1 h2 have hb := augmented_gram_error (exactG_transpose j a (goeMatrix_transpose _ g)) (goeMatrix_transpose _ g) (diagonal a) hB hε.le (fun r => (p r).ofLp) u.ofLp hunit h00 h0u h1u h0 h1 h2 have hb' : ‖actualAugmentedGram j a p u g-diagonalAugmentedGram a p‖ ≤ augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε := by simpa only [actualAugmentedGram,diagonalAugmentedGram,augmentedGramTolerance, Fintype.card_fin,Nat.cast_ofNat,show (3:ℝ)+1=4 by norm_num] using hb exact hg.elim (fun hn => hn hpath) (fun he => not_lt_of_ge hb' he)end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122import Mathlibimport OAI.Probability.SKGap.Gaussian.GOEScalarTail
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Matrix MeasureTheory ProbabilityTheory Real Setopen scoped BigOperators MatrixOrder Matrix.Norms.Frobenius
theorem compact_conditional_uniform_tail {α : Type*} [TopologicalSpace α] [CompactSpace α] {j A : ℝ} (hj : 0 < j) (hj1 : j < 1) (hA : 0 < A) (hsub : sqrt j*A < 1) (b e s q κ : α → ℝ) (hb : Continuous b) (he : Continuous e) (hs : Continuous s) (hq : Continuous q) (hk : Continuous κ) (hb0 : ∀ x,0 < b x) (hb1 : ∀ x,b x ≤ 1) (he0 : ∀ x,0 ≤ e x) (hs0 : ∀ x,0 < s x) (hq0 : ∀ x,0 < q x) (hkq : ∀ x,κ x^2=1-j*q x/s x) : ∃ δ ρ : ℝ, 0 < δ ∧ δ < 1 ∧ 0 < ρ ∧ ∀ U : ℝ, 0 ≤ U → ∀ ε τ : ℝ, 0 < ε → 0 < τ → ∃ c : ℝ, ∃ N : ℕ, 0 < c ∧ 0 < N ∧ ∀ n, N ≤ n → ∀ a : Fin n → ℝ, (∀ i,0 ≤ a i) → (∀ i,a i ≤ A) → 0 < j/(n:ℝ)*∑ i,a i → augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε < ρ/2 → ∀ p : Fin 3 → EuclideanSpace ℝ (Fin n), ∀ u : EuclideanSpace ℝ (Fin n), (∀ r,‖p r‖ ≤ U) → ‖u‖ ≤ U → u.ofLp⬝ᵥu.ofLp=1 → ∀ x (C E : Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ), C.IsHermitian → E.IsHermitian → τ*‖E‖ < ρ/2 → ‖diagonalAugmentedGram a p-augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))‖ < ρ/2 → ‖C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) j ((κ x-1)*√(j*b x)/√(q x))‖ < ρ/2 → (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real {g | ¬(conditionalBase j a g- pathDiagonal a 1*conditionalUpdateColumns j a p u g* (C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E)* (conditionalUpdateColumns j a p u g)ᵀ*pathDiagonal a 1- (δ*((1-sqrt j*A)^2/4)) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef} ≤ 101*exp (-c*(n:ℝ)) := by obtain ⟨δ,ρ,hδ,hδ1,hρ,hcrit⟩ := compact_conditional_rank_criterion hj hj1 b e s q κ hb he hs hq hk hb0 hb1 he0 hs0 hq0 hkq refine ⟨δ,ρ,hδ,hδ1,hρ,?_⟩ intro U hU ε τ hε hτ obtain ⟨c₀,N,hc₀,hN,hgram⟩ := conditional_augmented_gram_tail hj hA hsub hU hε let c₁ := τ^2/(π^2*(2*(U+1)^2)^2*j) have hc₁ : 0 < c₁ := by dsimp [c₁]; positivity refine ⟨min c₀ c₁,N,lt_min hc₀ hc₁,hN,?_⟩ intro n hn a ha haA hB heps p u hp hu hunit x C E hC hE hEbound hdiag hcoef let μ := Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1) let badG := {g | ¬bilinearPathGood j A a g ∨ augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε < ‖actualAugmentedGram j a p u g-diagonalAugmentedGram a p‖} let badS := {g | τ ≤ |matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u|} have hnpos := hN.trans_le hn have hgprob : μ.real badG ≤ 99*exp (-c₀*(n:ℝ)) := hgram n hn a ha haA hB p u hp hu hunit have hsprob : μ.real badS ≤ 2*exp (-c₁*(n:ℝ)) := by have hh := goe_scalar_tail hnpos hj hU hτ.le u hu convert hh using 1 congr 2 dsimp [c₁] ring have hsubsets : {g | ¬(conditionalBase j a g- pathDiagonal a 1*conditionalUpdateColumns j a p u g* (C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E)* (conditionalUpdateColumns j a p u g)ᵀ*pathDiagonal a 1- (δ*((1-sqrt j*A)^2/4)) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef} ⊆ badG ∪ badS := by intro g hg by_contra hbad have hgG : g ∉ badG := fun hh => hbad (Or.inl hh) have hgS : g ∉ badS := fun hh => hbad (Or.inr hh) simp only [badG,mem_ofPred_eq,not_or,not_lt] at hgG have hgS' : |matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u| < τ := lt_of_not_ge hgS let D := pathDiagonal a 1 let S := conditionalBase j a g let V := conditionalUpdateColumns j a p u g let Cg := C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E let lo := (1-sqrt j*A)^2/4 have hmargin : (S-lo • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef := bilinearPathGood_margin a g (not_not.mp hgG.1) have hlo : 0 ≤ lo := by dsimp [lo]; positivity have hSpos : S.PosDef := by have hh := hmargin.add_posSemidef ((Matrix.PosSemidef.one : (1 : Matrix (Fin n) (Fin n) ℝ).PosSemidef).smul hlo) convert hh using 1; abel have hD : D.IsHermitian := isHermitian_diagonal_iff.mpr (fun i => isSelfAdjoint_iff.mpr (star_trivial _)) have hCg : Cg.IsHermitian := hC.add (hE.smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial _))) have hG : ‖Vᵀ*D*S⁻¹*D*V-augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))‖ < ρ := by have hh := norm_sub_le_norm_sub_add_norm_sub (actualAugmentedGram j a p u g) (diagonalAugmentedGram a p) (augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))) have heq : Vᵀ*D*S⁻¹*D*V=actualAugmentedGram j a p u g := by simp only [V,D,S,conditionalUpdateColumns,conditionalBase,actualAugmentedGram, exactG,Fintype.card_fin,Matrix.mul_assoc] rw [heq] exact hh.trans_lt (by linarith [hgG.2]) have hCgclose : ‖Cg-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) j ((κ x-1)*√(j*b x)/√(q x))‖ < ρ := by have hn : ‖matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E‖ ≤ τ*‖E‖ := by rw [norm_smul,Real.norm_eq_abs] exact mul_le_mul_of_nonneg_right hgS'.le (norm_nonneg _) have hh := norm_add_le (C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) j ((κ x-1)*√(j*b x)/√(q x))) (matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E) have heq : Cg-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) j ((κ x-1)*√(j*b x)/√(q x))= (C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) j ((κ x-1)*√(j*b x)/√(q x)))+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E := by dsimp [Cg]; abel rw [heq] exact hh.trans_lt (by linarith) exact hg (hcrit x (Fin n) S D V Cg lo hSpos hD hCg hmargin.posSemidef hG hCgclose) apply (measureReal_mono hsubsets (measure_ne_top _ _)).trans apply (measureReal_union_le badG badS).trans apply (add_le_add hgprob hsprob).trans have he₀ : exp (-c₀*(n:ℝ)) ≤ exp (-min c₀ c₁*(n:ℝ)) := by apply exp_le_exp.mpr; simpa only [neg_mul] using neg_le_neg (mul_le_mul_of_nonneg_right (min_le_left c₀ c₁) (Nat.cast_nonneg n : (0:ℝ) ≤ n)) have he₁ : exp (-c₁*(n:ℝ)) ≤ exp (-min c₀ c₁*(n:ℝ)) := by apply exp_le_exp.mpr; simpa only [neg_mul] using neg_le_neg (mul_le_mul_of_nonneg_right (min_le_right c₀ c₁) (Nat.cast_nonneg n : (0:ℝ) ≤ n)) nlinarithend SKGapendend
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import Mathlibimport OAI.Probability.SKGap.Matrix.GOEDiagonalSquareimport OAI.Probability.SKGap.Matrix.GOESubmatrix
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Matrix Real Set MeasureTheory ProbabilityTheoryopen RealComplexopen scoped BigOperators Matrix.Norms.Frobenius
theorem zeroDiagGOE_norm_tail {j : ℝ} (hj : 0<j) {n : ℕ} (hn : 0<n) : (Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)) {g | 2*sqrt j+1+1<opNorm (removeDiagonal (goeMatrix (j/n) g))} ≤ ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))) := by let : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hn let μ := gaussianCoordinates (MatrixCoordinates (Fin n)) have hr : 0<j/(n:ℝ) := div_pos hj (Nat.cast_pos.mpr hn) let E := {g : MatrixCoordinates (Fin n)→ℝ | 2*sqrt j+1<opNorm (goeMatrix (j/n) g)} let V := {g : MatrixCoordinates (Fin n)→ℝ | ∃ i,1 < |goeMatrix (j/n) g i i|} have hs : {g | 2*sqrt j+1+1<opNorm (removeDiagonal (goeMatrix (j/n) g))}⊆E∪V := by intro g hg by_contra hh have hh' : ¬2*sqrt j+1<opNorm (goeMatrix (j/n) g) ∧ ¬∃ i,1 < |goeMatrix (j/n) g i i| := by simpa only [Set.mem_union,E,V,Set.mem_ofPred_eq,not_or] using hh have hd : opNorm (Matrix.diagonal (fun i=>goeMatrix (j/n) g i i))≤1 := opNorm_diagonal_le zero_le_one (fun i=>le_of_not_gt (fun hi=>hh'.2 ⟨i,hi⟩)) have hsub := opNorm_sub (goeMatrix (j/n) g) (Matrix.diagonal (fun i=>goeMatrix (j/n) g i i)) exact (not_lt_of_ge (hsub.trans (add_le_add (le_of_not_gt hh'.1) hd))) hg have he : μ E≤ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j))) := by rw [←ofReal_measureReal] apply ENNReal.ofReal_le_ofReal have ht := goe_norm_tail (ι:=Fin n) hj (show (0:ℝ)≤1 by norm_num) simpa only [one_pow,neg_mul,one_mul,Fintype.card_fin,matrixOperator,μ,E,opNorm] using ht have hv : μ V≤ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))) := by rw [←ofReal_measureReal] apply ENNReal.ofReal_le_ofReal simpa only [one_pow,Fintype.card_fin] using goe_diagonal_tail (ι:=Fin n) hr (show (0:ℝ)≤1 by norm_num) exact ((measure_mono hs).trans (measure_union_le E V)).trans (add_le_add he hv)end SKGapendend
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374import Mathlibimport OAI.Probability.SKGap.Localization.EntryLM
namespace OAI
noncomputable section
open MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealopen Filteropen scoped Topologyopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius ENNReal NNRealopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius NNRealopen MeasureTheory ProbabilityTheory Real Set Filteropen MeasureTheory.Measureopen scoped ENNReal NNReal MeasureTheory Topologyopen MeasureTheoryopen MeasureTheory Set NormedSpaceopen scoped Topologyopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobeniusnamespace SKGap.ComplexMatrixopen MeasureTheory NormedSpaceopen scoped FourierTransform SchwartzMapvariable {ι : Type*} [Fintype ι] [DecidableEq ι]
noncomputable def fourierMoment (f : 𝓢(ℝ,ℂ)) (k : ℕ) : ℝ := ∫ t : ℝ, ‖(𝓕 f) t‖*|t|^k
lemma fourierMoment_nonneg (f : 𝓢(ℝ,ℂ)) (k : ℕ) : 0 ≤ fourierMoment f k := by apply integral_nonneg intro t positivity
lemma fourierMoment_integrable (f : 𝓢(ℝ,ℂ)) (k : ℕ) : Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|^k) := by simpa only [Real.norm_eq_abs,mul_comm] using (𝓕 f).integrable_pow_mul volume k
lemma opNorm_rsmul (r : ℝ) (M : Matrix ι ι ℂ) : opNorm (r • M) = |r| * opNorm M := by change opNorm ((r:ℂ) • M) = _ rw [opNorm_csmul,Complex.norm_real,Real.norm_eq_abs]
lemma schwartzMatrix_lipschitz (f : 𝓢(ℝ,ℂ)) (M N : Matrix ι ι ℂ) (hM : Mᴴ = M) (hN : Nᴴ = N) : ‖schwartzMatrix f M-schwartzMatrix f N‖ ≤ (2*Real.pi*fourierMoment f 1)*‖M-N‖ := by have hf₁ : Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|) := by simpa only [pow_one] using fourierMoment_integrable f 1 have hh := kernelMatrix_lipschitz (𝓕 f).integrable hf₁ ((2*Real.pi:ℝ) • M) ((2*Real.pi:ℝ) • N) (by simp [hM]) (by simp [hN]) rw [← smul_sub,norm_smul,Real.norm_eq_abs,abs_of_pos (by positivity : 0 < (2*Real.pi:ℝ))] at hh exact hh.trans_eq (by simp only [fourierMoment,pow_one]; ring)
lemma schwartzMatrix_four_point (f : 𝓢(ℝ,ℂ)) (a b c d : Matrix ι ι ℂ) (ha : aᴴ = a) (hb : bᴴ = b) (hc : cᴴ = c) (hd : dᴴ = d) : ‖(schwartzMatrix f a-schwartzMatrix f b)-(schwartzMatrix f c-schwartzMatrix f d)‖ ≤ (2*Real.pi*fourierMoment f 1)*‖(a-b)-(c-d)‖ + ((2*Real.pi)^2*fourierMoment f 2)*(opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by have hf₁ : Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|) := by simpa only [pow_one] using fourierMoment_integrable f 1 have hh := kernelMatrix_four_point (𝓕 f).integrable hf₁ (fourierMoment_integrable f 2) ((2*Real.pi:ℝ) • a) ((2*Real.pi:ℝ) • b) ((2*Real.pi:ℝ) • c) ((2*Real.pi:ℝ) • d) (by simp [ha]) (by simp [hb]) (by simp [hc]) (by simp [hd]) simp only [← smul_sub,norm_smul,opNorm_rsmul,Real.norm_eq_abs, abs_of_pos (by positivity : 0 < (2*Real.pi:ℝ))] at hh exact hh.trans_eq (by simp only [fourierMoment,pow_one]; ring)
end SKGap.ComplexMatrix
end
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import Mathlibimport OAI.Probability.SKGap.Matrix.MatrixCoordinatesimport OAI.Probability.SKGap.Gaussian.GaussianRegression
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Matrix Realopen scoped BigOperators ENNReal
variable {ι : Type*} [Fintype ι] [DecidableEq ι]
def goeEntryCoeff (r : ℝ) : Matrix (ι × ι) (MatrixCoordinates ι) ℝ := fun p a => sqrt (2*r)/2 * ((if a=Sum.inl p then 1 else 0)+ (if a=Sum.inl (p.2,p.1) then 1 else 0))
lemma goeEntryCoeff_sample (r : ℝ) (g : MatrixCoordinates ι → ℝ) (i k : ι) : (goeEntryCoeff r*ᵥg) (i,k) = goeMatrix r g i k := by simp only [mulVec,dotProduct,goeEntryCoeff,mul_assoc,add_mul] rw [← Finset.mul_sum,Finset.sum_add_distrib] simp [goeMatrix]
lemma goe_matrix_gaussian (r : ℝ) : HasGaussianLaw (fun (g : MatrixCoordinates ι → ℝ) (p : ι × ι) => goeMatrix r g p.1 p.2) (gaussianCoordinates (MatrixCoordinates ι)) := by have hh := matrix_sample_gaussian (goeEntryCoeff (ι := ι) r) simpa only [show (fun g => goeEntryCoeff (ι := ι) r*ᵥg) = (fun g p => goeMatrix r g p.1 p.2) from funext (fun g => funext (fun p => goeEntryCoeff_sample r g p.1 p.2))] using hh
lemma goe_mean_zero (r : ℝ) (i k : ι) : (∫ g, goeMatrix r g i k ∂gaussianCoordinates (MatrixCoordinates ι))=0 := by simpa only [← goeEntryCoeff_sample,mulVec,dotProduct] using linear_gaussian_mean (goeEntryCoeff (ι := ι) r (i,k))
lemma goe_entry_cov {r : ℝ} (hr : 0 ≤ r) (i k l m : ι) : cov[fun g => goeMatrix r g i k,fun g => goeMatrix r g l m; gaussianCoordinates (MatrixCoordinates ι)] = r*((if i=l then 1 else 0)*(if k=m then 1 else 0)+ (if i=m then 1 else 0)*(if k=l then 1 else 0)) := by let μ := gaussianCoordinates (MatrixCoordinates ι) have hm (a : MatrixCoordinates ι) := (coordinate_hasLaw a).hasGaussianLaw.memLp_two change cov[fun g : MatrixCoordinates ι → ℝ => sqrt (2*r)/2*(g (.inl (i,k))+g (.inl (k,i))), fun g => sqrt (2*r)/2*(g (.inl (l,m))+g (.inl (m,l))); μ]=_ rw [covariance_const_mul_left,covariance_const_mul_right] change sqrt (2*r)/2*(sqrt (2*r)/2*cov[(fun g => g (.inl (i,k))) + (fun g => g (.inl (k,i))), (fun g => g (.inl (l,m))) + (fun g => g (.inl (m,l)));gaussianCoordinates (MatrixCoordinates ι)]) = _ rw [covariance_add_left (hm _) (hm _) ((hm _).add (hm _)), covariance_add_right (hm _) (hm _) (hm _), covariance_add_right (hm _) (hm _) (hm _)] simp only [coordinate_covariance,Sum.inl.injEq,Prod.mk.injEq] have hs : (sqrt (2*r)/2)^2=r/2 := by rw [div_pow,sq_sqrt (by positivity)]; ring have hs' : sqrt (2*r)/2*(sqrt (2*r)/2)=r/2 := by nlinarith only [hs] rw [← mul_assoc,hs'] have hind (p q : Prop) [Decidable p] [Decidable q] : (if p ∧ q then (1:ℝ) else 0)=(if p then 1 else 0)*(if q then 1 else 0) := by split_ifs <;> simp_all simp_rw [hind] ring
end SKGapendend
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798import Mathlibimport OAI.Probability.SKGap.Entropy.SparseSubsetEntropyimport OAI.Probability.SKGap.Matrix.TanhMatrixBoundsimport OAI.Probability.SKGap.Matrix.GOERowLaw
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Matrix Real Setopen scoped BigOperatorsvariable {n : ℕ}
lemma coupling_goe_offdiag (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) (i k : Fin n) (hik : i≠k) : coupling (goeDisorder r g) i k=goeMatrix r g i k := by have h := congrFun (congrFun (coupling_goeDisorder r g) i) k simpa only [of_apply,Matrix.sub_apply,diagonal_apply_ne _ hik,sub_zero] using h
lemma coupling_goe_row_square_sum (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) (i : Fin n) (S : Finset (Fin n)) : (∑ k∈S,coupling (goeDisorder r g) i k^2)=∑ k : S.erase i,goeMatrix r g i k^2 := by rw [Finset.sum_coe_sort (S.erase i) (fun k : Fin n=>goeMatrix r g i k^2)] calc _ = ∑ k∈S.erase i,coupling (goeDisorder r g) i k^2 := by by_cases hi : i∈S · rw [Finset.sum_erase_eq_sub hi] simp [coupling] · rw [Finset.erase_eq_self.mpr hi] _ = _ := Finset.sum_congr rfl (fun k hk=>by rw [coupling_goe_offdiag r g i k (Ne.symm (Finset.ne_of_mem_erase hk))])
lemma coupling_goe_row_tail {r : ℝ} (hr : 0 < r) (i : Fin n) (S : Finset (Fin n)) (t : ℝ) : (gaussianCoordinates (MatrixCoordinates (Fin n))).real {g | t < ∑ k∈S,coupling (goeDisorder r g) i k^2} ≤ exp (-t/(4*r)+(S.card:ℝ)*log 2) := by let e : S.erase i ↪ Fin n := ⟨Subtype.val,Subtype.val_injective⟩ have havoid (k : S.erase i) : e k≠i := Finset.ne_of_mem_erase k.2 have hm : MeasurableSet {v : S.erase i→ℝ | t < ∑ k,v k^2} := by measurability simp_rw [coupling_goe_row_square_sum] have heq := (goe_row_hasLaw hr.le i e havoid).measureReal_eq hm change (gaussianCoordinates (MatrixCoordinates (Fin n))).real {g | t < ∑ k : S.erase i,goeMatrix r g i k^2} = (Measure.pi (fun _ : S.erase i=>gaussianReal 0 (Real.toNNReal r))).real {v | t < ∑ k,v k^2} at heq rw [heq] apply (scaled_gaussian_square_tail hr t).trans apply exp_le_exp.mpr have hcard : (Fintype.card (S.erase i):ℝ) ≤ S.card := by rw [Fintype.card_coe] exact_mod_cast Finset.card_erase_le exact add_le_add (le_refl _) (mul_le_mul_of_nonneg_right hcard (log_nonneg (show (1:ℝ) ≤ 2 by norm_num)))
lemma coupling_goe_sparse_rows_tail [NeZero n] {j α l t : ℝ} (hj : 0 < j) (_hα : 0 ≤ α) (hl : 0 ≤ l) : (gaussianCoordinates (MatrixCoordinates (Fin n))).real {g | ∃ i : Fin n,∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} ≤ (n:ℝ)*exp (-(n:ℝ)*(t/(4*j)-(l*α+log (1+exp (-l))+α*log 2))) := by have hn : (0:ℝ) < n := by exact_mod_cast NeZero.pos n have hsingle (i : Fin n) : (gaussianCoordinates (MatrixCoordinates (Fin n))).real {g | ∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} ≤ exp (-(n:ℝ)*(t/(4*j)-(l*α+log (1+exp (-l))+α*log 2))) := by have he : {g : MatrixCoordinates (Fin n)→ℝ | ∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2}= ⋃ S∈smallSupports (ι:=Fin n) α,{g | t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} := by ext g;simp [smallSupports] rw [he] have hb := sparse_union_bound (gaussianCoordinates (MatrixCoordinates (Fin n))) (ι:=Fin n) (C:=1) (q:=t/(4*j)-α*log 2) (α:=α) (fun S=>{g | t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2}) hl (by norm_num : (0:ℝ) ≤ 1) ?_ · convert hb using 1 simp only [one_mul,Fintype.card_fin] congr 1 ring intro S hS have hc : (S.card:ℝ) ≤ α*(n:ℝ) := by simpa only [Fintype.card_fin] using (Finset.mem_filter.mp hS).2 apply (coupling_goe_row_tail (div_pos hj hn) i S t).trans simp only [one_mul,Fintype.card_fin] apply exp_le_exp.mpr have hh := mul_le_mul_of_nonneg_right hc (log_nonneg (show (1:ℝ) ≤ 2 by norm_num)) have he' : -t/(4*(j/(n:ℝ))) = -(n:ℝ)*(t/(4*j)) := by field_simp rw [he'] nlinarith only [hh] have he : {g : MatrixCoordinates (Fin n)→ℝ | ∃ i : Fin n,∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2}= ⋃ i : Fin n,{g | ∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} := by ext g;simp rw [he] apply (measureReal_iUnion_fintype_le _).trans apply (Finset.sum_le_sum (fun i _=>hsingle i)).trans_eq simpend SKGap
endend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158import Mathlibimport OAI.Probability.SKGap.Gaussian.ConditionalGramTailimport OAI.Probability.SKGap.Localization.ConditionalRankAlgebra
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Matrix MeasureTheory ProbabilityTheory Realopen scoped BigOperators Matrix.Norms.Frobenius
theorem goe_scalar_tail {n : ℕ} (hn : 0 < n) {j U ε : ℝ} (hj : 0 < j) (hU : 0 ≤ U) (hε : 0 ≤ ε) (u : EuclideanSpace ℝ (Fin n)) (hu : ‖u‖ ≤ U) : (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real {g | ε ≤ |matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u|} ≤ 2*exp (-(n:ℝ)*ε^2/(π^2*(2*(U+1)^2)^2*j)) := by let : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hn have h := goe_bilinear_concentration hj (by norm_num : (0:ℝ)≤1) hU (by norm_num : (0:ℝ)≤0) hε (fun M => M) (fun _ _ _ => rfl) (fun M N => by simp) 0 (by intro i; simp [goeEntry_integral]) u u hu hu have hz : (diagonal (0 : Fin n → ℝ) : Matrix (Fin n) (Fin n) ℝ)=0 := by ext i k; simp [Matrix.diagonal] rw [hz] at h simpa only [Fintype.card_fin,zero_mul,zero_add,sub_zero, show (1:ℝ)+1=2 by norm_num] using hend SKGapendend
sectionnoncomputable sectionnamespace SKGapopen Matrix MeasureTheory ProbabilityTheory Real Setopen scoped BigOperators MatrixOrder Matrix.Norms.Frobenius
def conditionalBase {n : ℕ} (j : ℝ) (a : Fin n → ℝ) (g : MatrixCoordinates (Fin n) → ℝ) : Matrix (Fin n) (Fin n) ℝ := 1-pathDiagonal a 1*(goeMatrix (j/(n:ℝ)) g-((j/(n:ℝ))*∑ i,a i) • 1)*pathDiagonal a 1
def conditionalUpdateColumns {n : ℕ} (j : ℝ) (a : Fin n → ℝ) (p : Fin 3 → EuclideanSpace ℝ (Fin n)) (u : EuclideanSpace ℝ (Fin n)) (g : MatrixCoordinates (Fin n) → ℝ) : Matrix (Fin n) ((Fin 3) ⊕ Unit) ℝ := extendColumns (fun r => (p r).ofLp) (residualGramVector (j/(n:ℝ)*∑ i,a i) (goeMatrix (j/(n:ℝ)) g) u.ofLp)
theorem compact_conditional_fixed_tail {α : Type*} [TopologicalSpace α] [CompactSpace α] {j A U : ℝ} (hj : 0 < j) (hj1 : j < 1) (hA : 0 < A) (hsub : sqrt j*A < 1) (hU : 0 ≤ U) (b e s q κ : α → ℝ) (hb : Continuous b) (he : Continuous e) (hs : Continuous s) (hq : Continuous q) (hk : Continuous κ) (hb0 : ∀ x,0 < b x) (hb1 : ∀ x,b x ≤ 1) (he0 : ∀ x,0 ≤ e x) (hs0 : ∀ x,0 < s x) (hq0 : ∀ x,0 < q x) (hkq : ∀ x,κ x^2=1-j*q x/s x) : ∃ δ ρ : ℝ, 0 < δ ∧ δ < 1 ∧ 0 < ρ ∧ ∀ ε τ : ℝ, 0 < ε → 0 < τ → ∃ c : ℝ, ∃ N : ℕ, 0 < c ∧ 0 < N ∧ ∀ n, N ≤ n → ∀ a : Fin n → ℝ, (∀ i,0 ≤ a i) → (∀ i,a i ≤ A) → 0 < j/(n:ℝ)*∑ i,a i → augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε < ρ/2 → ∀ p : Fin 3 → EuclideanSpace ℝ (Fin n), ∀ u : EuclideanSpace ℝ (Fin n), (∀ r,‖p r‖ ≤ U) → ‖u‖ ≤ U → u.ofLp⬝ᵥu.ofLp=1 → ∀ x (C E : Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ), C.IsHermitian → E.IsHermitian → τ*‖E‖ < ρ/2 → ‖diagonalAugmentedGram a p-augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))‖ < ρ/2 → ‖C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) j ((κ x-1)*√(j*b x)/√(q x))‖ < ρ/2 → (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real {g | ¬(conditionalBase j a g- pathDiagonal a 1*conditionalUpdateColumns j a p u g* (C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E)* (conditionalUpdateColumns j a p u g)ᵀ*pathDiagonal a 1- (δ*((1-sqrt j*A)^2/4)) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef} ≤ 101*exp (-c*(n:ℝ)) := by obtain ⟨δ,ρ,hδ,hδ1,hρ,hcrit⟩ := compact_conditional_rank_criterion hj hj1 b e s q κ hb he hs hq hk hb0 hb1 he0 hs0 hq0 hkq refine ⟨δ,ρ,hδ,hδ1,hρ,?_⟩ intro ε τ hε hτ obtain ⟨c₀,N,hc₀,hN,hgram⟩ := conditional_augmented_gram_tail hj hA hsub hU hε let c₁ := τ^2/(π^2*(2*(U+1)^2)^2*j) have hc₁ : 0 < c₁ := by dsimp [c₁]; positivity refine ⟨min c₀ c₁,N,lt_min hc₀ hc₁,hN,?_⟩ intro n hn a ha haA hB heps p u hp hu hunit x C E hC hE hEbound hdiag hcoef let μ := Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1) let badG := {g | ¬bilinearPathGood j A a g ∨ augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε < ‖actualAugmentedGram j a p u g-diagonalAugmentedGram a p‖} let badS := {g | τ ≤ |matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u|} have hnpos := hN.trans_le hn have hgprob : μ.real badG ≤ 99*exp (-c₀*(n:ℝ)) := hgram n hn a ha haA hB p u hp hu hunit have hsprob : μ.real badS ≤ 2*exp (-c₁*(n:ℝ)) := by have hh := goe_scalar_tail hnpos hj hU hτ.le u hu convert hh using 1 congr 2 dsimp [c₁] ring have hsubsets : {g | ¬(conditionalBase j a g- pathDiagonal a 1*conditionalUpdateColumns j a p u g* (C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E)* (conditionalUpdateColumns j a p u g)ᵀ*pathDiagonal a 1- (δ*((1-sqrt j*A)^2/4)) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef} ⊆ badG ∪ badS := by intro g hg by_contra hbad have hgG : g ∉ badG := fun hh => hbad (Or.inl hh) have hgS : g ∉ badS := fun hh => hbad (Or.inr hh) simp only [badG,mem_ofPred_eq,not_or,not_lt] at hgG have hgS' : |matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u| < τ := lt_of_not_ge hgS let D := pathDiagonal a 1 let S := conditionalBase j a g let V := conditionalUpdateColumns j a p u g let Cg := C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E let lo := (1-sqrt j*A)^2/4 have hmargin : (S-lo • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef := bilinearPathGood_margin a g (not_not.mp hgG.1) have hlo : 0 ≤ lo := by dsimp [lo]; positivity have hSpos : S.PosDef := by have hh := hmargin.add_posSemidef ((Matrix.PosSemidef.one : (1 : Matrix (Fin n) (Fin n) ℝ).PosSemidef).smul hlo) convert hh using 1; abel have hD : D.IsHermitian := isHermitian_diagonal_iff.mpr (fun i => isSelfAdjoint_iff.mpr (star_trivial _)) have hCg : Cg.IsHermitian := hC.add (hE.smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial _))) have hG : ‖Vᵀ*D*S⁻¹*D*V-augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))‖ < ρ := by have hh := norm_sub_le_norm_sub_add_norm_sub (actualAugmentedGram j a p u g) (diagonalAugmentedGram a p) (augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))) have heq : Vᵀ*D*S⁻¹*D*V=actualAugmentedGram j a p u g := by simp only [V,D,S,conditionalUpdateColumns,conditionalBase,actualAugmentedGram, exactG,Fintype.card_fin,Matrix.mul_assoc] rw [heq] exact hh.trans_lt (by linarith [hgG.2]) have hCgclose : ‖Cg-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) j ((κ x-1)*√(j*b x)/√(q x))‖ < ρ := by have hn : ‖matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E‖ ≤ τ*‖E‖ := by rw [norm_smul,Real.norm_eq_abs] exact mul_le_mul_of_nonneg_right hgS'.le (norm_nonneg _) have hh := norm_add_le (C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) j ((κ x-1)*√(j*b x)/√(q x))) (matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E) have heq : Cg-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) j ((κ x-1)*√(j*b x)/√(q x))= (C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) j ((κ x-1)*√(j*b x)/√(q x)))+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E := by dsimp [Cg]; abel rw [heq] exact hh.trans_lt (by linarith) exact hg (hcrit x (Fin n) S D V Cg lo hSpos hD hCg hmargin.posSemidef hG hCgclose) apply (measureReal_mono hsubsets (measure_ne_top _ _)).trans apply (measureReal_union_le badG badS).trans apply (add_le_add hgprob hsprob).trans have he₀ : exp (-c₀*(n:ℝ)) ≤ exp (-min c₀ c₁*(n:ℝ)) := by apply exp_le_exp.mpr; simpa only [neg_mul] using neg_le_neg (mul_le_mul_of_nonneg_right (min_le_left c₀ c₁) (Nat.cast_nonneg n : (0:ℝ) ≤ n)) have he₁ : exp (-c₁*(n:ℝ)) ≤ exp (-min c₀ c₁*(n:ℝ)) := by apply exp_le_exp.mpr; simpa only [neg_mul] using neg_le_neg (mul_le_mul_of_nonneg_right (min_le_right c₀ c₁) (Nat.cast_nonneg n : (0:ℝ) ≤ n)) nlinarithend SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511import Mathlibimport OAI.Probability.SKGap.Model
namespace OAI
sectionopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen scoped BigOperatorsopen scoped BigOperators NNReal ENNRealopen MeasureTheory Metric Setopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Setopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators ENNReal NNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Matrixopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators ENNReal NNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNRealopen scoped BigOperatorsopen Filter Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal NNReal Topology BigOperatorsopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal NNReal Topology BigOperatorsopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal NNReal Topology BigOperatorsopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal NNReal Topology BigOperatorsopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Set Matrixopen scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen Filter MeasureTheory ProbabilityTheoryopen scoped Topology NNReal ENNRealopen Filter MeasureTheory ProbabilityTheoryopen scoped Topology NNReal ENNRealopen MeasureTheory Filteropen scoped Topology NNReal ENNRealnamespace SKGapCutoff.Clock
noncomputable def gaussMoment (a : ℝ) (k : ℕ) (x : ℝ) : ℝ := x^k*Real.exp (-a*x^2)
lemma integrable_gaussMoment {a : ℝ} (ha : 0 < a) (k : ℕ) : Integrable (gaussMoment a k) := by have hk : (-1:ℝ) < (k:ℝ) := by have := (Nat.cast_nonneg k : (0:ℝ)≤k); linarith have hh := integrable_rpow_mul_exp_neg_mul_sq ha hk convert! hh using 1 ext x exact (Real.rpow_natCast x k).symm |> congrArg (fun t => t*Real.exp (-a*x^2))
lemma hasDerivAt_gaussMoment (a : ℝ) (k : ℕ) (x : ℝ) : HasDerivAt (gaussMoment a k) ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x) x := by have he := ((((hasDerivAt_id x).pow 2).const_mul (-a)).exp) convert! ((hasDerivAt_id x).pow k).mul he using 1 simp only [gaussMoment,pow_succ,Pi.pow_apply,id_eq,Nat.cast_ofNat,mul_one,pow_zero] ring
lemma integrable_abs_add_one_pow_gauss {a : ℝ} (ha : 0 < a) (k : ℕ) : Integrable (fun x : ℝ => (|x|+1)^k*Real.exp (-a*x^2)) := by have hi (j : ℕ) : Integrable (fun x : ℝ => |x|^j*Real.exp (-a*x^2)) := by simpa only [gaussMoment,Real.norm_eq_abs,abs_mul,abs_pow, abs_of_nonneg (Real.exp_nonneg _)] using (integrable_gaussMoment ha j).norm have hh := integrable_finsetSum (Finset.range (k+1)) (fun j _ => (hi j).mul_const (k.choose j:ℝ)) convert! hh using 1 ext x rw [add_pow,Finset.sum_mul] apply Finset.sum_congr rfl intro j hj simp only [one_pow,mul_one] ring
noncomputable def momentEnvelope (a : ℝ) (k : ℕ) (x : ℝ) : ℝ := ((k:ℝ)*(|x|+1)^(k-1)+2*a*(|x|+1)^(k+1))*Real.exp a*Real.exp (-(a/2)*x^2)
lemma integrable_momentEnvelope {a : ℝ} (ha : 0 < a) (k : ℕ) : Integrable (momentEnvelope a k) := by have hhalf : 0 < a/2 := by positivity have hh := (((integrable_abs_add_one_pow_gauss hhalf (k-1)).const_mul (k:ℝ)).add ((integrable_abs_add_one_pow_gauss hhalf (k+1)).const_mul (2*a))).const_mul (Real.exp a) convert! hh using 1 ext x simp only [momentEnvelope,Pi.add_apply] ring
lemma gaussMoment_deriv_bound {a : ℝ} (ha : 0 < a) (k : ℕ) (x z : ℝ) (hz : z ∈ Set.Icc (x-1) (x+1)) : |(k:ℝ)*gaussMoment a (k-1) z-2*a*gaussMoment a (k+1) z| ≤ momentEnvelope a k x := by have hdist : |z-x| ≤ 1 := abs_le.mpr ⟨by linarith [hz.1],by linarith [hz.2]⟩ have hzabs : |z| ≤ |x|+1 := by calc |z| = |(z-x)+x| := by rw [sub_add_cancel] _ ≤ |z-x|+|x| := abs_add_le _ _ _ ≤ |x|+1 := by linarith have hsq : (z-x)^2 ≤ 1 := by have hh := mul_self_le_mul_self (abs_nonneg (z-x)) hdist nlinarith [sq_abs (z-x)] have hquad : x^2/2-1 ≤ z^2 := by nlinarith [sq_nonneg (x-2*z)] have he : Real.exp (-a*z^2) ≤ Real.exp a*Real.exp (-(a/2)*x^2) := by rw [← Real.exp_add] apply Real.exp_le_exp.mpr nlinarith [mul_nonneg ha.le (sub_nonneg.mpr hquad)] have h1 := pow_le_pow_left₀ (abs_nonneg z) hzabs (k-1) have h2 := pow_le_pow_left₀ (abs_nonneg z) hzabs (k+1) calc _ ≤ |(k:ℝ)*gaussMoment a (k-1) z|+|2*a*gaussMoment a (k+1) z| := by simpa only [Real.norm_eq_abs] using norm_sub_le ((k:ℝ)*gaussMoment a (k-1) z) (2*a*gaussMoment a (k+1) z) _ = ((k:ℝ)*|z|^(k-1)+2*a*|z|^(k+1))*Real.exp (-a*z^2) := by norm_num only [gaussMoment,abs_mul,abs_pow,abs_of_nonneg (Nat.cast_nonneg k : (0:ℝ)≤k), abs_of_nonneg ha.le,abs_of_nonneg (Real.exp_nonneg _)] ring _ ≤ ((k:ℝ)*(|x|+1)^(k-1)+2*a*(|x|+1)^(k+1))* (Real.exp a*Real.exp (-(a/2)*x^2)) := by apply mul_le_mul _ he (Real.exp_nonneg _) (by positivity) exact add_le_add (mul_le_mul_of_nonneg_left h1 (Nat.cast_nonneg _)) (mul_le_mul_of_nonneg_left h2 (by positivity)) _ = _ := by dsimp [momentEnvelope]; ring
noncomputable def diffMoment (a : ℝ) (k : ℕ) (h x : ℝ) : ℝ := (gaussMoment a k (x+h)-gaussMoment a k x)/h
lemma diffMoment_bound {a : ℝ} (ha : 0 < a) (k : ℕ) {h : ℝ} (hh : 0 < h) (hh1 : h ≤ 1) (x : ℝ) : |diffMoment a k h x| ≤ momentEnvelope a k x := by have hmv := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le (s := Set.Icc (x-1) (x+1)) (f := gaussMoment a k) (f' := fun z => (k:ℝ)*gaussMoment a (k-1) z-2*a*gaussMoment a (k+1) z) (fun z _ => (hasDerivAt_gaussMoment a k z).hasDerivWithinAt) (fun z hz => by simpa only [Real.norm_eq_abs] using gaussMoment_deriv_bound ha k x z hz) (convex_Icc _ _) (show x ∈ Set.Icc (x-1) (x+1) from ⟨by linarith,by linarith⟩) (show x+h ∈ Set.Icc (x-1) (x+1) from ⟨by linarith,by linarith⟩) rw [Real.norm_eq_abs,Real.norm_eq_abs,add_sub_cancel_left,abs_of_pos hh] at hmv unfold diffMoment rw [abs_div,abs_of_pos hh] exact (div_le_iff₀ hh).mpr hmv
lemma integrable_diffMoment {a : ℝ} (ha : 0 < a) (k : ℕ) (h : ℝ) : Integrable (diffMoment a k h) := (((integrable_gaussMoment ha k).comp_add_right h).sub (integrable_gaussMoment ha k)).div_const h
lemma gaussMoment_derivative_L1 {a : ℝ} (ha : 0 < a) (k : ℕ) : Tendsto (fun n : ℕ => ∫ x : ℝ, |diffMoment a k (1/((n:ℝ)+1)) x- ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x)|) atTop (𝓝 0) := by let dg : ℝ → ℝ := fun x => (k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x have hdg : Integrable dg := ((integrable_gaussMoment ha (k-1)).const_mul (k:ℝ)).sub ((integrable_gaussMoment ha (k+1)).const_mul (2*a)) have hstep : Tendsto (fun n : ℕ => 1/((n:ℝ)+1)) atTop (𝓝[≠] (0:ℝ)) := by refine tendsto_nhdsWithin_iff.mpr ⟨tendsto_one_div_add_atTop_nhds_zero_nat, ?_⟩ exact Filter.Eventually.of_forall (fun n => by simp only [Set.mem_compl_iff,Set.mem_singleton_iff] exact ne_of_gt (by positivity)) have hp (x : ℝ) : Tendsto (fun n : ℕ => diffMoment a k (1/((n:ℝ)+1)) x) atTop (𝓝 (dg x)) := by have hh := (hasDerivAt_gaussMoment a k x).tendsto_slope_zero.comp hstep simpa only [Function.comp_def,smul_eq_mul,div_eq_mul_inv,mul_comm,diffMoment,dg] using hh have ht := tendsto_integral_of_dominated_convergence (fun x => momentEnvelope a k x+|dg x|) (F := fun n : ℕ => fun x => |diffMoment a k (1/((n:ℝ)+1)) x-dg x|) (f := fun _ => (0:ℝ)) (fun n => ((integrable_diffMoment ha k _).sub hdg).abs.aestronglyMeasurable) ((integrable_momentEnvelope ha k).add hdg.abs) (fun n => Filter.Eventually.of_forall (fun x => by rw [Real.norm_eq_abs,abs_abs] have htri : |diffMoment a k (1/((n:ℝ)+1)) x-dg x| ≤ |diffMoment a k (1/((n:ℝ)+1)) x|+|dg x| := by simpa only [Real.norm_eq_abs] using norm_sub_le (diffMoment a k (1/((n:ℝ)+1)) x) (dg x) exact htri.trans (add_le_add (diffMoment_bound ha k (h := 1/((n:ℝ)+1)) (by positivity) (by have := (Nat.cast_nonneg n : (0:ℝ)≤n); apply (div_le_one (by positivity)).mpr; linarith) x) le_rfl))) (Filter.Eventually.of_forall (fun x => by simpa using ((hp x).sub_const (dg x)).abs)) simpa only [integral_zero] using ht
noncomputable def momentL1 (a : ℝ) (ha : 0 < a) (k : ℕ) (y : ℝ) : Lp ℝ 1 (volume : Measure ℝ) := Integrable.toL1 (fun x : ℝ => gaussMoment a k (x+y)) ((integrable_gaussMoment ha k).comp_add_right y)
lemma norm_toL1_real {f : ℝ → ℝ} (hf : Integrable f) : ‖hf.toL1 f‖ = ∫ x : ℝ, |f x| := by rw [Integrable.norm_toL1_eq_lintegral_enorm, ← integral_norm_eq_lintegral_enorm hf.aestronglyMeasurable] simp only [Real.norm_eq_abs]
lemma momentL1_derivative {a : ℝ} (ha : 0 < a) (k : ℕ) (y : ℝ) : Tendsto (fun n : ℕ => ((1/((n:ℝ)+1))⁻¹) • (momentL1 a ha k (y+1/((n:ℝ)+1))-momentL1 a ha k y)) atTop (𝓝 ((k:ℝ) • momentL1 a ha (k-1) y-(2*a) • momentL1 a ha (k+1) y)) := by apply tendsto_iff_norm_sub_tendsto_zero.mpr have he (n : ℕ) : ‖((1/((n:ℝ)+1))⁻¹) • (momentL1 a ha k (y+1/((n:ℝ)+1))- momentL1 a ha k y)-((k:ℝ) • momentL1 a ha (k-1) y- (2*a) • momentL1 a ha (k+1) y)‖ = ∫ x : ℝ, |diffMoment a k (1/((n:ℝ)+1)) x- ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x)| := by let h : ℝ := 1/((n:ℝ)+1) let f : ℝ → ℝ := fun x => h⁻¹ * (gaussMoment a k (x+(y+h))- gaussMoment a k (x+y))- ((k:ℝ)*gaussMoment a (k-1) (x+y)-(2*a)*gaussMoment a (k+1) (x+y)) have hf : Integrable f := ((((integrable_gaussMoment ha k).comp_add_right (y+h)).sub ((integrable_gaussMoment ha k).comp_add_right y)).const_mul h⁻¹).sub ((((integrable_gaussMoment ha (k-1)).comp_add_right y).const_mul (k:ℝ)).sub (((integrable_gaussMoment ha (k+1)).comp_add_right y).const_mul (2*a))) change ‖hf.toL1 f‖ = _ rw [norm_toL1_real] have hfun : (fun x => |f x|) = fun x => |diffMoment a k h (x+y)- ((k:ℝ)*gaussMoment a (k-1) (x+y)-2*a*gaussMoment a (k+1) (x+y))| := by funext x simp only [f,diffMoment,add_assoc,div_eq_mul_inv,mul_comm] rw [hfun] exact integral_add_right_eq_self (fun x => |diffMoment a k h x- ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x)|) y simp_rw [he] exact gaussMoment_derivative_L1 ha k
lemma momentL1_mem_of_gaussian {a : ℝ} (ha : 0 < a) (S : Submodule ℝ (Lp ℝ 1 (volume : Measure ℝ))) (hS : IsClosed (S : Set (Lp ℝ 1 (volume : Measure ℝ)))) (hbase : ∀ y, momentL1 a ha 0 y ∈ S) : ∀ k y, momentL1 a ha k y ∈ S := by intro k induction k using Nat.strong_induction_on with | h k ih => intro y cases k with | zero => exact hbase y | succ k => have hder : (k:ℝ) • momentL1 a ha (k-1) y- (2*a) • momentL1 a ha (k+1) y ∈ S := hS.mem_of_tendsto (momentL1_derivative ha k y) (Filter.Eventually.of_forall (fun n => S.smul_mem _ (S.sub_mem (ih k (by omega) _) (ih k (by omega) _)))) have hlow : (k:ℝ) • momentL1 a ha (k-1) y ∈ S := S.smul_mem _ (ih (k-1) (by omega) y) have hhigh := S.sub_mem hlow hder rw [sub_sub_cancel] at hhigh have hn : (2*a) ≠ 0 := ne_of_gt (by positivity) have hh := S.smul_mem (2*a)⁻¹ hhigh simpa only [smul_smul,inv_mul_cancel₀ hn,one_smul] using hh
noncomputable def gaussianTaylor (a c : ℝ) (N : ℕ) (x : ℝ) : ℝ := ∑ k ∈ Finset.range N, ((-c)^k/(Nat.factorial k : ℝ))*gaussMoment a (2*k) x
lemma gaussianTaylor_eq (a c : ℝ) (N : ℕ) (x : ℝ) : gaussianTaylor a c N x = (∑ k ∈ Finset.range N, (-c*x^2)^k/(Nat.factorial k : ℝ))*Real.exp (-a*x^2) := by unfold gaussianTaylor gaussMoment rw [Finset.sum_mul] apply Finset.sum_congr rfl intro k _ rw [mul_pow,← pow_mul] ring
lemma gaussianTaylor_bound (a : ℝ) {c : ℝ} (hc : 0 ≤ c) (N : ℕ) (x : ℝ) : |gaussianTaylor a c N x| ≤ Real.exp (-(a-c)*x^2) := by rw [gaussianTaylor_eq,abs_mul,abs_of_pos (Real.exp_pos _)] have habs : |∑ k ∈ Finset.range N, (-c*x^2)^k/(Nat.factorial k : ℝ)| ≤ ∑ k ∈ Finset.range N, (c*x^2)^k/(Nat.factorial k : ℝ) := by calc _ ≤ ∑ k ∈ Finset.range N, |(-c*x^2)^k/(Nat.factorial k : ℝ)| := Finset.abs_sum_le_sum_abs _ _ _ = _ := by apply Finset.sum_congr rfl intro k _ rw [abs_div,abs_pow,abs_mul,abs_neg,abs_of_nonneg hc, abs_of_nonneg (sq_nonneg x),abs_of_nonneg (Nat.cast_nonneg _)] calc _ ≤ Real.exp (c*x^2)*Real.exp (-a*x^2) := mul_le_mul_of_nonneg_right (habs.trans (Real.sum_le_exp_of_nonneg (by positivity) N)) (Real.exp_nonneg _) _ = _ := by rw [← Real.exp_add]; congr 1; ring
lemma integrable_gaussianTaylor {a : ℝ} (ha : 0 < a) (c : ℝ) (N : ℕ) : Integrable (gaussianTaylor a c N) := integrable_finsetSum _ (fun k _ => (integrable_gaussMoment ha (2*k)).const_mul _)
lemma gaussianTaylor_tendsto (a c x : ℝ) : Tendsto (fun N : ℕ => gaussianTaylor a c N x) atTop (𝓝 (gaussMoment (a+c) 0 x)) := by have ht := (NormedSpace.expSeries_div_hasSum_exp (-c*x^2)).tendsto_sum_nat.mul_const (Real.exp (-a*x^2)) simpa only [gaussianTaylor_eq,← Real.exp_eq_exp_ℝ,← Real.exp_add,gaussMoment,pow_zero,one_mul, show -c*x^2+-a*x^2=-(a+c)*x^2 by ring] using ht
lemma gaussianTaylor_L1 {a c : ℝ} (ha : 0 < a) (hc : 0 ≤ c) (hca : c < a) : Tendsto (fun N : ℕ => ∫ x : ℝ, |gaussianTaylor a c N x-gaussMoment (a+c) 0 x|) atTop (𝓝 0) := by have hp : 0 < a+c := by linarith have hm : 0 < a-c := by linarith have hh := tendsto_integral_of_dominated_convergence (fun x => Real.exp (-(a-c)*x^2)+Real.exp (-(a+c)*x^2)) (F := fun N : ℕ => fun x => |gaussianTaylor a c N x-gaussMoment (a+c) 0 x|) (f := fun _ => (0:ℝ)) (fun N => ((integrable_gaussianTaylor ha c N).sub (integrable_gaussMoment hp 0)).abs.aestronglyMeasurable) (by simpa only [Pi.add_def,gaussMoment,pow_zero,one_mul] using (integrable_gaussMoment hm 0).add (integrable_gaussMoment hp 0)) (fun N => Filter.Eventually.of_forall (fun x => by rw [Real.norm_eq_abs,abs_abs] have htri := norm_sub_le (gaussianTaylor a c N x) (gaussMoment (a+c) 0 x) simp only [Real.norm_eq_abs,gaussMoment,pow_zero,one_mul,abs_of_pos (Real.exp_pos _)] at htri simpa only [gaussMoment,pow_zero,one_mul] using htri.trans (add_le_add (gaussianTaylor_bound a hc N x) le_rfl))) (Filter.Eventually.of_forall (fun x => by simpa using ((gaussianTaylor_tendsto a c x).sub_const (gaussMoment (a+c) 0 x)).abs)) simpa only [integral_zero] using hh
lemma toL1_finsetSum {ι : Type*} (s : Finset ι) (f : ι → ℝ → ℝ) (hf : ∀ i, Integrable (f i)) : (integrable_finsetSum s (fun i _ => hf i)).toL1 (fun x => ∑ i ∈ s, f i x) = ∑ i ∈ s, (hf i).toL1 (f i) := by classical induction s using Finset.induction_on with | empty => simp only [Finset.sum_empty] exact Integrable.toL1_zero _ | @insert i s hi ih => simp only [Finset.sum_insert hi] change (((hf i).add (integrable_finsetSum s (fun j _ => hf j))).toL1 (f i+(fun x => ∑ j ∈ s, f j x))) = _ rw [Integrable.toL1_add _ _ (hf i) (integrable_finsetSum s (fun j _ => hf j)),ih]
lemma toL1_tendsto_of_integral_abs_sub {f : ℕ → ℝ → ℝ} {g : ℝ → ℝ} (hf : ∀ n, Integrable (f n)) (hg : Integrable g) (ht : Tendsto (fun n => ∫ x : ℝ, |f n x-g x|) atTop (𝓝 0)) : Tendsto (fun n => (hf n).toL1 (f n)) atTop (𝓝 (hg.toL1 g)) := by apply tendsto_iff_norm_sub_tendsto_zero.mpr have he (n : ℕ) : ‖(hf n).toL1 (f n)-hg.toL1 g‖ = ∫ x : ℝ, |f n x-g x| := by change ‖((hf n).sub hg).toL1 (f n-g)‖ = _ exact norm_toL1_real _ simpa only [he] using ht
lemma gaussian_increment_mem {a c : ℝ} (ha : 0 < a) (hc : 0 ≤ c) (hca : c < a) (S : Submodule ℝ (Lp ℝ 1 (volume : Measure ℝ))) (hS : IsClosed (S : Set (Lp ℝ 1 (volume : Measure ℝ)))) (hbase : ∀ y, momentL1 a ha 0 y ∈ S) : ∀ y, momentL1 (a+c) (by linarith) 0 y ∈ S := by intro y have hm := momentL1_mem_of_gaussian ha S hS hbase let fp : ℕ → ℝ → ℝ := fun N x => gaussianTaylor a c N (x+y) have hfp (N : ℕ) : Integrable (fp N) := (integrable_gaussianTaylor ha c N).comp_add_right y have hin (N : ℕ) : (hfp N).toL1 (fp N) ∈ S := by have he : (hfp N).toL1 (fp N) = ∑ k ∈ Finset.range N, ((-c)^k/(Nat.factorial k:ℝ)) • momentL1 a ha (2*k) y := by exact toL1_finsetSum (Finset.range N) (fun k x => ((-c)^k/(Nat.factorial k:ℝ))*gaussMoment a (2*k) (x+y)) (fun k => ((integrable_gaussMoment ha (2*k)).comp_add_right y).const_mul _) rw [he] exact S.sum_mem (fun k _ => S.smul_mem _ (hm _ y)) have ht : Tendsto (fun N => ∫ x : ℝ, |fp N x-gaussMoment (a+c) 0 (x+y)|) atTop (𝓝 0) := by have he (N : ℕ) : (∫ x : ℝ, |fp N x-gaussMoment (a+c) 0 (x+y)|) = ∫ x : ℝ, |gaussianTaylor a c N x-gaussMoment (a+c) 0 x| := integral_add_right_eq_self (fun x => |gaussianTaylor a c N x-gaussMoment (a+c) 0 x|) y simpa only [he] using gaussianTaylor_L1 ha hc hca exact hS.mem_of_tendsto (toL1_tendsto_of_integral_abs_sub hfp ((integrable_gaussMoment (by linarith : 0 < a+c) 0).comp_add_right y) ht) (Filter.Eventually.of_forall hin)
lemma gaussian_wider_precision_mem {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) (S : Submodule ℝ (Lp ℝ 1 (volume : Measure ℝ))) (hS : IsClosed (S : Set (Lp ℝ 1 (volume : Measure ℝ)))) (hbase : ∀ y, momentL1 a ha 0 y ∈ S) : ∀ y, momentL1 b (ha.trans_le hab) 0 y ∈ S := by obtain ⟨N,hN⟩ := exists_nat_gt ((b-a)/a+1) have hN0 : (0:ℝ) < N := by have : 0 ≤ (b-a)/a := div_nonneg (sub_nonneg.mpr hab) ha.le linarith let c : ℝ := (b-a)/N have hc : 0 ≤ c := div_nonneg (sub_nonneg.mpr hab) hN0.le have hca : c < a := by apply (div_lt_iff₀ hN0).mpr have : (b-a)/a < (N:ℝ) := by linarith have := (div_lt_iff₀ ha).mp this linarith have hall (n : ℕ) : ∀ y, momentL1 (a+(n:ℝ)*c) (by positivity) 0 y ∈ S := by induction n with | zero => simpa only [Nat.cast_zero,zero_mul,add_zero] using hbase | succ n ih => have hh := gaussian_increment_mem (show 0 < a+(n:ℝ)*c by positivity) hc (show c < a+(n:ℝ)*c by have := mul_nonneg (Nat.cast_nonneg n) hc; linarith) S hS ih have he : a+(↑(n+1):ℝ)*c=(a+(n:ℝ)*c)+c := by push_cast; ring simpa only [he] using hh have he : a+(N:ℝ)*c = b := by dsimp [c]; field_simp [ne_of_gt hN0]; ring simpa only [he] using hall N
lemma gaussian_mem_closed_span {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) (y : ℝ) : momentL1 b (ha.trans_le hab) 0 y ∈ (Submodule.span ℝ (Set.range (momentL1 a ha 0))).topologicalClosure := by apply gaussian_wider_precision_mem ha hab _ (Submodule.isClosed_topologicalClosure _) (fun z => ?_) y exact Submodule.le_topologicalClosure _ (Submodule.subset_span ⟨z,rfl⟩)
theorem finite_gaussian_approximation {a b ε : ℝ} (ha : 0 < a) (hab : a ≤ b) (hε : 0 < ε) : ∃ (s : Finset ℝ) (c : ℝ → ℝ), (∫ x : ℝ, |gaussMoment b 0 x- ∑ y ∈ s, c y*gaussMoment a 0 (x+y)|) < ε := by classical have hm := gaussian_mem_closed_span ha hab 0 change momentL1 b (ha.trans_le hab) 0 0 ∈ closure (↑(Submodule.span ℝ (Set.range (momentL1 a ha 0))) : Set _) at hm obtain ⟨w,hw,hclose⟩ := Metric.mem_closure_iff.mp hm ε hε obtain ⟨c,rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp hw refine ⟨c.support,c,?_⟩ let f : ℝ → ℝ := fun x => ∑ y ∈ c.support, c y*gaussMoment a 0 (x+y) have hf : Integrable f := integrable_finsetSum _ (fun y _ => ((integrable_gaussMoment ha 0).comp_add_right y).const_mul (c y)) have hfL : hf.toL1 f = c.sum (fun y z => z • momentL1 a ha 0 y) := toL1_finsetSum c.support (fun y x => c y*gaussMoment a 0 (x+y)) (fun y => ((integrable_gaussMoment ha 0).comp_add_right y).const_mul (c y)) rw [dist_eq_norm,← hfL] at hclose change ‖((((integrable_gaussMoment (ha.trans_le hab) 0).comp_add_right 0).sub hf).toL1 (fun x => gaussMoment b 0 (x+0)-f x))‖ < ε at hclose rw [norm_toL1_real] at hclose simpa only [add_zero] using hclose
end SKGapCutoff.Clock
open MeasureTheory Filter ProbabilityTheoryopen scoped Topology NNReal ENNReal
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186import Mathlibimport OAI.Probability.SKGap.Localization.ScalarEmpiricalimport OAI.Probability.SKGap.Gaussian.SquareTail
namespace OAI
sectionnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Set Filteropen scoped NNReal ENNReal Topologynoncomputable sectionopen Real Setnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Set Filteropen scoped Topology NNReal ENNReal BoundedContinuousFunctionopen MeasureTheory ProbabilityTheory Filter Set Topology Realopen scoped NNReal ENNReal BoundedContinuousFunctionnoncomputable sectionopen Set Filter Topologynoncomputable sectionopen MeasureTheory ProbabilityTheory Filter Set Topology Realopen scoped NNReal ENNReal BoundedContinuousFunctionnoncomputable sectionopen MeasureTheory ProbabilityTheory Filter Set Topology Realopen scoped NNReal ENNReal BoundedContinuousFunctionnoncomputable sectionopen MeasureTheory ProbabilityTheory Filter Set Topology Realopen scoped NNReal ENNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Filter Setopen scoped Topology NNReal ENNReal BoundedContinuousFunctionnamespace SKGap
theorem gaussian_compact_tail_rate {X : Type*} [TopologicalSpace X] {K : Set X} (hK : IsCompact K) {P : X → ProbabilityMeasure ℝ} {d s ψ : X → ℝ} (hP : ContinuousOn P K) (hd : ContinuousOn d K) (hs : ContinuousOn s K) (hψ : ContinuousOn ψ K) (hpos : ∀ x ∈ K, 0 < s x) (R : ℝ) {α ν : ℝ} (hα : 0 < α) (hν : 0 < ν) (hαs : ∀ x ∈ K, α < 1/(4*s x)) (hW : ∀ ε > 0, ∀ x ∈ K, ∃ f : ℝ →ᵇ ℝ, ψ x-(∫ y, f y ∂P x)+ log (∫ y, exp (f y) ∂gaussianReal (d x) (s x).toNNReal) < ε) : ∃ R₁ : ℝ, ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, ∀ z : (Fin n → ℝ) → X, ∀ E : Set (Fin n → ℝ), MeasurableSet E → (∀ y ∈ E, z y ∈ K) → (∀ y ∈ E, P (z y) = @empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y) → (∀ y ∈ E, ∑ i, (y i)^2 ≤ (n:ℝ)*R) → (∀ y ∈ E, (n:ℝ)*ν ≤ ∑ i, squareTail R₁ (y i)) → (∫⁻ y in E, ENNReal.ofReal (exp ((n:ℝ)*ψ (z y))*productNormal (d (z y)) (s (z y)) y)) ≤ ENNReal.ofReal (exp (-(α*ν/2)*(n:ℝ))) := by classical have hav : 0 < α*ν := mul_pos hα hν obtain ⟨C,f,hC⟩ := finite_gaussian_test_cover hK hP hd hs hψ hpos R (α*ν/8) (hW _ (by positivity)) have hinc (x : K) : ∀ᶠ r : ℝ in atTop, log (∫ y, exp (f x y+α*squareTail r y) ∂gaussianReal (d x) (s x).toNNReal) ≤ log (∫ y, exp (f x y) ∂gaussianReal (d x) (s x).toNNReal)+α*ν/8 := by have hp : (0:ℝ≥0) < (s x).toNNReal := Real.toNNReal_pos.mpr (hpos x x.2) have ha : α < 1/(4*((s x).toNNReal:ℝ)) := by simpa only [Real.coe_toNNReal _ (hpos x x.2).le] using hαs x x.2 have h := (tendsto_gaussian_tail_tilt (f x) (d := d x) hp hα.le ha).log (tiltedNormal_mass_pos (f x) (d x) (s x).toNNReal).ne' exact (h.eventually_lt_const (by linarith : log (∫ y, exp (f x y) ∂gaussianReal (d x) (s x).toNNReal) < log (∫ y, exp (f x y) ∂gaussianReal (d x) (s x).toNNReal)+α*ν/8)).mono (fun _ hr => hr.le) have hall : ∀ᶠ r : ℝ in atTop, ∀ x ∈ C, log (∫ y, exp (f x y+α*squareTail r y) ∂gaussianReal (d x) (s x).toNNReal) ≤ log (∫ y, exp (f x y) ∂gaussianReal (d x) (s x).toNNReal)+α*ν/8 := (eventually_all_finset C).mpr (fun x _ => hinc x) obtain ⟨R₁,hR₁⟩ := hall.exists obtain ⟨N,hN⟩ := absorb_finite_exponential_factor C.card (show 0 < α*ν/4 by positivity) refine ⟨R₁,N,?_⟩ intro n hn hn' z E hE hz hemp hmom htail let : Nonempty (Fin n) := ⟨⟨0,hn'⟩⟩ have hh := gaussian_covered_tail_laplace C f (fun x : K => d x) (fun x : K => s x) (fun x _ => hpos x x.2) (fun y => d (z y)) (fun y => s (z y)) (fun y => ψ (z y)) R (α*ν/8) (α*ν/8) α ν R₁ hα.le hE (fun y hy => hpos (z y) (hz y hy)) (by simpa only [Fintype.card_fin] using hmom) (by simpa only [Fintype.card_fin] using htail) (fun x _ => integrable_gaussian_tail_test (f x) (Real.toNNReal_pos.mpr (hpos x x.2)) hα.le (by simpa only [Real.coe_toNNReal _ (hpos x x.2).le] using hαs x x.2) R₁) hR₁ (fun y hy => by obtain ⟨x,hx,hcx⟩ := hC (z y) (hz y hy) rw [hemp y hy] at hcx exact ⟨x,hx,hcx⟩) simp only [Fintype.card_fin] at hh refine hh.trans (ENNReal.ofReal_le_ofReal ?_) convert hN n hn (α*ν/8+α*ν/8-α*ν) using 1 congr 1 ring
end SKGap
namespace SKGaplemma squareTail_antitone {R₁ R₂ : ℝ} (hR : R₁ ≤ R₂) (y : ℝ) : squareTail R₂ y ≤ squareTail R₁ y := by unfold squareTail split_ifs <;> try positivity · exact le_rfl · exact (not_lt_of_ge hR (lt_of_lt_of_le (by assumption) (le_of_not_gt (by assumption)))).elim
theorem scalar_rate_iv {j t₀ T ν : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht₀ : 0 < t₀) (hT : t₀ ≤ T) (hν : 0 < ν) : ∃ R₁ : ℝ, ∃ a > 0, ∃ N : ℕ, ∀ R₂ ≥ R₁, ∀ n ≥ N, ∀ hn : 0 < n, ∀ t ∈ Icc t₀ T, ∀ σ ∈ Icc 0 1, ∀ E : Set (Fin n → ℝ), MeasurableSet E → (∀ y ∈ E, (n:ℝ)*ν ≤ ∑ i, squareTail R₂ (y i)) → (∫⁻ y in E, ENNReal.ofReal (@scalarIntegrand (Fin n) _ ⟨⟨0,hn⟩⟩ j t σ y)) ≤ ENNReal.ofReal (exp (-a*(n:ℝ))) := by have hT0 : 0 ≤ T := ht₀.le.trans hT obtain ⟨R,hR,hTail⟩ := scalar_uniform_tail hj.le hT0 ht₀ 1 let K := scalarBox j R T t₀ let α := 1/(8*(T+1+j)) have hα : 0 < α := by dsimp [α]; positivity have hs (p : ScalarPoint) (hp : p ∈ K) : 0 < scalarS j p := ht₀.trans_le hp.2 have hmom : K ⊆ scalarMomentDomain R := fun _ hp => ⟨hp.1.1,mem_univ _⟩ have hαs (p : ScalarPoint) (hp : p ∈ K) : α < 1/(4*scalarS j p) := by have hq := (scalarQMoment_bounds p.1).2 have hz := hp.1.2.2 have ht := hp.1.2.1 have hsup : scalarS j p ≤ T+1+j := by unfold scalarS have hmul := mul_le_mul_of_nonneg_left hq hj.le nlinarith [sq_nonneg p.2.2,hz.1,hz.2,ht.2] have hsp := hs p hp dsimp [α] apply one_div_lt_one_div_of_lt (by positivity : 0 < 4*scalarS j p) nlinarith [hs p hp] obtain ⟨R₁,N,hN⟩ := gaussian_compact_tail_rate (isCompact_scalarBox j R T t₀) (P := fun p : ScalarPoint => p.1) continuous_fst.continuousOn (continuous_scalarD j).continuousOn (continuous_scalarS j).continuousOn (continuousOn_scalarPsi_of_pos hj.le hR.le hmom hs) hs R hα hν hαs (fun ε hε p hp => scalar_weak_test (hmom hp) hj hj1 hp.1.2.1.1 (hs p hp) hε) let b := min (α*ν/2) 1 have hb : 0 < b := lt_min (by positivity) zero_lt_one obtain ⟨M,hM⟩ := absorb_finite_exponential_factor 2 (half_pos hb) refine ⟨R₁,b/2,half_pos hb,max N M,?_⟩ intro R₂ hR₂ n hn hn' t ht σ hσ E hE htail let : Nonempty (Fin n) := ⟨⟨0,hn'⟩⟩ have hsE (y : Fin n → ℝ) : t₀ ≤ scalarS j (scalarEmpirical y t σ) := by unfold scalarS scalarEmpirical dsimp only have hq := mul_nonneg hj.le (scalarQMoment_bounds (empiricalLaw y)).1 nlinarith [sq_nonneg σ,ht.1] let B : Set (Fin n → ℝ) := {y | ∑ i, (y i)^2 ≤ (n:ℝ)*R} have hB : MeasurableSet B := isClosed_le (by fun_prop) continuous_const |>.measurableSet have hc := hN n (le_trans (le_max_left _ _) hn) hn' (fun y => scalarEmpirical y t σ) (E ∩ B) (hE.inter hB) (fun y hy => ⟨⟨empirical_momentBall y hR.le (by simpa only [Fintype.card_fin] using (show ∑ i, (y i)^2 ≤ (n:ℝ)*R from hy.2)), ⟨ht₀.le.trans ht.1,ht.2⟩,hσ⟩,hsE y⟩) (fun _ _ => rfl) (fun _ hy => hy.2) (fun y hy => (htail y hy.1).trans (Finset.sum_le_sum (fun i _ => squareTail_antitone hR₂ (y i)))) have hc' : (∫⁻ y in E ∩ B, ENNReal.ofReal (scalarIntegrand j t σ y)) ≤ ENNReal.ofReal (exp (-b*(n:ℝ))) := by have hab : exp (-(α*ν/2)*(n:ℝ)) ≤ exp (-b*(n:ℝ)) := exp_le_exp.mpr (by have hh := mul_le_mul_of_nonneg_right (min_le_left (α*ν/2) 1) (Nat.cast_nonneg (α := ℝ) n) dsimp [b]; linarith only [hh]) simpa only [scalarIntegrand,Fintype.card_fin] using hc.trans (ENNReal.ofReal_le_ofReal hab) have htail' := hTail n hn' t ⟨ht₀.le.trans ht.1,ht.2⟩ σ hσ (E ∩ Bᶜ) (hE.inter hB.compl) (fun y _ => hsE y) (fun _ hy => le_of_lt (not_le.mp hy.2)) have he : exp (-(1:ℝ)*(n:ℝ)) ≤ exp (-b*(n:ℝ)) := exp_le_exp.mpr (by have hh := mul_le_mul_of_nonneg_right (min_le_right (α*ν/2) 1) (Nat.cast_nonneg (α := ℝ) n) dsimp [b]; linarith only [hh]) have htotal := (lintegral_split_le volume (fun y => ENNReal.ofReal (scalarIntegrand j t σ y)) E B).trans (add_le_add hc' (htail'.trans (ENNReal.ofReal_le_ofReal he))) have hadd : ENNReal.ofReal (exp (-b*(n:ℝ)))+ENNReal.ofReal (exp (-b*(n:ℝ))) = ENNReal.ofReal (2*exp ((n:ℝ)*(-b))) := by rw [← ENNReal.ofReal_add (exp_pos _).le (exp_pos _).le] congr 1 ring_nf rw [hadd] at htotal refine htotal.trans (ENNReal.ofReal_le_ofReal ?_) convert hM n (le_trans (le_max_right _ _) hn) (-b) using 1 congr 1 ring
end SKGapendendendendendendendendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109import Mathlibimport OAI.Probability.SKGap.Matrix.MatrixCoordinates
namespace OAI
sectionnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealopen Filteropen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius ENNReal NNRealnoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius NNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Set Filteropen MeasureTheory.Measureopen scoped ENNReal NNReal MeasureTheory Topologyopen MeasureTheorynoncomputable sectionnoncomputable sectionopen MeasureTheory Set NormedSpaceopen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobeniusnoncomputable sectionopen Set Realopen scoped Topologynoncomputable sectionopen Matrix Set Filteropen scoped Topology Matrix.Norms.Frobeniusnoncomputable sectionopen Matrix NormedSpace ContinuousLinearMapopen scoped Matrix.Norms.Frobeniusnoncomputable sectionopen Matrixnamespace SKGapopen MeasureTheory ProbabilityTheory Realopen scoped ENNReal NNRealvariable {ι : Type*} [Fintype ι]
lemma gaussianCoordinate_memLp (a : MatrixCoordinates ι) : MemLp (fun g : MatrixCoordinates ι → ℝ => g a) 2 (Measure.pi (fun _ => gaussianReal 0 1)) := by exact (IsGaussian.memLp_id (gaussianReal 0 1) 2 (by norm_num)).comp_measurePreserving (measurePreserving_eval (fun _ : MatrixCoordinates ι => gaussianReal 0 1) a)
lemma gaussianCoordinate_integral_sq (a : MatrixCoordinates ι) : (∫ g : MatrixCoordinates ι → ℝ, (g a)^2 ∂Measure.pi (fun _ => gaussianReal 0 1)) = 1 := by rw [integral_comp_eval (μ := fun _ : MatrixCoordinates ι => gaussianReal 0 1) (i := a) (by fun_prop : AEStronglyMeasurable (fun x : ℝ => x^2) (gaussianReal 0 1))] have hh := variance_fun_id_gaussianReal (μ := 0) (v := 1) rw [variance_eq_integral (by fun_prop),integral_id_gaussianReal] at hh simpa only [sub_zero,NNReal.coe_one] using hh
lemma goeEntry_memLp (r : ℝ) (i b : ι) : MemLp (fun g => goeMatrix r g i b) 2 (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) := by exact ((gaussianCoordinate_memLp (.inl (i,b))).add (gaussianCoordinate_memLp (.inl (b,i)))).const_mul _
lemma goeEntry_integral_sq_le {r : ℝ} (hr : 0 ≤ r) (i b : ι) : (∫ g, (goeMatrix r g i b)^2 ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) ≤ 2*r := by let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) have h1 := (gaussianCoordinate_memLp (.inl (i,b))).integrable_sq have h2 := (gaussianCoordinate_memLp (.inl (b,i))).integrable_sq have hb (g : MatrixCoordinates ι → ℝ) : (goeMatrix r g i b)^2 ≤ r*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2) := by have hx : (g (.inl (i,b))+g (.inl (b,i)))^2 ≤ 2*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2) := by nlinarith only [sq_nonneg (g (.inl (i,b))-g (.inl (b,i)))] simp only [goeMatrix,mul_pow] calc _ ≤ (sqrt (2*r)/2)^2*(2*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2)) := mul_le_mul_of_nonneg_left hx (sq_nonneg _) _ = _ := by rw [div_pow,sq_sqrt (by positivity)]; ring calc _ ≤ ∫ g, r*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2) ∂μ := integral_mono (goeEntry_memLp r i b).integrable_sq ((h1.add h2).const_mul r) hb _ = 2*r := by rw [integral_const_mul,integral_add h1 h2,gaussianCoordinate_integral_sq, gaussianCoordinate_integral_sq] ring
end SKGap
noncomputable sectionopen MeasureTheory ProbabilityTheory Real Setopen scoped ENNReal NNReal
endendendendendendendendendendendendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187import Mathlibimport OAI.Probability.SKGap.Localization.FiniteMax
namespace OAI
sectionnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealopen Filteropen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius ENNReal NNRealnoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius NNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Set Filteropen MeasureTheory.Measureopen scoped ENNReal NNReal MeasureTheory Topologyopen MeasureTheorynoncomputable sectionnoncomputable sectionopen MeasureTheory Set NormedSpaceopen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobeniusnoncomputable sectionopen Set Realopen scoped Topologynoncomputable sectionopen Matrix Set Filteropen scoped Topology Matrix.Norms.Frobeniusnoncomputable sectionopen Matrix NormedSpace ContinuousLinearMapopen scoped Matrix.Norms.Frobeniusnoncomputable sectionopen Matrixnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Setopen scoped ENNReal NNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealnamespace SKGapsection ArbitraryCoordinatesvariable {I κ : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] [Fintype κ]
def gaussianCoordinates (κ : Type*) [Fintype κ] : Measure (κ → ℝ) := Measure.pi (fun _ => gaussianReal 0 1)
instance : IsProbabilityMeasure (gaussianCoordinates κ) := by unfold gaussianCoordinates infer_instance
def gaussianAffine (m : I → ℝ) (a : I → κ → ℝ) (z : κ → ℝ) (i : I) : ℝ := m i + ∑ k, a i k * z k
def gaussianSup (m : I → ℝ) (a : I → κ → ℝ) (z : κ → ℝ) : ℝ := sSup (Set.range (gaussianAffine m a z))
omit [CompactSpace I] [Nonempty I] in theorem continuous_gaussianAffine {m : I → ℝ} {a : I → κ → ℝ} (hm : Continuous m) (ha : Continuous a) (z : κ → ℝ) : Continuous (gaussianAffine m a z) := hm.add (continuous_finsetSum _ (fun k _ => ((continuous_apply k).comp ha).mul continuous_const))
theorem gaussianSup_attained {m : I → ℝ} {a : I → κ → ℝ} (hm : Continuous m) (ha : Continuous a) (z : κ → ℝ) : ∃ i, gaussianSup m a z = gaussianAffine m a z i ∧ ∀ j, gaussianAffine m a z j ≤ gaussianAffine m a z i := by obtain ⟨i, _, he, hi⟩ := isCompact_univ.exists_sSup_image_eq_and_ge Set.univ_nonempty (continuous_gaussianAffine hm ha z).continuousOn exact ⟨i, by simpa [gaussianSup] using he, fun j => hi j (Set.mem_univ _)⟩
theorem gaussianSup_le {m : I → ℝ} {a : I → κ → ℝ} (hm : Continuous m) (ha : Continuous a) (z : κ → ℝ) {c : ℝ} (hc : ∀ i, gaussianAffine m a z i ≤ c) : gaussianSup m a z ≤ c := by obtain ⟨i, he, _⟩ := gaussianSup_attained hm ha z rw [he] exact hc i
omit [Nonempty I] in theorem continuous_gaussianSup {m : I → ℝ} {a : I → κ → ℝ} (hm : Continuous m) (ha : Continuous a) : Continuous (gaussianSup m a) := by have hc : Continuous (fun p : (κ → ℝ) × I => gaussianAffine m a p.1 p.2) := by exact (hm.comp continuous_snd).add (continuous_finsetSum _ (fun k _ => (((continuous_apply k).comp ha).comp continuous_snd).mul ((continuous_apply k).comp continuous_fst))) change Continuous (fun z => sSup (Set.range (gaussianAffine m a z))) simpa only [Set.image_univ] using isCompact_univ.continuous_sSup hc
theorem integrable_gaussianSup {m : I → ℝ} {a : I → κ → ℝ} (hm : Continuous m) (ha : Continuous a) : Integrable (gaussianSup m a) (gaussianCoordinates κ) := by obtain ⟨M, hM⟩ := isCompact_univ.exists_bound_of_continuousOn hm.continuousOn obtain ⟨A, hA⟩ := isCompact_univ.exists_bound_of_continuousOn ha.continuousOn have hMb : ∀ i, |m i| ≤ M := fun i => by simpa only [Real.norm_eq_abs] using hM i (Set.mem_univ _) have hAb : ∀ i k, |a i k| ≤ A := by intro i k have hk : |a i k| ≤ ‖a i‖ := by simpa only [Real.norm_eq_abs] using norm_le_pi_norm (a i) k exact hk.trans (hA i (Set.mem_univ _)) apply ((integrable_const M).add ((integrable_finsetSum (Finset.univ : Finset κ) (fun k _ => ((integrable_eval (i := k) IsGaussian.integrable_id).norm))).const_mul A)).mono' (continuous_gaussianSup hm ha).aestronglyMeasurable apply Filter.Eventually.of_forall intro z obtain ⟨i, he, _⟩ := gaussianSup_attained hm ha z rw [he, Real.norm_eq_abs] change |gaussianAffine m a z i| ≤ M + A * ∑ k, |z k| calc _ ≤ |m i| + |∑ k, a i k * z k| := abs_add_le _ _ _ ≤ M + ∑ k, |a i k * z k| := add_le_add (hMb i) (Finset.abs_sum_le_sum_abs _ _) _ ≤ M + ∑ k, A * |z k| := by gcongr with k rw [abs_mul] exact mul_le_mul_of_nonneg_right (hAb i k) (abs_nonneg _) _ = _ := by rw [Finset.mul_sum]
theorem gaussianSup_comparison [Nonempty κ] {m : I → ℝ} {a b : I → κ → ℝ} (hm : Continuous m) (ha : Continuous a) (hb : Continuous b) (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) : (∫ z, gaussianSup m b z ∂gaussianCoordinates κ) ≤ ∫ z, gaussianSup m a z ∂gaussianCoordinates κ := by obtain ⟨n, hn⟩ := Nat.exists_eq_succ_of_ne_zero (Fintype.card_ne_zero (α := κ)) let e : Fin (n + 1) ≃ κ := (finCongr hn.symm).trans (Fintype.equivFin κ).symm let E := MeasurableEquiv.piCongrLeft (fun _ : κ => ℝ) e let a' : I → Fin (n + 1) → ℝ := fun i k => a i (e k) let b' : I → Fin (n + 1) → ℝ := fun i k => b i (e k) have ha' : Continuous a' := continuous_pi (fun k => (continuous_apply (e k)).comp ha) have hb' : Continuous b' := continuous_pi (fun k => (continuous_apply (e k)).comp hb) have he (f : κ → ℝ) : ∑ k : Fin (n + 1), f (e k) = ∑ k : κ, f k := e.sum_comp f have horth' (i j : I) : ∑ k, (a' i k - a' j k) * (b' i k - b' j k) = 0 := by dsimp [a', b'] rw [he (fun k => (a i k - a j k) * (b i k - b j k))] exact horth i j have hinc' (i j : I) : (∑ k, (b' i k - b' j k)^2) ≤ ∑ k, (a' i k - a' j k)^2 := by dsimp [a', b'] rw [he (fun k => (b i k - b j k)^2), he (fun k => (a i k - a j k)^2)] exact hinc i j have hpres : MeasurePreserving E (standardGaussianProduct (n + 1)) (gaussianCoordinates κ) := measurePreserving_piCongrLeft (fun _ => gaussianReal 0 1) e have hpoint (c : I → κ → ℝ) (z : Fin (n + 1) → ℝ) : gaussianSup m c (E z) = supProcess m (fun i k => c i (e k)) z := by unfold gaussianSup supProcess congr 1 congr 1 funext i dsimp [gaussianAffine, affineProcess] rw [← he (fun k => c i k * E z k)] simp [E, MeasurableEquiv.piCongrLeft, Equiv.piCongrLeft] rw [← hpres.integral_comp' (gaussianSup m b), ← hpres.integral_comp' (gaussianSup m a)] simp_rw [hpoint] exact gaussian_supProcess_comparison hm ha' hb' horth' hinc'
end ArbitraryCoordinatesend SKGap
noncomputable sectionopen scoped BigOperatorsopen MeasureTheory ProbabilityTheory
endendendendendendendendendendendendendendend
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianRegression
namespace OAI
section
noncomputable sectionopen MeasureTheory ProbabilityTheory Matrixopen scoped BigOperators ENNRealnamespace SKGap.GaussianRegression
lemma residual_joint_gaussian {Ω ι κ : Type*} [MeasurableSpace Ω] [Fintype ι] [Fintype κ] {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ} (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) : HasGaussianLaw (fun w => (X w-K*ᵥ Y w,Y w)) P := hXY.map_fun (((ContinuousLinearMap.fst ℝ (ι → ℝ) (κ → ℝ))- (matrixCLM K).comp (ContinuousLinearMap.snd ℝ (ι → ℝ) (κ → ℝ))).prod (ContinuousLinearMap.snd ℝ (ι → ℝ) (κ → ℝ)))
theorem regression_joint_law {Ω ι κ : Type*} [MeasurableSpace Ω] [Fintype ι] [Fintype κ] {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ} (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) (hcov : ∀ i k, cov[fun w => X w i, fun w => Y w k; P] = ∑ l, K i l * cov[fun w => Y w l,fun w => Y w k; P]) : P.map (fun w => (X w,Y w)) = ((P.map (fun w => X w-K*ᵥ Y w)).prod (P.map Y)).map (fun z : (ι → ℝ) × (κ → ℝ) => (z.1+K*ᵥ z.2,z.2)) := by have := hXY.isProbabilityMeasure have hR := residual_joint_gaussian hXY K have hi := residual_independent hXY K hcov rw [← hi.map_prod_eq_prod_map_map hR.fst.aemeasurable hR.snd.aemeasurable, AEMeasurable.map_map_of_aemeasurable (by fun_prop) hR.aemeasurable] congr 1 funext w simp only [Function.comp_apply,sub_add_cancel]
theorem regression_lintegral {Ω ι κ : Type*} [MeasurableSpace Ω] [Fintype ι] [Fintype κ] {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ} (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) (hcov : ∀ i k, cov[fun w => X w i, fun w => Y w k; P] = ∑ l, K i l * cov[fun w => Y w l,fun w => Y w k; P]) (F : (ι → ℝ) × (κ → ℝ) → ℝ≥0∞) (hF : Measurable F) : (∫⁻ w, F (X w,Y w) ∂P) = ∫⁻ y, ∫⁻ r, F (r+K*ᵥ y,y) ∂P.map (fun w => X w-K*ᵥ Y w) ∂P.map Y := by have := hXY.isProbabilityMeasure rw [← lintegral_map' hF.aemeasurable hXY.aemeasurable, regression_joint_law hXY K hcov,lintegral_map (by fun_prop) (by fun_prop), lintegral_prod_symm] fun_prop
end SKGap.GaussianRegressionendend
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243import Mathlibimport OAI.Probability.SKGap.Localization.CoordinateDeriv
namespace OAI
noncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealopen Filteropen scoped Topologynamespace SKGapvariable {κ : Type*} [Fintype κ] [DecidableEq κ]
theorem gaussianFinite_IBP_error (i : κ) {f d : (κ → ℝ) → ℝ} {L : ℝ≥0} {C D : ℝ} {s : Set (κ → ℝ)} (hf : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) (hd : Measurable d) (hD : ∀ x, ‖d x‖ ≤ D) (hs : MeasurableSet s) (hder : ∀ x ∈ s, HasDerivAt (fun z => f (Function.update x i z)) (d x) (x i)) : |(∫ x, x i*f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1))- ∫ x, d x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)| ≤ ((L:ℝ)+D)*(Measure.pi (fun _ : κ => gaussianReal 0 1)).real sᶜ := by let μ := Measure.pi (fun _ : κ => gaussianReal 0 1) have hi : Integrable (finiteCoordinateDeriv i f) μ := Integrable.of_bound (measurable_finiteCoordinateDeriv i hf.continuous).aestronglyMeasurable (L:ℝ) (ae_of_all _ (norm_finiteCoordinateDeriv_le i hf)) have hid : Integrable d μ := Integrable.of_bound hd.aestronglyMeasurable D (ae_of_all _ hD) rw [gaussianFinite_lipschitz_IBP i hf hC,← integral_sub hi hid] have he : (fun x => finiteCoordinateDeriv i f x-d x) = sᶜ.indicator (fun x => finiteCoordinateDeriv i f x-d x) := by funext x by_cases hx : x ∈ s · simp only [Set.indicator_of_notMem (show x ∉ sᶜ by simpa using hx),finiteCoordinateDeriv] rw [(hder x hx).deriv,sub_self] · rw [Set.indicator_of_mem hx] rw [he,integral_indicator hs.compl] exact norm_setIntegral_le_of_norm_le_const (measure_lt_top μ sᶜ) (fun x _ => (norm_sub_le _ _).trans (add_le_add (norm_finiteCoordinateDeriv_le i hf x) (hD x)))
end SKGap
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197import Mathlibimport OAI.Probability.SKGap.Localization.FiniteRankPositiveimport OAI.Probability.SKGap.Localization.ScalarFixedPointJoined
namespace OAI
section
noncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealnamespace SKGap
end SKGap
namespace SKGap
def scalarGramVariance (y : ℝ) := 1-tanh y^2
def spinMixed (y : ℝ) := tanh y^2*scalarGramVariance y
lemma spinVariance_nonneg (y : ℝ) : 0 ≤ scalarGramVariance y := sub_nonneg.mpr (tanh_sq_lt_one y).le
lemma abs_spinVariance_le_one (y : ℝ) : |scalarGramVariance y| ≤ 1 := by rw [abs_of_nonneg (spinVariance_nonneg y)] unfold scalarGramVariance nlinarith [sq_nonneg (tanh y)]
lemma abs_spinMixed_le_one (y : ℝ) : |spinMixed y| ≤ 1 := by unfold spinMixed rw [abs_mul,abs_of_nonneg (sq_nonneg _)] calc _ ≤ 1*1 := mul_le_mul (tanh_sq_lt_one y).le (abs_spinVariance_le_one y) (abs_nonneg _) zero_le_one _ = 1 := one_mul 1
lemma integrable_spinVariance {μ : Measure ℝ} [IsFiniteMeasure μ] : Integrable scalarGramVariance μ := Integrable.of_bound (by unfold scalarGramVariance; fun_prop) 1 (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using abs_spinVariance_le_one y))
lemma integrable_spinMixed {μ : Measure ℝ} [IsFiniteMeasure μ] : Integrable spinMixed μ := Integrable.of_bound (by unfold spinMixed scalarGramVariance; fun_prop) 1 (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using abs_spinMixed_le_one y))
lemma gaussian_nishimori_variance (s : ℝ≥0) : (∫ y, oddVariance y ∂gaussianReal s s) = ∫ y, spinMixed y ∂gaussianReal s s := by by_cases hs : s = 0 · subst s; simp [oddVariance,spinMixed,scalarGramVariance] have hi := (integrable_gaussian_iff hs).mp (integrable_oddVariance.sub (integrable_spinMixed (μ := gaussianReal s s))) let f : ℝ → ℝ := fun y => gaussianPDFReal s s y*(oddVariance y-spinMixed y) have hf : Integrable f := hi have hid (y : ℝ) : f y+f (-y) = 0 := by have hh := gaussianPDFReal_diagonal_symmetry hs y dsimp [f,oddVariance,spinMixed,scalarGramVariance] rw [tanh_neg,neg_sq] nlinarith [congrArg (fun x => tanh y*(1-tanh y^2)*x) hh] have hz : (∫ y, f y)+(∫ y, f (-y)) = 0 := by rw [← integral_add hf hf.comp_neg] simp only [hid,integral_zero] rw [integral_neg_eq_self] at hz have hsub : ∫ y, oddVariance y-spinMixed y ∂gaussianReal s s = 0 := by rw [integral_gaussianReal_eq_integral_smul hs] change (∫ y, f y) = 0 linarith rw [integral_sub integrable_oddVariance integrable_spinMixed] at hsub exact sub_eq_zero.mp hsub
lemma hasDerivAt_spinVariance (y : ℝ) : HasDerivAt scalarGramVariance (-2*oddVariance y) y := by convert! (hasDerivAt_const y (1:ℝ)).sub ((hasDerivAt_tanh y).pow 2) using 1 simp only [oddVariance]; norm_num; ring
lemma hasDerivAt_oddVariance (y : ℝ) : HasDerivAt oddVariance (scalarGramVariance y-3*spinMixed y) y := by convert! (hasDerivAt_tanh y).mul (hasDerivAt_spinVariance y) using 1 simp only [spinMixed,scalarGramVariance,oddVariance]; ring
lemma integrable_center_spinVariance (d : ℝ) (s : ℝ≥0) : Integrable (fun y => (y-d)*scalarGramVariance y) (gaussianReal d s) := by have h := ((IsGaussian.integrable_id (μ := gaussianReal d s)).sub (integrable_const d)).bdd_mul (f := scalarGramVariance) (by unfold scalarGramVariance; fun_prop) (c := 1) (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using abs_spinVariance_le_one y)) simpa only [mul_comm,Pi.sub_apply,id_eq] using h
lemma integrable_center_oddVariance (d : ℝ) (s : ℝ≥0) : Integrable (fun y => (y-d)*oddVariance y) (gaussianReal d s) := by have h := ((IsGaussian.integrable_id (μ := gaussianReal d s)).sub (integrable_const d)).bdd_mul (f := oddVariance) (by unfold oddVariance; fun_prop) (c := 1) (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using abs_oddVariance_le_one y)) simpa only [mul_comm,Pi.sub_apply,id_eq] using h
lemma integrable_center_sq_spinVariance (d : ℝ) (s : ℝ≥0) : Integrable (fun y => (y-d)^2*scalarGramVariance y) (gaussianReal d s) := by have hmem : MemLp (fun y : ℝ => y-d) 2 (gaussianReal d s) := (IsGaussian.memLp_id (gaussianReal d s) 2 (by norm_num)).sub (memLp_const d) have h := hmem.integrable_sq.bdd_mul (f := scalarGramVariance) (by unfold scalarGramVariance; fun_prop) (c := 1) (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using abs_spinVariance_le_one y)) simpa only [mul_comm,Pi.sub_apply,id_eq] using h
theorem gaussian_weighted_gram_moments {s : ℝ≥0} (hs : 0 < s) : (∫ y, (y-(s:ℝ))*scalarGramVariance y ∂gaussianReal s s) = -2*(s:ℝ)*(∫ y, spinMixed y ∂gaussianReal s s) ∧ (∫ y, (y-(s:ℝ))*oddVariance y ∂gaussianReal s s) = (s:ℝ)*((∫ y, scalarGramVariance y ∂gaussianReal s s)-3*(∫ y, spinMixed y ∂gaussianReal s s)) ∧ (∫ y, (y-(s:ℝ))^2*scalarGramVariance y ∂gaussianReal s s) = (s:ℝ)*(∫ y, scalarGramVariance y ∂gaussianReal s s)+ (s:ℝ)^2*(-2*(∫ y, scalarGramVariance y ∂gaussianReal s s)+6*(∫ y, spinMixed y ∂gaussianReal s s)) := by have h1 := gaussian_integration_by_parts hs.ne' hasDerivAt_spinVariance integrable_spinVariance (integrable_oddVariance.const_mul (-2)) (integrable_center_spinVariance s s) rw [integral_const_mul,gaussian_nishimori_variance] at h1 have h2 := gaussian_integration_by_parts hs.ne' hasDerivAt_oddVariance integrable_oddVariance (integrable_spinVariance.sub (integrable_spinMixed.const_mul 3)) (integrable_center_oddVariance s s) rw [integral_sub integrable_spinVariance (integrable_spinMixed.const_mul 3),integral_const_mul] at h2 have hder (y : ℝ) : HasDerivAt (fun y => (y-(s:ℝ))*scalarGramVariance y) (scalarGramVariance y-2*((y-(s:ℝ))*oddVariance y)) y := by convert! ((hasDerivAt_id y).sub_const (s:ℝ)).mul (hasDerivAt_spinVariance y) using 1 simp only [id_eq,one_mul]; ring have h3 := gaussian_integration_by_parts hs.ne' hder (integrable_center_spinVariance s s) (integrable_spinVariance.sub ((integrable_center_oddVariance s s).const_mul 2)) ((integrable_center_sq_spinVariance s s).congr (ae_of_all _ (fun y => by ring))) have h3' : (∫ y, (y-(s:ℝ))^2*scalarGramVariance y ∂gaussianReal s s) = (s:ℝ)*((∫ y, scalarGramVariance y ∂gaussianReal s s)-2*(∫ y, (y-(s:ℝ))*oddVariance y ∂gaussianReal s s)) := by convert h3 using 1 · congr 1; funext y; ring · rw [integral_sub integrable_spinVariance ((integrable_center_oddVariance s s).const_mul 2),integral_const_mul] refine ⟨?_,h2,?_⟩ · linarith [h1] · rw [h3',h2]; ring
end SKGapendend
sectionnoncomputable sectionnamespace SKGapopen Real Matrix MeasureTheory ProbabilityTheoryopen scoped NNReal BigOperators
def scalarGramVector (s y : ℝ) : Fin 3 → ℝ := ![1,tanh y,(y-s)/s]
theorem gaussian_weighted_gram_matrix {s : ℝ≥0} (hs : 0 < s) : (fun i k : Fin 3 => ∫ y, scalarGramVariance y*scalarGramVector s y i*scalarGramVector s y k ∂gaussianReal s s)= limitingGram (∫ y,scalarGramVariance y ∂gaussianReal s s) (∫ y,spinMixed y ∂gaussianReal s s) s := by have hsR : (s:ℝ) ≠ 0 := by exact_mod_cast hs.ne' obtain ⟨h1,h2,h3⟩ := gaussian_weighted_gram_moments hs have h01 : (∫ y,scalarGramVariance y*tanh y ∂gaussianReal s s)=∫ y,spinMixed y ∂gaussianReal s s := by convert gaussian_nishimori_variance s using 1 congr 1; funext y; unfold oddVariance scalarGramVariance; ring have h02 : (∫ y,scalarGramVariance y*((y-(s:ℝ))/(s:ℝ)) ∂gaussianReal s s)= -2*(∫ y,spinMixed y ∂gaussianReal s s) := by calc _ = (∫ y,(y-(s:ℝ))*scalarGramVariance y ∂gaussianReal s s)/(s:ℝ) := by rw [← integral_div]; congr 1; funext y; ring _ = _ := by rw [h1]; field_simp have h11 : (∫ y,scalarGramVariance y*tanh y*tanh y ∂gaussianReal s s)= ∫ y,spinMixed y ∂gaussianReal s s := by congr 1; funext y; unfold spinMixed; ring have h12 : (∫ y,scalarGramVariance y*tanh y*((y-(s:ℝ))/(s:ℝ)) ∂gaussianReal s s)= (∫ y,scalarGramVariance y ∂gaussianReal s s)-3*(∫ y,spinMixed y ∂gaussianReal s s) := by calc _ = (∫ y,(y-(s:ℝ))*oddVariance y ∂gaussianReal s s)/(s:ℝ) := by rw [← integral_div]; congr 1; funext y; unfold oddVariance scalarGramVariance; ring _ = _ := by rw [h2]; field_simp have h22 : (∫ y,scalarGramVariance y*((y-(s:ℝ))/(s:ℝ))*((y-(s:ℝ))/(s:ℝ)) ∂gaussianReal s s)= (∫ y,scalarGramVariance y ∂gaussianReal s s)/(s:ℝ)- 2*(∫ y,scalarGramVariance y ∂gaussianReal s s)+6*(∫ y,spinMixed y ∂gaussianReal s s) := by calc _ = (∫ y,(y-(s:ℝ))^2*scalarGramVariance y ∂gaussianReal s s)/(s:ℝ)^2 := by rw [← integral_div]; congr 1; funext y; ring _ = _ := by rw [h3]; field_simp; ring have hsym (i k : Fin 3) : (∫ y,scalarGramVariance y*scalarGramVector s y i*scalarGramVector s y k ∂gaussianReal s s)= ∫ y,scalarGramVariance y*scalarGramVector s y k*scalarGramVector s y i ∂gaussianReal s s := by congr 1; funext y; ring ext i k fin_cases i <;> fin_cases k · simp [scalarGramVector,limitingGram] · simpa [scalarGramVector,limitingGram] using h01 · simpa [scalarGramVector,limitingGram] using h02 · simpa [scalarGramVector,limitingGram] using (hsym 1 0).trans (by simpa [scalarGramVector] using h01) · simpa [scalarGramVector,limitingGram] using h11 · simpa [scalarGramVector,limitingGram] using h12 · simpa [scalarGramVector,limitingGram] using (hsym 2 0).trans (by simpa [scalarGramVector] using h02) · simpa [scalarGramVector,limitingGram] using (hsym 2 1).trans (by simpa [scalarGramVector] using h12) · simpa [scalarGramVector,limitingGram] using h22
end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianRegressionimport OAI.Probability.SKGap.Localization.EqualityCurveimport OAI.Probability.SKGap.Localization.RankCovariance
namespace OAI
sectionnoncomputable sectionnamespace SKGap.GaussianDensityopen MeasureTheory ProbabilityTheory Matrix Realopen scoped BigOperators ENNReal NNRealvariable {ι Ω : Type*} [Fintype ι] [DecidableEq ι] [MeasurableSpace Ω] {P : Measure Ω} {X : Ω → ι → ℝ}
theorem gaussian_density_of_matrix (hX : HasGaussianLaw X P) (A : Matrix ι ι ℝ) (hA : A.det ≠ 0) (hm : ∀ i,(∫ w,X w i ∂P)=0) (hc : ∀ i k,cov[fun w => X w i,fun w => X w k;P]=(A*Aᵀ) i k) : P.map X=(volume : Measure (ι → ℝ)).withDensity (fun x => ENNReal.ofReal (|A.det⁻¹| *∏ i,gaussianPDFReal 0 1 ((A⁻¹*ᵥx) i))) := by have hl : P.map X=(gaussianCoordinates ι).map (fun x => A*ᵥx) := by apply GaussianRegression.law_eq_of_mean_covariance hX (matrix_sample_gaussian A) · intro i rw [hm] exact (linear_gaussian_mean (A i)).symm · intro i k rw [hc,matrix_sample_covariance] rw [hl] exact matrix_map_gaussian_density A hA
lemma gaussian_rankOne_density (hX : HasGaussianLaw X P) {a b : ℝ} (ha : 0 < a) (hb : 0 < b) {u : ι → ℝ} (hu : u⬝ᵥu=1) (hm : ∀ i,(∫ w,X w i ∂P)=0) (hc : ∀ i k,cov[fun w => X w i,fun w => X w k;P]= rankOneTransform (a^2) (b^2) u i k) : P.map X=(volume : Measure (ι → ℝ)).withDensity (fun x => ENNReal.ofReal ((a^(Fintype.card ι)*(b/a))⁻¹*∏ i,gaussianPDFReal 0 1 ((rankOneTransform a⁻¹ b⁻¹ u*ᵥx) i))) := by have hd : 0 < (rankOneTransform a b u).det := by rw [rankOneTransform_det ha.ne' b hu] positivity have hc' : ∀ i k,cov[fun w => X w i,fun w => X w k;P]= (rankOneTransform a b u*(rankOneTransform a b u)ᵀ) i k := by intro i k rw [hc,rankOneTransform_transpose,rankOneTransform_mul hu] simp only [← pow_two] rw [gaussian_density_of_matrix hX _ hd.ne' hm hc', rankOneTransform_inv ha.ne' hb.ne' hu,abs_of_pos (inv_pos.mpr hd),rankOneTransform_det ha.ne' b hu]
end SKGap.GaussianDensityendend
sectionnoncomputable sectionnamespace SKGap.GaussianDensityopen MeasureTheory ProbabilityTheory Matrix Realopen scoped BigOperators ENNReal NNRealvariable {ι : Type*} [Fintype ι] [DecidableEq ι]
def radialDensity (a : ℝ) (x : ι → ℝ) : ℝ := ((sqrt (2*Real.pi)*a)⁻¹)^(Fintype.card ι)*exp (-(x⬝ᵥx)/(2*a^2))
omit [DecidableEq ι] inlemma product_gaussianPDF_formula (v : ℝ≥0) (x : ι → ℝ) : (∏ i,gaussianPDFReal 0 v (x i))=(sqrt (2*Real.pi*v))⁻¹^(Fintype.card ι)* exp (-(x⬝ᵥx)/(2*v)) := by simp only [gaussianPDFReal,sub_zero,Finset.prod_mul_distrib,Finset.prod_const, Finset.card_univ,← exp_sum,← Finset.sum_div,← Finset.sum_neg_distrib,dotProduct,← pow_two]
omit [DecidableEq ι] inlemma product_gaussianPDF_radial {a : ℝ} (ha : 0 ≤ a) (x : ι → ℝ) : (∏ i,gaussianPDFReal 0 (NNReal.mk (a^2) (sq_nonneg a)) (x i))=radialDensity a x := by rw [product_gaussianPDF_formula] simp only [NNReal.coe_mk,radialDensity,sqrt_mul (by positivity : 0 ≤ 2*Real.pi),sqrt_sq ha]
lemma rankOne_density_radial {a b : ℝ} (ha : a ≠ 0) (hb : b ≠ 0) {u : ι → ℝ} (hu : u⬝ᵥu=1) (x : ι → ℝ) : (a^(Fintype.card ι)*(b/a))⁻¹*(∏ i,gaussianPDFReal 0 1 ((rankOneTransform a⁻¹ b⁻¹ u*ᵥx) i)) = (a/b)*radialDensity a x*exp ((b^2-a^2)/(2*a^2*b^2)*(u⬝ᵥx)^2) := by rw [product_gaussianPDF_formula,rankOneTransform_norm_sq hu] simp only [NNReal.coe_one,mul_one] have he : -(a⁻¹^2*(x⬝ᵥx)+(b⁻¹^2-a⁻¹^2)*(u⬝ᵥx)^2)/2 = -(x⬝ᵥx)/(2*a^2)+(b^2-a^2)/(2*a^2*b^2)*(u⬝ᵥx)^2 := by field_simp ring rw [he,exp_add] unfold radialDensity have hc : (a^(Fintype.card ι)*(b/a))⁻¹*(sqrt (2*Real.pi))⁻¹^(Fintype.card ι)= (a/b)*((sqrt (2*Real.pi)*a)⁻¹)^(Fintype.card ι) := by simp only [_root_.mul_inv_rev,mul_pow,inv_pow,inv_inv,div_eq_mul_inv] ring rw [← mul_assoc,← mul_assoc,hc] ring
end SKGap.GaussianDensityendend
sectionnoncomputable sectionnamespace SKGap.GaussianDensityopen MeasureTheory ProbabilityTheory Matrix Realopen scoped BigOperators ENNReal NNRealvariable {ι Ω : Type*} [Fintype ι] [DecidableEq ι] [MeasurableSpace Ω] {P : Measure Ω} {X : Ω → ι → ℝ}
def rankOneDensity (s r : ℝ) (m x : ι → ℝ) : ℝ := sqrt (s/(s+r*(m⬝ᵥm)))*radialDensity (sqrt s) x* exp (r/(2*s*(s+r*(m⬝ᵥm)))*(m⬝ᵥx)^2)
omit [Fintype ι] inlemma rankOne_scaled_covariance (s r c : ℝ) (u : ι → ℝ) : rankOneCovariance s r (c • u)=rankOneTransform s (s+r*c^2) u := by ext i k simp only [rankOneCovariance,rankOneTransform,Matrix.add_apply,Matrix.smul_apply, smul_eq_mul,Matrix.vecMulVec_apply,Pi.smul_apply] ring
lemma scaled_unit_exists [Nonempty ι] (m : ι → ℝ) : ∃ (c : ℝ) (u : ι → ℝ), 0 ≤ c ∧ u⬝ᵥu=1 ∧ m=c • u := by by_cases hm : m=0 · let i : ι := Classical.choice inferInstance refine ⟨0,Pi.single i 1,le_rfl,?_,by simp [hm]⟩ simp [dotProduct,Pi.single_apply] · have hq : 0 < m⬝ᵥm := lt_of_le_of_ne (Finset.sum_nonneg (fun i _ => mul_self_nonneg (m i))) (Ne.symm (mt dotProduct_self_eq_zero.mp hm)) have hc : 0 < sqrt (m⬝ᵥm) := sqrt_pos.mpr hq refine ⟨sqrt (m⬝ᵥm),(sqrt (m⬝ᵥm))⁻¹ • m,hc.le,?_,?_⟩ · simp only [smul_dotProduct,dotProduct_smul,smul_eq_mul] have hh := sq_sqrt hq.le field_simp nlinarith · simp [smul_smul,hc.ne']
theorem gaussian_rankOne_covariance_density [Nonempty ι] (hX : HasGaussianLaw X P) {s r : ℝ} (hs : 0 < s) (hr : 0 ≤ r) (m : ι → ℝ) (hm : ∀ i,(∫ w,X w i ∂P)=0) (hc : ∀ i k,cov[fun w => X w i,fun w => X w k;P]=rankOneCovariance s r m i k) : P.map X=(volume : Measure (ι → ℝ)).withDensity (fun x => ENNReal.ofReal (rankOneDensity s r m x)) := by obtain ⟨c,u,hcpos,hu,rfl⟩ := scaled_unit_exists m have hS : 0 < s+r*c^2 := add_pos_of_pos_of_nonneg hs (mul_nonneg hr (sq_nonneg c)) have ha : 0 < sqrt s := sqrt_pos.mpr hs have hb : 0 < sqrt (s+r*c^2) := sqrt_pos.mpr hS have hc' : ∀ i k,cov[fun w => X w i,fun w => X w k;P]= rankOneTransform ((sqrt s)^2) ((sqrt (s+r*c^2))^2) u i k := by intro i k rw [sq_sqrt hs.le,sq_sqrt hS.le,hc,rankOne_scaled_covariance] rw [gaussian_rankOne_density hX ha hb hu hm hc'] congr 1 ext x rw [rankOne_density_radial ha.ne' hb.ne' hu x] simp only [rankOneDensity,smul_dotProduct,dotProduct_smul,smul_eq_mul,hu,mul_one, sq_sqrt hs.le,sq_sqrt hS.le] have hq : c*c=c^2 := by ring rw [hq] have hpref : sqrt s/sqrt (s+r*c^2)=sqrt (s/(s+r*c^2)) := (sqrt_div hs.le _).symm rw [hpref] congr 2 congr 1 field_simp ring
end SKGap.GaussianDensityendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175import Mathlibimport OAI.Probability.SKGap.Posterior.History
namespace OAI
namespace SKGap.GaussianHistoryopen MeasureTheory ProbabilityTheory Real Set Filteropen scoped BigOperators ENNReal NNRealopen GaussianStepnoncomputable sectionvariable {n : ℕ}
lemma pi_gaussian_add (m₁ m₂ : Fin n → ℝ) (v₁ v₂ : ℝ≥0) : ((Measure.pi fun i => gaussianReal (m₁ i) v₁).prod (Measure.pi fun i => gaussianReal (m₂ i) v₂)).map (fun z : (Fin n → ℝ) × (Fin n → ℝ) => fun i => z.1 i+z.2 i) = Measure.pi (fun i => gaussianReal (m₁ i+m₂ i) (v₁+v₂)) := by rw [← (measurePreserving_arrowProdEquivProdArrow ℝ ℝ (Fin n) (fun i => gaussianReal (m₁ i) v₁) (fun i => gaussianReal (m₂ i) v₂)).map_eq] rw [Measure.map_map (by fun_prop) (MeasurableEquiv.measurable _)] change (Measure.pi (fun i => (gaussianReal (m₁ i) v₁).prod (gaussianReal (m₂ i) v₂))).map (fun z i => (z i).1+(z i).2) = _ rw [Measure.pi_map_pi (f := fun _ (z : ℝ × ℝ) => z.1+z.2) (fun _ => by fun_prop)] congr 1 funext i exact gaussianReal_conv_gaussianReal
def field (t : ℝ) : {k : ℕ} → History n k → (Fin n → ℝ) | 0, _ => 0 | _+1, h => fun i => field t h.1 i+sqrt t*h.2 i
lemma continuous_field (t : ℝ) : ∀k,Continuous (field (n := n) t (k := k)) | 0 => continuous_const | k+1 => (continuous_field t k).comp continuous_fst |>.add (by fun_prop)
lemma map_scaled_reference {t : ℝ} (ht : 0≤t) : (GaussianStep.reference n).map (fun z : Fin n→ℝ => fun i => sqrt t*z i) = Measure.pi (fun _ : Fin n => gaussianReal 0 (toNNReal t)) := by unfold GaussianStep.reference rw [Measure.pi_map_pi (fun _ => by fun_prop)] congr 1 funext i rw [gaussianReal_map_const_mul] congr 1 · simp · apply NNReal.coe_injective simp [sq_sqrt ht,ht]
lemma map_field_reference {t : ℝ} (ht : 0≤t) : ∀k, (reference n k).map (field t (k := k)) = Measure.pi (fun _ : Fin n => gaussianReal 0 (toNNReal ((k:ℝ)*t))) | 0 => by simp only [reference,field,Nat.cast_zero,zero_mul,toNNReal_zero,gaussianReal_zero_var] rw [Measure.map_dirac' (by fun_prop) ()] apply (Measure.pi_eq (μ := fun _ : Fin n => Measure.dirac (0:ℝ)) (μ' := Measure.dirac (0:Fin n→ℝ)) ?_).symm intro s hs by_cases hx : ∀i:Fin n,(0:ℝ)∈s i · rw [Measure.dirac_apply_of_mem (by simpa only [mem_univ_pi,Pi.zero_apply] using hx)] symm exact Finset.prod_eq_one (fun i _ => Measure.dirac_apply_of_mem (hx i)) · push Not at hx obtain ⟨i,hi⟩ := hx rw [Measure.dirac_apply' _ (MeasurableSet.univ_pi hs), Set.indicator_of_notMem (by simp only [mem_univ_pi,Pi.zero_apply]; exact not_forall.mpr ⟨i,hi⟩)] symm exact Finset.prod_eq_zero (Finset.mem_univ i) (by rw [Measure.dirac_apply' _ (hs i),Set.indicator_of_notMem hi]) | k+1 => by change ((reference n k).prod (GaussianStep.reference n)).map ((fun z : (Fin n→ℝ) × (Fin n→ℝ) => fun i => z.1 i+z.2 i) ∘ Prod.map (field t) (fun z : Fin n→ℝ => fun i => sqrt t*z i)) = _ rw [← Measure.map_map (by fun_prop) ((continuous_field t k).measurable.prodMap (by fun_prop)), ← Measure.map_prod_map (reference n k) (GaussianStep.reference n) (continuous_field t k).measurable (by fun_prop), map_field_reference ht k,map_scaled_reference ht,pi_gaussian_add] congr 1 funext i simp only [zero_add] congr 1 rw [←toNNReal_add (mul_nonneg (by positivity) ht) ht] congr 1 push_cast ring
lemma likelihood_field (t : ℝ) (x : Spin n) : ∀{k : ℕ} (h : History n k), likelihood t x h = exp ((∑i,spinValue (x i)*field t h i)-(k:ℝ)*t*(n:ℝ)/2) | 0, _ => by simp [likelihood,field] | k+1, h => by rw [likelihood,likelihood_field t x h.1,GaussianStep.likelihood,←exp_add] congr 1 simp only [field,Finset.sum_add_distrib,mul_add,Nat.cast_add,Nat.cast_one] have he : (∑i,spinValue (x i)*(sqrt t*h.2 i)) = sqrt t*∑i,spinValue (x i)*h.2 i := by rw [Finset.mul_sum] apply Finset.sum_congr rfl intro i _ ring rw [he] ring
lemma map_withDensity_comp {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] (μ : Measure α) (f : α→β) (g : β→ℝ≥0∞) (hf : Measurable f) (hg : Measurable g) : (μ.withDensity (g ∘ f)).map f = (μ.map f).withDensity g := by ext s hs rw [Measure.map_apply hf hs,withDensity_apply _ (hf hs),withDensity_apply _ hs] rw [←lintegral_indicator (hf hs),←lintegral_indicator hs, lintegral_map (hg.indicator hs) hf] apply lintegral_congr intro x by_cases hx : f x∈s <;> simp [hx]
theorem field_law (p : Prior n) {t : ℝ} (ht : 0≤t) (k : ℕ) : (law p t k).map (field t) = ((GaussianStep.reference n).withDensity (fun z => ENNReal.ofReal (GaussianStep.density p ((k:ℝ)*t) z))).map (fun z : Fin n→ℝ => fun i => sqrt ((k:ℝ)*t)*z i) := by let D : (Fin n→ℝ)→ℝ≥0∞ := fun y => ENNReal.ofReal (∑ x, p x*exp ((∑i,spinValue (x i)*y i)-(k:ℝ)*t*(n:ℝ)/2)) have hD : Measurable D := by unfold D; fun_prop have hd : (fun h : History n k => ENNReal.ofReal (density p t h))=D ∘ field t := by funext h simp only [density,likelihood_field,Function.comp_def,D] have hs : (fun z => ENNReal.ofReal (GaussianStep.density p ((k:ℝ)*t) z)) = D ∘ (fun z : Fin n→ℝ => fun i => sqrt ((k:ℝ)*t)*z i) := by funext z unfold D GaussianStep.density GaussianStep.likelihood dsimp congr 1 apply Finset.sum_congr rfl intro x _ congr 2 rw [Finset.mul_sum] congr 1 apply Finset.sum_congr rfl intro i _ ring rw [law,hd,hs,map_withDensity_comp _ _ _ (continuous_field t k).measurable hD, map_withDensity_comp _ _ _ (by fun_prop) hD,map_field_reference ht, map_scaled_reference (mul_nonneg (by positivity) ht)]
lemma weight_field (g : Disorder n) (h₀ y : Fin n→ℝ) (x : Spin n) : weight g (h₀+y) x=weight g h₀ x*exp (∑i,spinValue (x i)*y i) := by unfold weight hamiltonian rw [←exp_add] congr 1 simp only [Pi.add_apply,add_mul,Finset.sum_add_distrib] have he : (∑i,y i*spinValue (x i))=∑i,spinValue (x i)*y i := Finset.sum_congr rfl (fun i _ => mul_comm _ _) rw [he] ring
lemma posterior_gibbs_field (g : Disorder n) (h₀ : Fin n→ℝ) (t : ℝ) {k : ℕ} (h : History n k) : posterior (gibbsPrior g h₀) t h = gibbsPrior g (h₀+field t h) := by have he (x : Spin n) : gibbsPrior g h₀ x*likelihood t x h = (exp (-(k:ℝ)*t*(n:ℝ)/2)/partition g h₀)*weight g (h₀+field t h) x := by rw [likelihood_field,weight_field] change (weight g h₀ x/partition g h₀)*exp (_-_) = _ rw [exp_sub] have hn : -(k:ℝ)*t*(n:ℝ)/2 = -((k:ℝ)*t*(n:ℝ)/2) := by ring rw [hn,exp_neg] ring have hd : density (gibbsPrior g h₀) t h = (exp (-(k:ℝ)*t*(n:ℝ)/2)/partition g h₀)*partition g (h₀+field t h) := by simp only [density,he,←Finset.mul_sum,partition] apply Prior.ext funext x change gibbsPrior g h₀ x*likelihood t x h/density (gibbsPrior g h₀) t h = weight g (h₀+field t h) x/partition g (h₀+field t h) rw [he,hd] exact mul_div_mul_left _ _ (div_ne_zero (exp_ne_zero _) (partition_pos _ _).ne')
endend SKGap.GaussianHistory
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182import Mathlibimport OAI.Probability.SKGap.Gaussian.MatrixNormTailimport OAI.Probability.SKGap.Localization.BoxChaining
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Matrix Real MeasureTheory ProbabilityTheory Set Filteropen scoped BigOperators Matrix.Norms.Frobenius Topologyvariable {κ α : Type*} [Fintype κ] [Fintype α] [DecidableEq α]
def gaussianMatrixChainConstant (H B : ℝ) : ℝ := 5*(matrixNormConstant*H+π*H*sqrt (B+1))
lemma gaussianMatrixChain_exponent {H B s : ℝ} (hH : 0<H) (hB : 0 ≤ B) (n : ℕ) : -2*(π*H*sqrt (B+1))^2*s^2*(n:ℝ)/(π^2*H^2)= -(2*(B+1))*s^2*(n:ℝ) := by rw [mul_pow,mul_pow,sq_sqrt (by linarith : 0 ≤ B+1)] field_simp
theorem gaussianMatrix_box_chaining {n : ℕ} (hn : 1 ≤ n) {H B : ℝ} (hH : 0<H) (hB : 0 ≤ B) (hdim : log 16*(Fintype.card α:ℝ) ≤ B*(n:ℝ)) (F : (α→Icc (0:ℝ) 1)→EuclideanSpace ℝ κ→Matrix (Fin n) (Fin n) ℝ) (hF : ∀ θ,LipschitzWith (Real.toNNReal (H/sqrt n)) (F θ)) (hi : ∀ k θ η,dist θ η ≤ 2*(1/4:ℝ)^k→ LipschitzWith (Real.toNNReal (H*(1/2:ℝ)^k/sqrt n)) (fun x=>F θ x-F η x)) (hc : ∀ g : κ→ℝ,Continuous (fun θ=>matrixCentered (F θ) (WithLp.toLp 2 g))) (p : Bool) : (Measure.pi (fun _ : κ=>gaussianReal 0 1)) {g | ∃ θ,gaussianMatrixChainConstant H B< matrixWordSeminorm p (matrixCentered (F θ) (WithLp.toLp 2 g))} ≤ ENNReal.ofReal (3*exp (-(n:ℝ))) := by let T := π*H*sqrt (B+1) let b := matrixNormConstant*H+T have hT : 0 ≤ T := by dsimp [T];positivity have hC : 0 ≤ matrixNormConstant := zero_le_one.trans matrixNormConstant_bounds.1 have hb0 : 0 ≤ b := add_nonneg (mul_nonneg hC hH.le) hT let r : ℕ→ℝ := fun k=>b*((k:ℝ)+1)*(1/2:ℝ)^k have hsum : HasSum r (b*4) := by have he : r=(fun k : ℕ=>b*(((k:ℝ)+1)*(1/2:ℝ)^k)) := by funext k dsimp [r] ring rw [he] exact arithmetic_half_geometric_hasSum.mul_left b have hbase (θ : α→Icc (0:ℝ) 1) : (Measure.pi (fun _ : κ=>gaussianReal 0 1)) {g | b< matrixWordSeminorm p (matrixCentered (F θ) (WithLp.toLp 2 g))} ≤ ENNReal.ofReal (exp (-(2*(B+1))*(n:ℝ))) := by have hh := gaussianMatrix_scaled_semnorm_tail hn hH (by norm_num : (0:ℝ)<1) hT (by norm_num : (0:ℝ) ≤ 1) (F:=F θ) (by simpa only [mul_one] using hF θ) p rw [gaussianMatrixChain_exponent hH hB] at hh simpa only [T,b,mul_one,one_pow] using hh have hincr (k : ℕ) (θ η : α→Icc (0:ℝ) 1) (hθ : dist θ η ≤ 2*(1/4:ℝ)^k) : (Measure.pi (fun _ : κ=>gaussianReal 0 1)) {g | r k< matrixWordSeminorm p (matrixCentered (F θ) (WithLp.toLp 2 g)-matrixCentered (F η) (WithLp.toLp 2 g))} ≤ ENNReal.ofReal (exp (-(2*(B+1))*((k:ℝ)+1)^2*(n:ℝ))) := by have hh := gaussianMatrix_scaled_semnorm_tail hn hH (by positivity : (0:ℝ)<(1/2:ℝ)^k) hT (by positivity : 0 ≤ (k:ℝ)+1) (hi k θ η hθ) p rw [gaussianMatrixChain_exponent hH hB] at hh simp_rw [matrixCentered_sub (hF θ) (hF η)] at hh apply (measure_mono (show {g | r k< matrixWordSeminorm p (matrixCentered (F θ) (WithLp.toLp 2 g)-matrixCentered (F η) (WithLp.toLp 2 g))}⊆ {g | (matrixNormConstant*H+T*((k:ℝ)+1))*(1/2:ℝ)^k< matrixWordSeminorm p (matrixCentered (F θ) (WithLp.toLp 2 g)-matrixCentered (F η) (WithLp.toLp 2 g))} from ?_)).trans hh intro g hg change r k<_ at hg change (matrixNormConstant*H+T*((k:ℝ)+1))*(1/2:ℝ)^k<_ apply lt_of_le_of_lt _ hg dsimp [r,b] apply mul_le_mul_of_nonneg_right _ (by positivity) nlinarith only [mul_nonneg (mul_nonneg hC hH.le) (Nat.cast_nonneg k)] have hh := box_chaining_probability (Measure.pi (fun _ : κ=>gaussianReal 0 1)) (matrixWordSeminorm p) (matrixWordSeminorm_lipschitz p).continuous (matrixWordSeminorm_add p) (fun θ g=>matrixCentered (F θ) (WithLp.toLp 2 g)) hc hn hB (by linarith : B+1 ≤ 2*(B+1)) hdim b r (fun k=>by dsimp [r];positivity) hsum.summable hbase hincr rw [hsum.tsum_eq] at hh have he : b+b*4=gaussianMatrixChainConstant H B := by dsimp [b,T,gaussianMatrixChainConstant];ring rwa [he] at hhend SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussMoment
namespace OAI
sectionopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen scoped BigOperatorsopen scoped BigOperators NNReal ENNRealopen MeasureTheory Metric Setopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Setopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators ENNReal NNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Matrixopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators ENNReal NNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNRealopen scoped BigOperatorsopen Filter Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal NNReal Topology BigOperatorsopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal NNReal Topology BigOperatorsopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal NNReal Topology BigOperatorsopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal NNReal Topology BigOperatorsopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Set Matrixopen scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwiseopen Filter MeasureTheory ProbabilityTheoryopen scoped Topology NNReal ENNRealopen Filter MeasureTheory ProbabilityTheoryopen scoped Topology NNReal ENNRealopen MeasureTheory Filteropen scoped Topology NNReal ENNRealopen MeasureTheory Filter ProbabilityTheoryopen scoped Topology NNReal ENNRealnamespace SKGapCutoff.Clock
lemma gaussianPDF_moment (v : ℝ≥0) (y x : ℝ) : gaussianPDFReal y v x = (Real.sqrt (2*Real.pi*v))⁻¹ * gaussMoment (1/(2*(v:ℝ))) 0 (x-y) := by unfold gaussianPDFReal gaussMoment simp only [pow_zero,one_mul] congr 2 ring
theorem finite_gaussianPDF_approximation {v w : ℝ≥0} (hv : 0 < v) (hw : 0 < w) (hwv : w ≤ v) {ε : ℝ} (hε : 0 < ε) : ∃ (s : Finset ℝ) (c : ℝ → ℝ), (∫ x : ℝ, |gaussianPDFReal 0 w x- ∑ y ∈ s, c y*gaussianPDFReal (-y) v x|) < ε := by have hvR : (0:ℝ) < v := hv have hwR : (0:ℝ) < w := hw let kv : ℝ := (Real.sqrt (2*Real.pi*v))⁻¹ let kw : ℝ := (Real.sqrt (2*Real.pi*w))⁻¹ have hkv : 0 < kv := by dsimp [kv]; positivity have hkw : 0 < kw := by dsimp [kw]; positivity have hra : 0 < 1/(2*(v:ℝ)) := by positivity have hrab : 1/(2*(v:ℝ)) ≤ 1/(2*(w:ℝ)) := by apply one_div_le_one_div_of_le (by positivity) exact mul_le_mul_of_nonneg_left (show (w:ℝ) ≤ v from hwv) (by norm_num) obtain ⟨s,c,hc⟩ := finite_gaussian_approximation hra hrab (show 0 < ε/kw by positivity) refine ⟨s,fun y => kw*c y/kv,?_⟩ have he (x : ℝ) : |gaussianPDFReal 0 w x- ∑ y ∈ s, (kw*c y/kv)*gaussianPDFReal (-y) v x| = kw*|gaussMoment (1/(2*(w:ℝ))) 0 x- ∑ y ∈ s, c y*gaussMoment (1/(2*(v:ℝ))) 0 (x+y)| := by simp only [gaussianPDF_moment,sub_zero,sub_neg_eq_add] change |kw*gaussMoment (1/(2*(w:ℝ))) 0 x- ∑ y ∈ s, (kw*c y/kv)*(kv*gaussMoment (1/(2*(v:ℝ))) 0 (x+y))| = _ have hterm (y : ℝ) : (kw*c y/kv)*(kv*gaussMoment (1/(2*(v:ℝ))) 0 (x+y)) = kw*(c y*gaussMoment (1/(2*(v:ℝ))) 0 (x+y)) := by field_simp simp_rw [hterm] rw [← Finset.mul_sum,← mul_sub,abs_mul,abs_of_pos hkw] simp_rw [he] rw [integral_const_mul] have hh := mul_lt_mul_of_pos_left hc hkw rwa [mul_div_cancel₀ _ hkw.ne'] at hh
end SKGapCutoff.Clock
open MeasureTheory Filteropen scoped Topology
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163import Mathlibimport OAI.Probability.SKGap.Terminal.SpinEnergyimport OAI.Probability.SKGap.Entropy.GaussianExponentialLinear
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Realopen scoped BigOperators
def edgeCoefficient {n : ℕ} (r : ℝ) (x : Spin n) : Edge n→ℝ := fun e=>sqrt r*spinValue (x e.1.1)*spinValue (x e.1.2)
def gaussianSpinPartition (n : ℕ) (r : ℝ) (g : Disorder n) : ℝ := ∑ x : Spin n,exp (∑ e,edgeCoefficient r x e*g e)
lemma gaussianSpinPartition_eq_partition {n : ℕ} (r : ℝ) (g : Disorder n) : gaussianSpinPartition n r g=partition (fun e=>sqrt r*g e) 0 := by unfold gaussianSpinPartition partition weight apply Finset.sum_congr rfl;intro x _ rw [edge_energy_formula] congr 1 apply Finset.sum_congr rfl;intro e _ unfold edgeCoefficient;ring
lemma edgeCoefficient_sq_sum {n : ℕ} {r : ℝ} (hr : 0 ≤ r) (x : Spin n) : (∑ e,edgeCoefficient r x e^2)= r*(Fintype.card (Edge n):ℝ) := by simp only [edgeCoefficient,mul_pow,spinValue_sq,sq_sqrt hr,mul_one, Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_comm]
lemma edgeCoefficient_add_sq {n : ℕ} {r : ℝ} (hr : 0 ≤ r) (x y : Spin n) (e : Edge n) : (edgeCoefficient r x e+edgeCoefficient r y e)^2= 2*r+2*r*spinValue (spinMul x y e.1.1)*spinValue (spinMul x y e.1.2) := by have hc : edgeCoefficient r x e*edgeCoefficient r y e= r*spinValue (spinMul x y e.1.1)*spinValue (spinMul x y e.1.2) := by rw [spinValue_mul,spinValue_mul] unfold edgeCoefficient calc _ = (sqrt r)^2*spinValue (x e.1.1)*spinValue (y e.1.1)*spinValue (x e.1.2)*spinValue (y e.1.2) := by ring _ = _ := by rw [sq_sqrt hr];ring have hs (z : Spin n) : edgeCoefficient r z e^2=r := by simp only [edgeCoefficient,mul_pow,spinValue_sq,sq_sqrt hr,mul_one] nlinarith only [hc,hs x,hs y]
lemma edgeCoefficient_add_sq_sum {n : ℕ} {r : ℝ} (hr : 0 ≤ r) (x y : Spin n) : (∑ e,(edgeCoefficient r x e+edgeCoefficient r y e)^2)= 2*r*(Fintype.card (Edge n):ℝ)+r*((∑ i,spinValue (spinMul x y i))^2-(n:ℝ)) := by simp_rw [edgeCoefficient_add_sq hr x y] rw [Finset.sum_add_distrib] have he := edge_symmetric_sum (fun i=>spinValue (spinMul x y i)) simp only [spinValue_sq,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] at he simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] have hsum : (∑ e : Edge n,2*r*spinValue (spinMul x y e.1.1)*spinValue (spinMul x y e.1.2))= r*(2*∑ e : Edge n,spinValue (spinMul x y e.1.1)*spinValue (spinMul x y e.1.2)) := by simp only [Finset.mul_sum];apply Finset.sum_congr rfl;intro e _;ring rw [hsum,he];ring
lemma gaussianSpinPartition_integrable (n : ℕ) (r : ℝ) : Integrable (gaussianSpinPartition n r) (gaussianCoordinates (Edge n)) := integrable_finsetSum _ (fun x _=>linear_gaussian_exp_integrable (edgeCoefficient r x))
lemma gaussianSpinPartition_integral {n : ℕ} {r : ℝ} (hr : 0 ≤ r) : (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))= (Fintype.card (Spin n):ℝ)*exp (r*(Fintype.card (Edge n):ℝ)/2) := by unfold gaussianSpinPartition rw [integral_finsetSum _ (fun x _=>linear_gaussian_exp_integrable (edgeCoefficient r x))] simp only [linear_gaussian_exp_integral,edgeCoefficient_sq_sum hr, Finset.sum_const,Finset.card_univ,nsmul_eq_mul]
lemma gaussianSpinPartition_square (n : ℕ) (r : ℝ) (g : Disorder n) : (gaussianSpinPartition n r g)^2= ∑ x : Spin n,∑ y : Spin n,exp (∑ e,(edgeCoefficient r x e+edgeCoefficient r y e)*g e) := by unfold gaussianSpinPartition rw [sq,Finset.sum_mul_sum] apply Finset.sum_congr rfl;intro x _ apply Finset.sum_congr rfl;intro y _ rw [← exp_add] congr 1 simp only [add_mul,Finset.sum_add_distrib]
lemma gaussianSpinPartition_square_integrable (n : ℕ) (r : ℝ) : Integrable (fun g=>(gaussianSpinPartition n r g)^2) (gaussianCoordinates (Edge n)) := by simp_rw [gaussianSpinPartition_square] exact integrable_finsetSum _ (fun x _=>integrable_finsetSum _ (fun y _=>linear_gaussian_exp_integrable (fun e=>edgeCoefficient r x e+edgeCoefficient r y e)))
lemma gaussianSpinPartition_square_integral {n : ℕ} {r : ℝ} (hr : 0 ≤ r) : (∫ g,(gaussianSpinPartition n r g)^2 ∂gaussianCoordinates (Edge n))= (Fintype.card (Spin n):ℝ)*exp (r*(Fintype.card (Edge n):ℝ)-r*(n:ℝ)/2)* ∑ x : Spin n,exp (r/2*(∑ i,spinValue (x i))^2) := by simp_rw [gaussianSpinPartition_square] rw [integral_finsetSum _ (fun x _=>integrable_finsetSum _ (fun y _=>linear_gaussian_exp_integrable (fun e=>edgeCoefficient r x e+edgeCoefficient r y e)))] simp_rw [integral_finsetSum _ (fun y _=>linear_gaussian_exp_integrable _), linear_gaussian_exp_integral,edgeCoefficient_add_sq_sum hr] have he (x y : Spin n) : exp ((2*r*(Fintype.card (Edge n):ℝ)+ r*((∑ i,spinValue (spinMul x y i))^2-(n:ℝ)))/2)= exp (r*(Fintype.card (Edge n):ℝ)-r*(n:ℝ)/2)*exp (r/2*(∑ i,spinValue (spinMul x y i))^2) := by rw [← exp_add];congr 1;ring simp_rw [he,← Finset.mul_sum] have hs (x : Spin n) : (∑ y : Spin n,exp (r/2*(∑ i,spinValue (spinMul x y i))^2))= ∑ y : Spin n,exp (r/2*(∑ i,spinValue (y i))^2) := sum_spinMul x (fun y=>exp (r/2*(∑ i,spinValue (y i))^2)) simp_rw [hs] simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_assoc] ring
end SKGapendend
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Real Set
lemma second_moment_positive_probability {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (Z : Ω→ℝ) (hZ : Measurable Z) (hi : Integrable Z μ) (hi2 : Integrable (fun x=>Z x^2) μ) {M B : ℝ} (hM : 0 < M) (hB : 0 < B) (hmean : (∫ x,Z x ∂μ)=M) (hmoment : (∫ x,Z x^2 ∂μ) ≤ B*M^2) : 1/(4*B) ≤ μ.real {x | M/2 ≤ Z x} := by let S : Set Ω := {x | M/2 ≤ Z x} have hS : MeasurableSet S := measurableSet_le measurable_const hZ have hden : 0 < 4*B*M := by positivity have hpoint : ∀ x,Z x ≤ M/2+B*M*S.indicator (fun _=>1) x+Z x^2/(4*B*M) := by intro x by_cases hx : x∈S · rw [indicator_of_mem hx] apply (mul_le_mul_iff_right₀ hden).mp nlinarith [sq_nonneg (Z x-2*B*M),div_mul_cancel₀ (Z x^2) hden.ne', mul_nonneg hB.le (sq_nonneg M)] · rw [indicator_of_notMem hx] change ¬ M/2 ≤ Z x at hx have hn : 0 ≤ Z x^2/(4*B*M) := div_nonneg (sq_nonneg _) hden.le nlinarith [not_le.mp hx] have hiS : Integrable (S.indicator (fun _=> (1:ℝ))) μ := (integrable_const _).indicator hS have hiA : Integrable (fun x=>M/2+B*M*S.indicator (fun _=>(1:ℝ)) x) μ := (integrable_const (M/2)).add (hiS.const_mul (B*M)) have hiB : Integrable (fun x=>B*M*S.indicator (fun _=>(1:ℝ)) x) μ := hiS.const_mul _ have hiC : Integrable (fun x=>Z x^2/(4*B*M)) μ := hi2.div_const _ have hh := integral_mono hi (hiA.add hiC) hpoint change (∫ x,Z x ∂μ) ≤ ∫ x,M/2+B*M*S.indicator (fun _=>(1:ℝ)) x+Z x^2/(4*B*M) ∂μ at hh rw [hmean,integral_add hiA hiC,integral_add (integrable_const (M/2)) hiB, integral_const,integral_const_mul,integral_div,integral_indicator hS, setIntegral_const] at hh simp only [probReal_univ,smul_eq_mul,mul_one,one_mul] at hh have hterm : (∫ x,Z x^2 ∂μ)/(4*B*M) ≤ M/4 := by apply (div_le_iff₀ hden).mpr nlinarith only [hmoment] have hh' : 1 ≤ 4*B*μ.real S := by have h : M/4 ≤ B*M*μ.real S := by linarith only [hh,hterm] apply (mul_le_mul_iff_right₀ hM).mp nlinarith only [h] exact (div_le_iff₀ (show 0 < 4*B by positivity)).mpr (by nlinarith only [hh'])end SKGapendend
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273import Mathlibimport OAI.Probability.SKGap.Terminal.PowExponentialPair
namespace OAI
sectionnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealopen Filteropen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius ENNReal NNRealnoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius NNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Set Filteropen MeasureTheory.Measureopen scoped ENNReal NNReal MeasureTheory Topologynamespace SKGapopen MeasureTheory ProbabilityTheory Realopen scoped Topologysection ProductMomentsvariable {κ : Type*} [Fintype κ]
lemma gaussianProduct_integral (F : EuclideanSpace ℝ κ → ℝ) (hF : Continuous F) : (∫ g : κ → ℝ, F (WithLp.toLp 2 g) ∂Measure.pi (fun _ => gaussianReal 0 1)) = ∫ x, F x ∂stdGaussian (EuclideanSpace ℝ κ) := by rw [← map_pi_eq_stdGaussian] exact (integral_map (by fun_prop) hF.aestronglyMeasurable).symm
lemma gaussianProduct_integrable_lipschitz {F : EuclideanSpace ℝ κ → ℝ} {L : ℝ≥0} (hF : LipschitzWith L F) : Integrable (fun g : κ → ℝ => F (WithLp.toLp 2 g)) (Measure.pi (fun _ => gaussianReal 0 1)) := by have hi := gaussian_integrable_lipschitz (μ := stdGaussian (EuclideanSpace ℝ κ)) hF rw [← map_pi_eq_stdGaussian] at hi exact hi.comp_measurable (by fun_prop)
lemma gaussianProduct_abs_centered_moment {F : EuclideanSpace ℝ κ → ℝ} {L : ℝ≥0} (hF : LipschitzWith L F) (hL : 0 < L) (k : ℕ) : (∫ g : κ → ℝ, |F (WithLp.toLp 2 g)- ∫ h : κ → ℝ, F (WithLp.toLp 2 h) ∂Measure.pi (fun _ => gaussianReal 0 1)|^k ∂Measure.pi (fun _ => gaussianReal 0 1)) ≤ (2*(k.factorial : ℝ)*exp (π^2/8))*(L:ℝ)^k := by rw [gaussianProduct_integral F hF.continuous] rw [gaussianProduct_integral (fun x => |F x-∫ y, F y ∂stdGaussian _|^k) ((hF.continuous.sub continuous_const).abs.pow k)] exact stdGaussian_abs_centered_moment hF hL k
lemma gaussianProduct_centered_L1 {F : EuclideanSpace ℝ κ → ℝ} {L : ℝ≥0} (hF : LipschitzWith L F) (hL : 0 < L) : (∫ g : κ → ℝ, |F (WithLp.toLp 2 g)- ∫ h : κ → ℝ, F (WithLp.toLp 2 h) ∂Measure.pi (fun _ => gaussianReal 0 1)| ∂Measure.pi (fun _ => gaussianReal 0 1)) ≤ (2*exp (π^2/8))*(L:ℝ) := by simpa using gaussianProduct_abs_centered_moment hF hL 1
end ProductMomentsend SKGap
open MeasureTheorynoncomputable section
endendendendendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianProductIntegralimport OAI.Probability.SKGap.Matrix.MatrixSeminorm
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Real MeasureTheory ProbabilityTheoryopen scoped BigOperatorsvariable {κ : Type*} [Fintype κ]
lemma gaussianProduct_integrable_exp_lipschitz {F : EuclideanSpace ℝ κ→ℝ} {L : NNReal} (hF : LipschitzWith L F) (r : ℝ) : Integrable (fun g : κ→ℝ=>exp (r*F (WithLp.toLp 2 g))) (Measure.pi (fun _=>gaussianReal 0 1)) := by have hi := gaussian_integrable_exp_lipschitz (μ:=stdGaussian (EuclideanSpace ℝ κ)) hF r rw [←map_pi_eq_stdGaussian] at hi exact hi.comp_measurable (by fun_prop)
lemma gaussianProduct_integrable_abs_pow_lipschitz {F : EuclideanSpace ℝ κ→ℝ} {L : NNReal} (hF : LipschitzWith L F) (k : ℕ) : Integrable (fun g : κ→ℝ=>|F (WithLp.toLp 2 g)|^k) (Measure.pi (fun _=>gaussianReal 0 1)) := by let μ := Measure.pi (fun _ : κ=>gaussianReal 0 1) have h1 := gaussianProduct_integrable_exp_lipschitz hF 1 have h2 := gaussianProduct_integrable_exp_lipschitz hF (-1) have hh := (h1.add h2).const_mul (k.factorial:ℝ) apply hh.mono' · exact ((hF.continuous.comp (by fun_prop : Continuous (WithLp.toLp 2 : (κ→ℝ)→EuclideanSpace ℝ κ))).abs.pow k).aestronglyMeasurable · filter_upwards [] with g simpa only [Real.norm_eq_abs,abs_pow,abs_abs,one_pow,div_one,Pi.add_apply] using pow_le_exponential_pair (F (WithLp.toLp 2 g)) (by norm_num : (0:ℝ)<1) k
lemma gaussianProduct_integrable_pow_lipschitz {F : EuclideanSpace ℝ κ→ℝ} {L : NNReal} (hF : LipschitzWith L F) (k : ℕ) : Integrable (fun g : κ→ℝ=>F (WithLp.toLp 2 g)^k) (Measure.pi (fun _=>gaussianReal 0 1)) := by apply (gaussianProduct_integrable_abs_pow_lipschitz hF k).mono' · exact ((hF.continuous.comp (by fun_prop : Continuous (WithLp.toLp 2 : (κ→ℝ)→EuclideanSpace ℝ κ))).pow k).aestronglyMeasurable · filter_upwards [] with g simp only [Real.norm_eq_abs,abs_pow,le_refl]end SKGapendend
sectionnoncomputable sectionnamespace SKGapopen Real Matrix MeasureTheory ProbabilityTheory Setopen scoped BigOperators Matrix.Norms.Frobeniusvariable {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ]
def matrixEntryMean (F : EuclideanSpace ℝ κ→Matrix ι ι ℝ) : Matrix ι ι ℝ := fun i k=>∫ g : κ→ℝ,F (WithLp.toLp 2 g) i k ∂Measure.pi (fun _=>gaussianReal 0 1)def matrixCentered (F : EuclideanSpace ℝ κ→Matrix ι ι ℝ) (x : EuclideanSpace ℝ κ) := F x-matrixEntryMean F
lemma matrixCentered_lipschitz {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} {L : NNReal} (hF : LipschitzWith L F) : LipschitzWith L (matrixCentered F) := by apply LipschitzWith.of_dist_le_mul intro x y simpa only [matrixCentered,dist_sub_right] using hF.dist_le_mul x y
lemma matrixEntry_lip {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} {L : NNReal} (hF : LipschitzWith L F) (i k : ι) : LipschitzWith L (fun x=>F x i k) := by simpa only [one_mul,Function.comp_def] using (matrixEntry_lipschitz i k).comp hF
lemma diagonalCentered_lip {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} {L : NNReal} (hF : LipschitzWith L F) : LipschitzWith L (fun x=>diagonalSeminorm (matrixCentered F x)) := by simpa only [one_mul,Function.comp_def] using diagonalSeminorm_lipschitz.comp (matrixCentered_lipschitz hF)lemma offDiagonalCentered_lip {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} {L : NNReal} (hF : LipschitzWith L F) : LipschitzWith L (fun x=>offDiagonalSeminorm (matrixCentered F x)) := by simpa only [one_mul,Function.comp_def] using offDiagonalSeminorm_lipschitz.comp (matrixCentered_lipschitz hF)
lemma matrixCentered_even_moment {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} {L : NNReal} (hF : LipschitzWith L F) (hL : 0<L) (i b : ι) (k : ℕ) : (∫ g : κ→ℝ,(matrixCentered F (WithLp.toLp 2 g) i b)^(2*k) ∂Measure.pi (fun _=>gaussianReal 0 1))≤ (2*((2*k).factorial:ℝ)*exp (π^2/8))*(L:ℝ)^(2*k) := by have hh := gaussianProduct_abs_centered_moment (matrixEntry_lip hF i b) hL (2*k) simpa only [matrixCentered,matrixEntryMean,Matrix.sub_apply,pow_mul,sq_abs] using hh
lemma diagonalCentered_second_moment {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} {L : NNReal} (hF : LipschitzWith L F) (hL : 0<L) : (∫ g : κ→ℝ,diagonalSeminorm (matrixCentered F (WithLp.toLp 2 g))^2 ∂Measure.pi (fun _=>gaussianReal 0 1))≤ (Fintype.card ι:ℝ)*(4*exp (π^2/8))*(L:ℝ)^2 := by simp_rw [diagonalSeminorm_sq] rw [integral_finsetSum _ (fun i _=>gaussianProduct_integrable_pow_lipschitz (matrixEntry_lip (matrixCentered_lipschitz hF) i i) 2)] apply (Finset.sum_le_sum (fun i _=>matrixCentered_even_moment hF hL i i 1)).trans_eq norm_num [Finset.sum_const,mul_assoc]
lemma offDiagonalCentered_fourth_moment {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} {L : NNReal} (hF : LipschitzWith L F) (hL : 0<L) : (∫ g : κ→ℝ,offDiagonalSeminorm (matrixCentered F (WithLp.toLp 2 g))^4 ∂Measure.pi (fun _=>gaussianReal 0 1))≤ (Fintype.card ι:ℝ)^2*(48*exp (π^2/8))*(L:ℝ)^4 := by simp_rw [offDiagonalSeminorm_fourth] have hi (p : ι×ι) : Integrable (fun g : κ→ℝ=>if p.1=p.2 then 0 else matrixCentered F (WithLp.toLp 2 g) p.1 p.2^4) (Measure.pi (fun _=>gaussianReal 0 1)) := by split_ifs · exact integrable_const _ · exact gaussianProduct_integrable_pow_lipschitz (matrixEntry_lip (matrixCentered_lipschitz hF) p.1 p.2) 4 rw [integral_finsetSum _ (fun p _=>hi p)] have hb (p : ι×ι) : (∫ g : κ→ℝ,(if p.1=p.2 then 0 else matrixCentered F (WithLp.toLp 2 g) p.1 p.2^4) ∂Measure.pi (fun _=>gaussianReal 0 1)) ≤ (48*exp (π^2/8))*(L:ℝ)^4 := by split_ifs · simp only [integral_zero];positivity · have hh := matrixCentered_even_moment hF hL p.1 p.2 2 norm_num at hh exact hh apply (Finset.sum_le_sum (fun p _=>hb p)).trans_eq simp only [Finset.sum_const,Finset.card_univ,Fintype.card_prod,nsmul_eq_mul,Nat.cast_mul] ring
lemma gaussianProduct_jensen_pow {F : EuclideanSpace ℝ κ→ℝ} {L : NNReal} (hF : LipschitzWith L F) (hpos : ∀ x,0≤F x) (k : ℕ) : (∫ g : κ→ℝ,F (WithLp.toLp 2 g) ∂Measure.pi (fun _=>gaussianReal 0 1))^k≤ ∫ g : κ→ℝ,F (WithLp.toLp 2 g)^k ∂Measure.pi (fun _=>gaussianReal 0 1) := by exact (convexOn_pow (𝕜:=ℝ) k).map_integral_le (by fun_prop) isClosed_Ici (ae_of_all _ (fun g=>hpos (WithLp.toLp 2 g))) (gaussianProduct_integrable_lipschitz hF) (gaussianProduct_integrable_pow_lipschitz hF k)
def matrixNormConstant : ℝ := 1+48*exp (π^2/8)
omit [Fintype ι] [DecidableEq ι] [Fintype κ] inlemma matrixNormConstant_bounds : 1≤ matrixNormConstant ∧ 4*exp (π^2/8)≤ matrixNormConstant^2 ∧ 48*exp (π^2/8)≤ matrixNormConstant^4 := by have hE := (exp_pos (π^2/8)).le have hC : 1≤ matrixNormConstant := by unfold matrixNormConstant;linarith have hC2 : matrixNormConstant≤ matrixNormConstant^2 := by simpa only [pow_one] using pow_le_pow_right₀ hC (by decide : 1≤2) have hC4 : matrixNormConstant≤ matrixNormConstant^4 := by simpa only [pow_one] using pow_le_pow_right₀ hC (by decide : 1≤4) refine ⟨hC,?_,?_⟩ <;> unfold matrixNormConstant at * <;> linarith
lemma gaussianProduct_centered_matrix_norms {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} {L : NNReal} (hF : LipschitzWith L F) (hL : 0<L) : (∫ g : κ→ℝ,diagonalSeminorm (matrixCentered F (WithLp.toLp 2 g)) ∂Measure.pi (fun _=>gaussianReal 0 1))≤ matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ) ∧ (∫ g : κ→ℝ,offDiagonalSeminorm (matrixCentered F (WithLp.toLp 2 g)) ∂Measure.pi (fun _=>gaussianReal 0 1))≤ matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ) := by let : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ have hC0 : 0≤ matrixNormConstant := zero_le_one.trans matrixNormConstant_bounds.1 have hcn : (0:ℝ)≤Fintype.card ι := Nat.cast_nonneg _ constructor · apply le_of_pow_le_pow_left₀ (by decide : 2≠0) (by positivity) have hJ := gaussianProduct_jensen_pow (diagonalCentered_lip hF) (fun x=>norm_nonneg (diagonalVector (matrixCentered F x))) 2 apply (hJ.trans (diagonalCentered_second_moment hF hL)).trans rw [mul_pow,mul_pow,sq_sqrt hcn] have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left matrixNormConstant_bounds.2.1 hcn) (sq_nonneg (L:ℝ)) nlinarith only [hh] · apply le_of_pow_le_pow_left₀ (by decide : 4≠0) (by positivity) have hJ := gaussianProduct_jensen_pow (offDiagonalCentered_lip hF) (fun x=>norm_nonneg (offDiagonalVector (matrixCentered F x))) 4 apply (hJ.trans (offDiagonalCentered_fourth_moment hF hL)).trans have hs : sqrt (Fintype.card ι)^4=(Fintype.card ι:ℝ)^2 := by calc _ = (sqrt (Fintype.card ι)^2)^2 := by ring _ = _ := by rw [sq_sqrt hcn] rw [mul_pow,mul_pow,hs] have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left matrixNormConstant_bounds.2.2 (sq_nonneg (Fintype.card ι:ℝ))) (by positivity : (0:ℝ)≤(L:ℝ)^4) nlinarith only [hh]end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103import Mathlibimport OAI.Probability.SKGap.Gaussian.StdGaussianMgfLipschitz
namespace OAI
sectionnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealopen Filteropen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius ENNReal NNRealnoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius NNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Set Filteropen MeasureTheory.Measureopen scoped ENNReal NNReal MeasureTheory Topologyopen MeasureTheorynoncomputable sectionnoncomputable sectionopen MeasureTheory Set NormedSpaceopen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobeniusnoncomputable sectionopen Set Realopen scoped Topologynoncomputable sectionopen Matrix Set Filteropen scoped Topology Matrix.Norms.Frobeniusnoncomputable sectionopen Matrix NormedSpace ContinuousLinearMapopen scoped Matrix.Norms.Frobeniusnoncomputable sectionopen Matrixnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Setopen scoped ENNReal NNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealnoncomputable sectionopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen Realnamespace SKGapsection ProductGaussianConcentrationvariable {κ : Type*} [Fintype κ]
theorem gaussianProduct_upper_tail_lipschitz {f : (κ → ℝ) → ℝ} {L : ℝ≥0} (hf : LipschitzWith L (fun x : EuclideanSpace ℝ κ => f x.ofLp)) (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : (Measure.pi (fun _ : κ => gaussianReal 0 1)).real {x | u ≤ f x - ∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)} ≤ Real.exp (-2*u^2/(π^2*(L:ℝ)^2)) := by let e : (κ → ℝ) ≃ᵐ EuclideanSpace ℝ κ := MeasurableEquiv.toLp 2 _ have hp : MeasurePreserving e (Measure.pi (fun _ : κ => gaussianReal 0 1)) (stdGaussian (EuclideanSpace ℝ κ)) := ⟨e.measurable, map_pi_eq_stdGaussian⟩ have hi := hp.integral_comp' (fun x : EuclideanSpace ℝ κ => f x.ofLp) change (∫ x, f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)) = _ at hi have h := stdGaussian_upper_tail_lipschitz hf hL hu rw [← hi] at h have hs : MeasurableSet {x : EuclideanSpace ℝ κ | u ≤ f x.ofLp - ∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)} := measurableSet_le measurable_const (hf.continuous.measurable.sub_const _) have he := hp.measure_preimage hs.nullMeasurableSet have her := congrArg ENNReal.toReal he change (Measure.pi (fun _ : κ => gaussianReal 0 1)).real {x | u ≤ f x - ∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)} = _ at her rw [her] exact h
end ProductGaussianConcentrationend SKGap
noncomputable sectionopen scoped BigOperators Topologyopen Filter Real
endendendendendendendendendendendendendendendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202import Mathlibimport OAI.Probability.SKGap.Terminal.FiniteSpinCalculusimport OAI.Probability.SKGap.Gaussian.StandardGaussianProduct
namespace OAI
sectionnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealopen Filteropen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius ENNReal NNRealnoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius NNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Set Filteropen MeasureTheory.Measureopen scoped ENNReal NNReal MeasureTheory Topologyopen MeasureTheorynoncomputable sectionnoncomputable sectionopen MeasureTheory Set NormedSpaceopen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobeniusnoncomputable sectionopen Set Realopen scoped Topologynoncomputable sectionopen Matrix Set Filteropen scoped Topology Matrix.Norms.Frobeniusnoncomputable sectionopen Matrix NormedSpace ContinuousLinearMapopen scoped Matrix.Norms.Frobeniusnoncomputable sectionopen Matrixnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Setopen scoped ENNReal NNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealnoncomputable sectionopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen Realnamespace SKGapopen scoped BigOperators
lemma gaussian_integrable_pow (k : ℕ) : Integrable (fun x : ℝ => x^k) (gaussianReal 0 1) := by apply (integrable_norm_iff (by fun_prop)).mp simpa only [id_eq, norm_pow] using (IsGaussian.memLp_id (gaussianReal 0 1) (k : ℝ≥0∞) (by simp)).integrable_norm_pow'
lemma gaussian_memLp_sq : MemLp (fun x : ℝ => x^2) 2 (gaussianReal 0 1) := by apply (memLp_two_iff_integrable_sq (by fun_prop)).mpr simpa only [← pow_mul] using gaussian_integrable_pow 4
lemma gaussian_integral_sq : (∫ x : ℝ, x^2 ∂gaussianReal 0 1) = 1 := by have h := variance_fun_id_gaussianReal (μ := 0) (v := 1) rw [variance_eq_integral (by fun_prop), integral_id_gaussianReal] at h simpa only [sub_zero, NNReal.coe_one] using h
lemma gaussian_integral_fourth : (∫ x : ℝ, x^4 ∂gaussianReal 0 1) = 3 := by have hd (x : ℝ) : HasDerivAt (fun x : ℝ => x^3) (3*x^2) x := by convert! (hasDerivAt_id x).pow 3 using 1; norm_num [Pi.pow_apply, id_eq] have hi : Integrable (fun x : ℝ => (x - 0)*x^3) (gaussianReal 0 1) := by simpa only [sub_zero, ← pow_succ'] using gaussian_integrable_pow 4 have h := gaussian_integration_by_parts (by norm_num : (1 : ℝ≥0) ≠ 0) hd (gaussian_integrable_pow 3) ((gaussian_integrable_pow 2).const_mul 3) hi simpa only [sub_zero, ← pow_succ', integral_const_mul, gaussian_integral_sq, NNReal.coe_one, one_mul, mul_one] using h
lemma gaussian_variance_sq : Var[fun x : ℝ => x^2; gaussianReal 0 1] = 2 := by rw [variance_eq_sub gaussian_memLp_sq] simp only [Pi.pow_apply, ← pow_mul, gaussian_integral_fourth, gaussian_integral_sq] norm_num
section Quadraticvariable {ι : Type*} [Fintype ι]
def gaussianQuadratic (a : ι → ℝ) (x : ι → ℝ) : ℝ := ∑ i, a i * (x i)^2
lemma gaussianQuadratic_memLp (a : ι → ℝ) : MemLp (gaussianQuadratic a) 2 (Measure.pi (fun _ : ι => gaussianReal 0 1)) := by apply memLp_finsetSum intro i _ exact ((gaussian_memLp_sq.const_mul (a i)).comp_measurePreserving (measurePreserving_eval (fun _ : ι => gaussianReal 0 1) i))
lemma gaussianQuadratic_mean (a : ι → ℝ) : (∫ x, gaussianQuadratic a x ∂Measure.pi (fun _ : ι => gaussianReal 0 1)) = ∑ i, a i := by unfold gaussianQuadratic have hi (i : ι) : Integrable (fun x : ι → ℝ => a i * (x i)^2) (Measure.pi (fun _ : ι => gaussianReal 0 1)) := ((gaussian_memLp_sq.const_mul (a i)).comp_measurePreserving (measurePreserving_eval (fun _ : ι => gaussianReal 0 1) i)).integrable (by norm_num) rw [integral_finsetSum _ (fun i _ => hi i)] apply Finset.sum_congr rfl intro i _ rw [integral_const_mul] have he : (∫ x : ι → ℝ, (x i)^2 ∂Measure.pi (fun _ : ι => gaussianReal 0 1)) = ∫ y : ℝ, y^2 ∂gaussianReal 0 1 := integral_comp_eval (μ := fun _ : ι => gaussianReal 0 1) (i := i) (f := fun y : ℝ => y^2) (by fun_prop) rw [he, gaussian_integral_sq, mul_one]
lemma gaussianQuadratic_variance (a : ι → ℝ) : Var[gaussianQuadratic a; Measure.pi (fun _ : ι => gaussianReal 0 1)] = 2 * ∑ i, (a i)^2 := by have h : Var[gaussianQuadratic a; Measure.pi (fun _ : ι => gaussianReal 0 1)] = ∑ i, Var[fun x : ℝ => a i * x^2; gaussianReal 0 1] := by convert variance_sum_pi (fun i : ι => gaussian_memLp_sq.const_mul (a i)) using 1 congr 1 funext x simp only [gaussianQuadratic, Finset.sum_apply] rw [h] simp only [variance_const_mul, gaussian_variance_sq, ← Finset.sum_mul] ring
end Quadratic
lemma sqrt_sub_sq_le_abs_sub {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : (sqrt x - sqrt y)^2 ≤ |x-y| := by have hx2 := sq_sqrt hx have hy2 := sq_sqrt hy rcases le_total x y with h | h · rw [abs_of_nonpos (sub_nonpos.mpr h)] have hh := sqrt_le_sqrt h nlinarith [mul_nonneg (sqrt_nonneg x) (sub_nonneg.mpr hh)] · rw [abs_of_nonneg (sub_nonneg.mpr h)] have hh := sqrt_le_sqrt h nlinarith [mul_nonneg (sqrt_nonneg y) (sub_nonneg.mpr hh)]
section Fluctuationvariable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]
omit [IsProbabilityMeasure μ] inlemma memLp_sqrt_of_nonneg {f : Ω → ℝ} (hf : Integrable f μ) (hpos : ∀ x, 0 ≤ f x) : MemLp (fun x => sqrt (f x)) 2 μ := by apply (memLp_two_iff_integrable_sq (Real.continuous_sqrt.comp_aestronglyMeasurable hf.aestronglyMeasurable)).mpr exact hf.congr (Filter.Eventually.of_forall (fun x => (sq_sqrt (hpos x)).symm))
lemma integral_abs_le_sqrt_sq {f : Ω → ℝ} (hf : MemLp f 2 μ) : (∫ x, |f x| ∂μ) ≤ sqrt (∫ x, (f x)^2 ∂μ) := by have h0 := ProbabilityTheory.variance_nonneg (fun x => ‖f x‖) μ rw [variance_eq_sub hf.norm] at h0 have hsq : (∫ x, |f x| ∂μ)^2 ≤ ∫ x, (f x)^2 ∂μ := by simpa only [Real.norm_eq_abs, Pi.pow_apply, sq_abs, sub_nonneg] using h0 have hi : 0 ≤ ∫ x, (f x)^2 ∂μ := integral_nonneg (fun x => sq_nonneg _) have hh := sq_sqrt hi have hp := sqrt_nonneg (∫ x, (f x)^2 ∂μ) nlinarith [sq_nonneg ((∫ x, |f x| ∂μ) - sqrt (∫ x, (f x)^2 ∂μ))]
theorem integral_sqrt_fluctuation {f : Ω → ℝ} (hf : MemLp f 2 μ) (hpos : ∀ x, 0 ≤ f x) : (∫ x, |sqrt (f x) - sqrt (∫ y, f y ∂μ)| ∂μ) ≤ sqrt (sqrt (Var[f; μ])) := by let m := ∫ y, f y ∂μ have hm : 0 ≤ m := integral_nonneg hpos have hg : MemLp (fun x => f x - m) 2 μ := hf.sub (memLp_const m) have hroot : MemLp (fun x => sqrt (f x) - sqrt m) 2 μ := by apply (memLp_two_iff_integrable_sq ((Real.continuous_sqrt.comp_aestronglyMeasurable hf.aestronglyMeasurable).sub aestronglyMeasurable_const)).mpr apply hg.integrable (by norm_num) |>.norm |>.mono' (((Real.continuous_sqrt.comp_aestronglyMeasurable hf.aestronglyMeasurable).sub aestronglyMeasurable_const).pow 2) filter_upwards [] with x change |(sqrt (f x) - sqrt m)^2| ≤ |f x - m| rw [abs_of_nonneg (sq_nonneg (sqrt (f x) - sqrt m))] exact sqrt_sub_sq_le_abs_sub (hpos x) hm have hdiff : (∫ x, (sqrt (f x) - sqrt m)^2 ∂μ) ≤ ∫ x, |f x-m| ∂μ := by apply integral_mono hroot.integrable_sq (hg.integrable (by norm_num)).norm exact fun x => sqrt_sub_sq_le_abs_sub (hpos x) hm have hc := integral_abs_le_sqrt_sq hg rw [← variance_eq_integral hf.aemeasurable] at hc exact (integral_abs_le_sqrt_sq hroot).trans (sqrt_le_sqrt (hdiff.trans hc))
end Fluctuationend SKGap
endendendendendendendendendendendendendendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianCoordinatesimport OAI.Probability.SKGap.Localization.QuadraticCoeff
namespace OAI
sectionnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealopen Filteropen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius ENNReal NNRealnoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobenius NNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Set Filteropen MeasureTheory.Measureopen scoped ENNReal NNReal MeasureTheory Topologyopen MeasureTheorynoncomputable sectionnoncomputable sectionopen MeasureTheory Set NormedSpaceopen scoped Topologynoncomputable sectionopen Matrix Realopen scoped BigOperators Matrix.Norms.Frobeniusnoncomputable sectionopen Set Realopen scoped Topologynoncomputable sectionopen Matrix Set Filteropen scoped Topology Matrix.Norms.Frobeniusnoncomputable sectionopen Matrix NormedSpace ContinuousLinearMapopen scoped Matrix.Norms.Frobeniusnoncomputable sectionopen Matrixnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Setopen scoped ENNReal NNRealnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Setopen scoped NNReal ENNRealnoncomputable sectionopen scoped BigOperatorsopen MeasureTheory ProbabilityTheorynamespace SKGapsection QuadraticComparisonvariable {I ι : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] [Fintype ι] [Nonempty ι]
theorem gaussian_quadraticSup_comparison {m : I → ℝ} {w : I → EuclideanSpace ℝ ι} (hm : Continuous m) (hw : Continuous w) {r : ℝ} (hr : 0 ≤ r) (z : ℝ) : (∫ g, gaussianSup m (fun i k => z * quadraticCoeff r (w i) k) g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ ∫ g, gaussianSup m (fun i k => z * linearCoeff r (w i) k) g ∂gaussianCoordinates (MatrixCoordinates ι) := by have hc {q : EuclideanSpace ℝ ι → MatrixCoordinates ι → ℝ} (hq : Continuous q) : Continuous (fun i k => z * q (w i) k) := by apply continuous_pi intro k exact continuous_const.mul ((continuous_apply k).comp (hq.comp hw)) apply gaussianSup_comparison hm (hc (continuous_linearCoeff r)) (hc (continuous_quadraticCoeff r)) · intro i j simp_rw [← mul_sub] simp_rw [show ∀ k, (z * (linearCoeff r (w i) k - linearCoeff r (w j) k)) * (z * (quadraticCoeff r (w i) k - quadraticCoeff r (w j) k)) = z^2 * ((linearCoeff r (w i) k - linearCoeff r (w j) k) * (quadraticCoeff r (w i) k - quadraticCoeff r (w j) k)) by intros; ring] rw [← Finset.mul_sum, quadratic_linear_orthogonal, mul_zero] · intro i j simp_rw [← mul_sub, mul_pow, ← Finset.mul_sum] exact mul_le_mul_of_nonneg_left (quadratic_linear_increment_le r hr (w i) (w j)) (sq_nonneg z)end QuadraticComparisonend SKGap
namespace SKGapsection SupLipschitzvariable {I κ : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] [Fintype κ]
lemma gaussianAffine_le_gaussianSup {m : I → ℝ} {a : I → κ → ℝ} (hm : Continuous m) (ha : Continuous a) (x : κ → ℝ) (i : I) : gaussianAffine m a x i ≤ gaussianSup m a x := by obtain ⟨j, hj, hmax⟩ := gaussianSup_attained hm ha x rw [hj] exact hmax i
lemma gaussianSup_sub_le {m : I → ℝ} {a : I → κ → ℝ} (hm : Continuous m) (ha : Continuous a) {L : ℝ} (hL : ∀ i, ‖WithLp.toLp 2 (a i)‖ ≤ L) (x y : EuclideanSpace ℝ κ) : gaussianSup m a x.ofLp - gaussianSup m a y.ofLp ≤ L * ‖x-y‖ := by obtain ⟨i, hi, _⟩ := gaussianSup_attained hm ha x.ofLp calc _ ≤ gaussianAffine m a x.ofLp i - gaussianAffine m a y.ofLp i := by rw [hi] exact sub_le_sub_left (gaussianAffine_le_gaussianSup hm ha y.ofLp i) _ _ = inner ℝ (WithLp.toLp 2 (a i)) (x-y) := by simp only [gaussianAffine, PiLp.inner_apply, WithLp.ofLp_sub, Pi.sub_apply, RCLike.inner_apply, conj_trivial] rw [add_sub_add_left_eq_sub, ← Finset.sum_sub_distrib] apply Finset.sum_congr rfl intro k _ ring _ ≤ ‖WithLp.toLp 2 (a i)‖ * ‖x-y‖ := real_inner_le_norm _ _ _ ≤ L * ‖x-y‖ := mul_le_mul_of_nonneg_right (hL i) (norm_nonneg _)
theorem gaussianSup_lipschitz {m : I → ℝ} {a : I → κ → ℝ} (hm : Continuous m) (ha : Continuous a) {L : ℝ≥0} (hL : ∀ i, ‖WithLp.toLp 2 (a i)‖ ≤ (L : ℝ)) : LipschitzWith L (fun x : EuclideanSpace ℝ κ => gaussianSup m a x.ofLp) := by apply LipschitzWith.of_dist_le_mul intro x y rw [Real.dist_eq, dist_eq_norm] apply abs_le.mpr constructor · have h := gaussianSup_sub_le hm ha hL y x rw [norm_sub_rev] at h linarith · exact gaussianSup_sub_le hm ha hL x y
end SupLipschitzend SKGap
endendendendendendendendendendendendendendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429import Mathlibimport OAI.Probability.SKGap.Localization.BilinearCoefficientimport OAI.Probability.SKGap.Localization.QueryResidualimport OAI.Probability.SKGap.Gaussian.SubgaussianAbsTail
namespace OAI
sectionopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen scoped BigOperatorsopen scoped BigOperators NNReal ENNRealopen MeasureTheory Metric Setopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Setopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators ENNReal NNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Matrixopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators ENNReal NNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNRealnamespace SKGapCutoff.Regression
noncomputable def gaussianRankCorrection {ι κ η : Type*} [Fintype κ] [Fintype η] (V : ι → κ → ℝ) (W : κ → η → ℝ) (g : η → ℝ) (i : ι) : ℝ := ∑ a, V i a * ∑ j, W a j * g j
lemma rankCorrection_sq_bound {ι κ : Type*} [Fintype ι] [Fintype κ] (V : ι → κ → ℝ) (c : κ → ℝ) (M : ℝ) (hV : ∀ a, ∑ i, V i a ^ 2 ≤ M) : ∑ i, (∑ a, V i a * c a)^2 ≤ M * Fintype.card κ * ∑ a, c a^2 := by calc _ ≤ ∑ i, (∑ a, V i a^2) * ∑ a, c a^2 := Finset.sum_le_sum (fun i _ => Finset.sum_mul_sq_le_sq_mul_sq _ _ _) _ = (∑ a, ∑ i, V i a^2) * ∑ a, c a^2 := by rw [← Finset.sum_mul, Finset.sum_comm] _ ≤ (∑ _a : κ, M) * ∑ a, c a^2 := by exact mul_le_mul_of_nonneg_right (Finset.sum_le_sum (fun a _ => hV a)) (Finset.sum_nonneg (fun a _ => sq_nonneg _)) _ = _ := by simp [mul_comm]
lemma gaussian_linear_unit_tail {η : Type*} [Fintype η] (W : η → ℝ) (hW : ∑ j, W j^2 ≤ 1) (b : ℝ) (hb : 0 < b) : standardArrayLaw η {g | b ≤ |∑ j, W j * g j|} ≤ 2 * ENNReal.ofReal (Real.exp (-b^2/2)) := by have h := RandomMatrix.gaussian_linear_abs_tail 1 W b b hb refine h.trans (mul_le_mul' (le_refl 2) (ENNReal.ofReal_le_ofReal (Real.exp_le_exp.mpr ?_))) simp only [NNReal.coe_one, one_mul] nlinarith [mul_le_mul_of_nonneg_right hW (sq_nonneg b)]
theorem gaussian_rank_correction_tail {ι κ η : Type*} [Fintype ι] [Fintype κ] [Fintype η] [Nonempty κ] (V : ι → κ → ℝ) (W : κ → η → ℝ) (hV : ∀ a, ∑ i, V i a^2 ≤ 2) (hW : ∀ a, ∑ j, W a j^2 ≤ 1) (N ε : ℝ) (hN : 0 < N) (hε : 0 < ε) : standardArrayLaw η {g | N*ε < ∑ i, gaussianRankCorrection V W g i^2} ≤ (2 * Fintype.card κ : ℝ≥0∞) * ENNReal.ofReal (Real.exp (-(N*ε)/(4*(Fintype.card κ : ℝ)^2))) := by classical let m : ℝ := Fintype.card κ have hm : 0 < m := by dsimp [m] exact_mod_cast (Fintype.card_pos : 0 < Fintype.card κ) let b : ℝ := Real.sqrt (N*ε/(2*m^2)) have hb : 0 < b := Real.sqrt_pos.mpr (by positivity) have hb2 : b^2 = N*ε/(2*m^2) := Real.sq_sqrt (by positivity) have hsub : {g | N*ε < ∑ i, gaussianRankCorrection V W g i^2} ⊆ ⋃ a : κ, {g | b ≤ |∑ j, W a j*g j|} := by intro g hg by_contra hnot have hcoeff (a : κ) : (∑ j, W a j*g j)^2 ≤ b^2 := by have ha : |∑ j, W a j*g j| < b := lt_of_not_ge (fun ha => hnot (Set.mem_iUnion.mpr ⟨a, ha⟩)) nlinarith [sq_abs (∑ j, W a j*g j), abs_nonneg (∑ j, W a j*g j)] have he := rankCorrection_sq_bound V (fun a => ∑ j, W a j*g j) 2 hV have hs : (∑ a, (∑ j, W a j*g j)^2) ≤ m*b^2 := by calc _ ≤ ∑ _a : κ, b^2 := Finset.sum_le_sum (fun a _ => hcoeff a) _ = _ := by simp [m] have he' : ∑ i, gaussianRankCorrection V W g i^2 ≤ N*ε := by calc _ ≤ 2*m * ∑ a, (∑ j, W a j*g j)^2 := he _ ≤ 2*m*(m*b^2) := mul_le_mul_of_nonneg_left hs (by positivity) _ = _ := by rw [hb2]; field_simp exact not_lt_of_ge he' hg calc _ ≤ standardArrayLaw η (⋃ a : κ, {g | b ≤ |∑ j, W a j*g j|}) := measure_mono hsub _ ≤ ∑ a : κ, standardArrayLaw η {g | b ≤ |∑ j, W a j*g j|} := measure_iUnion_fintype_le _ _ _ ≤ ∑ _a : κ, 2 * ENNReal.ofReal (Real.exp (-b^2/2)) := Finset.sum_le_sum (fun a _ => gaussian_linear_unit_tail (W a) (hW a) b hb) _ = _ := by have hbexp : -b^2/2 = -(N*ε)/(4*(Fintype.card κ : ℝ)^2) := by rw [hb2]; dsimp [m]; ring rw [hbexp] simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] ring
noncomputable def innovationErrorVectors {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) (i : Fin n) : Fin r ⊕ Bool → ℝ := Sum.elim (fun a => -U i a) (fun b => if b then Real.sqrt 2*q i else -q i)
def innovationErrorCoefficients {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) : (Fin r ⊕ Bool) → (Fin n ⊕ Unit) → ℝ := Sum.elim (fun a => Sum.elim (fun j => U j a) (fun _ => 0)) (fun b => if b then Sum.elim (fun _ => 0) (fun _ => 1) else Sum.elim q (fun _ => 0))
lemma innovationErrorVectors_sq_le {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) (hU : ∀ a, ∑ i, U i a^2 ≤ 1) (hq : ∑ i, q i^2 ≤ 1) (a : Fin r ⊕ Bool) : ∑ i, innovationErrorVectors U q i a^2 ≤ 2 := by rcases a with a | (_ | _) · simpa [innovationErrorVectors] using (hU a).trans (by norm_num : (1:ℝ) ≤ 2) · simpa [innovationErrorVectors] using hq.trans (by norm_num : (1:ℝ) ≤ 2) · simp only [innovationErrorVectors, Sum.elim_inr, ↓reduceIte, mul_pow, Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2), ← Finset.mul_sum] linarith
lemma innovationErrorCoefficients_sq_le {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) (hU : ∀ a, ∑ i, U i a^2 ≤ 1) (hq : ∑ i, q i^2 ≤ 1) (a : Fin r ⊕ Bool) : ∑ j, innovationErrorCoefficients U q a j^2 ≤ 1 := by rcases a with a | (_ | _) · simpa [innovationErrorCoefficients, Fintype.sum_sum_type] using hU a · simpa [innovationErrorCoefficients, Fintype.sum_sum_type] using hq · simp [innovationErrorCoefficients, Fintype.sum_sum_type]
lemma queryInnovation_error_eq {n r : ℕ} (hn : 0 < n) (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) (g : (Fin n ⊕ Unit) → ℝ) (i : Fin n) : Real.sqrt n * queryInnovation (residualProjection U) q g i - g (Sum.inl i) = gaussianRankCorrection (innovationErrorVectors U q) (innovationErrorCoefficients U q) g i := by have hsn : Real.sqrt (n:ℝ) ≠ 0 := (Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn)).ne' have hh : ∑ k, (residualProjection U i k-q i*q k)*g (Sum.inl k) = g (Sum.inl i) - ∑ a, U i a * (∑ k, U k a*g (Sum.inl k)) - q i*(∑ k, q k*g (Sum.inl k)) := by simp only [residualProjection, Matrix.sub_apply, Matrix.mul_apply, Matrix.transpose_apply, sub_mul, Finset.sum_sub_distrib, Finset.sum_mul, mul_assoc] rw [Finset.sum_comm] simp [Matrix.one_apply, Finset.mul_sum] simp only [queryInnovation, queryComplement_apply] rw [mul_div_cancel₀ _ hsn, hh] simp only [gaussianRankCorrection, innovationErrorVectors, innovationErrorCoefficients, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, Fintype.sum_bool, Bool.false_eq_true, ↓reduceIte, zero_mul, one_mul, Finset.sum_const_zero, add_zero, Fintype.sum_unique, neg_mul, Finset.sum_neg_distrib] ring
theorem queryInnovation_iid_error_tail {n r : ℕ} (hn : 0 < n) (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) (hU : ∀ a, ∑ i, U i a^2 ≤ 1) (hq : ∑ i, q i^2 ≤ 1) (ε : ℝ) (hε : 0 < ε) : standardArrayLaw (Fin n ⊕ Unit) {g | (n:ℝ)*ε < ∑ i, (Real.sqrt n * queryInnovation (residualProjection U) q g i - g (Sum.inl i))^2} ≤ (2*(r+2) : ℝ≥0∞) * ENNReal.ofReal (Real.exp (-((n:ℝ)*ε)/(4*((r:ℝ)+2)^2))) := by simp_rw [queryInnovation_error_eq hn U q] have h := gaussian_rank_correction_tail (innovationErrorVectors U q) (innovationErrorCoefficients U q) (innovationErrorVectors_sq_le U q hU hq) (innovationErrorCoefficients_sq_le U q hU hq) n ε (Nat.cast_pos.mpr hn) hε simpa only [Fintype.card_sum, Fintype.card_fin, Fintype.card_bool, Nat.cast_add, Nat.cast_ofNat] using h
lemma probability_prod_section_bound {H A : Type*} [MeasurableSpace H] [MeasurableSpace A] (ρ : Measure H) [IsProbabilityMeasure ρ] (μ : Measure A) [SFinite μ] (s : Set (H × A)) (hs : MeasurableSet s) (b : ℝ≥0∞) (hb : ∀ h, μ (Prod.mk h ⁻¹' s) ≤ b) : (ρ.prod μ) s ≤ b := by rw [Measure.prod_apply hs] calc _ ≤ ∫⁻ _h, b ∂ρ := lintegral_mono hb _ = _ := by simp
theorem adaptive_queryInnovation_iid_error_tail {n r : ℕ} (hn : 0 < n) {H : Type*} [MeasurableSpace H] (ρ : Measure H) [IsProbabilityMeasure ρ] (U : H → Fin n → Fin r → ℝ) (q : H → Fin n → ℝ) (hUm : Measurable U) (hqm : Measurable q) (hU : ∀ h a, ∑ i, U h i a^2 ≤ 1) (hq : ∀ h, ∑ i, q h i^2 ≤ 1) (ε : ℝ) (hε : 0 < ε) : (ρ.prod (standardArrayLaw (Fin n ⊕ Unit))) {z | (n:ℝ)*ε < ∑ i, (Real.sqrt n * queryInnovation (residualProjection (U z.1)) (q z.1) z.2 i - z.2 (Sum.inl i))^2} ≤ (2*(r+2) : ℝ≥0∞) * ENNReal.ofReal (Real.exp (-((n:ℝ)*ε)/(4*((r:ℝ)+2)^2))) := by have hP : Measurable (fun h => fun i j => residualProjection (U h) i j) := by apply Measurable.of_eval intro i apply Measurable.of_eval intro j change Measurable (fun h => (if i=j then (1:ℝ) else 0) - ∑ a, U h i a*U h j a) apply measurable_const.sub apply Finset.measurable_sum intro a _ exact ((measurable_pi_apply a).comp ((measurable_pi_apply i).comp hUm)).mul ((measurable_pi_apply a).comp ((measurable_pi_apply j).comp hUm)) have hI := measurable_queryInnovation_comp (fun z : H × ((Fin n ⊕ Unit) → ℝ) => residualProjection (U z.1)) (fun z => q z.1) (fun z => z.2) (hP.comp measurable_fst) (hqm.comp measurable_fst) measurable_snd apply probability_prod_section_bound · apply measurableSet_lt measurable_const apply Finset.measurable_sum intro i _ exact (((measurable_pi_apply i).comp hI).const_mul _ |>.sub ((measurable_pi_apply (Sum.inl i)).comp measurable_snd)).pow_const 2 · intro h exact queryInnovation_iid_error_tail hn (U h) (q h) (hU h) (hq h) ε hε
lemma independent_bounded_average_tail {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] {n : ℕ} (hn : 0 < n) (X : Fin n → Ω → ℝ) (hXi : iIndepFun X μ) (hX : ∀ i, HasLaw (X i) (gaussianReal 0 1) μ) (f : Fin n → ℝ → ℝ) (hf : ∀ i, Measurable (f i)) (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ i z, |f i z| ≤ B) (ε : ℝ) (hε : 0 ≤ ε) : μ {g | ε ≤ |((∑ i, f i (X i g)) - ∑ i, ∫ z, f i z ∂gaussianReal 0 1)/(n:ℝ)|} ≤ 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(2*B^2))) := by let m (i : Fin n) := ∫ z, f i z ∂gaussianReal 0 1 have hi : iIndepFun (fun i (g : Ω) => f i (X i g)-m i) μ := hXi.comp (fun i z => f i z-m i) (fun i => (hf i).sub_const (m i)) have hm (i : Fin n) : (∫ g : Ω, f i (X i g) ∂μ) = m i := (hX i).integral_comp (hf i).aestronglyMeasurable have hsub (i : Fin n) : HasSubgaussianMGF (fun g : Ω => f i (X i g)-m i) ((‖B-(-B)‖₊/2)^2) μ := by have hb : ∀ᵐ g : Ω ∂μ, f i (X i g) ∈ Set.Icc (-B) B := Filter.Eventually.of_forall (fun g => abs_le.mp (hbound i (X i g))) simpa only [hm] using hasSubgaussianMGF_of_mem_Icc (show AEMeasurable (fun g : Ω => f i (X i g)) μ from (hf i).comp_aemeasurable (hX i).aemeasurable) hb have hh := subgaussian_abs_tail (HasSubgaussianMGF.sum_of_iIndepFun hi (s := Finset.univ) (fun i _ => hsub i)) (ε*n) (by positivity) have he (g : Ω) : (ε*(n:ℝ) ≤ |∑ i, (f i (X i g)-m i)|) ↔ ε ≤ |((∑ i, f i (X i g)) - ∑ i, m i)/(n:ℝ)| := by rw [Finset.sum_sub_distrib, abs_div, abs_of_pos (show (0:ℝ) < n from Nat.cast_pos.mpr hn)] exact (le_div_iff₀ (Nat.cast_pos.mpr hn)).symm simp only [he] at hh convert hh using 1 congr 3 simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, NNReal.coe_mul, NNReal.coe_natCast, NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat, coe_nnnorm, Real.norm_eq_abs] rw [abs_of_nonneg (by linarith : 0 ≤ B-(-B))] have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) by_cases hB0 : B=0 · simp [hB0] · field_simp ring
lemma average_Lipschitz_error_sq {n : ℕ} (hn : 0 < n) (f : Fin n → ℝ → ℝ) {K : ℝ≥0} (hf : ∀ i, LipschitzWith K (f i)) (v w : Fin n → ℝ) : |((∑ i, f i (v i))-(∑ i, f i (w i)))/(n:ℝ)|^2 ≤ (K:ℝ)^2 * (∑ i, (v i-w i)^2)/(n:ℝ) := by have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn rw [sq_abs, div_pow, ← Finset.sum_sub_distrib] have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun i : Fin n => (1:ℝ)) (fun i => f i (v i)-f i (w i)) simp only [one_mul, one_pow, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one] at hcs have hsite (i : Fin n) : (f i (v i)-f i (w i))^2 ≤ (K:ℝ)^2*(v i-w i)^2 := by have h := (hf i).dist_le_mul (v i) (w i) rw [Real.dist_eq, Real.dist_eq] at h have hs := mul_self_le_mul_self (abs_nonneg _) h simpa [← pow_two, mul_pow] using hs apply (div_le_iff₀ (sq_pos_of_pos hnR)).mpr calc _ ≤ (n:ℝ) * ∑ i, (f i (v i)-f i (w i))^2 := hcs _ ≤ (n:ℝ) * ∑ i, (K:ℝ)^2*(v i-w i)^2 := mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun i _ => hsite i)) hnR.le _ = _ := by rw [← Finset.mul_sum]; field_simp
theorem queryInnovation_empirical_tail {n r : ℕ} (hn : 0 < n) (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) (hU : ∀ a, ∑ i, U i a^2 ≤ 1) (hq : ∑ i, q i^2 ≤ 1) (f : Fin n → ℝ → ℝ) {K : ℝ≥0} (hf : ∀ i, LipschitzWith K (f i)) (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ i z, |f i z| ≤ B) (ε : ℝ) (hε : 0 < ε) : standardArrayLaw (Fin n ⊕ Unit) {g | ε ≤ |((∑ i, f i (Real.sqrt n * queryInnovation (residualProjection U) q g i)) - ∑ i, ∫ z, f i z ∂gaussianReal 0 1)/(n:ℝ)|} ≤ 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) + (2*(r+2) : ℝ≥0∞) * ENNReal.ofReal (Real.exp (-((n:ℝ)*ε^2)/(64*((K:ℝ)+1)^2*((r:ℝ)+2)^2))) := by let δ := ε^2/(16*((K:ℝ)+1)^2) have hδ : 0 < δ := by dsimp [δ]; positivity have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn let M := ∑ i, ∫ z, f i z ∂gaussianReal 0 1 let A (g : (Fin n ⊕ Unit) → ℝ) := ∑ i, f i (g (Sum.inl i)) let C (g : (Fin n ⊕ Unit) → ℝ) := ∑ i, f i (Real.sqrt n * queryInnovation (residualProjection U) q g i) let E (g : (Fin n ⊕ Unit) → ℝ) := ∑ i, (Real.sqrt n * queryInnovation (residualProjection U) q g i-g (Sum.inl i))^2 have hi : iIndepFun (fun i : Fin n => fun g : (Fin n ⊕ Unit) → ℝ => g (Sum.inl i)) (standardArrayLaw (Fin n ⊕ Unit)) := coordinates_independent.precomp Sum.inl_injective have h1 := independent_bounded_average_tail (μ := standardArrayLaw (Fin n ⊕ Unit)) hn (fun i g => g (Sum.inl i)) hi (fun i => coordinate_hasLaw (Sum.inl i)) f (fun i => (hf i).continuous.measurable) B hB hbound (ε/2) (by positivity) have h2 := queryInnovation_iid_error_tail hn U q hU hq δ hδ have hsub : {g | ε ≤ |(C g-M)/(n:ℝ)|} ⊆ {g | ε/2 ≤ |(A g-M)/(n:ℝ)|} ∪ {g | (n:ℝ)*δ < E g} := by intro g hg by_cases ha : ε/2 ≤ |(A g-M)/(n:ℝ)| · exact Or.inl ha apply Or.inr by_contra he have he' : E g ≤ (n:ℝ)*δ := le_of_not_gt he have hcs := average_Lipschitz_error_sq hn f hf (fun i => Real.sqrt n * queryInnovation (residualProjection U) q g i) (fun i => g (Sum.inl i)) change |(C g-A g)/(n:ℝ)|^2 ≤ (K:ℝ)^2*E g/(n:ℝ) at hcs have hk : (K:ℝ)^2*δ ≤ ε^2/16 := by dsimp [δ] have hkp : 0 < ((K:ℝ)+1)^2 := by positivity apply (le_div_iff₀ (by norm_num : (0:ℝ)<16)).mpr field_simp have hkk : (K:ℝ)^2 ≤ ((K:ℝ)+1)^2 := by nlinarith [K.coe_nonneg] exact hkk have hsq : |(C g-A g)/(n:ℝ)|^2 ≤ ε^2/16 := hcs.trans ((calc (K:ℝ)^2*E g/(n:ℝ) ≤ (K:ℝ)^2*((n:ℝ)*δ)/(n:ℝ) := by gcongr _ = (K:ℝ)^2*δ := by field_simp).trans hk) have hd : |(C g-A g)/(n:ℝ)| ≤ ε/2 := by nlinarith [abs_nonneg ((C g-A g)/(n:ℝ))] have ht := abs_add_le ((C g-A g)/(n:ℝ)) ((A g-M)/(n:ℝ)) rw [← add_div, sub_add_sub_cancel] at ht have ha' : |(A g-M)/(n:ℝ)| < ε/2 := lt_of_not_ge ha change ε ≤ |(C g-M)/(n:ℝ)| at hg linarith apply (measure_mono hsub).trans ((measure_union_le _ _).trans _) have h1' : standardArrayLaw (Fin n ⊕ Unit) {g | ε/2 ≤ |(A g-M)/(n:ℝ)|} ≤ 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) := by convert h1 using 1 congr 3 ring have h2' : standardArrayLaw (Fin n ⊕ Unit) {g | (n:ℝ)*δ < E g} ≤ (2*(r+2) : ℝ≥0∞) * ENNReal.ofReal (Real.exp (-((n:ℝ)*ε^2)/(64*((K:ℝ)+1)^2*((r:ℝ)+2)^2))) := by convert h2 using 1 congr 3 dsimp [δ] field_simp ring exact add_le_add h1' h2'
lemma measurable_residualProjection_comp {n r : ℕ} {H : Type*} [MeasurableSpace H] (U : H → Fin n → Fin r → ℝ) (hU : Measurable U) : Measurable (fun h => fun i j => residualProjection (U h) i j) := by apply Measurable.of_eval intro i apply Measurable.of_eval intro j change Measurable (fun h => (if i=j then (1:ℝ) else 0) - ∑ a, U h i a*U h j a) apply measurable_const.sub apply Finset.measurable_sum intro a _ exact ((measurable_pi_apply a).comp ((measurable_pi_apply i).comp hU)).mul ((measurable_pi_apply a).comp ((measurable_pi_apply j).comp hU))
theorem adaptive_queryInnovation_empirical_tail {n r : ℕ} (hn : 0 < n) {H : Type*} [MeasurableSpace H] (ρ : Measure H) [IsProbabilityMeasure ρ] (U : H → Fin n → Fin r → ℝ) (q : H → Fin n → ℝ) (hUm : Measurable U) (hqm : Measurable q) (hU : ∀ h a, ∑ i, U h i a^2 ≤ 1) (hq : ∀ h, ∑ i, q h i^2 ≤ 1) (f : H → Fin n → ℝ → ℝ) (hfm : ∀ i, Measurable (fun z : H × ℝ => f z.1 i z.2)) {K : ℝ≥0} (hf : ∀ h i, LipschitzWith K (f h i)) (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ h i z, |f h i z| ≤ B) (ε : ℝ) (hε : 0 < ε) : (ρ.prod (standardArrayLaw (Fin n ⊕ Unit))) {z | ε ≤ |((∑ i, f z.1 i (Real.sqrt n * queryInnovation (residualProjection (U z.1)) (q z.1) z.2 i)) - ∑ i, ∫ x, f z.1 i x ∂gaussianReal 0 1)/(n:ℝ)|} ≤ 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) + (2*(r+2) : ℝ≥0∞) * ENNReal.ofReal (Real.exp (-((n:ℝ)*ε^2)/(64*((K:ℝ)+1)^2*((r:ℝ)+2)^2))) := by have hI := measurable_queryInnovation_comp (fun z : H × ((Fin n ⊕ Unit) → ℝ) => residualProjection (U z.1)) (fun z => q z.1) (fun z => z.2) ((measurable_residualProjection_comp U hUm).comp measurable_fst) (hqm.comp measurable_fst) measurable_snd have hM (i : Fin n) : Measurable (fun h => ∫ x, f h i x ∂gaussianReal 0 1) := (hfm i).stronglyMeasurable.integral_prod_right.measurable apply probability_prod_section_bound · apply measurableSet_le measurable_const apply Measurable.abs apply Measurable.div_const apply Measurable.sub · apply Finset.measurable_sum intro i _ exact (hfm i).comp (measurable_fst.prodMk (((measurable_pi_apply i).comp hI).const_mul _)) · apply Finset.measurable_sum intro i _ exact (hM i).comp measurable_fst · intro h exact queryInnovation_empirical_tail hn (U h) (q h) (hU h) (hq h) (f h) (hf h) B hB (hbound h) ε hε
end SKGapCutoff.Regression
open scoped BigOperatorsopen Filter Topology
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121import Mathlibimport OAI.Probability.SKGap.Matrix.PrimaryWordEventBinding
namespace OAI
section
noncomputable sectionopen scoped BigOperatorsnamespace SKGapCutoff.Recipeopen SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary MeasureTheory ProbabilityTheory Real Set
def ordinaryWordTail (j : ℝ) (L n : ℕ) : ENNReal := 2*((wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2)))+ (ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n))))))def recipeNormTail (j : ℝ) (n : ℕ) : ENNReal := ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n))))
theorem gaussian_recipe_event {j A : ℝ} (hj : 0<j) (hj1 : j<1) (hA : 1≤A) (M Nmax : ℕ) : ∃R B W C : ℝ, ∃N : ℕ, 1≤R ∧ 0≤B ∧ 0≤W ∧ 0<C ∧ 0<N ∧ ∀n,N≤n→ (Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)) {g | ¬RecipeMatrixEvent j R A B W C M Nmax (removeDiagonal (goeMatrix (j/n) g))}≤ recipeNormTail j n+ordinaryWordTail j (2*M+2*Nmax+3) n := by let R:=max A (2*sqrt j+1+1) have hAR : A≤R:=le_max_left _ _ have hR : 1≤R:=hA.trans hAR obtain ⟨C,N,hC,hN,hword⟩:=ordinary_word_event hj hj1 hA (2*M+2*Nmax+3) refine ⟨R,primaryEventBudget j R C M,R^(2*Nmax+3)+C,C,N,hR, primaryEventBudget_nonneg (by linarith) hC.le M, add_nonneg (pow_nonneg (by linarith) _) hC.le,hC,hN,?_⟩ intro n hn have hn0 : 0<n:=lt_of_lt_of_le hN hn let μ:=Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1) let E : Set (MatrixCoordinates (Fin n)→ℝ):= {g | 2*sqrt j+1+1<SKGap.opNorm (removeDiagonal (goeMatrix (j/n) g))} let F : Set (MatrixCoordinates (Fin n)→ℝ):= {g | ¬WordSeminormBound (removeDiagonal (goeMatrix (j/n) g)) j A C (2*M+2*Nmax+3)} have hE : μ E≤recipeNormTail j n:=zeroDiagGOE_norm_tail hj hn0 have hF : μ F≤ordinaryWordTail j (2*M+2*Nmax+3) n:=hword n hn apply (measure_mono (t:=E∪F) ?_).trans ((measure_union_le _ _).trans (add_le_add hE hF)) intro g hg by_contra hh have hJ : SKGap.opNorm (removeDiagonal (goeMatrix (j/n) g))≤R := by apply le_trans (le_of_not_gt (fun hbad=>hh (.inl hbad))) (le_max_right _ _) have hw : WordSeminormBound (removeDiagonal (goeMatrix (j/n) g)) j A C (2*M+2*Nmax+3):=by by_contra hbad; exact hh (.inr hbad) exact hg (wordEvent_recipeEvent _ hn0 hR hA hAR hC.le hJ M Nmax hw)
end SKGapCutoff.Recipe
endend
section
noncomputable sectionopen scoped BigOperators Topologyopen Filter MeasureTheory ProbabilityTheory Realnamespace SKGapCutoff.Recipeopen SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary
lemma exp_rate_limit {c : ℝ} (hc : 0<c) : Tendsto (fun n : ℕ=>exp (-c*(n:ℝ))) atTop (𝓝 0) := by simpa using (summable_pow_mul_exp_neg_nat_mul 0 hc).tendsto_atTop_zerolemma n_exp_rate_limit {c : ℝ} (hc : 0<c) : Tendsto (fun n : ℕ=>(n:ℝ)*exp (-c*(n:ℝ))) atTop (𝓝 0) := by simpa using (summable_pow_mul_exp_neg_nat_mul 1 hc).tendsto_atTop_zero
lemma recipeNormTail_limit {j : ℝ} (hj : 0<j) : Tendsto (recipeNormTail j) atTop (𝓝 0) := by have h₁ : Tendsto (fun n : ℕ=>ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))) atTop (𝓝 0) := by have H:=ENNReal.tendsto_ofReal ((exp_rate_limit (c:=1/(π^2*j)) (by positivity)).const_mul 2) simpa only [mul_zero,ENNReal.ofReal_zero,show ∀(n : ℕ),-(1/(π^2*j))*(n:ℝ)=-(n:ℝ)/(π^2*j) by intro n;ring] using H have h₂ : Tendsto (fun n : ℕ=>ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n))))) atTop (𝓝 0) := by have H:=ENNReal.tendsto_ofReal ((n_exp_rate_limit (c:=1/(8*j)) (by positivity)).const_mul 2) have HH : Tendsto (fun n : ℕ=>ENNReal.ofReal (2*((n:ℝ)*exp (-(1/(8*j))*(n:ℝ))))) atTop (𝓝 0):=by simpa using H apply HH.congr' filter_upwards [eventually_ge_atTop 1] with n hn have hn0 : (n:ℝ)≠0:=by exact_mod_cast (by omega : n≠0) congr 1 rw [mul_assoc] congr 2 field_simp convert h₁.add h₂ using 1 <;> first | rfl | simp
lemma ordinaryWordTail_limit {j : ℝ} (hj : 0<j) (L : ℕ) : Tendsto (ordinaryWordTail j L) atTop (𝓝 0) := by have h₁ : Tendsto (fun n : ℕ=>ENNReal.ofReal (3*exp (-(n:ℝ)))) atTop (𝓝 0) := by simpa using ENNReal.tendsto_ofReal ((exp_rate_limit (c:=1) (by norm_num)).const_mul 3) have h₂ : Tendsto (fun n : ℕ=>ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2)))) atTop (𝓝 0) := by have hsq : 0<(sqrt (2*j))^2:=by rw [sq_sqrt (by positivity)]; positivity have H:=ENNReal.tendsto_ofReal (exp_rate_limit (c:=2/(π^2*(sqrt (2*j))^2)) (by positivity)) simpa only [ENNReal.ofReal_zero,show ∀(n : ℕ),-(2/(π^2*(sqrt (2*j))^2))*(n:ℝ)= -2*(n:ℝ)/(π^2*(sqrt (2*j))^2) by intro n;ring] using H have h₃:=(ENNReal.Tendsto.const_mul h₁ (a:=((wordPatternSet L L).card:ENNReal)) (Or.inr (by simp))).add h₂ |>.add (recipeNormTail_limit hj) convert ENNReal.Tendsto.const_mul h₃ (a:=2) (Or.inr (by simp)) using 1 <;> first | rfl | simp
theorem gaussian_recipe_event_probability {j A : ℝ} (hj : 0<j) (hj1 : j<1) (hA : 1≤A) (M Nmax : ℕ) : ∃R B W C : ℝ, 1≤R ∧ 0≤B ∧ 0≤W ∧ 0<C ∧ Tendsto (fun n=>(Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)) {g | ¬RecipeMatrixEvent j R A B W C M Nmax (removeDiagonal (goeMatrix (j/n) g))}) atTop (𝓝 0) := by obtain ⟨R,B,W,C,N,hR,hB,hW,hC,hN,hb⟩:=gaussian_recipe_event hj hj1 hA M Nmax refine ⟨R,B,W,C,hR,hB,hW,hC,?_⟩ apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (show Tendsto (fun n=>recipeNormTail j n+ordinaryWordTail j (2*M+2*Nmax+3) n) atTop (𝓝 0) from by simpa using (recipeNormTail_limit hj).add (ordinaryWordTail_limit hj _)) (Filter.Eventually.of_forall (fun _=>bot_le)) filter_upwards [eventually_ge_atTop N] with n hn exact hb n hn
end SKGapCutoff.Recipe
endend
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273import Mathlibimport OAI.Probability.SKGap.Localization.ConditionalHessianLawimport OAI.Probability.SKGap.Localization.ScalarEmpiricalimport OAI.Probability.SKGap.Gaussian.ScalarGaussianReductionAlgebra
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensityopen scoped BigOperators Matrix.Norms.Frobenius ENNReal
lemma tapField_planted_observation {n : ℕ} [NeZero n] (j t σ : ℝ) (y x : Fin n → ℝ) (W : Matrix (Fin n) (Fin n) ℝ) : tapField j (plantedInteraction j W) (fun i=>t+x i) y= empiricalObservation j t σ y-W*ᵥmagnetization y-x := by ext i simp only [tapField,plantedInteraction,Matrix.add_apply,Matrix.smul_apply, smul_eq_mul,vecMulVec_apply,mul_one,add_mul,Finset.sum_add_distrib, ← Finset.mul_sum,empiricalObservation,scalarD,scalarM,integral_empiricalLaw, Fintype.card_fin,scalarBMoment,scalarQMoment_empirical_overlap,onsager, magnetization,Pi.sub_apply,Matrix.mulVec,dotProduct] ring
lemma scalar_density_cancellation {n : ℕ} [NeZero n] {j t σ : ℝ} (hj : 0 ≤ j) (ht : 0 ≤ t) (hσ : 0 < σ) (y : Fin n → ℝ) : rankOneDensity ((j/(n:ℝ))*(magnetization y⬝ᵥmagnetization y)+(t+σ^2)) (j/(n:ℝ)) (magnetization y) (empiricalObservation j t σ y)* exp ((n:ℝ)*j*(1-overlap y)^2/2)= sqrt (scalarS j (scalarEmpirical y t σ)/ (scalarS j (scalarEmpirical y t σ)+j*scalarQMoment (empiricalLaw y)))*scalarIntegrand j t σ y := by let p := scalarEmpirical y t σ let q := scalarQMoment (empiricalLaw y) let s := scalarS j p let S := s+j*q have hn : (n:ℝ) ≠ 0 := by exact_mod_cast NeZero.ne n have hq : 0 ≤ q := (scalarQMoment_bounds _).1 have hs : 0 < s := add_pos_of_pos_of_nonneg (add_pos_of_nonneg_of_pos ht (sq_pos_of_pos hσ)) (mul_nonneg hj hq) have hS : 0 < S := add_pos_of_pos_of_nonneg hs (mul_nonneg hj hq) have hm : magnetization y⬝ᵥmagnetization y=(n:ℝ)*q := by dsimp [q] rw [scalarQMoment_empirical_overlap] simp only [overlap,magnetization,dotProduct,← pow_two] field_simp have hx : (fun i=>y i-scalarD j p)⬝ᵥmagnetization y=(n:ℝ)*scalarA j p := by rw [dotProduct_comm] exact scalarA_empirical_sum j t σ y have hs' : (j/(n:ℝ))*(magnetization y⬝ᵥmagnetization y)+(t+σ^2)=s := by rw [hm]; dsimp [s,scalarS,p,scalarEmpirical,q]; field_simp; ring rw [hs'] have hobs : empiricalObservation j t σ y=(fun i=>y i-scalarD j p)+(j*(1-q)) • magnetization y := rfl rw [hobs] have hc := rankOneDensity_cancellation hn hs hS.ne' (rfl : S=s+j*q) (fun i=>y i-scalarD j p) (magnetization y) hm hx (b := 1-q) have hb : 1-overlap y=1-q := by rw [← scalarQMoment_empirical_overlap] rw [hb,hc] have hd : productNormal (scalarD j p) s y=radialDensity (sqrt s) (fun i=>y i-scalarD j p) := by unfold productNormal rw [show s.toNNReal=NNReal.mk s hs.le from by ext; exact Real.coe_toNNReal _ hs.le] exact gaussian_density_shift _ hs.le y rw [scalarIntegrand,show scalarEmpirical y t σ=p from rfl,hd] simp only [Fintype.card_fin] have he : (n:ℝ)*j*(scalarA j p-s*(1-q))^2/(2*s*S)=(n:ℝ)*scalarPsi j p := by dsimp [S,s,q,p,scalarPsi,scalarEmpirical] ring rw [he] ringend SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianCoordinates
namespace OAI
section
noncomputable sectionopen MeasureTheory ProbabilityTheory Matrixopen scoped BigOperators ENNRealnamespace SKGap.GaussianRegression
theorem law_eq_of_mean_covariance {Ω Ω' ι : Type*} [MeasurableSpace Ω] [MeasurableSpace Ω'] [Fintype ι] [DecidableEq ι] {P : Measure Ω} {P' : Measure Ω'} {X : Ω → ι → ℝ} {Y : Ω' → ι → ℝ} (hX : HasGaussianLaw X P) (hY : HasGaussianLaw Y P') (hm : ∀ i, (∫ w, X w i ∂P) = ∫ w, Y w i ∂P') (hc : ∀ i k, cov[fun w => X w i, fun w => X w k; P] = cov[fun w => Y w i, fun w => Y w k; P']) : P.map X = P'.map Y := by classical have := hX.isProbabilityMeasure have := hY.isProbabilityMeasure apply Measure.ext_of_charFunDual ext L rw [hX.charFunDual_map_eq,hY.charFunDual_map_eq] let c : ι → ℝ := fun i => L (fun k => if i=k then 1 else 0) have hL (x : ι → ℝ) : L x = ∑ i, x i * c i := by simpa only [c, smul_eq_mul, ContinuousLinearMap.coe_coe] using L.toLinearMap.pi_apply_eq_sum_univ x have hLX : L ∘ X = fun w => ∑ i, X w i*c i := funext (fun w => hL (X w)) have hLY : L ∘ Y = fun w => ∑ i, Y w i*c i := funext (fun w => hL (Y w)) have hiX (i : ι) := (hX.eval i).memLp_two have hiY (i : ι) := (hY.eval i).memLp_two have hem : (∫ w, (L ∘ X) w ∂P) = ∫ w, (L ∘ Y) w ∂P' := by rw [hLX,hLY] rw [integral_finsetSum _ (fun i _ => ((hX.eval i).integrable.mul_const _)), integral_finsetSum _ (fun i _ => ((hY.eval i).integrable.mul_const _))] simp only [integral_mul_const,hm] have hev : Var[L ∘ X; P] = Var[L ∘ Y; P'] := by rw [← covariance_self (hX.map L).aemeasurable, ← covariance_self (hY.map L).aemeasurable] rw [hLX,hLY] rw [covariance_fun_sum_fun_sum (fun i => (hiX i).mul_const _) (fun i => (hiX i).mul_const _), covariance_fun_sum_fun_sum (fun i => (hiY i).mul_const _) (fun i => (hiY i).mul_const _)] simp only [covariance_mul_const_left,covariance_mul_const_right,hc] rw [hev,hem]
def matrixCLM {ι κ : Type*} [Fintype κ] (A : Matrix ι κ ℝ) : (κ → ℝ) →L[ℝ] (ι → ℝ) := A.mulVecLin.toContinuousLinearMap
@[simp] lemma matrixCLM_apply {ι κ : Type*} [Fintype κ] (A : Matrix ι κ ℝ) (x : κ → ℝ) : matrixCLM A x = A *ᵥ x := rfl
theorem residual_independent {Ω ι κ : Type*} [MeasurableSpace Ω] [Fintype ι] [Fintype κ] {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ} (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) (hcov : ∀ i k, cov[fun w => X w i, fun w => Y w k; P] = ∑ l, K i l * cov[fun w => Y w l,fun w => Y w k; P]) : IndepFun (fun w => X w-K*ᵥ Y w) Y P := by have := hXY.isProbabilityMeasure have hR : HasGaussianLaw (fun w => (X w-K*ᵥ Y w,Y w)) P := by exact hXY.map_fun (((ContinuousLinearMap.fst ℝ (ι → ℝ) (κ → ℝ))- (matrixCLM K).comp (ContinuousLinearMap.snd ℝ (ι → ℝ) (κ → ℝ))).prod (ContinuousLinearMap.snd ℝ (ι → ℝ) (κ → ℝ))) apply hR.indepFun_of_covariance_eval intro i k change cov[fun w => X w i-∑ l, K i l*Y w l,fun w => Y w k; P]=0 have hK : MemLp (fun w => ∑ l, K i l*Y w l) 2 P := ((hXY.snd.map (matrixCLM K)).eval i).memLp_two rw [covariance_fun_sub_left (hXY.fst.eval i).memLp_two hK (hXY.snd.eval k).memLp_two] rw [covariance_fun_sum_left (fun l => (hXY.snd.eval l).memLp_two.const_mul _) (hXY.snd.eval k).memLp_two] simp only [covariance_const_mul_left,hcov,sub_self]
end SKGap.GaussianRegressionendend
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Matrixopen scoped BigOperators ENNReal
lemma coordinate_hasLaw {κ : Type*} [Fintype κ] (i : κ) : HasLaw (fun g : κ → ℝ => g i) (gaussianReal 0 1) (gaussianCoordinates κ) := ⟨(measurable_pi_apply i).aemeasurable, (measurePreserving_eval (fun _ : κ => gaussianReal 0 1) i).map_eq⟩
lemma coordinates_gaussian {κ : Type*} [Fintype κ] : HasGaussianLaw (fun g : κ → ℝ => g) (gaussianCoordinates κ) := (iIndepFun_pi (fun _ : κ => aemeasurable_id)).hasGaussianLaw (fun i => (coordinate_hasLaw i).hasGaussianLaw)
lemma coordinate_covariance {κ : Type*} [Fintype κ] [DecidableEq κ] (i k : κ) : cov[fun g : κ → ℝ => g i,fun g : κ → ℝ => g k;gaussianCoordinates κ] = if i=k then 1 else 0 := by by_cases h : i=k · subst k rw [ite_eq_left rfl,covariance_self (measurable_pi_apply i).aemeasurable, (coordinate_hasLaw i).variance_eq] simp · rw [ite_eq_right h] exact ((iIndepFun_pi (fun _ : κ => aemeasurable_id)).indepFun h).covariance_eq_zero (coordinate_hasLaw i).hasGaussianLaw.memLp_two (coordinate_hasLaw k).hasGaussianLaw.memLp_two
lemma linear_gaussian_mean {κ : Type*} [Fintype κ] (a : κ → ℝ) : (∫ g, ∑ i, a i*g i ∂gaussianCoordinates κ) = 0 := by rw [integral_finsetSum _ (fun i _ => (coordinate_hasLaw i).hasGaussianLaw.integrable.const_mul _)] simp [integral_const_mul,(coordinate_hasLaw _).integral_eq]
lemma linear_gaussian_covariance {κ : Type*} [Fintype κ] [DecidableEq κ] (a b : κ → ℝ) : cov[fun g => ∑ i, a i*g i,fun g => ∑ i, b i*g i;gaussianCoordinates κ] = ∑ i, a i*b i := by rw [covariance_fun_sum_fun_sum (fun i => (coordinate_hasLaw i).hasGaussianLaw.memLp_two.const_mul _) (fun i => (coordinate_hasLaw i).hasGaussianLaw.memLp_two.const_mul _)] simp only [covariance_const_mul_left,covariance_const_mul_right,coordinate_covariance] simp [mul_comm]
lemma matrix_sample_gaussian {ι κ : Type*} [Fintype ι] [Fintype κ] (A : Matrix ι κ ℝ) : HasGaussianLaw (fun g => A*ᵥg) (gaussianCoordinates κ) := coordinates_gaussian.map_fun (GaussianRegression.matrixCLM A)
lemma matrix_sample_covariance {ι κ : Type*} [Fintype κ] [DecidableEq κ] (A : Matrix ι κ ℝ) (i k : ι) : cov[fun g => (A*ᵥg) i,fun g => (A*ᵥg) k;gaussianCoordinates κ] = (A*Aᵀ) i k := linear_gaussian_covariance (A i) (A k)
end SKGapendend
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import Mathlibimport OAI.Probability.SKGap.Localization.Conjugation
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Matrix MeasureTheory ProbabilityTheoryopen scoped BigOperators
noncomputable def gaussianSignEquiv {κ : Type*} (q : κ → ℝ) (hq : ∀ b, q b^2=1) : (κ → ℝ) ≃ᵐ (κ → ℝ) where toFun g b := q b*g b invFun g b := q b*g b left_inv g := by ext b; dsimp; rw [← mul_assoc,← sq,hq b,one_mul] right_inv g := by ext b; dsimp; rw [← mul_assoc,← sq,hq b,one_mul] measurable_toFun := by change Measurable (fun g : κ → ℝ => fun b => q b*g b); fun_prop measurable_invFun := by change Measurable (fun g : κ → ℝ => fun b => q b*g b); fun_prop
lemma gaussianSign_map {κ : Type*} [Fintype κ] (q : κ → ℝ) (hq : ∀ b, q b^2=1) : (Measure.pi (fun _ : κ => gaussianReal 0 1)).map (gaussianSignEquiv q hq) = Measure.pi (fun _ : κ => gaussianReal 0 1) := by have he (b : κ) : (gaussianReal 0 1).map (fun x => q b*x) = gaussianReal 0 1 := by rcases sq_eq_one_iff.mp (hq b) with h|h · simp [h] · simpa only [h,neg_one_mul,neg_zero] using (gaussianReal_map_neg (μ := (0:ℝ)) (v := 1)) change (Measure.pi (fun _ : κ => gaussianReal 0 1)).map (fun g b => q b*g b) = _ rw [Measure.pi_map_pi (fun _ => by fun_prop)] simp only [he]
lemma gaussianSign_integral {κ : Type*} [Fintype κ] (q : κ → ℝ) (hq : ∀ b, q b^2=1) (F : (κ → ℝ) → ℝ) : (∫ g, F (gaussianSignEquiv q hq g) ∂Measure.pi (fun _ : κ => gaussianReal 0 1)) = ∫ g, F g ∂Measure.pi (fun _ : κ => gaussianReal 0 1) := by rw [← integral_map_equiv,gaussianSign_map]
variable {ι : Type*} [Fintype ι] [DecidableEq ι]def goeSign (s : ι → ℝ) : MatrixCoordinates ι → ℝ := Sum.elim (fun p => s p.1*s p.2) (fun _ => 1)
omit [Fintype ι] [DecidableEq ι] inlemma goeSign_sq (s : ι → ℝ) (hs : ∀ i, s i^2=1) (b : MatrixCoordinates ι) : goeSign s b^2=1 := by rcases b with ⟨i,k⟩|i · simp only [goeSign,Sum.elim_inl,mul_pow,hs,one_mul] · norm_num [goeSign]
omit [Fintype ι] [DecidableEq ι] inlemma goeMatrix_sign (r : ℝ) (s : ι → ℝ) (hs : ∀ i, s i^2=1) (g : MatrixCoordinates ι → ℝ) : goeMatrix r (gaussianSignEquiv (goeSign s) (goeSign_sq s hs) g) = signConjugate s (goeMatrix r g) := by ext i k dsimp [goeMatrix,gaussianSignEquiv,goeSign,signConjugate] ring
lemma goe_equivariant_offdiag (r : ℝ) (F : Matrix ι ι ℝ → Matrix ι ι ℝ) (hF : ∀ (s : ι → ℝ), (∀ i, s i^2=1) → ∀ M, F (signConjugate s M)=signConjugate s (F M)) (i k : ι) (hik : i ≠ k) : (∫ g, F (goeMatrix r g) i k ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))=0 := by let s : ι → ℝ := fun b => if b=i then -1 else 1 have hs : ∀ b, s b^2=1 := by intro b; dsimp [s]; split <;> norm_num have hi := gaussianSign_integral (goeSign s) (goeSign_sq s hs) (fun g => F (goeMatrix r g) i k) have hsi : s i = -1 := by simp [s] have hsk : s k = 1 := by simp [s,Ne.symm hik] have heq : (fun g => F (goeMatrix r (gaussianSignEquiv (goeSign s) (goeSign_sq s hs) g)) i k) = (fun g => -F (goeMatrix r g) i k) := by funext g rw [goeMatrix_sign r s hs g,hF s hs] change s i*s k*F (goeMatrix r g) i k = _ rw [hsi,hsk,neg_one_mul,neg_mul,one_mul] rw [heq,integral_neg] at hi linarithend SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianRegression
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Realopen scoped BigOperators
lemma gaussian_square_exp_integral : (∫ x : ℝ,exp (x^2/4) ∂gaussianReal 0 1) ≤ 2 := by rw [gaussianReal_of_var_ne_zero 0 (one_ne_zero), integral_withDensity_eq_integral_toReal_smul (measurable_gaussianPDF 0 1) (ae_of_all _ (fun y=>by simp [gaussianPDF]))] simp only [gaussianPDF,ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _),smul_eq_mul] have he : (fun x : ℝ=>gaussianPDFReal 0 1 x*exp (x^2/4))= (fun x : ℝ=>(1/sqrt (2*Real.pi))*exp (-(1/4:ℝ)*x^2)) := by funext x simp only [gaussianPDFReal,NNReal.coe_one,sub_zero,mul_one] rw [mul_assoc,← exp_add] congr 2 <;> ring rw [he,integral_const_mul,integral_gaussian] have hp := Real.pi_pos have h1 := sq_sqrt (show 0 ≤ 2*Real.pi by positivity) have h2 := sq_sqrt (show 0 ≤ Real.pi/(1/4:ℝ) by positivity) have h3 := sqrt_nonneg (2*Real.pi) have h4 := sqrt_nonneg (Real.pi/(1/4:ℝ)) rw [one_div,mul_comm,← div_eq_mul_inv] apply (div_le_iff₀ (sqrt_pos.mpr (by positivity))).mpr nlinarith
lemma gaussian_square_exp_integrable : Integrable (fun x : ℝ=>exp (x^2/4)) (gaussianReal 0 1) := by rw [gaussianReal_of_var_ne_zero 0 (one_ne_zero),integrable_withDensity_iff (measurable_gaussianPDF 0 1) (ae_of_all _ (fun y=>by simp [gaussianPDF]))] simp only [gaussianPDF,ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _)] have hi := (integrable_exp_neg_mul_sq (show (0:ℝ) < 1/4 by norm_num)).const_mul (1/sqrt (2*Real.pi)) have he : (fun g : ℝ=>exp (g^2/4)*gaussianPDFReal 0 1 g)= (fun g : ℝ=>(1/sqrt (2*Real.pi))*exp (-(1/4:ℝ)*g^2)) := by funext g simp only [gaussianPDFReal,NNReal.coe_one,sub_zero,mul_one] rw [mul_left_comm,← exp_add] congr 2 <;> ring rw [he] exact hi
lemma product_gaussian_square_exp_integral {ι : Type*} [Fintype ι] : (∫ g : ι→ℝ,exp ((∑ i,g i^2)/4) ∂Measure.pi (fun _ : ι=>gaussianReal 0 1)) ≤ exp ((Fintype.card ι:ℝ)*log 2) := by have he (g : ι→ℝ) : exp ((∑ i,g i^2)/4)=∏ i,exp (g i^2/4) := by rw [← exp_sum,Finset.sum_div] simp_rw [he] rw [integral_fintype_prod_eq_prod (f:=fun _ : ι=>fun x : ℝ=>exp (x^2/4))] calc _ ≤ ∏ _i : ι,(2:ℝ) := Finset.prod_le_prod₀ (fun i _=>integral_nonneg (fun x=>(exp_pos _).le)) (fun i _=>gaussian_square_exp_integral) _ = _ := by rw [Finset.prod_const,Finset.card_univ,exp_nat_mul,exp_log (by norm_num : (0:ℝ)<2)]
lemma product_gaussian_square_exp_integrable {ι : Type*} [Fintype ι] : Integrable (fun g : ι→ℝ=>exp ((∑ i,g i^2)/4)) (Measure.pi (fun _ : ι=>gaussianReal 0 1)) := by have hi := Integrable.fintype_prod (fun _ : ι=>gaussian_square_exp_integrable) convert hi using 1 ext g rw [← exp_sum,Finset.sum_div]
lemma product_gaussian_square_tail {ι : Type*} [Fintype ι] (t : ℝ) : (Measure.pi (fun _ : ι=>gaussianReal 0 1)).real {g | t < ∑ i,g i^2} ≤ exp (-t/4+(Fintype.card ι:ℝ)*log 2) := by have hm := mul_meas_ge_le_integral_of_nonneg (ae_of_all (Measure.pi (fun _ : ι=>gaussianReal 0 1)) (fun g=>(exp_pos ((∑ i,g i^2)/4)).le)) product_gaussian_square_exp_integrable (exp (t/4)) have hs : {g : ι→ℝ| t < ∑ i,g i^2} ⊆ {g | exp (t/4) ≤ exp ((∑ i,g i^2)/4)} := by intro g hg exact exp_le_exp.mpr (by linarith only [show t < ∑ i,g i^2 from hg]) have hb := (mul_le_mul_of_nonneg_left (measureReal_mono hs) (exp_pos (t/4)).le).trans (hm.trans product_gaussian_square_exp_integral) rw [show -t/4+(Fintype.card ι:ℝ)*log 2=(Fintype.card ι:ℝ)*log 2-t/4 by ring,exp_sub] apply (le_div_iff₀ (exp_pos _)).mpr simpa only [mul_comm] using hbend SKGapendend
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Realopen scoped BigOperators NNRealvariable {κ : Type*} [Fintype κ]
lemma gaussian_scaled_coordinates_hasLaw {r : ℝ} (hr : 0 ≤ r) : HasLaw (fun g : κ→ℝ=>fun k=>sqrt r*g k) (Measure.pi (fun _ : κ=>gaussianReal 0 (Real.toNNReal r))) (gaussianCoordinates κ) := by have hl (k : κ) : HasLaw (fun g : κ→ℝ=>sqrt r*g k) (gaussianReal 0 (Real.toNNReal r)) (gaussianCoordinates κ) := by have h := gaussianReal_const_mul (coordinate_hasLaw (κ:=κ) k) (sqrt r) have hv : (⟨(sqrt r)^2,sq_nonneg _⟩:ℝ≥0)*1=Real.toNNReal r := by apply NNReal.eq change (sqrt r)^2*1=↑(Real.toNNReal r) rw [mul_one,sq_sqrt hr,Real.coe_toNNReal _ hr] rw [mul_zero] at h convert h using 1 exact congrArg (gaussianReal 0) hv.symm exact iIndepFun.hasLaw_pi hl ((iIndepFun_pi (fun _ : κ=>aemeasurable_id)).comp (fun _=>fun x : ℝ=>sqrt r*x) (fun _=>by fun_prop))
lemma scaled_gaussian_square_tail {r : ℝ} (hr : 0 < r) (t : ℝ) : (Measure.pi (fun _ : κ=>gaussianReal 0 (Real.toNNReal r))).real {g | t < ∑ i,g i^2} ≤ exp (-t/(4*r)+(Fintype.card κ:ℝ)*log 2) := by have hm : MeasurableSet {g : κ→ℝ | t < ∑ i,g i^2} := by measurability rw [← (gaussian_scaled_coordinates_hasLaw (κ:=κ) hr.le).measureReal_eq hm] have he : {g : κ→ℝ | t < ∑ i,(sqrt r*g i)^2}={g | t/r < ∑ i,g i^2} := by ext g simp only [Set.mem_ofPred_eq,mul_pow,sq_sqrt hr.le,← Finset.mul_sum] rw [div_lt_iff₀ hr,mul_comm] rw [he] simpa only [gaussianCoordinates,neg_div,div_div,mul_comm r (4:ℝ)] using product_gaussian_square_tail (ι:=κ) (t/r)end SKGapendend
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Realopen scoped BigOperators
lemma gaussian_real_square_tail {r : ℝ} (hr : 0 < r) (t : ℝ) : (gaussianReal 0 (Real.toNNReal r)).real {x : ℝ | t < x^2} ≤ exp (-t/(4*r)+log 2) := by have h : HasLaw (fun v : Unit→ℝ=>v ()) (gaussianReal 0 (Real.toNNReal r)) (Measure.pi (fun _ : Unit=>gaussianReal 0 (Real.toNNReal r))) := ⟨(measurable_pi_apply ()).aemeasurable,(measurePreserving_eval (fun _ : Unit=>gaussianReal 0 (Real.toNNReal r)) ()).map_eq⟩ rw [← h.measureReal_eq (by measurability : MeasurableSet {x : ℝ | t < x^2})] simpa using scaled_gaussian_square_tail (κ:=Unit) hr t
lemma gaussian_real_abs_tail {r : ℝ} (hr : 0 < r) {d : ℝ} (hd : 0 ≤ d) : (gaussianReal 0 (Real.toNNReal r)).real {x : ℝ | d < |x|} ≤ 2*exp (-d^2/(4*r)) := by have he : {x : ℝ | d < |x|}={x | d^2 < x^2} := by ext x simpa only [Set.mem_ofPred_eq,sq_abs] using (sq_lt_sq₀ hd (abs_nonneg x)).symm rw [he] apply (gaussian_real_square_tail hr (d^2)).trans_eq rw [exp_add,exp_log (by norm_num : (0:ℝ) < 2),mul_comm]end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179import Mathlibimport OAI.Probability.SKGap.Localization.PartitionLogLipschitz
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Real Filter Setopen scoped BigOperators NNReal Topology
lemma exists_gaussian_tail_quantile {p : ℝ} (hp : 0 < p) : ∃ c : ℝ, 0 < c ∧ exp (-2*c^2/π^2) < p := by let c : ℝ := sqrt (π^2/2*(|log p|+1)) have hc : 0 < c := sqrt_pos.mpr (mul_pos (div_pos (sq_pos_of_pos pi_pos) (by norm_num)) (by positivity)) have hc2 : c^2=π^2/2*(|log p|+1) := sq_sqrt (by positivity) refine ⟨c,hc,?_⟩ have he : -2*c^2/π^2= -(|log p|+1) := by rw [hc2];field_simp rw [he] apply lt_of_lt_of_eq ?_ (exp_log hp) apply exp_lt_exp.mpr linarith only [neg_abs_le (log p)]
lemma eventually_sqrt_cost_le_linear {δ c : ℝ} (hδ : 0 < δ) (hc : 0 ≤ c) : ∀ᶠ n : ℕ in atTop, log 2+c*sqrt (n:ℝ) ≤ δ*(n:ℝ)/2 := by have hl : 0 ≤ log (2:ℝ) := log_nonneg (by norm_num) have hlarge : ∀ᶠ n : ℕ in atTop, (4*c/δ)^2+4*log 2/δ ≤ (n:ℝ) := tendsto_natCast_atTop_atTop.eventually (eventually_ge_atTop _) filter_upwards [hlarge] with n hn have hn0 : (0:ℝ) ≤ n := by positivity have hs : 4*c/δ ≤ sqrt (n:ℝ) := by apply (sq_le_sq₀ (by positivity) (sqrt_nonneg _)).mp rw [sq_sqrt hn0] linarith only [hn,div_nonneg (mul_nonneg (by norm_num : (0:ℝ) ≤ 4) hl) hδ.le] have hs' := (div_le_iff₀ hδ).mp hs have he := sq_sqrt hn0 have hm := mul_le_mul_of_nonneg_right hs' (sqrt_nonneg (n:ℝ)) have hn' : 4*log 2/δ ≤ (n:ℝ) := by linarith only [hn,sq_nonneg (4*c/δ)] have hl' := (div_le_iff₀ hδ).mp hn' have hm' : 4*c*sqrt (n:ℝ) ≤ δ*(n:ℝ) := hm.trans_eq (by calc sqrt (n:ℝ)*δ*sqrt (n:ℝ) = δ*(sqrt (n:ℝ))^2 := by ring _ = δ*(n:ℝ) := by rw [he]) linarith only [hm',hl']
end SKGapendend
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Real Filter Setopen scoped BigOperators NNReal Topology
lemma gaussianSpinPartition_log_mean_lower {j c : ℝ} (hj0 : 0 ≤ j) (hj : j < 1) (hc : 0 < c) (hpc : exp (-2*c^2/π^2) < 1/(4*quadraticGaussianBound j)) {n : ℕ} (hn : 0 < n) {r : ℝ} (hr : 0 ≤ r) (hnr : (n:ℝ)*r ≤ j) : log (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))-log 2-c*sqrt (n:ℝ) ≤ ∫ g,log (gaussianSpinPartition n r g) ∂gaussianCoordinates (Edge n) := by have hM := gaussianSpinPartition_mean_pos (n:=n) hr have hsub : {g | (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))/2 ≤ gaussianSpinPartition n r g} ⊆ {g | log (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))-log 2 ≤ log (gaussianSpinPartition n r g)} := by intro g hg simp only [mem_ofPred_eq] at hg ⊢ have h := log_le_log (div_pos hM (by norm_num)) hg rwa [log_div hM.ne' (by norm_num : (2:ℝ) ≠ 0)] at h exact gaussian_log_anchor (f:=fun g=>log (gaussianSpinPartition n r g)) (gaussianSpinPartition_log_lipschitz hr (hnr.trans hj.le)) (by exact_mod_cast sqrt_pos.mpr (show (0:ℝ) < n by exact_mod_cast hn)) hc hpc ((gaussianSpinPartition_positive_probability hj0 hj hr hnr).trans (measureReal_mono hsub (measure_ne_top _ _)))
lemma gaussianSpinPartition_lower_tail_bound {j c δ : ℝ} (hj0 : 0 ≤ j) (hj : j < 1) (hc : 0 < c) (hpc : exp (-2*c^2/π^2) < 1/(4*quadraticGaussianBound j)) (hδ : 0 < δ) {n : ℕ} (hn : 0 < n) {r : ℝ} (hr : 0 ≤ r) (hnr : (n:ℝ)*r ≤ j) (hbudget : log 2+c*sqrt (n:ℝ) ≤ δ*(n:ℝ)/2) : (gaussianCoordinates (Edge n)).real {g | gaussianSpinPartition n r g/(∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n)) < exp (-δ*(n:ℝ))} ≤ exp (-δ^2*(n:ℝ)/(2*π^2)) := by have hnp : (0:ℝ) < n := by exact_mod_cast hn have hM := gaussianSpinPartition_mean_pos (n:=n) hr have ha := gaussianSpinPartition_log_mean_lower hj0 hj hc hpc hn hr hnr have hsub : {g | gaussianSpinPartition n r g/(∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n)) < exp (-δ*(n:ℝ))} ⊆ {g | log (gaussianSpinPartition n r g)-(∫ g,log (gaussianSpinPartition n r g) ∂gaussianCoordinates (Edge n)) ≤ -(δ*(n:ℝ)/2)} := by intro g hg simp only [mem_ofPred_eq] at hg have hg' := (div_lt_iff₀ hM).mp hg have hlog := log_lt_log (gaussianSpinPartition_pos n r g) hg' rw [log_mul (exp_pos _).ne' hM.ne',log_exp] at hlog simp only [mem_ofPred_eq] linarith only [hlog,ha,hbudget] have htail := gaussianProduct_lower_tail_lipschitz (f:=fun g=>log (gaussianSpinPartition n r g)) (gaussianSpinPartition_log_lipschitz hr (hnr.trans hj.le)) (show (0:ℝ≥0) < ⟨sqrt (n:ℝ),sqrt_nonneg _⟩ from sqrt_pos.mpr hnp) (show 0 ≤ δ*(n:ℝ)/2 by positivity) have he : -2*(δ*(n:ℝ)/2)^2/(π^2*(sqrt (n:ℝ))^2)= -δ^2*(n:ℝ)/(2*π^2) := by rw [sq_sqrt hnp.le] field_simp change _ ≤ exp (-2*(δ*(n:ℝ)/2)^2/(π^2*(sqrt (n:���))^2)) at htail rw [he] at htail exact (measureReal_mono hsub (measure_ne_top _ _)).trans htail
lemma gaussianSpinPartition_lower_tail_tendsto {j : ℝ} (hj0 : 0 ≤ j) (hj : j < 1) {δ : ℝ} (hδ : 0 < δ) : Tendsto (fun n : ℕ=>(gaussianCoordinates (Edge n)).real {g | gaussianSpinPartition n (j/(n:ℝ)) g/ (∫ g,gaussianSpinPartition n (j/(n:ℝ)) g ∂gaussianCoordinates (Edge n)) < exp (-δ*(n:ℝ))}) atTop (𝓝 0) := by obtain ⟨c,hc,hpc⟩ := exists_gaussian_tail_quantile (show 0 < 1/(4*quadraticGaussianBound j) by have hB := quadraticGaussianBound_ge_one hj0 hj; positivity) have hb : ∀ᶠ n : ℕ in atTop, (gaussianCoordinates (Edge n)).real {g | gaussianSpinPartition n (j/(n:ℝ)) g/ (∫ g,gaussianSpinPartition n (j/(n:ℝ)) g ∂gaussianCoordinates (Edge n)) < exp (-δ*(n:ℝ))} ≤ exp (-δ^2*(n:ℝ)/(2*π^2)) := by filter_upwards [eventually_gt_atTop 0,eventually_sqrt_cost_le_linear hδ hc.le] with n hn hbudget have hnp : (0:ℝ) < n := by exact_mod_cast hn apply gaussianSpinPartition_lower_tail_bound hj0 hj hc hpc hδ hn (div_nonneg hj0 hnp.le) _ hbudget rw [mul_div_cancel₀ _ hnp.ne'] have ht : Tendsto (fun n : ℕ=>exp (-δ^2*(n:ℝ)/(2*π^2))) atTop (𝓝 0) := by have hpos : 0 < δ^2/(2*π^2) := by positivity have hh : Tendsto (fun n : ℕ=>(δ^2/(2*π^2))*(n:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop.const_mul_atTop hpos convert tendsto_exp_neg_atTop_nhds_zero.comp hh using 1; ext n; congr 1; ring exact squeeze_zero' (Eventually.of_forall (fun _=>measureReal_nonneg)) hb htend SKGapendend
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Real Filter Setopen scoped BigOperators NNReal Topology
lemma gaussian_disorder_hasLaw (β : ℝ) (n : ℕ) : HasLaw (fun g : Disorder n=>fun e=>sqrt (β^2/(n:ℝ))*g e) (disorderLaw β n) (gaussianCoordinates (Edge n)) := by have hr : 0 ≤ β^2/(n:ℝ) := by positivity have hl (e : Edge n) : HasLaw (fun g : Disorder n=>sqrt (β^2/(n:ℝ))*g e) (gaussianReal 0 (Real.toNNReal (β^2/(n:ℝ)))) (gaussianCoordinates (Edge n)) := by have h := gaussianReal_const_mul (coordinate_hasLaw (κ:=Edge n) e) (sqrt (β^2/(n:ℝ))) have hv : (⟨(sqrt (β^2/(n:ℝ)))^2,sq_nonneg _⟩:ℝ≥0)*1=Real.toNNReal (β^2/(n:ℝ)) := by apply NNReal.eq change (sqrt (β^2/(n:ℝ)))^2*1=↑(Real.toNNReal (β^2/(n:ℝ))) rw [mul_one,sq_sqrt hr,Real.coe_toNNReal _ hr] rw [mul_zero] at h convert h using 1 exact congrArg (gaussianReal 0) hv.symm exact iIndepFun.hasLaw_pi hl ((iIndepFun_pi (fun _ : Edge n=>aemeasurable_id)).comp (fun _=>fun x : ℝ=>sqrt (β^2/(n:ℝ))*x) (fun _=>by fun_prop))
lemma partition_zero_measurable (n : ℕ) : Measurable (fun g : Disorder n=>partition g 0) := by have he : (fun g : Disorder n=>partition g 0)=gaussianSpinPartition n 1 := by ext g rw [gaussianSpinPartition_eq_partition] simp only [sqrt_one,one_mul] rw [he] exact gaussianSpinPartition_measurable n 1
lemma disorder_partition_mean (β : ℝ) (n : ℕ) : (∫ g,partition g 0 ∂disorderLaw β n)= ∫ g,gaussianSpinPartition n (β^2/(n:ℝ)) g ∂gaussianCoordinates (Edge n) := by have h := (gaussian_disorder_hasLaw β n).integral_comp (partition_zero_measurable n).aestronglyMeasurable simpa only [Function.comp_def,gaussianSpinPartition_eq_partition] using h.symm
theorem disorder_partition_lower_tail {β : ℝ} (hβ : 0 < β) (hβ1 : β < 1) {δ : ℝ} (hδ : 0 < δ) : Tendsto (fun n : ℕ=>(disorderLaw β n).real {g | partition g 0/(∫ g,partition g 0 ∂disorderLaw β n) < exp (-δ*(n:ℝ))}) atTop (𝓝 0) := by have ht := gaussianSpinPartition_lower_tail_tendsto (sq_nonneg β) (show β^2 < 1 by nlinarith) hδ apply ht.congr intro n rw [← (gaussian_disorder_hasLaw β n).measureReal_eq (measurableSet_lt ((partition_zero_measurable n).div_const _) measurable_const)] simp only [disorder_partition_mean,gaussianSpinPartition_eq_partition]end SKGapendend
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianRegressionimport OAI.Probability.SKGap.Gaussian.ProductGaussianDensity
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Realopen scoped BigOperators ENNReal
lemma gaussianPDFReal_standard_tilt (a x : ℝ) : gaussianPDFReal a 1 x=gaussianPDFReal 0 1 x*exp (a*x-a^2/2) := by simp only [gaussianPDFReal,NNReal.coe_one,mul_one,sub_zero] have he : -(x-a)^2/2= -x^2/2+(a*x-a^2/2) := by ring rw [he,exp_add] ring
lemma gaussianCoordinates_tilt {κ : Type*} [Fintype κ] (a : κ→ℝ) : (gaussianCoordinates κ).withDensity (fun g=>ENNReal.ofReal (exp ((∑ i,a i*g i)-(∑ i,a i^2)/2))) = Measure.pi (fun i=>gaussianReal (a i) 1) := by have hp (g : κ→ℝ) : (∏ i,gaussianPDFReal (a i) 1 (g i))= (∏ i,gaussianPDFReal 0 1 (g i))*exp ((∑ i,a i*g i)-(∑ i,a i^2)/2) := by calc _ = ∏ i, (gaussianPDFReal 0 1 (g i)*exp (a i*g i-a i^2/2)) := Finset.prod_congr rfl (fun i _=>gaussianPDFReal_standard_tilt _ _) _ = _ := by rw [Finset.prod_mul_distrib,← exp_sum] congr 2 rw [Finset.sum_sub_distrib,Finset.sum_div] change (Measure.pi (fun _ : κ=>gaussianReal 0 1)).withDensity _=_ rw [GaussianDensity.pi_gaussian_density (fun _ : κ=>0) (fun _=>1) (fun _=>one_ne_zero), GaussianDensity.pi_gaussian_density a (fun _=>1) (fun _=>one_ne_zero)] rw [← withDensity_mul _ (GaussianDensity.measurable_productPDF _ _) (by fun_prop)] congr 1 ext g simp only [Pi.mul_apply,hp] exact (ENNReal.ofReal_mul (Finset.prod_nonneg (fun i _=>gaussianPDFReal_nonneg 0 1 (g i)))).symm
lemma gaussianCoordinates_shift_hasLaw {κ : Type*} [Fintype κ] (a : κ→ℝ) : HasLaw (fun g : κ→ℝ => fun i=>g i+a i) (Measure.pi (fun i=>gaussianReal (a i) 1)) (gaussianCoordinates κ) := by have hl (i : κ) : HasLaw (fun g : κ→ℝ=>g i+a i) (gaussianReal (a i) 1) (gaussianCoordinates κ) := by simpa only [zero_add] using gaussianReal_add_const (coordinate_hasLaw i) (a i) exact iIndepFun.hasLaw_pi hl ((iIndepFun_pi (fun _ : κ=>aemeasurable_id)).comp (fun i=>fun x : ℝ=>x+a i) (fun _=>by fun_prop))
lemma gaussian_tilt_lintegral {κ : Type*} [Fintype κ] (a : κ→ℝ) (f : (κ→ℝ)→ℝ≥0∞) (hf : Measurable f) : (∫⁻ g,ENNReal.ofReal (exp ((∑ i,a i*g i)-(∑ i,a i^2)/2))*f g ∂gaussianCoordinates κ)= ∫⁻ g,f (fun i=>g i+a i) ∂gaussianCoordinates κ := by have he := lintegral_withDensity_eq_lintegral_mul (gaussianCoordinates κ) (f:=fun g=>ENNReal.ofReal (exp ((∑ i,a i*g i)-(∑ i,a i^2)/2))) (by fun_prop) hf simp only [Pi.mul_apply] at he rw [← he,gaussianCoordinates_tilt] exact (gaussianCoordinates_shift_hasLaw a).lintegral_comp hf.aemeasurable |>.symmend SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171import Mathlibimport OAI.Probability.SKGap.Localization.EmpiricalLawimport OAI.Probability.SKGap.Matrix.NormalLogConst
namespace OAI
sectionnoncomputable sectionopen MeasureTheory ProbabilityTheory InformationTheory Real Set Filteropen scoped NNReal ENNReal Topologynoncomputable sectionopen Real Setnoncomputable sectionopen MeasureTheory ProbabilityTheory Real Set Filteropen scoped Topology NNReal ENNReal BoundedContinuousFunctionopen MeasureTheory ProbabilityTheory Filter Set Topology Realopen scoped NNReal ENNReal BoundedContinuousFunctionnoncomputable sectionopen Set Filter Topologynoncomputable sectionopen MeasureTheory ProbabilityTheory Filter Set Topology Realopen scoped NNReal ENNReal BoundedContinuousFunctionnoncomputable sectionopen MeasureTheory ProbabilityTheory Filter Set Topology Realopen scoped NNReal ENNReal BoundedContinuousFunctionnamespace SKGap
variable {ι : Type*} [Fintype ι] [Nonempty ι]
end SKGap
namespace SKGapvariable {ι : Type*} [Fintype ι] [Nonempty ι]
omit [Nonempty ι] inlemma gaussian_tilt_mass (f : ℝ →ᵇ ℝ) (d : ℝ) {s : ℝ} (hs : 0 < s) (r : ℝ) : (∫ y : ι → ℝ, exp ((Fintype.card ι : ℝ)*r - (Fintype.card ι : ℝ)*log (∫ x, exp (f x) ∂gaussianReal d s.toNNReal)) * (exp (∑ i, f (y i))*productNormal d s y)) = exp ((Fintype.card ι : ℝ)*r) := by rw [integral_const_mul, product_tiltedNormal_integral f d hs, ← exp_add] congr 1 ring
theorem gaussian_covered_laplace {X : Type*} (C : Finset X) (f : X → ℝ →ᵇ ℝ) (d₀ s₀ : X → ℝ) (hs₀ : ∀ x ∈ C, 0 < s₀ x) (d s ψ : (ι → ℝ) → ℝ) (R r : ℝ) {E : Set (ι → ℝ)} (hE : MeasurableSet E) (hpos : ∀ y ∈ E, 0 < s y) (hmom : ∀ y ∈ E, ∑ i, (y i)^2 ≤ (Fintype.card ι : ℝ)*R) (hcover : ∀ y ∈ E, ∃ x ∈ C, ψ y-(∫ u, f x u ∂empiricalLaw y)+normalDensityError R (d y) (s y) (d₀ x) (s₀ x)+ log (∫ u, exp (f x u) ∂gaussianReal (d₀ x) (s₀ x).toNNReal) < r) : (∫⁻ y in E, ENNReal.ofReal (exp ((Fintype.card ι : ℝ)*ψ y)*productNormal (d y) (s y) y)) ≤ ENNReal.ofReal ((C.card : ℝ)*exp ((Fintype.card ι : ℝ)*r)) := by classical let F (x : X) (y : ι → ℝ) : ℝ := exp ((Fintype.card ι : ℝ)*r-(Fintype.card ι : ℝ)* log (∫ u, exp (f x u) ∂gaussianReal (d₀ x) (s₀ x).toNNReal)) * (exp (∑ i, f x (y i))*productNormal (d₀ x) (s₀ x) y) have hFi (x : X) : Integrable (F x) := (product_tiltedNormal_integrable (f x) (d₀ x) (s₀ x)).const_mul _ have hFnn (x : X) (y : ι → ℝ) : 0 ≤ F x y := mul_nonneg (exp_pos _).le (mul_nonneg (exp_pos _).le (productNormal_nonneg _ _ _)) have hnorm (x : X) (hx : x ∈ C) : ∫ y, F x y = exp ((Fintype.card ι : ℝ)*r) := gaussian_tilt_mass (f x) (d₀ x) (hs₀ x hx) r have hdom (y : ι → ℝ) (hy : y ∈ E) : exp ((Fintype.card ι : ℝ)*ψ y)*productNormal (d y) (s y) y ≤ ∑ x ∈ C, F x y := by obtain ⟨x,hx,hc⟩ := hcover y hy have hdens := normalLogDensity_sum_sub_le (hmom y hy) (d y) (s y) (d₀ x) (s₀ x) change _ ≤ (Fintype.card ι : ℝ)*normalDensityError R (d y) (s y) (d₀ x) (s₀ x) at hdens have hn : (0 : ℝ) < Fintype.card ι := by exact_mod_cast (Fintype.card_pos (α := ι)) have hc' := mul_lt_mul_of_pos_left hc hn have hemp := card_mul_integral_empiricalLaw y (f x) have hsmall : exp ((Fintype.card ι : ℝ)*ψ y)*productNormal (d y) (s y) y ≤ F x y := by dsimp only [F] rw [productNormal_eq_exp _ (hpos y hy), productNormal_eq_exp _ (hs₀ x hx), ← exp_add, ← exp_add, ← exp_add] apply exp_le_exp.mpr nlinarith exact hsmall.trans (Finset.single_le_sum (fun a _ => hFnn a y) hx) have hsumI : Integrable (fun y => ∑ x ∈ C, F x y) := integrable_finsetSum C (fun x _ => hFi x) calc _ ≤ ∫⁻ y in E, ENNReal.ofReal (∑ x ∈ C, F x y) := lintegral_mono_ae ((ae_restrict_mem hE).mono (fun y hy => ENNReal.ofReal_le_ofReal (hdom y hy))) _ ≤ ∫⁻ y, ENNReal.ofReal (∑ x ∈ C, F x y) := lintegral_mono' Measure.restrict_le_self (fun _ => le_rfl) _ = ENNReal.ofReal (∫ y, ∑ x ∈ C, F x y) := (ofReal_integral_eq_lintegral_ofReal hsumI (ae_of_all _ (fun y => Finset.sum_nonneg (fun x _ => hFnn x y)))).symm _ = _ := by rw [integral_finsetSum C (fun x _ => hFi x)] simp_rw [Finset.sum_congr rfl hnorm] simp
end SKGap
namespace SKGap
theorem gaussian_compact_laplace {X : Type*} [TopologicalSpace X] {K : Set X} (hK : IsCompact K) {P : X → ProbabilityMeasure ℝ} {d s ψ : X → ℝ} (hP : ContinuousOn P K) (hd : ContinuousOn d K) (hs : ContinuousOn s K) (hψ : ContinuousOn ψ K) (hpos : ∀ x ∈ K, 0 < s x) (R r : ℝ) (hW : ∀ x ∈ K, ∃ f : ℝ →ᵇ ℝ, ψ x-(∫ y, f y ∂P x)+ log (∫ y, exp (f y) ∂gaussianReal (d x) (s x).toNNReal) < r) : ∃ M : ℕ, ∀ n : ℕ, ∀ hn : 0 < n, ∀ z : (Fin n → ℝ) → X, ∀ E : Set (Fin n → ℝ), MeasurableSet E → (∀ y ∈ E, z y ∈ K) → (∀ y ∈ E, P (z y) = @empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y) → (∀ y ∈ E, ∑ i, (y i)^2 ≤ (n:ℝ)*R) → (∫⁻ y in E, ENNReal.ofReal (exp ((n:ℝ)*ψ (z y))*productNormal (d (z y)) (s (z y)) y)) ≤ ENNReal.ofReal ((M:ℝ)*exp ((n:ℝ)*r)) := by classical obtain ⟨C,f,hC⟩ := finite_gaussian_test_cover hK hP hd hs hψ hpos R r hW refine ⟨C.card, ?_⟩ intro n hn z E hE hz hemp hmom let : Nonempty (Fin n) := ⟨⟨0,hn⟩⟩ have hh := gaussian_covered_laplace C f (fun x : K => d x) (fun x : K => s x) (fun x _ => hpos x x.2) (fun y => d (z y)) (fun y => s (z y)) (fun y => ψ (z y)) R r hE (fun y hy => hpos (z y) (hz y hy)) (by simpa only [Fintype.card_fin] using hmom) (fun y hy => by obtain ⟨x,hx,hcx⟩ := hC (z y) (hz y hy) rw [hemp y hy] at hcx exact ⟨x,hx,hcx⟩) simpa only [Fintype.card_fin] using hh
lemma absorb_finite_exponential_factor (M : ℕ) {ε : ℝ} (hε : 0 < ε) : ∃ N : ℕ, ∀ n ≥ N, ∀ r : ℝ, (M:ℝ)*exp ((n:ℝ)*r) ≤ exp ((n:ℝ)*(r+ε)) := by obtain ⟨N,hN⟩ := exists_nat_gt (log ((M:ℝ)+1)/ε) refine ⟨N,?_⟩ intro n hn r have hcast : (N:ℝ) ≤ n := by exact_mod_cast hn have hnlog : log ((M:ℝ)+1) ≤ (n:ℝ)*ε := by have h := (div_lt_iff₀ hε).mp hN nlinarith have he : (M:ℝ) ≤ exp ((n:ℝ)*ε) := by have h := exp_le_exp.mpr hnlog rw [exp_log (by positivity)] at h linarith calc _ ≤ exp ((n:ℝ)*ε)*exp ((n:ℝ)*r) := mul_le_mul_of_nonneg_right he (exp_pos _).le _ = _ := by rw [← exp_add]; congr 1; ring
theorem gaussian_compact_rate {X : Type*} [TopologicalSpace X] {K : Set X} (hK : IsCompact K) {P : X → ProbabilityMeasure ℝ} {d s ψ : X → ℝ} (hP : ContinuousOn P K) (hd : ContinuousOn d K) (hs : ContinuousOn s K) (hψ : ContinuousOn ψ K) (hpos : ∀ x ∈ K, 0 < s x) (R r : ℝ) (hW : ∀ x ∈ K, ∃ f : ℝ →ᵇ ℝ, ψ x-(∫ y, f y ∂P x)+ log (∫ y, exp (f y) ∂gaussianReal (d x) (s x).toNNReal) < r) {ε : ℝ} (hε : 0 < ε) : ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, ∀ z : (Fin n → ℝ) → X, ∀ E : Set (Fin n → ℝ), MeasurableSet E → (∀ y ∈ E, z y ∈ K) → (∀ y ∈ E, P (z y) = @empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y) → (∀ y ∈ E, ∑ i, (y i)^2 ≤ (n:ℝ)*R) → (∫⁻ y in E, ENNReal.ofReal (exp ((n:ℝ)*ψ (z y))*productNormal (d (z y)) (s (z y)) y)) ≤ ENNReal.ofReal (exp ((n:ℝ)*(r+ε))) := by obtain ⟨M,hM⟩ := gaussian_compact_laplace hK hP hd hs hψ hpos R r hW obtain ⟨N,hN⟩ := absorb_finite_exponential_factor M hε refine ⟨N,?_⟩ intro n hn hn' z E hE hz hemp hmom exact (hM n hn' z E hE hz hemp hmom).trans (ENNReal.ofReal_le_ofReal (hN n hn r))
end SKGap
endendendendendendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianQuadraticimport OAI.Probability.SKGap.Gaussian.GaussianRegression
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Matrix Realopen scoped BigOperators ENNReal NNReal
lemma gaussian_integral_fourth_variance (v : ℝ≥0) : (∫ x : ℝ,x^4 ∂gaussianReal 0 v)=3*(v:ℝ)^2 := by have hm : (gaussianReal 0 1).map (fun x : ℝ => sqrt (v:ℝ)*x)=gaussianReal 0 v := by rw [gaussianReal_map_const_mul] congr 1 · simp · ext; simp [Real.sq_sqrt v.coe_nonneg] rw [← hm,integral_map (by fun_prop) (by fun_prop)] simp only [mul_pow,integral_const_mul,gaussian_integral_fourth] rw [show sqrt (v:ℝ)^4=(v:ℝ)^2 by rw [show 4=2*2 by norm_num,pow_mul,Real.sq_sqrt v.coe_nonneg]] ring
lemma gaussian_fourth_integrable (v : ℝ≥0) : Integrable (fun x : ℝ => x^4) (gaussianReal 0 v) := by apply (integrable_norm_iff (by fun_prop)).mp simpa only [id_eq,norm_pow] using (IsGaussian.memLp_id (gaussianReal 0 v) (4:ℝ≥0∞) (by norm_num)).integrable_norm_pow'
lemma linear_gaussian_fourth {κ : Type*} [Fintype κ] [DecidableEq κ] (a : κ → ℝ) : (∫ g,(∑ i,a i*g i)^4 ∂gaussianCoordinates κ)=3*(∑ i,a i^2)^2 := by let A : Matrix Unit κ ℝ := fun _ => a have hg := (matrix_sample_gaussian A).eval () change HasGaussianLaw (fun g : κ → ℝ => ∑ i,a i*g i) (gaussianCoordinates κ) at hg have hl : HasLaw _ _ _ := ⟨hg.aemeasurable,hg.map_eq_gaussianReal⟩ have hm := linear_gaussian_mean a have hv : Var[fun g => ∑ i,a i*g i;gaussianCoordinates κ]=∑ i,a i^2 := by rw [← covariance_self hg.aemeasurable] simpa only [sq] using linear_gaussian_covariance a a change HasLaw (fun g : κ → ℝ => ∑ i,a i*g i) _ _ at hl rw [hm,hv] at hl have he := hl.integral_comp (f := fun x : ℝ => x^4) (by fun_prop) simp only [Function.comp_def] at he rw [he,gaussian_integral_fourth_variance] rw [Real.coe_toNNReal _ (Finset.sum_nonneg (fun i _ => sq_nonneg (a i)))]
lemma linear_gaussian_fourth_integrable {κ : Type*} [Fintype κ] (a : κ → ℝ) : Integrable (fun g => (∑ i,a i*g i)^4) (gaussianCoordinates κ) := by let A : Matrix Unit κ ℝ := fun _ => a have hg := (matrix_sample_gaussian A).eval () change HasGaussianLaw (fun g : κ → ℝ => ∑ i,a i*g i) (gaussianCoordinates κ) at hg have hl : HasLaw _ _ _ := ⟨hg.aemeasurable,hg.map_eq_gaussianReal⟩ rw [linear_gaussian_mean a] at hl have hi := gaussian_fourth_integrable (Var[fun g : κ → ℝ => ∑ i,a i*g i;gaussianCoordinates κ].toNNReal) rw [← hl.map_eq] at hi exact (integrable_map_measure (by fun_prop) hl.aemeasurable).mp hi
end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234import Mathlibimport OAI.Probability.SKGap.Entropy.ProdFst
namespace OAI
sectionopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen scoped BigOperatorsopen scoped BigOperators NNReal ENNRealopen MeasureTheory Metric Setopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators Matrix.Norms.L2Operatoropen MeasureTheory ProbabilityTheory Filter Setopen scoped BigOperators Matrix Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filter Setopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators ENNReal NNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Matrixopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators ENNReal NNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealopen scoped BigOperatorsopen MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNRealopen scoped BigOperatorsopen Filter Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen Matrixopen scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwiseopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Topologyopen MeasureTheory ProbabilityTheory Filter Matrixopen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNReal Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologyopen MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topologynamespace SKGapCutoff.Regressionlemma independent_bounded_average_tail_law {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] {F : Type*} [MeasurableSpace F] (τ : Measure F) {n : ℕ} (hn : 0 < n) (X : Fin n → Ω → F) (hXi : iIndepFun X μ) (hX : ∀ i, HasLaw (X i) τ μ) (f : Fin n → F → ℝ) (hf : ∀ i, Measurable (f i)) (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ i z, |f i z| ≤ B) (ε : ℝ) (hε : 0 ≤ ε) : μ {g | ε ≤ |((∑ i, f i (X i g)) - ∑ i, ∫ z, f i z ∂τ)/(n:ℝ)|} ≤ 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(2*B^2))) := by let m (i : Fin n) := ∫ z, f i z ∂τ have hi : iIndepFun (fun i (g : Ω) => f i (X i g)-m i) μ := hXi.comp (fun i z => f i z-m i) (fun i => (hf i).sub_const (m i)) have hm (i : Fin n) : (∫ g : Ω, f i (X i g) ∂μ) = m i := (hX i).integral_comp (hf i).aestronglyMeasurable have hsub (i : Fin n) : HasSubgaussianMGF (fun g : Ω => f i (X i g)-m i) ((‖B-(-B)‖₊/2)^2) μ := by have hb : ∀ᵐ g : Ω ∂μ, f i (X i g) ∈ Set.Icc (-B) B := Filter.Eventually.of_forall (fun g => abs_le.mp (hbound i (X i g))) simpa only [hm] using hasSubgaussianMGF_of_mem_Icc (show AEMeasurable (fun g : Ω => f i (X i g)) μ from (hf i).comp_aemeasurable (hX i).aemeasurable) hb have hh := subgaussian_abs_tail (HasSubgaussianMGF.sum_of_iIndepFun hi (s := Finset.univ) (fun i _ => hsub i)) (ε*n) (by positivity) have he (g : Ω) : (ε*(n:ℝ) ≤ |∑ i, (f i (X i g)-m i)|) ↔ ε ≤ |((∑ i, f i (X i g)) - ∑ i, m i)/(n:ℝ)| := by rw [Finset.sum_sub_distrib, abs_div, abs_of_pos (show (0:ℝ) < n from Nat.cast_pos.mpr hn)] exact (le_div_iff₀ (Nat.cast_pos.mpr hn)).symm simp only [he] at hh convert hh using 1 congr 3 simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, NNReal.coe_mul, NNReal.coe_natCast, NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat, coe_nnnorm, Real.norm_eq_abs] rw [abs_of_nonneg (by linarith : 0 ≤ B-(-B))] have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) by_cases hB0 : B=0 · simp [hB0] · field_simp ring
lemma probability_average_lipschitz {E F : Type*} [PseudoMetricSpace E] [PseudoMetricSpace F] [MeasurableSpace F] [BorelSpace F] (τ : Measure F) [IsProbabilityMeasure τ] {f : E × F → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) (B : ℝ) (hB : ∀ z, |f z| ≤ B) : LipschitzWith K (fun x => ∫ y, f (x,y) ∂τ) := by have hi (x : E) : Integrable (fun y => f (x,y)) τ := by apply integrable_bounded_lipschitz τ (K := K) _ B (fun y => hB (x,y)) apply LipschitzWith.of_dist_le_mul intro y z simpa only [Prod.dist_eq, dist_self, max_eq_right (dist_nonneg)] using hf.dist_le_mul (x,y) (x,z) apply LipschitzWith.of_dist_le_mul intro x y rw [Real.dist_eq, ← integral_sub (hi x) (hi y)] have hh := norm_integral_le_of_norm_le_const (μ := τ) (C := (K:ℝ)*dist x y) (f := fun z => f (x,z)-f (y,z)) (Filter.Eventually.of_forall (fun z => by simpa only [Real.norm_eq_abs, ← Real.dist_eq, Prod.dist_eq, dist_self, max_eq_left (dist_nonneg)] using hf.dist_le_mul (x,z) (y,z))) simpa using hh
lemma probability_average_bound {E F : Type*} [MeasurableSpace F] (τ : Measure F) [IsProbabilityMeasure τ] {f : E × F → ℝ} (B : ℝ) (hB : ∀ z, |f z| ≤ B) (x : E) : |∫ z, f (x,z) ∂τ| ≤ B := by have h := norm_integral_le_of_norm_le_const (μ := τ) (C := B) (f := fun z => f (x,z)) (Filter.Eventually.of_forall (fun z => by simpa only [Real.norm_eq_abs] using hB (x,z))) simpa using h
lemma iid_seed_empirical_tail {E F H : Type*} [MeasurableSpace E] [MeasurableSpace F] [MeasurableSpace H] (τ : Measure F) [IsProbabilityMeasure τ] (ρ : Measure H) [IsProbabilityMeasure ρ] {n : ℕ} (hn : 0 < n) (X : H → Fin n → E) (hX : Measurable X) (f : E × F → ℝ) (hf : Measurable f) (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ z, |f z| ≤ B) (ε : ℝ) (hε : 0 ≤ ε) : (ρ.prod (Measure.pi (fun _ : Fin n => τ))) {z | ε ≤ |((∑ i, f (X z.1 i,z.2 i)) - ∑ i, ∫ w, f (X z.1 i,w) ∂τ)/(n:ℝ)|} ≤ 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(2*B^2))) := by have hM : Measurable (fun x => ∫ y, f (x,y) ∂τ) := (show StronglyMeasurable (Function.uncurry (fun x y => f (x,y))) from hf.stronglyMeasurable).integral_prod_right.measurable apply probability_prod_section_bound · apply measurableSet_le measurable_const apply Measurable.abs apply Measurable.div_const apply Measurable.sub · apply Finset.measurable_sum intro i _ exact hf.comp ((((measurable_pi_apply i).comp hX).comp measurable_fst).prodMk ((measurable_pi_apply i).comp measurable_snd)) · apply Finset.measurable_sum intro i _ exact hM.comp (((measurable_pi_apply i).comp hX).comp measurable_fst) · intro h exact independent_bounded_average_tail_law τ hn (fun i (z : Fin n → F) => z i) (iIndepFun_pi (fun _ => measurable_id.aemeasurable)) (fun i => (measurePreserving_eval (fun _ : Fin n => τ) i).hasLaw) (fun i w => f (X h i,w)) (fun i => hf.comp measurable_prodMk_left) B hB (fun i w => hbound _) ε hε
theorem ExponentialEmpiricalConcentration.iid_seed {E F : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] [PseudoMetricSpace F] [MeasurableSpace F] [BorelSpace F] [SecondCountableTopology F] {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] (ν : Measure E) [IsProbabilityMeasure ν] (τ : Measure F) [IsProbabilityMeasure τ] (X : ∀ n, H n → Fin n → E) (hXm : ∀ n, Measurable (X n)) (hX : ExponentialEmpiricalConcentration ρ X ν) : ExponentialEmpiricalConcentration (fun n => (ρ n).prod (Measure.pi (fun _ : Fin n => τ))) (fun n z i => (X n z.1 i,z.2 i)) (ν.prod τ) := by intro f K hf B hbound ε hε let D := |B|+1 have hD : 0 < D := by dsimp [D]; positivity have hb : ∀ z, |f z| ≤ D := fun z => (hbound z).trans (by dsimp [D]; linarith [le_abs_self B]) let ψ : E → ℝ := fun x => ∫ y, f (x,y) ∂τ have hp := probability_average_lipschitz τ hf D hb have hpb := probability_average_bound τ D hb have hm : ∫ z, f z ∂ν.prod τ = ∫ x, ψ x ∂ν := integral_prod f (integrable_bounded_lipschitz _ hf D hb) have hold := ((hX.average ψ hp D hpb) (ε/2) (by positivity)).prod_fst (fun n => Measure.pi (fun _ : Fin n => τ)) have hnew : ExponentiallyRare (fun n => (ρ n).prod (Measure.pi (fun _ : Fin n => τ))) (fun n => {z | ε/2 ≤ |((∑ i, f (X n z.1 i,z.2 i)) - ∑ i, ψ (X n z.1 i))/(n:ℝ)|}) := by refine ⟨2,ε^2/(8*D^2),by norm_num,by positivity,?_⟩ filter_upwards [eventually_ge_atTop 1] with n hn have hh := iid_seed_empirical_tail τ (ρ n) hn (X n) (hXm n) f hf.continuous.measurable D hD.le hb (ε/2) (by positivity) have he : -((ε/2)^2*(n:ℝ))/(2*D^2) = -(ε^2/(8*D^2))*(n:ℝ) := by field_simp ring simpa only [ψ, he, ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 2), ENNReal.ofReal_ofNat] using hh apply (hold.union hnew).mono refine Filter.Eventually.of_forall ?_ intro n z hz change ε ≤ |(∑ i, f (X n z.1 i,z.2 i))/(n:ℝ)-∫ w, f w ∂ν.prod τ| at hz rw [hm] at hz by_cases ho : ε/2 ≤ dist ((∑ i, ψ (X n z.1 i))/(n:ℝ)) (∫ x, ψ x ∂ν) · exact Or.inl ho apply Or.inr by_contra hn have ho' : |(∑ i, ψ (X n z.1 i))/(n:ℝ) - ∫ x, ψ x ∂ν| < ε/2 := lt_of_not_ge ho have hn' : |((∑ i, f (X n z.1 i,z.2 i)) - ∑ i, ψ (X n z.1 i))/(n:ℝ)| < ε/2 := lt_of_not_ge hn rw [sub_div] at hn' have ht := abs_add_le ((∑ i, f (X n z.1 i,z.2 i))/(n:ℝ) - (∑ i, ψ (X n z.1 i))/(n:ℝ)) ((∑ i, ψ (X n z.1 i))/(n:ℝ) - ∫ x, ψ x ∂ν) rw [sub_add_sub_cancel] at ht linarith
end SKGapCutoff.Regression
open MeasureTheory ProbabilityTheory Filteropen scoped NNReal ENNReal BigOperators Topology
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108import Mathlibimport OAI.Probability.SKGap.Localization.LiteralLocalWeak
namespace OAI
section
noncomputable sectionopen scoped BigOperators Matrix.Norms.Frobeniusnamespace SKGapCutoff.Recipeopen Primary Static SKGap.Stein SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series SKGap.Noncrossing.ClosedMarkeduniverse uvariable {Ω : Type u} {n : Ω→ℕ} {M : ℕ}theorem literal_local_weak_terminal_targets (j : ℝ) (J : ∀b,Interaction (n b)) (h : ∀b,Fin (n b)→ℝ) (l : Fin M) (f : KernelExpr) (a c : ∀b,Spin (n b)→ℝ) (r e : ∀b,Fin (n b)→ℝ) (w y : ∀b,VectorFields (n b)) (E : ∀b,Set (Spin (n b))) (hn : ∀b,0<n b) (he : ∀b,vectorNorm (e b)≤1) {K B R Bc Va Vc V S F W C : ℝ} (hK : 0≤K) (hB : 0≤B) (hBc : 0≤Bc) (hVa : 0≤Va) (hVc : 0≤Vc) (hV : 0≤V) (hS : 0≤S) (hF : 0≤F) (hW : 0≤W) (hC : 0≤C) (hop : ∀b,SKGap.opNorm (J b)≤K) (hformal : ∀b x,∀q<M,ShapeBound (formalField j (J b) (h b) x q) B) (ha : ∀b x,x∈flipNeighborhood (flipNeighborhood (E b))→|a b x|≤R) (hc : ∀b x,x∈flipNeighborhood (flipNeighborhood (E b))→|Real.sqrt (n b:ℝ)*c b x|≤Bc) (hDa : ∀b x,x∈flipNeighborhood (E b)→‖derivativeVector (a b) x‖≤Va) (hDc : ∀b x,x∈flipNeighborhood (E b)→‖derivativeVector (fun v=>Real.sqrt (n b:ℝ)*c b v) x‖≤Vc) (heq : ∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) l.val) (mag j (J b) (h b) l.val) (w b) (y b) (a b) (c b) (r b) (e b) x) (hdiag : ∀b x,x∈flipNeighborhood (E b)→LiteralInitialDiagnostics (literalInitial (J b) j (Real.sqrt (n b:ℝ)) f (fld j (J b) (h b) l.val) (mag j (J b) (h b) l.val) (a b) (c b) (r b) (e b)) (w b) (y b) (primaryTree j (J b) (h b) x l.val) x V S F (literalResidualBudget j f R Bc l.val)) (P : ∀b,Observables (n b)) (hP : ∀b x,0≤P b x) (hp : ∀b,∑x,P b x=1) (hm : ∀b x i,conditionalMean (P b) x i=mag j (J b) (h b) 1 x i) (hJ : ∀b,(J b).IsSymm) (hw : ∀b x,x∈flipNeighborhood (E b)→ClosedWordTestBound j (fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x)) (J b) (literalResidualBudget j f R Bc l.val) W (2*(2+2*l.val)+5)) (hd : ∀b x,x∈flipNeighborhood (E b)→ClosedWordDiagramBound j (fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x)) (J b) (literalResidualBudget j f R Bc l.val) C (2*M+2*(2+2*l.val)+4)) : (∀p≤l.val,LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) p x i*w b x i)) ∧ LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) l.val x i*y b x i) ∧ LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) l.val x i* (Real.tanh (fld j (J b) (h b) l.val x i)/Real.sqrt (n b:ℝ))) ∧ LocalUniformMultiplier E (fun b=>siteMean (fun x i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x))) ∧ LocalUniformMultiplier E (fun b x=>j*onsager j (J b) (h b) l.val x) ∧ LocalUniformMultiplier E (fun b x=>Real.sqrt (n b:ℝ)*c b x) := by let Kt:=2+|literalCoefficientBudget f j R Bc| have hKt : 2≤Kt := by dsimp [Kt];linarith [abs_nonneg (literalCoefficientBudget f j R Bc)] have hKt0 : 0≤Kt:=by linarith have hA : 1≤literalResidualBudget j f R Bc l.val := (by linarith : 1≤Kt).trans (residualCoefficientBudget_ge j hKt0 l.val 0) have C:=literal_finite_control j J h l f a c r e w y E hn he hK hB hBc hVa hVc hA hV hS hF hW hC hop hformal ha hc hDa hDc heq hdiag (2+2*l.val) hw hd have H:=literal_full_local_family j J h l f a c r e w y E hn he hBc ha hc heq have hclass : literalCoefficientBudget f j R Bc≤Kt := by dsimp [Kt];linarith [le_abs_self (literalCoefficientBudget f j R Bc)] have HH:=H.mono le_rfl le_rfl le_rfl hclass have hb:=residualCoefficientBudget_antitone j hKt0 l.val have rule:=local_uniform_residual_rule C hP hp hm hn hJ Sum.inl (fun _ _=>rfl) (residualCoefficientBudget j Kt l.val) hb l.val l.isLt (fun p _=>hb (Nat.zero_le p)) (fun p _=>hKt.trans (residualCoefficientBudget_ge j hKt0 l.val p)) (fun p hp=>le_of_eq (residualCoefficientBudget_step j Kt hp)) let D:=fun b=>literalFullData j (J b) (h b) l f (a b) (c b) (r b) (e b) have allw : ∀p≤l.val,LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) p x i*w b x i) := by intro p hp have H':=HH.mono hp le_rfl le_rfl (residualCoefficientBudget_ge j hKt0 l.val p) have hh:=rule p hp D 1 H' (by omega) apply hh.congr_on intro b x hx rw [(H.initial b x hx).1] refine ⟨allw,?_,?_,?_,?_,?_⟩ · have H' := HH.appendAuxiliary have hh:=rule l.val le_rfl (fun b=>(D b).appendAuxiliary 1) 2 (H'.mono le_rfl le_rfl (by norm_num) (residualCoefficientBudget_ge j hKt0 l.val l.val)) (by omega) apply hh.congr_on intro b x hx rw [show 2=1+1 from rfl,OrdinaryData.appendAuxiliary_started_source,(H.initial b x hx).2] · have H' := HH.appendPrimary hn hKt l le_rfl have hh:=rule l.val le_rfl (fun b=>(D b).appendPrimary 1 l) 2 (H'.mono le_rfl le_rfl (by norm_num) (residualCoefficientBudget_ge j hKt0 l.val l.val)) (by omega) apply hh.congr intro b x rw [show 2=1+1 from rfl,OrdinaryData.appendPrimary_started_source] rfl
· have hh:=C.means D 1 l.val Kt HH (by omega) (residualCoefficientBudget_ge j hKt0 l.val 0) 0 apply hh.congr intro b x congr 1 ext v i dsimp only [D,literalFullData] rw [OrdinaryData.unitPullback_auxCoefficient _ l Sum.inr _ _ _ rfl rfl] exact literalInitial_coefficient _ _ _ _ _ _ _ _ _ _ _ _ · exact C.local_onsager_multiplier l.val l.isLt.le · refine ⟨Bc,Vc,hBc,hVc,fun b x hx=>hc b x (Or.inl hx),?_⟩ intro b x hx simpa only [norm_derivativeVector_sq] using pow_le_pow_left₀ (norm_nonneg _) (hDc b x (Or.inl hx)) 2
end SKGapCutoff.Recipe
endend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianVectorMomentsimport OAI.Probability.SKGap.Localization.LocalWhitening
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Matrix Realopen scoped BigOperators ENNReal NNReal
lemma matrix_fourth_sum_integrable {ι κ : Type*} [Fintype ι] [Fintype κ] (A : Matrix ι κ ℝ) : Integrable (fun g => ∑ i,((A*ᵥg) i)^4) (gaussianCoordinates κ) := by apply integrable_finsetSum intro i _ exact linear_gaussian_fourth_integrable (A i)
lemma matrix_fourth_sum_mean {ι κ : Type*} [Fintype ι] [Fintype κ] [DecidableEq κ] (A : Matrix ι κ ℝ) : (∫ g,∑ i,((A*ᵥg) i)^4 ∂gaussianCoordinates κ)=3*∑ i,(∑ k,A i k^2)^2 := by simp only [Matrix.mulVec,dotProduct] rw [integral_finsetSum _ (fun i _ => linear_gaussian_fourth_integrable (A i)),Finset.mul_sum] apply Finset.sum_congr rfl intro i _ exact linear_gaussian_fourth (A i)
lemma matrix_fourth_sum_bound {n m : ℕ} (A : Matrix (Fin n) (Fin m) ℝ) {c : ℝ} (hc : 0 ≤ c) (hb : ∀ i,∑ k,A i k^2 ≤ c) : (∫ g,∑ i,((A*ᵥg) i)^4 ∂gaussianCoordinates (Fin m)) ≤ 3*(n:ℝ)*c^2 := by rw [matrix_fourth_sum_mean] have hs : (∑ i : Fin n,(∑ k,A i k^2)^2) ≤ ∑ _i : Fin n,c^2 := by apply Finset.sum_le_sum intro i _ exact (sq_le_sq₀ (Finset.sum_nonneg (fun k _ => sq_nonneg _)) hc).mpr (hb i) simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at hs nlinarith
lemma matrix_norm_fourth_integrable {n m : ℕ} (A : Matrix (Fin n) (Fin m) ℝ) : Integrable (fun g => vectorNorm (A*ᵥg)^4) (gaussianCoordinates (Fin m)) := by apply ((matrix_fourth_sum_integrable A).const_mul (n:ℝ)).mono' ?_ ?_ · have he : (fun g => vectorNorm (A*ᵥg)^4)=fun g => (∑ i,((A*ᵥg) i)^2)^2 := by funext g rw [show vectorNorm (A*ᵥg)^4=(vectorNorm (A*ᵥg)^2)^2 by ring,vectorNorm_sq] rfl rw [he] fun_prop · filter_upwards [] with g rw [Real.norm_eq_abs,abs_of_nonneg (by positivity)] exact vectorNorm_fourth_le (A*ᵥg)
lemma matrix_norm_fourth_bound {n m : ℕ} (A : Matrix (Fin n) (Fin m) ℝ) {c : ℝ} (hc : 0 ≤ c) (hb : ∀ i,∑ k,A i k^2 ≤ c) : (∫ g,vectorNorm (A*ᵥg)^4 ∂gaussianCoordinates (Fin m)) ≤ 3*(n:ℝ)^2*c^2 := by calc _ ≤ ∫ g,(n:ℝ)*(∑ i,((A*ᵥg) i)^4) ∂gaussianCoordinates (Fin m) := integral_mono (matrix_norm_fourth_integrable A) ((matrix_fourth_sum_integrable A).const_mul _) (fun g => vectorNorm_fourth_le _) _ = (n:ℝ)*(∫ g,∑ i,((A*ᵥg) i)^4 ∂gaussianCoordinates (Fin m)) := integral_const_mul _ _ _ ≤ (n:ℝ)*(3*(n:ℝ)*c^2) := mul_le_mul_of_nonneg_left (matrix_fourth_sum_bound A hc hb) (Nat.cast_nonneg _) _ = _ := by ring
theorem localGaussian_fourth_moments {n : ℕ} {U : Matrix (Fin n) (Fin n) ℝ} (hU : U.IsHermitian) {γ σ : ℝ} (hγ : 0 < γ) (hbound : ∀ g : Field n, vectorNorm (U*ᵥg) ≤ vectorNorm g/sqrt γ) : (∫ g,∑ i,((σ • U)*ᵥg) i^4 ∂gaussianCoordinates (Fin n)) ≤ 3*(n:ℝ)*σ^4/γ^2 ∧ (∫ g,vectorNorm ((σ • U)*ᵥg)^4 ∂gaussianCoordinates (Fin n)) ≤ 3*(n:ℝ)^2*σ^4/γ^2 := by have hb (i : Fin n) : ∑ k,(σ • U) i k^2 ≤ σ^2/γ := by have hh := symmetric_row_sq_bound hU (inv_nonneg.mpr (sqrt_nonneg γ)) (fun g => by simpa only [div_eq_mul_inv,mul_comm] using hbound g) i rw [inv_pow,Real.sq_sqrt hγ.le] at hh simp only [Matrix.smul_apply,smul_eq_mul,mul_pow,← Finset.mul_sum] exact (mul_le_mul_of_nonneg_left hh (sq_nonneg σ)).trans_eq (by ring) have h1 := matrix_fourth_sum_bound (σ • U) (div_nonneg (sq_nonneg σ) hγ.le) hb have h2 := matrix_norm_fourth_bound (σ • U) (div_nonneg (sq_nonneg σ) hγ.le) hb constructor · convert h1 using 1; ring · convert h2 using 1; ring
end SKGapendend
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Matrix Real Setopen scoped BigOperators ENNReal NNReal
lemma gaussian_vectorSqNorm_integrable (n : ℕ) : Integrable (vectorSqNorm (n := n)) (gaussianCoordinates (Fin n)) := by have hh := (gaussianQuadratic_memLp (fun _ : Fin n => (1:ℝ))).integrable (by norm_num) change Integrable (fun g : Field n => ∑ i,1*g i^2) (gaussianCoordinates (Fin n)) at hh change Integrable (fun g : Field n => ∑ i,g i^2) (gaussianCoordinates (Fin n)) simpa only [one_mul] using hh
lemma gaussian_vectorSqNorm_mean (n : ℕ) : (∫ g,vectorSqNorm g ∂gaussianCoordinates (Fin n))=(n:ℝ) := by simpa only [vectorSqNorm,gaussianQuadratic,one_mul,gaussianCoordinates,Finset.sum_const, Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] using gaussianQuadratic_mean (fun _ : Fin n => (1:ℝ))
def localGaussianBall (n : ℕ) : Set (Field n) := {g | vectorSqNorm g ≤ 4*(n:ℝ)}
lemma localGaussianBall_measurable (n : ℕ) : MeasurableSet (localGaussianBall n) := by unfold localGaussianBall vectorSqNorm exact measurableSet_le (by fun_prop) measurable_const
lemma localGaussianBall_norm {n : ℕ} {g : Field n} (hg : g ∈ localGaussianBall n) : vectorNorm g ≤ 2*sqrt (n:ℝ) := by apply (sq_le_sq₀ (vectorNorm_nonneg _) (by positivity)).mp rw [vectorNorm_sq,mul_pow,Real.sq_sqrt (Nat.cast_nonneg _)] simpa only [localGaussianBall,Set.mem_ofPred_eq,show (2:ℝ)^2=4 by norm_num] using hg
theorem localGaussianBall_probability {n : ℕ} (hn : 0 < n) : 3/4 ≤ (gaussianCoordinates (Fin n)).real (localGaussianBall n) := by let μ := gaussianCoordinates (Fin n) have hn0 : (0:ℝ) < n := by exact_mod_cast hn have hh := mul_meas_ge_le_integral_of_nonneg (μ := μ) (ae_of_all _ (fun g => vectorSqNorm_nonneg g)) (gaussian_vectorSqNorm_integrable n) (4*(n:ℝ)) rw [gaussian_vectorSqNorm_mean] at hh have hsub : (localGaussianBall n)ᶜ ⊆ {g | 4*(n:ℝ) ≤ vectorSqNorm g} := by intro g hg change ¬ vectorSqNorm g ≤ 4*(n:ℝ) at hg exact (lt_of_not_ge hg).le have hmono := measureReal_mono hsub (measure_ne_top μ _) have hc := probReal_compl_eq_one_sub (μ := μ) (localGaussianBall_measurable n) rw [hc] at hmono nlinarith
lemma localGaussianBall_ne_zero {n : ℕ} (hn : 0 < n) : gaussianCoordinates (Fin n) (localGaussianBall n) ≠ 0 := by intro he have hh := localGaussianBall_probability hn simp only [measureReal_def,he,ENNReal.toReal_zero] at hh norm_num at hh
lemma integrable_cond_of_integrable {Ω E : Type*} [MeasurableSpace Ω] [NormedAddCommGroup E] {μ : Measure Ω} {s : Set Ω} {f : Ω → E} (hs : μ s ≠ 0) (hf : Integrable f μ) : Integrable f (cond μ s) := by exact hf.restrict.smul_measure (ENNReal.inv_ne_top.mpr hs)
lemma integral_cond_nonneg_le_two {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] {s : Set Ω} {f : Ω → ℝ} (hp : 1/2 ≤ μ.real s) (hf : Integrable f μ) (hn : 0 ≤ᵐ[μ] f) : (∫ x,f x ∂cond μ s) ≤ 2*∫ x,f x ∂μ := by have hps : 0 < μ.real s := by linarith have his : 0 ≤ ∫ x in s,f x ∂μ := integral_nonneg_of_ae (ae_restrict_of_ae hn) have hsle : (∫ x in s,f x ∂μ) ≤ ∫ x,f x ∂μ := integral_mono_measure μ.restrict_le_self hn hf have hinv : (μ.real s)⁻¹ ≤ 2 := by rw [inv_eq_one_div] exact (div_le_iff₀ hps).mpr (by linarith) rw [ProbabilityTheory.cond,integral_smul_measure,ENNReal.toReal_inv] change (μ.real s)⁻¹*(∫ x in s,f x ∂μ) ≤ _ exact (mul_le_mul_of_nonneg_right hinv his).trans (mul_le_mul_of_nonneg_left hsle (by norm_num))
end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianProductUpperTailLipschitzimport OAI.Probability.SKGap.Gaussian.GaussianProductPower
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Matrix Real MeasureTheory ProbabilityTheory Setopen scoped BigOperators Matrix.Norms.Frobeniusvariable {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ]
def matrixWordSeminorm (p : Bool) (M : Matrix ι ι ℝ) : ℝ := if p then offDiagonalSeminorm M else diagonalSeminorm Mlemma matrixWordSeminorm_lipschitz (p : Bool) : LipschitzWith 1 (matrixWordSeminorm (ι:=ι) p) := by cases p · exact diagonalSeminorm_lipschitz · exact offDiagonalSeminorm_lipschitzlemma matrixWordSeminorm_add (p : Bool) (M N : Matrix ι ι ℝ) : matrixWordSeminorm p (M+N)≤ matrixWordSeminorm p M+matrixWordSeminorm p N := by cases p · exact diagonalSeminorm_add M N · exact offDiagonalSeminorm_add M Nlemma matrixWordSeminorm_nonneg (p : Bool) (M : Matrix ι ι ℝ) : 0≤ matrixWordSeminorm p M := by let : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ cases p · exact norm_nonneg (diagonalVector M) · exact norm_nonneg (offDiagonalVector M)
lemma matrixCentered_sub {F G : EuclideanSpace ℝ κ→Matrix ι ι ℝ} {L K : NNReal} (hF : LipschitzWith L F) (hG : LipschitzWith K G) (x : EuclideanSpace ℝ κ) : matrixCentered (fun y=>F y-G y) x=matrixCentered F x-matrixCentered G x := by have hm : matrixEntryMean (fun y=>F y-G y)=matrixEntryMean F-matrixEntryMean G := by ext i k exact integral_sub (gaussianProduct_integrable_lipschitz (matrixEntry_lip hF i k)) (gaussianProduct_integrable_lipschitz (matrixEntry_lip hG i k)) simp only [matrixCentered,hm] abel
lemma gaussianProduct_centered_matrix_tail {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} {L : NNReal} (hF : LipschitzWith L F) (hL : 0<L) (p : Bool) {u : ℝ} (hu : 0≤u) : (Measure.pi (fun _ : κ=>gaussianReal 0 1)) {g | matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ)+u< matrixWordSeminorm p (matrixCentered F (WithLp.toLp 2 g))}≤ ENNReal.ofReal (exp (-2*u^2/(π^2*(L:ℝ)^2))) := by let μ := Measure.pi (fun _ : κ=>gaussianReal 0 1) let X : (κ→ℝ)→ℝ := fun g=>matrixWordSeminorm p (matrixCentered F (WithLp.toLp 2 g)) have hXL : LipschitzWith L (fun x : EuclideanSpace ℝ κ=>X x.ofLp) := by simpa only [X,WithLp.toLp_ofLp,one_mul,Function.comp_def] using (matrixWordSeminorm_lipschitz p).comp (matrixCentered_lipschitz hF) have hE : (∫ g,X g ∂μ)≤ matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ) := by cases p · exact (gaussianProduct_centered_matrix_norms hF hL).1 · exact (gaussianProduct_centered_matrix_norms hF hL).2 have htail := gaussianProduct_upper_tail_lipschitz hXL hL hu have hmono : μ {g | matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ)+u<X g}≤ μ {g | u≤X g-∫ h,X h ∂μ} := by apply measure_mono intro g hg change matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ)+u<X g at hg change u≤X g-∫ h,X h ∂μ linarith only [hg,hE] apply hmono.trans rw [←ENNReal.ofReal_toReal (measure_ne_top μ _)] exact ENNReal.ofReal_le_ofReal htailend SKGapendend
sectionnoncomputable sectionnamespace SKGapopen Matrix Real MeasureTheory ProbabilityTheory Setopen scoped BigOperators Matrix.Norms.Frobeniusvariable {κ : Type*} [Fintype κ]
lemma gaussianMatrix_scaled_semnorm_tail {n : ℕ} (hn : 1 ≤ n) {F : EuclideanSpace ℝ κ→Matrix (Fin n) (Fin n) ℝ} {H r T s : ℝ} (hH : 0<H) (hr : 0<r) (hT : 0 ≤ T) (hs : 0 ≤ s) (hF : LipschitzWith (Real.toNNReal (H*r/sqrt n)) F) (p : Bool) : (Measure.pi (fun _ : κ=>gaussianReal 0 1)) {g | (matrixNormConstant*H+T*s)*r< matrixWordSeminorm p (matrixCentered F (WithLp.toLp 2 g))} ≤ ENNReal.ofReal (exp (-2*T^2*s^2*(n:ℝ)/(π^2*H^2))) := by have hn0 : (0:ℝ)<n := by exact_mod_cast (show 0<n by omega) have hnS := sqrt_pos.mpr hn0 have hL : 0<Real.toNNReal (H*r/sqrt n) := by exact_mod_cast (Real.toNNReal_pos.mpr (div_pos (mul_pos hH hr) hnS)) have hh := gaussianProduct_centered_matrix_tail hF hL p (mul_nonneg (mul_nonneg hT hs) hr.le) have he : (matrixNormConstant*sqrt (Fintype.card (Fin n))*(Real.toNNReal (H*r/sqrt n):ℝ)+T*s*r)= (matrixNormConstant*H+T*s)*r := by rw [Fintype.card_fin,Real.coe_toNNReal _ (by positivity)] field_simp have he' : -2*(T*s*r)^2/(π^2*(Real.toNNReal (H*r/sqrt n):ℝ)^2)= -2*T^2*s^2*(n:ℝ)/(π^2*H^2) := by rw [Real.coe_toNNReal _ (by positivity)] field_simp rw [sq_sqrt hn0.le] rw [he,he'] at hh exact hhend SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianProductIntegralimport OAI.Probability.SKGap.Matrix.MatrixWordRegularity
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen Real Matrix MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix.Norms.Frobenius
lemma goe_word_even_centered_moment {n : ℕ} (hn : 0<n) {j : ℝ} (hj : 0<j) (F : List (Matrix (Fin n) (Fin n) ℝ→Matrix (Fin n) (Fin n) ℝ)) (hFl : 0<F.length) {R : NNReal} (hR : 0<R) (hF : ∀ f∈F,∀ M,opNorm (f M) ≤ R) (hL : ∀ f∈F,LipschitzWith R f) (i b : Fin n) (k : ℕ) : (∫ g : MatrixCoordinates (Fin n)→ℝ, |matrixFactorProduct F (goeMatrix (j/n) g) i b- ∫ h : MatrixCoordinates (Fin n)→ℝ,matrixFactorProduct F (goeMatrix (j/n) h) i b ∂Measure.pi (fun _=>gaussianReal 0 1)|^(2*k) ∂Measure.pi (fun _=>gaussianReal 0 1)) ≤ (2*((2*k).factorial:ℝ)*exp (π^2/8)) * (((F.length:ℝ)*(R:ℝ)^F.length)^2*(2*j))^k/(n:ℝ)^k := by have hnr : (0:ℝ)<n := Nat.cast_pos.mpr hn have hRr : (0:ℝ)<R := hR have hlr : (0:ℝ)<F.length := Nat.cast_pos.mpr hFl let L : NNReal := ((F.length:NNReal)*R^F.length)*⟨sqrt (2*(j/n)),sqrt_nonneg _⟩ have hLp : 0<L := by change 0<((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*(j/n)); positivity have hh := gaussianProduct_abs_centered_moment (goe_word_entry_lipschitz F hF hL (j/n) i b) hLp (2*k) apply hh.trans_eq change (2*((2*k).factorial:ℝ)*exp (π^2/8)) * (((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*(j/n)))^(2*k) = _ rw [pow_mul,mul_pow,sq_sqrt (by positivity : 0 ≤ 2*(j/n))] rw [show ((F.length:ℝ)*(R:ℝ)^F.length)^2*(2*(j/n))= (((F.length:ℝ)*(R:ℝ)^F.length)^2*(2*j))/(n:ℝ) by ring,div_pow] ring
lemma goe_word_trace_lip_scaled {n : ℕ} (hn : 0<n) {j : ℝ} (hj : 0≤j) (F : List (Matrix (Fin n) (Fin n) ℝ→Matrix (Fin n) (Fin n) ℝ)) {R : NNReal} (hF : ∀ f∈F,∀ M,opNorm (f M) ≤ R) (hL : ∀ f∈F,LipschitzWith R f) : LipschitzWith ⟨((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*j)/(n:ℝ),by positivity⟩ (fun z : EuclideanSpace ℝ (MatrixCoordinates (Fin n))=> trace (matrixFactorProduct F (goeMatrix (j/n) z))/(n:ℝ)) := by have hnr : (0:ℝ)<n := Nat.cast_pos.mpr hn have he : (n:ℝ)⁻¹*(sqrt (n:ℝ)*((F.length:ℝ)*(R:ℝ)^F.length))*sqrt (2*(j/n))= ((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*j)/(n:ℝ) := by rw [show 2*(j/(n:ℝ))=(2*j)/(n:ℝ) by ring,sqrt_div (mul_nonneg (by norm_num) hj)] field_simp [ne_of_gt hnr,ne_of_gt (sqrt_pos.2 hnr)] have hh := goe_word_normalized_trace_lipschitz F hF hL (j/n) simpa only [Fintype.card_fin,show (⟨(n:ℝ)⁻¹,inv_nonneg.mpr (Nat.cast_nonneg n)⟩ * (⟨sqrt (n:ℝ),sqrt_nonneg _⟩*((F.length:NNReal)*R^F.length))*⟨sqrt (2*(j/n)),sqrt_nonneg _⟩ : NNReal)= ⟨((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*j)/(n:ℝ),by positivity⟩ from NNReal.eq he] using hh
theorem goe_word_trace_centered_L1 {n : ℕ} (hn : 0<n) {j : ℝ} (hj : 0<j) (F : List (Matrix (Fin n) (Fin n) ℝ→Matrix (Fin n) (Fin n) ℝ)) (hFl : 0<F.length) {R : NNReal} (hR : 0<R) (hF : ∀ f∈F,∀ M,opNorm (f M) ≤ R) (hL : ∀ f∈F,LipschitzWith R f) : (∫ g : MatrixCoordinates (Fin n)→ℝ, |trace (matrixFactorProduct F (goeMatrix (j/n) g))/(n:ℝ)- ∫ h : MatrixCoordinates (Fin n)→ℝ,trace (matrixFactorProduct F (goeMatrix (j/n) h))/(n:ℝ) ∂Measure.pi (fun _=>gaussianReal 0 1)| ∂Measure.pi (fun _=>gaussianReal 0 1)) ≤ (2*exp (π^2/8))*((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*j)/(n:ℝ) := by have hnr : (0:ℝ)<n := Nat.cast_pos.mpr hn have hRr : (0:ℝ)<R := hR have hlr : (0:ℝ)<F.length := Nat.cast_pos.mpr hFl have hh := gaussianProduct_centered_L1 (goe_word_trace_lip_scaled hn hj.le F hF hL) (by change 0<((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*j)/(n:ℝ); positivity) apply hh.trans_eq change (2*exp (π^2/8))*(((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*j)/(n:ℝ))=_ ring
lemma goe_word_trace_centered_L1_all {n : ℕ} (hn : 0<n) {j : ℝ} (hj : 0<j) (F : List (Matrix (Fin n) (Fin n) ℝ→Matrix (Fin n) (Fin n) ℝ)) {R : NNReal} (hR : 0<R) (hF : ∀ f∈F,∀ M,opNorm (f M) ≤ R) (hL : ∀ f∈F,LipschitzWith R f) : (∫ g : MatrixCoordinates (Fin n)→ℝ, |trace (matrixFactorProduct F (goeMatrix (j/n) g))/(n:ℝ)- ∫ h : MatrixCoordinates (Fin n)→ℝ,trace (matrixFactorProduct F (goeMatrix (j/n) h))/(n:ℝ) ∂Measure.pi (fun _=>gaussianReal 0 1)| ∂Measure.pi (fun _=>gaussianReal 0 1)) ≤ (2*exp (π^2/8))*((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*j)/(n:ℝ) := by by_cases he : F=[] · subst F simp only [matrixFactorProduct_nil,List.length_nil,Nat.cast_zero,zero_mul,mul_zero,zero_div] simp · exact goe_word_trace_centered_L1 hn hj F (List.length_pos_iff.mpr he) hR hF hLend SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianProductUpperTailLipschitzimport OAI.Probability.SKGap.Terminal.SpinGaussianBoundimport OAI.Probability.SKGap.Gaussian.GaussianPartition
namespace OAI
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Realopen scoped BigOperators
def quadraticGaussianBound (j : ℝ) : ℝ := ∫ g : ℝ, exp (j*g^2/2) ∂gaussianReal 0 1
lemma quadraticGaussianBound_ge_one {j : ℝ} (hj : 0 ≤ j) (hj1 : j < 1) : 1 ≤ quadraticGaussianBound j := by have h := integral_mono (integrable_const (1:ℝ)) (gaussian_quadratic_integrable_sharp hj1) (fun g : ℝ=>one_le_exp (by positivity : 0 ≤ j*g^2/2)) simpa [quadraticGaussianBound] using h
lemma gaussianSpinPartition_pos (n : ℕ) (r : ℝ) (g : Disorder n) : 0 < gaussianSpinPartition n r g := Finset.sum_pos (fun _ _=>exp_pos _) Finset.univ_nonempty
lemma gaussianSpinPartition_measurable (n : ℕ) (r : ℝ) : Measurable (gaussianSpinPartition n r) := by unfold gaussianSpinPartition exact Finset.measurable_sum _ (fun x _=>Real.measurable_exp.comp (Finset.measurable_sum _ (fun e _=>(measurable_pi_apply e).const_mul _)))
lemma gaussianSpinPartition_mean_pos {n : ℕ} {r : ℝ} (hr : 0 ≤ r) : 0 < ∫ g, gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n) := by rw [gaussianSpinPartition_integral hr] exact mul_pos (by exact_mod_cast Fintype.card_pos) (exp_pos _)
lemma gaussianSpinPartition_second_moment {n : ℕ} {j r : ℝ} (hj : j < 1) (hr : 0 ≤ r) (hnr : (n:ℝ)*r ≤ j) : (∫ g,(gaussianSpinPartition n r g)^2 ∂gaussianCoordinates (Edge n)) ≤ quadraticGaussianBound j*(∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))^2 := by rw [gaussianSpinPartition_square_integral hr,gaussianSpinPartition_integral hr] have hc : (Fintype.card (Spin n):ℝ)=(2:ℝ)^n := by simp [Spin] have he : exp (r*(Fintype.card (Edge n):ℝ)-r*(n:ℝ)/2) ≤ exp (r*(Fintype.card (Edge n):ℝ)) := exp_le_exp.mpr (by nlinarith [mul_nonneg hr (show (0:ℝ) ≤ n by positivity)]) have hb := spin_quadratic_sum_bound hj hr hnr rw [← hc] at hb have hB : 0 ≤ quadraticGaussianBound j := integral_nonneg (fun _=>(exp_pos _).le) have hc0 : (0:ℝ) ≤ Fintype.card (Spin n) := by positivity calc _ ≤ (Fintype.card (Spin n):ℝ)*exp (r*(Fintype.card (Edge n):ℝ)-r*(n:ℝ)/2)* ((Fintype.card (Spin n):ℝ)*quadraticGaussianBound j) := mul_le_mul_of_nonneg_left hb (by positivity) _ ≤ (Fintype.card (Spin n):ℝ)*exp (r*(Fintype.card (Edge n):ℝ))* ((Fintype.card (Spin n):ℝ)*quadraticGaussianBound j) := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left he hc0) (mul_nonneg hc0 hB) _ = _ := by have h : exp (r*(Fintype.card (Edge n):ℝ))=exp (r*(Fintype.card (Edge n):ℝ)/2)^2 := by rw [← exp_nat_mul];congr 1;ring rw [h];ring
lemma gaussianSpinPartition_positive_probability {n : ℕ} {j r : ℝ} (hj0 : 0 ≤ j) (hj : j < 1) (hr : 0 ≤ r) (hnr : (n:ℝ)*r ≤ j) : 1/(4*quadraticGaussianBound j) ≤ (gaussianCoordinates (Edge n)).real {g | (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))/2 ≤ gaussianSpinPartition n r g} := by exact second_moment_positive_probability _ _ (gaussianSpinPartition_measurable n r) (gaussianSpinPartition_integrable n r) (gaussianSpinPartition_square_integrable n r) (gaussianSpinPartition_mean_pos hr) (lt_of_lt_of_le zero_lt_one (quadraticGaussianBound_ge_one hj0 hj)) rfl (gaussianSpinPartition_second_moment hj hr hnr)end SKGapendend
sectionnoncomputable sectionnamespace SKGapopen MeasureTheory ProbabilityTheory Real Setopen scoped BigOperators NNReal
lemma log_sum_exp_order {ι : Type*} [Fintype ι] [Nonempty ι] (f g : ι→ℝ) (d : ℝ) (h : ∀ i,f i ≤ g i+d) : log (∑ i,exp (f i)) ≤ log (∑ i,exp (g i))+d := by have hp : 0 < ∑ i,exp (f i) := Finset.sum_pos (fun i _=>exp_pos _) Finset.univ_nonempty have hq : 0 < ∑ i,exp (g i) := Finset.sum_pos (fun i _=>exp_pos _) Finset.univ_nonempty have hh : (∑ i,exp (f i)) ≤ (∑ i,exp (g i))*exp d := by rw [Finset.sum_mul] exact Finset.sum_le_sum (fun i _=> (exp_le_exp.mpr (h i)).trans_eq (exp_add _ _)) have he := log_le_log hp hh rw [log_mul hq.ne' (exp_pos _).ne',log_exp] at he exact he
lemma log_sum_exp_lipschitz {ι : Type*} [Fintype ι] [Nonempty ι] {E : Type*} [PseudoMetricSpace E] (f : ι→E→ℝ) {L : ℝ≥0} (hf : ∀ i,LipschitzWith L (f i)) : LipschitzWith L (fun x=>log (∑ i,exp (f i x))) := by apply LipschitzWith.of_dist_le_mul intro x y rw [Real.dist_eq,abs_le] constructor · have hh := log_sum_exp_order (fun i=>f i y) (fun i=>f i x) ((L:ℝ)*dist x y) (fun i=>by have hh := (hf i).dist_le_mul y x;rw [Real.dist_eq,dist_comm y x] at hh linarith only [le_abs_self (f i y-f i x),hh]) linarith only [hh] · have hh := log_sum_exp_order (fun i=>f i x) (fun i=>f i y) ((L:ℝ)*dist x y) (fun i=>by have hh := (hf i).dist_le_mul x y;rw [Real.dist_eq] at hh linarith only [le_abs_self (f i x-f i y),hh]) linarith only [hh]
lemma gaussianProduct_lower_tail_lipschitz {κ : Type*} [Fintype κ] {f : (κ→ℝ)→ℝ} {L : ℝ≥0} (hf : LipschitzWith L (fun x : EuclideanSpace ℝ κ=>f x.ofLp)) (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : (Measure.pi (fun _ : κ=>gaussianReal 0 1)).real {x | f x-∫ y,f y ∂Measure.pi (fun _ : κ=>gaussianReal 0 1) ≤ -u} ≤ exp (-2*u^2/(π^2*(L:ℝ)^2)) := by have hn : LipschitzWith L (fun x : EuclideanSpace ℝ κ=>-f x.ofLp) := by apply LipschitzWith.of_dist_le_mul intro x y simpa only [Real.dist_eq,neg_sub_neg,abs_sub_comm] using hf.dist_le_mul x y have h := gaussianProduct_upper_tail_lipschitz (f:=fun x=>-f x) hn hL hu simp only [integral_neg] at h convert h using 2 ext x;simp only [mem_ofPred_eq];constructor <;> intro hx <;> linarith only [hx]
lemma gaussian_log_anchor {κ : Type*} [Fintype κ] {f : (κ→ℝ)→ℝ} {L : ℝ≥0} (hf : LipschitzWith L (fun x : EuclideanSpace ℝ κ=>f x.ofLp)) (hL : 0 < L) {p b c : ℝ} (hc : 0 < c) (hpc : exp (-2*c^2/π^2) < p) (hp : p ≤ (Measure.pi (fun _ : κ=>gaussianReal 0 1)).real {x | b ≤ f x}) : b-c*(L:ℝ) ≤ ∫ y,f y ∂Measure.pi (fun _ : κ=>gaussianReal 0 1) := by by_contra hh have hs : {x | b ≤ f x} ⊆ {x | c*(L:ℝ) ≤ f x-∫ y,f y ∂Measure.pi (fun _ : κ=>gaussianReal 0 1)} := by intro x hx;dsimp only [mem_ofPred_eq] at *;linarith only [not_le.mp hh,hx] have ht := gaussianProduct_upper_tail_lipschitz hf hL (mul_nonneg hc.le (NNReal.coe_nonneg L)) have he : -2*(c*(L:ℝ))^2/(π^2*(L:ℝ)^2)= -2*c^2/π^2 := by have hLr : (L:ℝ) ≠ 0 := ne_of_gt hL field_simp rw [he] at ht have hm := measureReal_mono hs (measure_ne_top (Measure.pi (fun _ : κ=>gaussianReal 0 1)) _) linarith only [hp,ht,hm,hpc]end SKGapendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138import Mathlibimport OAI.Probability.SKGap.Localization.PhiBounds
namespace OAI
section
noncomputable sectionopen MeasureTheorynamespace SKGap.Stein
def hyper (b : Bool) (x : ℝ) : ℝ := if b then Real.sinh x else Real.cosh xlemma continuous_hyper (b : Bool) : Continuous (hyper b) := by unfold hyper; split_ifs <;> fun_proplemma hyper_hasDerivAt (b : Bool) (x : ℝ) : HasDerivAt (hyper b) (hyper (!b) x) x := by cases b <;> simpa only [hyper,Bool.not_false,Bool.not_true,Bool.false_eq_true,ite_false,ite_true] using (show HasDerivAt _ _ x from (by first | exact Real.hasDerivAt_cosh x | exact Real.hasDerivAt_sinh x))
lemma hyper_abs_le (b : Bool) (x : ℝ) : |hyper b x|≤Real.cosh x := by cases b · simp only [hyper,Bool.false_eq_true,ite_false,abs_of_pos (Real.cosh_pos _),le_refl] · exact abs_sinh_le_cosh x
def momentNum (p q : ℕ) (b : Bool) (d a : ℝ) : ℝ := ∫u in (0:ℝ)..1,weight a u*u^p*((1-u^2)/2)^q*hyper b (u*d)
def moment (p q : ℕ) (b : Bool) (z r a : ℝ) : ℝ := momentNum p q b (z-r) a/(Real.cosh z*Real.cosh r)
lemma moment_base (z r a : ℝ) : moment 0 0 false z r a=phi z r a := by rw [phi_eq] simp only [moment,momentNum,numerator,pow_zero,mul_one,hyper,Bool.false_eq_true,ite_false]
lemma momentNum_hasDerivAt_d (p q : ℕ) (b : Bool) (d a : ℝ) : HasDerivAt (fun d=>momentNum p q b d a) (momentNum (p+1) q (!b) d a) d := by unfold momentNum apply hasDerivAt_integral01 (F:=fun d u=>weight a u*u^p*((1-u^2)/2)^q*hyper b (u*d)) (F':=fun d u=>weight a u*u^(p+1)*((1-u^2)/2)^q*hyper (!b) (u*d)) · exact (((continuous_weight a).comp continuous_snd).mul (continuous_snd.pow p)|>.mul (((continuous_const.sub (continuous_snd.pow 2)).div_const 2).pow q)).mul ((continuous_hyper b).comp (continuous_snd.mul continuous_fst)) · exact (((continuous_weight a).comp continuous_snd).mul (continuous_snd.pow (p+1))|>.mul (((continuous_const.sub (continuous_snd.pow 2)).div_const 2).pow q)).mul ((continuous_hyper (!b)).comp (continuous_snd.mul continuous_fst)) · intro d u have H:=((hyper_hasDerivAt b (u*d)).comp d ((hasDerivAt_id d).const_mul u)).const_mul (weight a u*u^p*((1-u^2)/2)^q) convert! H using 1 simp only [pow_succ] ring
lemma momentNum_hasDerivAt_a (p q : ℕ) (b : Bool) (d a : ℝ) : HasDerivAt (fun a=>momentNum p q b d a) (momentNum p (q+1) b d a) a := by unfold momentNum apply hasDerivAt_integral01 (F:=fun a u=>weight a u*u^p*((1-u^2)/2)^q*hyper b (u*d)) (F':=fun a u=>weight a u*u^p*((1-u^2)/2)^(q+1)*hyper b (u*d)) · apply Continuous.mul · unfold weight; fun_prop · exact (continuous_hyper b).comp (continuous_snd.mul_const d) · apply Continuous.mul · unfold weight; fun_prop · exact (continuous_hyper b).comp (continuous_snd.mul_const d) · intro a u have H:=((((hasDerivAt_id a).mul_const (1-u^2)).div_const 2).exp).mul_const (u^p*((1-u^2)/2)^q*hyper b (u*d)) convert! H using 1 <;> (try funext x) <;> dsimp [weight] <;> simp only [pow_succ] <;> ring
lemma momentNum_abs_le (p q : ℕ) (b : Bool) (d a : ℝ) : |momentNum p q b d a|≤ momentNum 0 0 false d a := by unfold momentNum apply (intervalIntegral.abs_integral_le_integral_abs (by norm_num : (0:ℝ)≤1)).trans apply intervalIntegral.integral_mono_on (by norm_num : (0:ℝ)≤1) · apply Continuous.intervalIntegrable apply Continuous.abs exact (((continuous_weight a).mul (continuous_id.pow p)).mul (((continuous_const.sub (continuous_id.pow 2)).div_const 2).pow q)).mul ((continuous_hyper b).comp (continuous_id.mul_const d)) · apply Continuous.intervalIntegrable exact (((continuous_weight a).mul (continuous_id.pow 0)).mul (((continuous_const.sub (continuous_id.pow 2)).div_const 2).pow 0)).mul ((continuous_hyper false).comp (continuous_id.mul_const d)) · intro u hu have hu2 : u^2≤1 := by nlinarith [hu.1,hu.2] have hv0 : 0≤(1-u^2)/2 := by linarith have hv1 : (1-u^2)/2≤1 := by nlinarith [sq_nonneg u] have hp : u^p ≤ 1 := pow_le_one₀ hu.1 hu.2 have hq : ((1-u^2)/2)^q ≤ 1 := pow_le_one₀ hv0 hv1 simp only [abs_mul,abs_of_pos (show 0<weight a u from Real.exp_pos _), abs_pow,abs_of_nonneg hu.1,abs_of_nonneg hv0,pow_zero,mul_one, hyper,Bool.false_eq_true,ite_false] have hH:=hyper_abs_le b (u*d) change |if b=true then Real.sinh (u*d) else Real.cosh (u*d)|≤Real.cosh (u*d) at hH have hprod : u^p*((1-u^2)/2)^q≤1 := (mul_le_mul hp hq (pow_nonneg hv0 q) (by norm_num)).trans_eq (one_mul 1) have hh:=mul_le_mul (mul_le_mul_of_nonneg_left hprod (Real.exp_pos (a*(1-u^2)/2)).le) hH (abs_nonneg _) (by positivity) dsimp [weight] at * nlinarith only [hh]
lemma moment_relative_bound (p q : ℕ) (b : Bool) (z r a : ℝ) : |moment p q b z r a|≤phi z r a := by rw [moment,abs_div,abs_of_pos (mul_pos (Real.cosh_pos _) (Real.cosh_pos _)),←moment_base] exact div_le_div_of_nonneg_right (momentNum_abs_le p q b (z-r) a) (mul_pos (Real.cosh_pos _) (Real.cosh_pos _)).le
lemma moment_hasDerivAt_z (p q : ℕ) (b : Bool) (z r a : ℝ) : HasDerivAt (fun z=>moment p q b z r a) (moment (p+1) q (!b) z r a-Real.tanh z*moment p q b z r a) z := by have H:=((momentNum_hasDerivAt_d p q b (z-r) a).comp z ((hasDerivAt_id z).sub_const r)).div ((Real.hasDerivAt_cosh z).mul_const (Real.cosh r)) (ne_of_gt (mul_pos (Real.cosh_pos _) (Real.cosh_pos _))) convert! H using 1 dsimp [moment] rw [Real.tanh_eq_sinh_div_cosh] field_simp [ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)]
lemma moment_hasDerivAt_r (p q : ℕ) (b : Bool) (z r a : ℝ) : HasDerivAt (fun r=>moment p q b z r a) (-moment (p+1) q (!b) z r a-Real.tanh r*moment p q b z r a) r := by have H:=((momentNum_hasDerivAt_d p q b (z-r) a).comp r ((hasDerivAt_id r).const_sub z)).div ((Real.hasDerivAt_cosh r).const_mul (Real.cosh z)) (ne_of_gt (mul_pos (Real.cosh_pos _) (Real.cosh_pos _))) convert! H using 1 dsimp [moment] rw [Real.tanh_eq_sinh_div_cosh] field_simp [ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)]
lemma moment_hasDerivAt_a (p q : ℕ) (b : Bool) (z r a : ℝ) : HasDerivAt (fun a=>moment p q b z r a) (moment p (q+1) b z r a) a := by exact (momentNum_hasDerivAt_a p q b (z-r) a).div_const _
end SKGap.Stein
endend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135import Mathlibimport OAI.Probability.SKGap.Model
namespace OAI
section
noncomputable sectionopen MeasureTheory Filteropen scoped Topologynamespace SKGap.Stein
lemma hasDerivAt_integral01 {F F' : ℝ→ℝ→ℝ} (hF : Continuous (fun p : ℝ×ℝ=>F p.1 p.2)) (hF' : Continuous (fun p : ℝ×ℝ=>F' p.1 p.2)) (hd : ∀ z u,HasDerivAt (fun z=>F z u) (F' z u) z) (z : ℝ) : HasDerivAt (fun z=>∫u in (0:ℝ)..1,F z u) (∫u in (0:ℝ)..1,F' z u) z := by obtain ⟨C,hC⟩ := (isCompact_Icc.prod isCompact_Icc).exists_bound_of_continuousOn (hF'.continuousOn : ContinuousOn (fun p : ℝ×ℝ=>F' p.1 p.2) ((Set.Icc (z-1) (z+1))×ˢ(Set.Icc (0:ℝ) 1))) have hc (x : ℝ) : Continuous (F x) := hF.comp (continuous_const.prodMk continuous_id) have hc' (x : ℝ) : Continuous (F' x) := hF'.comp (continuous_const.prodMk continuous_id) exact (intervalIntegral.hasDerivAt_integral_of_dominated_loc_of_deriv_le (F:=F) (F':=F') (bound:=fun _=>C) (s:=Set.Icc (z-1) (z+1)) (Icc_mem_nhds (by linarith) (by linarith)) (Eventually.of_forall (fun x=>(hc x).aestronglyMeasurable)) (hc z|>.intervalIntegrable _ _) (hc' z).aestronglyMeasurable (Eventually.of_forall (by intro u hu x hx rw [Set.uIoc_of_le (by norm_num : (0:ℝ)≤1)] at hu exact hC (x,u) ⟨hx,hu.1.le,hu.2⟩)) intervalIntegrable_const (Eventually.of_forall (fun u _ x _=>hd x u))).2
def weight (a u : ℝ) : ℝ := Real.exp (a*(1-u^2)/2)def numerator (z r a : ℝ) : ℝ := ∫u in (0:ℝ)..1,weight a u*Real.cosh (u*(z-r))def numeratorZ (z r a : ℝ) : ℝ := ∫u in (0:ℝ)..1,weight a u*u*Real.sinh (u*(z-r))def phi (z r a : ℝ) : ℝ := ∫u in (0:ℝ)..1, weight a u*Real.cosh (u*(z-r))/(Real.cosh z*Real.cosh r)def phiZ (z r a : ℝ) : ℝ := numeratorZ z r a/(Real.cosh z*Real.cosh r)-Real.tanh z*phi z r a
lemma continuous_weight (a : ℝ) : Continuous (weight a) := by unfold weight; fun_prop
lemma phi_eq (z r a : ℝ) : phi z r a=numerator z r a/(Real.cosh z*Real.cosh r) := by exact intervalIntegral.integral_div _ _
lemma numerator_hasDerivAt (z r a : ℝ) : HasDerivAt (fun z=>numerator z r a) (numeratorZ z r a) z := by unfold numerator numeratorZ apply hasDerivAt_integral01 (F:=fun z u=>weight a u*Real.cosh (u*(z-r))) (F':=fun z u=>weight a u*u*Real.sinh (u*(z-r))) · unfold weight; fun_prop · unfold weight; fun_prop · intro z u convert! ((Real.hasDerivAt_cosh (u*(z-r))).comp z (((hasDerivAt_id z).sub_const r).const_mul u)).const_mul (weight a u) using 1 ring
lemma phi_hasDerivAt (z r a : ℝ) : HasDerivAt (fun z=>phi z r a) (phiZ z r a) z := by have h := (numerator_hasDerivAt z r a).div ((Real.hasDerivAt_cosh z).mul_const (Real.cosh r)) (ne_of_gt (mul_pos (Real.cosh_pos z) (Real.cosh_pos r))) convert! h using 1 · funext x; exact phi_eq x r a · rw [phiZ,phi_eq,Real.tanh_eq_sinh_div_cosh] field_simp [ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)]
lemma weight_hasDerivAt (a u : ℝ) : HasDerivAt (weight a) (-a*u*weight a u) u := by unfold weight convert! (Real.hasDerivAt_exp _).comp u ((((hasDerivAt_id u).pow 2).const_sub 1).const_mul a |>.div_const 2) using 1 dsimp ring
lemma boundary_hasDerivAt (z r a u : ℝ) : HasDerivAt (fun u=>weight a u*Real.sinh (u*(z-r))) (weight a u*((z-r)*Real.cosh (u*(z-r))-a*u*Real.sinh (u*(z-r)))) u := by convert! (weight_hasDerivAt a u).mul ((Real.hasDerivAt_sinh (u*(z-r))).comp u ((hasDerivAt_id u).mul_const (z-r))) using 1 dsimp ring
lemma numerator_boundary (z r a : ℝ) : (z-r)*numerator z r a-a*numeratorZ z r a=Real.sinh (z-r) := by have hc1 : Continuous (fun u=>weight a u*Real.cosh (u*(z-r))) := by exact (continuous_weight a).mul (by fun_prop) have hc2 : Continuous (fun u=>weight a u*u*Real.sinh (u*(z-r))) := by exact ((continuous_weight a).mul continuous_id).mul (by fun_prop) have he : (fun u=>weight a u*((z-r)*Real.cosh (u*(z-r))-a*u*Real.sinh (u*(z-r))))= (fun u=>(z-r)*(weight a u*Real.cosh (u*(z-r)))-a*(weight a u*u*Real.sinh (u*(z-r)))) := by funext u; ring have H:=intervalIntegral.integral_eq_sub_of_hasDerivAt (a:=(0:ℝ)) (b:=1) (fun u _=>boundary_hasDerivAt z r a u) (show IntervalIntegrable (fun u=>weight a u*((z-r)*Real.cosh (u*(z-r))-a*u*Real.sinh (u*(z-r)))) volume 0 1 from by rw [he]; exact ((hc1.const_mul (z-r)).sub (hc2.const_mul a)).intervalIntegrable _ _) rw [he,intervalIntegral.integral_sub ((hc1.const_mul (z-r)).intervalIntegrable _ _) ((hc2.const_mul a).intervalIntegrable _ _),intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at H simpa only [numerator,numeratorZ,weight,one_pow,sub_self,mul_zero,zero_div, Real.exp_zero,one_mul,zero_mul,Real.sinh_zero,sub_zero] using H
theorem phi_stein (z r a : ℝ) : (z-r-a*Real.tanh z)*phi z r a-a*phiZ z r a=Real.tanh z-Real.tanh r := by rw [phiZ,phi_eq] have H:=numerator_boundary z r a have hId : Real.sinh (z-r)/(Real.cosh z*Real.cosh r)=Real.tanh z-Real.tanh r := by rw [Real.sinh_sub,Real.tanh_eq_sinh_div_cosh,Real.tanh_eq_sinh_div_cosh] field_simp [ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)] rw [←hId] field_simp [ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)] nlinarith [H]
lemma phi_pos (z r a : ℝ) : 0<phi z r a := by apply intervalIntegral.integral_pos (by norm_num : (0:ℝ)<1) · apply Continuous.continuousOn; unfold weight exact Continuous.div_const (by fun_prop) _ · intro u _; exact (div_pos (mul_pos (Real.exp_pos _) (Real.cosh_pos _)) (mul_pos (Real.cosh_pos _) (Real.cosh_pos _))).le · exact ⟨0,by norm_num,div_pos (mul_pos (Real.exp_pos _) (Real.cosh_pos _)) (mul_pos (Real.cosh_pos _) (Real.cosh_pos _))⟩
lemma phiZ_at_diagonal (r a : ℝ) : phiZ r r a= -Real.tanh r*phi r r a := by simp [phiZ,numeratorZ]
lemma phi_stein_deriv (z r a : ℝ) : (z-r-a*Real.tanh z)*phi z r a-a*deriv (fun z=>phi z r a) z=Real.tanh z-Real.tanh r := by rw [(phi_hasDerivAt z r a).deriv] exact phi_stein z r a
end SKGap.Stein
endend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142import Mathlibimport OAI.Probability.SKGap.Model
namespace OAI
sectionnoncomputable sectionopen MeasureTheory ProbabilityTheory Matrixopen scoped BigOperators ENNReal NNRealnamespace SKGap.GaussianDensityvariable {ι : Type*} [Fintype ι]
theorem pi_gaussian_density (m : ι → ℝ) (v : ι → ℝ≥0) (hv : ∀ i,v i ≠ 0) : Measure.pi (fun i => gaussianReal (m i) (v i)) = (volume : Measure (ι → ℝ)).withDensity (fun x => ENNReal.ofReal (∏ i,gaussianPDFReal (m i) (v i) (x i))) := by apply Measure.pi_eq intro s hs rw [withDensity_apply _ (MeasurableSet.univ_pi hs)] have hi : Integrable (fun x : ι → ℝ => ∏ i,gaussianPDFReal (m i) (v i) (x i)) (volume.restrict (Set.univ.pi s)) := by exact (Integrable.fintype_prod (fun i => integrable_gaussianPDFReal (m i) (v i))).restrict rw [← ofReal_integral_eq_lintegral_ofReal hi (Filter.Eventually.of_forall (fun x => Finset.prod_nonneg (fun i _ => gaussianPDFReal_nonneg _ _ _)))] change ENNReal.ofReal (∫ x, (∏ i,gaussianPDFReal (m i) (v i) (x i)) ∂(Measure.pi (fun _ : ι => (volume : Measure ℝ))).restrict (Set.univ.pi s))=_ rw [Measure.restrict_pi_pi,integral_fintype_prod_eq_prod, ENNReal.ofReal_prod_of_nonneg (fun i _ => integral_nonneg (fun x => gaussianPDFReal_nonneg _ _ _))] apply Finset.prod_congr rfl intro i _ rw [gaussianReal_of_var_ne_zero _ (hv i),withDensity_apply _ (hs i)] exact ofReal_integral_eq_lintegral_ofReal (integrable_gaussianPDFReal (m i) (v i)).restrict (Filter.Eventually.of_forall (gaussianPDFReal_nonneg _ _))
lemma measurable_productPDF (m : ι → ℝ) (v : ι → ℝ≥0) : Measurable (fun x : ι → ℝ => ENNReal.ofReal (∏ i,gaussianPDFReal (m i) (v i) (x i))) := by fun_prop
end SKGap.GaussianDensityendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import Mathlibimport OAI.Probability.SKGap.Gaussian.GaussianDisintegration
namespace OAI
sectionnoncomputable sectionnamespace SKGap.GaussianRegressionopen MeasureTheory ProbabilityTheory Matrixopen scoped BigOperatorsvariable {Ω ι κ : Type*} [MeasurableSpace Ω] [Fintype ι] [Fintype κ] {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ}
lemma residual_mean_zero (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) (hx : ∀ i, (∫ w, X w i ∂P)=0) (hy : ∀ k, (∫ w, Y w k ∂P)=0) (i : ι) : (∫ w, (X w-K*ᵥY w) i ∂P)=0 := by have hK : Integrable (fun w => ∑ k,K i k*Y w k) P := ((hXY.snd.map (matrixCLM K)).eval i).integrable change (∫ w, X w i-∑ k, K i k*Y w k ∂P)=0 rw [integral_sub (hXY.fst.eval i).integrable hK, integral_finsetSum _ (fun k _ => (hXY.snd.eval k).integrable.const_mul _)] simp only [integral_const_mul,hx,hy,mul_zero,Finset.sum_const_zero,sub_zero]
lemma residual_cross_covariance (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) (hc : ∀ i k, cov[fun w => X w i,fun w => Y w k;P]= ∑ l, K i l*cov[fun w => Y w l,fun w => Y w k;P]) (i : ι) (k : κ) : cov[fun w => (X w-K*ᵥY w) i,fun w => Y w k;P]=0 := by have := hXY.isProbabilityMeasure have hK : MemLp (fun w => ∑ l,K i l*Y w l) 2 P := ((hXY.snd.map (matrixCLM K)).eval i).memLp_two change cov[fun w => X w i-∑ l,K i l*Y w l,fun w => Y w k;P]=0 rw [covariance_fun_sub_left (hXY.fst.eval i).memLp_two hK (hXY.snd.eval k).memLp_two, covariance_fun_sum_left (fun l => (hXY.snd.eval l).memLp_two.const_mul _) (hXY.snd.eval k).memLp_two] simp only [covariance_const_mul_left,hc,sub_self]
lemma residual_covariance (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) (hc : ∀ i k, cov[fun w => X w i,fun w => Y w k;P]= ∑ l, K i l*cov[fun w => Y w l,fun w => Y w k;P]) (i k : ι) : cov[fun w => (X w-K*ᵥY w) i,fun w => (X w-K*ᵥY w) k;P]= cov[fun w => X w i,fun w => X w k;P]- ∑ l, K i l*cov[fun w => Y w l,fun w => X w k;P] := by have := hXY.isProbabilityMeasure have hR := (residual_joint_gaussian hXY K).fst have hK (q : ι) : MemLp (fun w => ∑ l,K q l*Y w l) 2 P := ((hXY.snd.map (matrixCLM K)).eval q).memLp_two change cov[fun w => (X w-K*ᵥY w) i,fun w => X w k-∑ l,K k l*Y w l;P]=_ rw [covariance_fun_sub_right (hR.eval i).memLp_two (hXY.fst.eval k).memLp_two (hK k), covariance_fun_sum_right (fun l => (hXY.snd.eval l).memLp_two.const_mul _) (hR.eval i).memLp_two] simp only [covariance_const_mul_right,residual_cross_covariance hXY K hc,mul_zero, Finset.sum_const_zero,sub_zero] change cov[fun w => X w i-∑ l,K i l*Y w l,fun w => X w k;P]=_ rw [covariance_fun_sub_left (hXY.fst.eval i).memLp_two (hK i) (hXY.fst.eval k).memLp_two, covariance_fun_sum_left (fun l => (hXY.snd.eval l).memLp_two.const_mul _) (hXY.fst.eval k).memLp_two] simp only [covariance_const_mul_left]
end SKGap.GaussianRegressionendend
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318import Mathlibimport OAI.Probability.SKGap.Localization.LogPartitionDeviationProbability
namespace OAI
sectionopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperatorsopen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNRealopen MeasureTheory ProbabilityTheoryopen scoped BigOperators NNReal ENNRealopen MeasureTheory ProbabilityTheory Filteropen scoped BigOperators NNReal ENNRealnamespace SKGapCutoff
noncomputable def replicaTailWeight {n : ℕ} (J : Interaction n) (ε : ℝ) : ℝ := ∑ x : Spin n, ∑ y : Spin n, if ε * n < |replicaOverlap x y| then Real.exp (energy J x + energy J y) else 0
noncomputable def replicaTail {n : ℕ} (J : Interaction n) (ε : ℝ) : ℝ := ∑ x : Spin n, ∑ y : Spin n, if ε * n < |replicaOverlap x y| then gibbs J x * gibbs J y else 0
lemma replicaTailWeight_nonneg {n : ℕ} (J : Interaction n) (ε : ℝ) : 0 ≤ replicaTailWeight J ε := by apply Finset.sum_nonneg intro x _ apply Finset.sum_nonneg intro y _ split_ifs <;> positivity
lemma replicaTail_eq_ratio {n : ℕ} (J : Interaction n) (ε : ℝ) : replicaTail J ε = replicaTailWeight J ε / partition J ^ 2 := by unfold replicaTail replicaTailWeight gibbs simp_rw [Finset.sum_div] apply Finset.sum_congr rfl intro x _ apply Finset.sum_congr rfl intro y _ split_ifs · rw [Real.exp_add] ring · simp
lemma replicaTail_nonneg {n : ℕ} (J : Interaction n) (ε : ℝ) : 0 ≤ replicaTail J ε := by rw [replicaTail_eq_ratio] exact div_nonneg (replicaTailWeight_nonneg J ε) (sq_nonneg _)
lemma replicaTailWeight_le_partition_sq {n : ℕ} (J : Interaction n) (ε : ℝ) : replicaTailWeight J ε ≤ partition J ^ 2 := by rw [partition_sq_eq_sum] apply Finset.sum_le_sum intro x _ apply Finset.sum_le_sum intro y _ split_ifs · exact le_rfl · positivity
lemma replicaTail_le_one {n : ℕ} (J : Interaction n) (ε : ℝ) : replicaTail J ε ≤ 1 := by rw [replicaTail_eq_ratio, div_le_one (sq_pos_of_pos (partition_pos J))] exact replicaTailWeight_le_partition_sq J ε
lemma integrable_replicaTailWeight (β ε : ℝ) (n : ℕ) : Integrable (fun g => replicaTailWeight (sampledInteraction g) ε) (disorderLaw β n) := by apply integrable_finsetSum intro x _ apply integrable_finsetSum intro y _ by_cases h : ε * n < |replicaOverlap x y| · simp only [h, ite_true] exact integrable_exp_combined_energy β x y · simp only [h, ite_false] exact integrable_zero _ ℝ _
lemma integral_replicaTailWeight (β ε : ℝ) {n : ℕ} (hn : 0 < n) : (∫ g, replicaTailWeight (sampledInteraction g) ε ∂disorderLaw β n) = Real.exp (β^2*((n : ℝ)-2)/2) * ∑ x : Spin n, ∑ y : Spin n, if ε*n < |replicaOverlap x y| then Real.exp (β^2 * replicaOverlap x y ^ 2 / (2*n)) else 0 := by have hi (x y : Spin n) : Integrable (fun g => if ε*n < |replicaOverlap x y| then Real.exp (energy (sampledInteraction g) x + energy (sampledInteraction g) y) else 0) (disorderLaw β n) := by split_ifs · exact integrable_exp_combined_energy β x y · exact integrable_zero _ ℝ _ unfold replicaTailWeight rw [integral_finsetSum _ (fun x _ => integrable_finsetSum _ (fun y _ => hi x y))] simp_rw [integral_finsetSum _ (fun y _ => hi _ y), Finset.mul_sum] apply Finset.sum_congr rfl intro x _ apply Finset.sum_congr rfl intro y _ split_ifs · rw [integral_exp_combined_energy β hn, Real.exp_add] · simp
lemma replicaTailWeight_annealed_identity (β ε : ℝ) {n : ℕ} (hn : 0 < n) : (∫ g, replicaTailWeight (sampledInteraction g) ε ∂disorderLaw β n) / (∫ g, partition (sampledInteraction g) ∂disorderLaw β n)^2 = Real.exp (-β^2/2) * (∑ x : Spin n, if ε*n < |magnetization x| then Real.exp (β^2 * magnetization x ^ 2 / (2*n)) else 0) / (2 : ℝ)^n := by rw [integral_replicaTailWeight β ε hn, integral_partition_sampled β hn] simp_rw [sum_replicaOverlap _ (fun z => if ε*n < |z| then Real.exp (β^2*z^2/(2*n)) else 0)] simp only [Finset.sum_const, Finset.card_univ, card_spin, nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat, mul_pow] have he : Real.exp (β^2*((n : ℝ)-2)/2) = Real.exp (-β^2/2) * Real.exp (β^2*((n : ℝ)-1)/4)^2 := by rw [← Real.exp_nat_mul, ← Real.exp_add] congr 1 ring rw [he] field_simp
lemma sign_square_tail_le (β q ε : ℝ) (hβq : β^2 < q) (hq : q < 1) (hε : 0 < ε) {n : ℕ} (hn : 0 < n) : (∑ x : Spin n, if ε*n < |magnetization x| then Real.exp (β^2 * magnetization x ^ 2 / (2*n)) else 0) / (2 : ℝ)^n ≤ Real.exp (-((q-β^2)*ε^2*n/2)) * (Real.sqrt (1-q))⁻¹ := by have hq0 : 0 ≤ q := (sq_nonneg β).trans hβq.le have hqβ : 0 ≤ q-β^2 := sub_nonneg.mpr hβq.le have hnR : 0 < (n : ℝ) := by exact_mod_cast hn have hs := sign_square_moment_le (Real.sqrt q) (by rwa [Real.sq_sqrt hq0]) hn rw [Real.sq_sqrt hq0] at hs have hpoint (x : Spin n) : (if ε*n < |magnetization x| then Real.exp (β^2 * magnetization x ^ 2 / (2*n)) else 0) ≤ Real.exp (-((q-β^2)*ε^2*n/2)) * Real.exp (q * magnetization x ^ 2 / (2*n)) := by split_ifs with hx · rw [← Real.exp_add] apply Real.exp_le_exp.mpr have hsq : ε^2 * (n : ℝ)^2 ≤ magnetization x ^ 2 := by have h := (sq_le_sq₀ (by positivity : 0 ≤ ε*(n : ℝ)) (abs_nonneg _)).mpr hx.le simpa only [mul_pow, sq_abs] using h have hm := mul_le_mul_of_nonneg_left hsq hqβ have hd : (q-β^2)*ε^2*n/2 ≤ (q-β^2) * magnetization x ^ 2 / (2*n) := by apply (le_div_iff₀ (by positivity : 0 < (2 : ℝ)*n)).mpr nlinarith rw [sub_mul q (β^2) (magnetization x^2), sub_div] at hd linarith · positivity calc _ ≤ (∑ x : Spin n, Real.exp (-((q-β^2)*ε^2*n/2)) * Real.exp (q * magnetization x ^ 2 / (2*n))) / (2 : ℝ)^n := div_le_div_of_nonneg_right (Finset.sum_le_sum fun x _ => hpoint x) (by positivity) _ = Real.exp (-((q-β^2)*ε^2*n/2)) * ((∑ x : Spin n, Real.exp (q * magnetization x^2/(2*n))) / (2 : ℝ)^n) := by rw [← Finset.mul_sum] ring _ ≤ _ := mul_le_mul_of_nonneg_left hs (Real.exp_pos _).le
lemma replicaTailWeight_annealed_bound (β q ε : ℝ) (hβq : β^2 < q) (hq : q < 1) (hε : 0 < ε) {n : ℕ} (hn : 0 < n) : (∫ g, replicaTailWeight (sampledInteraction g) ε ∂disorderLaw β n) / (∫ g, partition (sampledInteraction g) ∂disorderLaw β n)^2 ≤ Real.exp (-((q-β^2)*ε^2*n/2)) * (Real.sqrt (1-q))⁻¹ := by rw [replicaTailWeight_annealed_identity β ε hn, mul_div_assoc] have he : Real.exp (-β^2/2) ≤ 1 := Real.exp_le_one_iff.mpr (by nlinarith [sq_nonneg β]) calc _ ≤ Real.exp (-β^2/2) * (Real.exp (-((q-β^2)*ε^2*n/2)) * (Real.sqrt (1-q))⁻¹) := mul_le_mul_of_nonneg_left (sign_square_tail_le β q ε hβq hq hε hn) (Real.exp_pos _).le _ ≤ _ := by simpa only [one_mul] using mul_le_mul_of_nonneg_right he (by positivity)
lemma probability_markov_real {E : Type*} [MeasurableSpace E] (μ : Measure E) [IsFiniteMeasure μ] (Y : E → ℝ) (hY : Integrable Y μ) (hY0 : ∀ x, 0 ≤ Y x) (t : ℝ) (ht : 0 < t) : μ {x | t ≤ Y x} ≤ ENNReal.ofReal ((∫ x, Y x ∂μ) / t) := by have h := mul_meas_ge_le_integral_of_nonneg (μ := μ) (Filter.Eventually.of_forall hY0) hY t rw [mul_comm t, ← le_div_iff₀ ht] at h rw [← ENNReal.ofReal_toReal (measure_ne_top μ _)] exact ENNReal.ofReal_le_ofReal h
lemma scalar_log_ratio_tail (Z m W δ a : ℝ) (hZ0 : 0 < Z) (hm : 0 < m) (hδ : 0 < δ) (hlog : Real.log m-a ≤ Real.log Z) (hW : δ < W/Z^2) : δ * Real.exp (-2*a) ≤ W/m^2 := by have hZ : m * Real.exp (-a) ≤ Z := by have he := Real.exp_le_exp.mpr hlog rw [show Real.log m-a = Real.log m + (-a) by ring, Real.exp_add, Real.exp_log hm, Real.exp_log hZ0] at he exact he have hZ2 := pow_le_pow_left₀ (mul_nonneg hm.le (Real.exp_pos _).le) hZ 2 have he : (m * Real.exp (-a))^2 = m^2 * Real.exp (-2*a) := by rw [mul_pow, ← Real.exp_nat_mul] congr 2 ring rw [he] at hZ2 rw [lt_div_iff₀ (sq_pos_of_pos hZ0)] at hW apply (le_div_iff₀ (sq_pos_of_pos hm)).mpr nlinarith [mul_le_mul_of_nonneg_left hZ2 hδ.le]
lemma divide_exponential_scalar (W m δ a : ℝ) : (W/m^2) / (δ*Real.exp (-2*a)) = (Real.exp (2*a)/δ) * (W/m^2) := by rw [show -2*a = -(2*a) by ring, Real.exp_neg] simp only [div_eq_mul_inv, mul_inv_rev, inv_inv] ring
lemma replicaTail_probability_transfer (β ε δ a : ℝ) {n : ℕ} (hn : 0 < n) (hδ : 0 < δ) : (disorderLaw β n) {g | δ < replicaTail (sampledInteraction g) ε} ≤ (disorderLaw β n) {g | Real.log (partition (sampledInteraction g)) < Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n) - a} + ENNReal.ofReal ((Real.exp (2*a)/δ) * ((∫ g, replicaTailWeight (sampledInteraction g) ε ∂disorderLaw β n) / (∫ g, partition (sampledInteraction g) ∂disorderLaw β n)^2)) := by let μ := disorderLaw β n let : IsProbabilityMeasure μ := by dsimp [μ, disorderLaw]; infer_instance let m := ∫ g, partition (sampledInteraction g) ∂μ have hm : 0 < m := by dsimp [m, μ]; rw [integral_partition_sampled β hn]; positivity let Y := fun g : GaussianCoordinates n => replicaTailWeight (sampledInteraction g) ε / m^2 let t := δ * Real.exp (-2*a) have ht : 0 < t := by dsimp [t]; positivity have hY : Integrable Y μ := (integrable_replicaTailWeight β ε n).div_const _ have hY0 (g) : 0 ≤ Y g := div_nonneg (replicaTailWeight_nonneg _ ε) (sq_nonneg _) have hsub : {g | δ < replicaTail (sampledInteraction g) ε} ⊆ {g | Real.log (partition (sampledInteraction g)) < Real.log m - a} ∪ {g | t ≤ Y g} := by intro g hg by_cases hl : Real.log (partition (sampledInteraction g)) < Real.log m - a · exact Or.inl hl right change δ * Real.exp (-2*a) ≤ replicaTailWeight (sampledInteraction g) ε / m^2 apply scalar_log_ratio_tail _ _ _ _ _ (partition_pos _) hm hδ (le_of_not_gt hl) rwa [← replicaTail_eq_ratio] have hmarkov := probability_markov_real μ Y hY hY0 t ht have hid : (∫ g, Y g ∂μ) / t = (Real.exp (2*a)/δ) * ((∫ g, replicaTailWeight (sampledInteraction g) ε ∂μ) / m^2) := by dsimp [Y, t] rw [integral_div, divide_exponential_scalar] rw [hid] at hmarkov exact (measure_mono hsub).trans ((measure_union_le _ _).trans (add_le_add le_rfl hmarkov))
lemma replicaTail_disorder_probability_bound (β q ε δ : ℝ) (hβq : β^2 < q) (hq : q < 1) (hε : 0 < ε) (hδ : 0 < δ) {n : ℕ} (hn : 0 < n) : (disorderLaw β n) {g | δ < replicaTail (sampledInteraction g) ε} ≤ (disorderLaw β n) {g | (q-β^2)*ε^2/8 < |(Real.log (partition (sampledInteraction g)) - Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) / n|} + ENNReal.ofReal (((Real.sqrt (1-q))⁻¹ / δ) * Real.exp (-((q-β^2)*ε^2*n/4))) := by have hnR : 0 < (n : ℝ) := by exact_mod_cast hn have h := replicaTail_probability_transfer β ε δ ((q-β^2)*ε^2*n/8) hn hδ apply h.trans apply add_le_add · apply measure_mono intro g hg have hd : (Real.log (partition (sampledInteraction g)) - Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) / n < -((q-β^2)*ε^2/8) := by apply (div_lt_iff₀ hnR).mpr change Real.log (partition (sampledInteraction g)) < _ at hg linarith change (q-β^2)*ε^2/8 < _ linarith [neg_le_abs ((Real.log (partition (sampledInteraction g)) - Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) / n)] · apply ENNReal.ofReal_le_ofReal calc _ ≤ (Real.exp (2*((q-β^2)*ε^2*n/8))/δ) * (Real.exp (-((q-β^2)*ε^2*n/2)) * (Real.sqrt (1-q))⁻¹) := mul_le_mul_of_nonneg_left (replicaTailWeight_annealed_bound β q ε hβq hq hε hn) (by positivity) _ = _ := by have he : Real.exp (2*((q-β^2)*ε^2*(n : ℝ)/8)) * Real.exp (-((q-β^2)*ε^2*n/2)) = Real.exp (-((q-β^2)*ε^2*n/4)) := by rw [← Real.exp_add] congr 1 ring calc _ = (Real.exp (2*((q-β^2)*ε^2*(n : ℝ)/8)) * Real.exp (-((q-β^2)*ε^2*n/2))) * (Real.sqrt (1-q))⁻¹ / δ := by ring _ = _ := by rw [he]; ring
lemma replica_overlap_vanishes (β : ℝ) (hβ : β^2 < 1) (ε : ℝ) (hε : 0 < ε) : DisorderLimit β (fun _ J => replicaTail J ε) 0 := by intro δ hδ let q := (β^2+1)/2 have hβq : β^2 < q := by dsimp [q]; linarith have hq : q < 1 := by dsimp [q]; linarith have ha : 0 < (q-β^2)*ε^2/8 := by positivity have hb : 0 < (q-β^2)*ε^2/4 := by positivity have hlog := log_partition_annealed_difference_limit β hβ ((q-β^2)*ε^2/8) ha simp only [sub_zero] at hlog have hexp : Tendsto (fun n : ℕ => Real.exp (-((q-β^2)*ε^2*n/4))) atTop (nhds 0) := by have hlin := (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n : ℝ)) atTop atTop) |>.const_mul_atTop hb have he := Real.tendsto_exp_neg_atTop_nhds_zero.comp hlin convert he using 1 ext n congr 1 ring have hbound : Tendsto (fun n : ℕ => ENNReal.ofReal (((Real.sqrt (1-q))⁻¹/δ) * Real.exp (-((q-β^2)*ε^2*n/4)))) atTop (nhds 0) := by simpa only [Function.comp_def, mul_zero, ENNReal.ofReal_zero] using ENNReal.continuous_ofReal.continuousAt.tendsto.comp (hexp.const_mul ((Real.sqrt (1-q))⁻¹/δ)) have hsum := hlog.add hbound simp only [zero_add] at hsum apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hsum (Eventually.of_forall (fun _ => bot_le)) filter_upwards [eventually_ge_atTop 1] with n hn simpa only [sub_zero, abs_of_nonneg (replicaTail_nonneg _ _)] using replicaTail_disorder_probability_bound β q ε δ hβq hq hε hδ (by omega : 0 < n)
end SKGapCutoff
open MeasureTheory ProbabilityTheoryopen scoped BigOperators Matrix Matrix.Norms.Elementwise
end
end OAIlean/OAI/Probability/SKGap/Entropy/WeightedMomentComparison.leanAdded+78
lean/OAI/Probability/SKGap/Entropy/WeightedRateAssembly.leanAdded+39
lean/OAI/Probability/SKGap/Entropy/WeightedScalarMoments.leanAdded+69
lean/OAI/Probability/SKGap/Entropy/WordUniformCost.leanAdded+106
lean/OAI/Probability/SKGap/Gaussian/AdaptiveInnovationSquareTails.leanAdded+96
lean/OAI/Probability/SKGap/Gaussian/ConditionalGramTail.leanAdded+94
lean/OAI/Probability/SKGap/Gaussian/ConditionalUniformTail.leanAdded+122
lean/OAI/Probability/SKGap/Gaussian/DiagonalNormTail.leanAdded+47
lean/OAI/Probability/SKGap/Gaussian/FourierMoment.leanAdded+74
lean/OAI/Probability/SKGap/Gaussian/GOEGaussian.leanAdded+64
lean/OAI/Probability/SKGap/Gaussian/GOERowTail.leanAdded+98
lean/OAI/Probability/SKGap/Gaussian/GOEScalarTail.leanAdded+158
lean/OAI/Probability/SKGap/Gaussian/GaussMoment.leanAdded+511
lean/OAI/Probability/SKGap/Gaussian/GaussianCompactTailRate.leanAdded+186
lean/OAI/Probability/SKGap/Gaussian/GaussianCoordinateMemLp.leanAdded+109
lean/OAI/Probability/SKGap/Gaussian/GaussianCoordinates.leanAdded+187
lean/OAI/Probability/SKGap/Gaussian/GaussianDisintegration.leanAdded+56
lean/OAI/Probability/SKGap/Gaussian/GaussianFiniteIBPError.leanAdded+43
lean/OAI/Probability/SKGap/Gaussian/GaussianGramMomentsJoined.leanAdded+197
lean/OAI/Probability/SKGap/Gaussian/GaussianLinearDensity.leanAdded+170
lean/OAI/Probability/SKGap/Gaussian/GaussianMarginal.leanAdded+175
lean/OAI/Probability/SKGap/Gaussian/GaussianMatrixChaining.leanAdded+82
lean/OAI/Probability/SKGap/Gaussian/GaussianPDFMoment.leanAdded+172
lean/OAI/Probability/SKGap/Gaussian/GaussianPartition.leanAdded+163
lean/OAI/Probability/SKGap/Gaussian/GaussianProductIntegral.leanAdded+73
lean/OAI/Probability/SKGap/Gaussian/GaussianProductPower.leanAdded+163
lean/OAI/Probability/SKGap/Gaussian/GaussianProductUpperTailLipschitz.leanAdded+103
lean/OAI/Probability/SKGap/Gaussian/GaussianQuadratic.leanAdded+202
lean/OAI/Probability/SKGap/Gaussian/GaussianQuadraticSupComparison.leanAdded+147
lean/OAI/Probability/SKGap/Gaussian/GaussianRankCorrection.leanAdded+429
lean/OAI/Probability/SKGap/Gaussian/GaussianRecipeEvent.leanAdded+121
lean/OAI/Probability/SKGap/Gaussian/GaussianReductionPointwise.leanAdded+73
lean/OAI/Probability/SKGap/Gaussian/GaussianRegression.leanAdded+134
lean/OAI/Probability/SKGap/Gaussian/GaussianSign.leanAdded+79
lean/OAI/Probability/SKGap/Gaussian/GaussianSquareTail.leanAdded+153
lean/OAI/Probability/SKGap/Gaussian/GaussianTailScale.leanAdded+179
lean/OAI/Probability/SKGap/Gaussian/GaussianTiltIdentity.leanAdded+64
lean/OAI/Probability/SKGap/Gaussian/GaussianTiltMass.leanAdded+171
lean/OAI/Probability/SKGap/Gaussian/GaussianVectorMoments.leanAdded+63
lean/OAI/Probability/SKGap/Gaussian/IndependentBoundedAverageTailLaw.leanAdded+234
lean/OAI/Probability/SKGap/Gaussian/LiteralWeakTail.leanAdded+108
lean/OAI/Probability/SKGap/Gaussian/LocalGaussianMoments.leanAdded+165
lean/OAI/Probability/SKGap/Gaussian/MatrixNormTail.leanAdded+104
lean/OAI/Probability/SKGap/Gaussian/MatrixWordMoments.leanAdded+93
lean/OAI/Probability/SKGap/Gaussian/PartitionSecondMoment.leanAdded+144
lean/OAI/Probability/SKGap/Gaussian/PhiMoments.leanAdded+138
lean/OAI/Probability/SKGap/Gaussian/PhiStein.leanAdded+135
lean/OAI/Probability/SKGap/Gaussian/ProductGaussianDensity.leanAdded+42
lean/OAI/Probability/SKGap/Gaussian/RegressionMoments.leanAdded+63
lean/OAI/Probability/SKGap/Gaussian/ReplicaTailWeight.leanAdded+318