Download data/lean/OAI/Probability/Perceptron/Variational/EnrichedMoments.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Perceptron/Variational/EnrichedMoments.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/Perceptron/Variational/EnrichedMoments.lean
-
curl -L -o EnrichedMoments.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Perceptron/Variational/EnrichedMoments.lean
10.5 kB
| import Mathlib | |
| import OAI.Probability.Perceptron.Variational.IndexedDiagonalField | |
| namespace OAI | |
| noncomputable section | |
| namespace SphericalPerceptronFreeEnergy | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction | |
| def enrichedDisorderLaw (n k : β) (p : Fin (n+1) β β) (z : Fin k β β) : | |
| Measure (EnrichedMark (n+1) (n+1) p Γ DecoratedCascade (EnrichedMark (n+1) (n+1) p) k) := | |
| (stdGaussian (EnrichedMark (n+1) (n+1) p)).prod | |
| (decoratedCascadeLaw (gaussianMarkLaw : ProbabilityMeasure (EnrichedMark (n+1) (n+1) p)) k z) | |
| instance (n k : β) (p : Fin (n+1) β β) (z : Fin k β β) : | |
| IsProbabilityMeasure (enrichedDisorderLaw n k p z) := by | |
| unfold enrichedDisorderLaw | |
| infer_instance | |
| lemma enrichedCascadeLog_joint_mean (n M k : β) (f : β βα΅ β) | |
| (g : Fin M β Fin (n+1) β β) (p d : Fin (n+1) β β) (u : Fin (n+1) β β) | |
| (h : Fin (k+1) β β) (z : Fin k β β) | |
| (hz : StrictMono z) (hz0 : β i, 0<z i) (hz1 : β i, z i<1) : | |
| Integrable (enrichedCascadeLog n M k f g p d u h) (enrichedDisorderLaw n k p z) β§ | |
| (β« a, enrichedCascadeLog n M k f g p d u h a βenrichedDisorderLaw n k p z)= | |
| β« a, gaussianLinearBackward (stdGaussian (EnrichedMark (n+1) (n+1) p)) | |
| (linearCascadeWord (enrichedIncrementMap p d h) k z) | |
| (enrichedTerminal n M f g p u (h (Fin.last k))) (enrichedRootMap p d h a) | |
| βstdGaussian (EnrichedMark (n+1) (n+1) p) := by | |
| exact gaussianLinearCascadeLog_mean (enrichedIncrementMap p d h) (enrichedRootMap p d h) | |
| (enrichedTerminal_lipschitz n M f g p u _) k z hz hz0 hz1 | |
| lemma enrichedCascadeLog_measurable (n M k : β) (f : β βα΅ β) | |
| (g : Fin M β Fin (n+1) β β) (p d : Fin (n+1) β β) (u : Fin (n+1) β β) | |
| (h : Fin (k+1) β β) (z : Fin k β β) : | |
| Measurable (enrichedCascadeLog n M k f g p d u h) := by | |
| exact gaussianLinearCascadeLog_measurable (enrichedIncrementMap p d h) (enrichedRootMap p d h) | |
| (enrichedTerminal_lipschitz n M f g p u _).continuous.measurable k z | |
| lemma enrichedCascadeLog_conditional_square (n M k : β) (f : β βα΅ β) | |
| (g : Fin M β Fin (n+1) β β) (p d : Fin (n+1) β β) (u : Fin (n+1) β β) | |
| (h : Fin (k+1) β β) (z : Fin k β β) | |
| (hz : StrictMono z) (hz0 : β i, 0<z i) (hz1 : β i, z i<1) | |
| (a : EnrichedMark (n+1) (n+1) p) : | |
| let Ξ½ : ProbabilityMeasure (EnrichedMark (n+1) (n+1) p) := gaussianMarkLaw | |
| let G := gaussianLinearBackward (Ξ½:Measure _) (linearCascadeWord (enrichedIncrementMap p d h) k z) | |
| (enrichedTerminal n M f g p u (h (Fin.last k))) (enrichedRootMap p d h a) | |
| MemLp (fun Ξ· => enrichedCascadeLog n M k f g p d u h (a,Ξ·)) 2 | |
| (decoratedCascadeLaw Ξ½ k z : Measure _) β§ | |
| (β« Ξ·, (enrichedCascadeLog n M k f g p d u h (a,Ξ·)-G)^2 | |
| βdecoratedCascadeLaw Ξ½ k z) β€ cascadeLogFluctuationConstant k z := by | |
| let Ξ½ : ProbabilityMeasure (EnrichedMark (n+1) (n+1) p) := gaussianMarkLaw | |
| let : IsGaussian (Ξ½:Measure (EnrichedMark (n+1) (n+1) p)) := (inferInstance : IsGaussian (stdGaussian (EnrichedMark (n+1) (n+1) p))) | |
| have hf := enrichedTerminal_lipschitz n M f g p u (h (Fin.last k)) | |
| have hr := gaussianLinearRecursion_realization Ξ½ (enrichedIncrementMap p d h) hf k z hz0 | |
| have H := finiteCascade_terminal_log_second_moment_bound Ξ½ | |
| (gaussianLinearMarkStep (enrichedIncrementMap p d h)) | |
| (gaussianLinearMarkStep_measurable _) k z hz hz0 hz1 | |
| (hf.continuous.measurable.comp (measurable_pi_apply 0)) hr.2 | |
| (fun _ => enrichedRootMap p d h a) | |
| simp only [Function.comp_def] at H | |
| rw [hr.1] at H | |
| exact H | |
| lemma normalizedPatternEnergy_source (Ξ± Ξ² : β) (Ο : β βα΅ β) (n : β) | |
| (g : Patterns Ξ± (n+1)) (x : NormalizedSpin (n+1)) : | |
| normalizedPatternEnergy (n+1) (patternCount Ξ± (n+1)) (Ξ² β’ Ο) g x= | |
| Ξ²*hamiltonian Ξ± Ο (n+1) g (Real.sqrt (n+1:β) β’ x.val) := by | |
| have hn : Real.sqrt ((n+1:β):β) β 0 := (Real.sqrt_pos.mpr (by positivity)).ne' | |
| have he (a : Fin (patternCount Ξ± (n+1))) : | |
| patternField g a (Real.sqrt (n+1:β) β’ x.val) = β i, g a i*x.val i := by | |
| unfold patternField | |
| simp only [PiLp.smul_apply,smul_eq_mul] | |
| have hs : (β i, g a i*(Real.sqrt (n+1:β)*x.val i)) = | |
| (β i, g a i*x.val i)*Real.sqrt (n+1:β) := by | |
| rw [Finset.sum_mul] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| ring | |
| rw [hs,mul_div_cancel_rightβ _ hn] | |
| simp only [normalizedPatternEnergy,BoundedContinuousFunction.coe_smul,smul_eq_mul, | |
| hamiltonian,he,Finset.mul_sum] | |
| variable {E : Type} [NormedAddCommGroup E] [InnerProductSpace β E] | |
| [FiniteDimensional β E] [MeasurableSpace E] [BorelSpace E] | |
| (ΞΌ : Measure E) [IsGaussian ΞΌ] | |
| lemma gaussianLinearEntropic_C1 {f : E β β} {D : E β StrongDual β E} {L : ββ₯0} | |
| (hf : LipschitzWith L f) (hd : β x, HasFDerivAt f (D x) x) (hD : Continuous D) | |
| {b : β} (hb : 0<b) (A : E βL[β] E) : | |
| β D' : E β StrongDual β E, Continuous D' β§ | |
| (β x, HasFDerivAt (gaussianLinearEntropic ΞΌ b A f) (D' x) x) β§ | |
| (β x, βD' xβ β€ L) := by | |
| have hfc : Continuous f := hf.continuous | |
| have hDC (x : E) : βD xβ β€ L := by | |
| rw [β (hd x).fderiv] | |
| exact norm_fderiv_le_of_lipschitz β hf | |
| let Z := fun x => β« y, Real.exp (b*f (x+A y)) βΞΌ | |
| let ZD := fun x => β« y, Real.exp (b*f (x+A y)) β’ (b β’ D (x+A y)) βΞΌ | |
| have hZpos (x : E) : 0<Z x := by | |
| apply integral_pos_iff_support_of_nonneg (fun y => (Real.exp_pos _).le) | |
| (gaussian_integrable_exp_linear_shift ΞΌ hf A b x) |>.mpr | |
| simp [Function.support,Real.exp_ne_zero] | |
| have hdom (xβ x y : E) (hx : x β Metric.ball xβ 1) : | |
| βReal.exp (b*f (x+A y)) β’ (b β’ D (x+A y))β β€ | |
| (Real.exp (b*L)*(b*L))*Real.exp (b*f (xβ+A y)) := by | |
| have hh := hf.dist_le_mul (x+A y) (xβ+A y) | |
| rw [dist_add_right,Real.dist_eq] at hh | |
| have hx' : dist x xβ β€ 1 := (Metric.mem_ball.mp hx).le | |
| have hff : f (x+A y)-f (xβ+A y) β€ L := | |
| (le_abs_self _).trans (hh.trans (by simpa using mul_le_mul_of_nonneg_left hx' L.coe_nonneg)) | |
| have hExp : Real.exp (b*f (x+A y)) β€ Real.exp (b*L)*Real.exp (b*f (xβ+A y)) := by | |
| rw [β Real.exp_add] | |
| apply Real.exp_le_exp.mpr | |
| nlinarith | |
| simp only [norm_smul,Real.norm_eq_abs,abs_of_pos (Real.exp_pos _),abs_of_pos hb] | |
| calc | |
| _ β€ (Real.exp (b*L)*Real.exp (b*f (xβ+A y)))*(b*L) := | |
| mul_le_mul hExp (mul_le_mul_of_nonneg_left (hDC _) hb.le) (by positivity) (by positivity) | |
| _ = _ := by ring | |
| have hZ (x : E) : HasFDerivAt Z (ZD x) x := by | |
| apply hasFDerivAt_integral_of_dominated_of_fderiv_le | |
| (F' := fun x y => Real.exp (b*f (x+A y)) β’ (b β’ D (x+A y))) | |
| (bound := fun y => (Real.exp (b*L)*(b*L))*Real.exp (b*f (x+A y))) | |
| (Metric.ball_mem_nhds x zero_lt_one) | |
| Β· exact Eventually.of_forall fun x => by fun_prop | |
| Β· exact gaussian_integrable_exp_linear_shift ΞΌ hf A b x | |
| Β· fun_prop | |
| Β· exact ae_of_all _ fun y x' hx' => hdom x x' y hx' | |
| Β· exact (gaussian_integrable_exp_linear_shift ΞΌ hf A b x).const_mul _ | |
| Β· exact ae_of_all _ fun y x' _ => by | |
| have hh := (hd (x'+A y)).comp x' ((hasFDerivAt_id x').add_const (A y)) | |
| simpa using (hh.const_mul b).exp | |
| have hZD : Continuous ZD := by | |
| apply continuous_iff_continuousAt.mpr | |
| intro x | |
| apply continuousAt_of_dominated | |
| (bound := fun y => (Real.exp (b*L)*(b*L))*Real.exp (b*f (x+A y))) | |
| Β· exact Eventually.of_forall fun x => by fun_prop | |
| Β· filter_upwards [Metric.ball_mem_nhds x zero_lt_one] with x' hx' | |
| exact ae_of_all _ fun y => hdom x x' y hx' | |
| Β· exact (gaussian_integrable_exp_linear_shift ΞΌ hf A b x).const_mul _ | |
| Β· exact ae_of_all _ fun y => by fun_prop | |
| let D' := fun x => bβ»ΒΉ β’ ((Z x)β»ΒΉ β’ ZD x) | |
| have he : gaussianLinearEntropic ΞΌ b A f = fun x => Real.log (Z x)/b := by | |
| funext x | |
| exact entropicMean_eq_div ΞΌ (fun s => gaussian_integrable_exp_linear_shift ΞΌ hf A s x) hb.ne' | |
| have hd' (x : E) : HasFDerivAt (gaussianLinearEntropic ΞΌ b A f) (D' x) x := by | |
| rw [he] | |
| have hh := ((hZ x).log (hZpos x).ne').const_mul bβ»ΒΉ | |
| simpa only [D',div_eq_mul_inv,mul_comm] using hh | |
| refine β¨D',?_,hd',?_β© | |
| Β· have hcZ : Continuous Z := continuous_iff_continuousAt.mpr (fun x => (hZ x).continuousAt) | |
| change Continuous (fun x => bβ»ΒΉ β’ ((Z x)β»ΒΉ β’ ZD x)) | |
| exact (continuous_const : Continuous (fun _ : E => (bβ»ΒΉ : β))).smul | |
| ((hcZ.invβ (fun x => (hZpos x).ne')).smul hZD) | |
| Β· intro x | |
| rw [β (hd' x).fderiv] | |
| exact norm_fderiv_le_of_lipschitz β (gaussianLinearEntropic_lipschitz ΞΌ hf hb.le A) | |
| lemma gaussianLinearBackward_C1 {f : E β β} {D : E β StrongDual β E} {L : ββ₯0} | |
| (hf : LipschitzWith L f) (hd : β x, HasFDerivAt f (D x) x) (hD : Continuous D) | |
| (l : List (βΓ(E βL[β] E))) (hl : β c β l, 0<c.1) : | |
| β D' : E β StrongDual β E, Continuous D' β§ | |
| (β x, HasFDerivAt (gaussianLinearBackward ΞΌ l f) (D' x) x) β§ | |
| (β x, βD' xβ β€ L) := by | |
| induction l with | |
| | nil => | |
| exact β¨D,hD,hd,fun x => by | |
| rw [β (hd x).fderiv] | |
| exact norm_fderiv_le_of_lipschitz β hfβ© | |
| | cons c l ih => | |
| have hl' : β d β l, 0<d.1 := fun d hd => hl d (List.mem_cons_of_mem c hd) | |
| obtain β¨D',hD',hd',_β© := ih hl' | |
| exact gaussianLinearEntropic_C1 ΞΌ | |
| (gaussianLinearBackward_lipschitz ΞΌ hf l (fun d hd => (hl' d hd).le)) | |
| hd' hD' (hl c List.mem_cons_self) c.2 | |
| lemma gaussianLinearBackward_root_variance {f : E β β} {D : E β StrongDual β E} | |
| {L : ββ₯0} (hf : LipschitzWith L f) (hd : β x, HasFDerivAt f (D x) x) | |
| (hD : Continuous D) (l : List (βΓ(E βL[β] E))) (hl : β c β l, 0<c.1) | |
| (R : E βL[β] E) : | |
| variance (fun x => gaussianLinearBackward ΞΌ l f (R x)) (stdGaussian E) β€ | |
| (Real.pi^2/8)*((L:β)*βRβ)^2 := by | |
| obtain β¨D',hD',hd',hbβ© := gaussianLinearBackward_C1 ΞΌ hf hd hD l hl | |
| apply stdGaussian_variance_le_of_fderiv_bound | |
| (D := fun x => (D' (R x)).comp R) | |
| (fun x => (hd' (R x)).comp x R.hasFDerivAt) | |
| Β· exact Continuous.clm_comp (hD'.comp R.continuous) continuous_const | |
| Β· positivity | |
| Β· intro x | |
| exact (ContinuousLinearMap.opNorm_comp_le _ _).trans | |
| (mul_le_mul_of_nonneg_right (hb _) (norm_nonneg R)) | |
| end SphericalPerceptronFreeEnergy | |
| end | |
| end OAI | |