Download data/lean/OAI/Probability/IsingPerceptron/EnergyShift.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 32 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/IsingPerceptron/EnergyShift.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/IsingPerceptron/EnergyShift.lean
-
curl -L -o EnergyShift.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/IsingPerceptron/EnergyShift.lean
32 kB
| import Mathlib | |
| import OAI.Probability.IsingPerceptron.VarianceOfConditionalCenterBound | |
| namespace OAI | |
| /-! Energy Shift. -/ | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| variable {I : Type} [Fintype I] [MeasurableSpace I] [MeasurableSingletonClass I] | |
| lemma energyRecursion_add_const (n : β) (b : β β β) | |
| (ΞΌ : β β ProbabilityMeasure (I β β)) (Ξ½ : Measure I) [IsProbabilityMeasure Ξ½] | |
| (hΞΌ : β i < n, ExponentialNormMoments (ΞΌ i : Measure (I β β))) | |
| (hb : β i < n, 0 < b i) (H : I β β) (c : β) : | |
| energyRecursion n b ΞΌ Ξ½ (fun x => c+H x) = c+energyRecursion n b ΞΌ Ξ½ H := by | |
| induction n generalizing b ΞΌ H with | |
| | zero => exact finiteLogIntegral_add_const Ξ½ H c | |
| | succ n ih => | |
| change logMean (b 0) (ΞΌ 0 : Measure (I β β)) | |
| (fun a => energyRecursion n (fun i => b (i+1)) (fun i => ΞΌ (i+1)) Ξ½ | |
| ((fun x => c+H x)+a)) = c+logMean (b 0) (ΞΌ 0 : Measure (I β β)) | |
| (fun a => energyRecursion n (fun i => b (i+1)) (fun i => ΞΌ (i+1)) Ξ½ (H+a)) | |
| have he (a : I β β) : ((fun x => c+H x)+a) = fun x => c+(H+a) x := by | |
| ext x; simp only [Pi.add_apply]; ring | |
| simp_rw [he,ih (fun i => b (i+1)) (fun i => ΞΌ (i+1)) | |
| (fun i hi => hΞΌ (i+1) (by omega)) (fun i hi => hb (i+1) (by omega))] | |
| apply logMean_const_add _ (hb 0 (by omega)).ne' | |
| exact integrable_exp_of_linearGrowth _ (hΞΌ 0 (by omega)) | |
| ((measurable_energyRecursion n _ _ Ξ½).comp (measurable_const.add measurable_id)) | |
| ((energyRecursion_linearGrowth n _ _ Ξ½ (fun i hi => hΞΌ (i+1) (by omega)) | |
| (fun i hi => hb (i+1) (by omega))).add_left H) _ | |
| def scalarShiftLaw (ΞΌ : ProbabilityMeasure (I β β)) (v : ββ₯0) : ProbabilityMeasure (I β β) := | |
| β¨((ΞΌ : Measure (I β β)).prod (gaussianReal 0 v)).map | |
| (fun p : (I β β) Γ β => fun x => p.1 x+p.2), | |
| inferInstanceβ© | |
| omit [MeasurableSpace I] [MeasurableSingletonClass I] in | |
| lemma scalarShiftLaw_exponentialNormMoments (ΞΌ : ProbabilityMeasure (I β β)) | |
| (hΞΌ : ExponentialNormMoments (ΞΌ : Measure (I β β))) (v : ββ₯0) : | |
| ExponentialNormMoments (scalarShiftLaw ΞΌ v : Measure (I β β)) := by | |
| intro a | |
| apply (integrable_map_measure (by fun_prop) (by fun_prop)).mpr | |
| have hi := (hΞΌ |a|).mul_prod (gaussianReal_exponentialNormMoments 0 v |a|) | |
| have hm : Measurable (fun p : (I β β) Γ β => fun x => p.1 x+p.2) := by fun_prop | |
| apply hi.mono' ((hm.norm.const_mul a).exp.aestronglyMeasurable) | |
| apply ae_of_all | |
| rintro β¨H,gβ© | |
| simp only [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] | |
| rw [β Real.exp_add] | |
| apply Real.exp_le_exp.mpr | |
| calc | |
| a*βfun x => H x+gβ β€ |a| *βfun x => H x+gβ := | |
| mul_le_mul_of_nonneg_right (le_abs_self _) (norm_nonneg _) | |
| _ β€ |a| *(βHβ+βgβ) := by | |
| gcongr | |
| exact (norm_add_le H (fun _ : I => g)).trans (add_le_add le_rfl ((pi_norm_le_iff_of_nonneg (norm_nonneg g)).mpr (fun _ => le_rfl))) | |
| _ = _ := by rw [Real.norm_eq_abs]; ring | |
| omit [MeasurableSpace I] [MeasurableSingletonClass I] in | |
| lemma logMean_scalarShift (ΞΌ : ProbabilityMeasure (I β β)) (v : ββ₯0) | |
| (r : β) {F : (I β β) β β} (hFm : Measurable F) | |
| (hFi : Integrable (fun H => Real.exp (r*F H)) (ΞΌ : Measure (I β β))) | |
| (hFc : β H c, F (fun x => c+H x) = c+F H) (hr : r β 0) : | |
| logMean r (scalarShiftLaw ΞΌ v : Measure (I β β)) F = | |
| (v:β)*r/2+logMean r (ΞΌ : Measure (I β β)) F := by | |
| change Real.log (β« p, Real.exp (r*F p) β((ΞΌ : Measure (I β β)).prod (gaussianReal 0 v)).map | |
| (fun p : (I β β) Γ β => fun x => p.1 x+p.2))/r = _ | |
| unfold logMean | |
| rw [integral_map (by fun_prop) ((hFm.const_mul r).exp).aestronglyMeasurable] | |
| have he (p : (I β β) Γ β) : Real.exp (r*F (fun x => p.1 x+p.2)) = | |
| Real.exp (r*F p.1)*Real.exp (r*p.2) := by | |
| rw [show (fun x => p.1 x+p.2) = (fun x => p.2+p.1 x) by ext x; ring,hFc] | |
| rw [mul_add,Real.exp_add,mul_comm] | |
| simp_rw [he] | |
| rw [integral_prod_mul (fun H : I β β => Real.exp (r*F H)) (fun g : β => Real.exp (r*g))] | |
| have hg : (β« g : β, Real.exp (r*g) βgaussianReal 0 v) = Real.exp ((v:β)*r^2/2) := by | |
| simpa [mgf] using (congrFun (mgf_fun_id_gaussianReal (ΞΌ := (0:β)) (v := v)) r) | |
| rw [hg,Real.log_mul (integral_exp_pos (ΞΌ : Measure (I β β)) F (b := r) hFi).ne' (Real.exp_ne_zero _),Real.log_exp] | |
| field_simp [hr] | |
| ring | |
| theorem energyRecursion_scalarShift (n : β) (b : β β β) | |
| (ΞΌ : β β ProbabilityMeasure (I β β)) (Ξ½ : Measure I) [IsProbabilityMeasure Ξ½] | |
| (hΞΌ : β i < n, ExponentialNormMoments (ΞΌ i : Measure (I β β))) | |
| (hb : β i < n, 0 < b i) (v : β β ββ₯0) (H : I β β) : | |
| energyRecursion n b (fun i => scalarShiftLaw (ΞΌ i) (v i)) Ξ½ H = | |
| (β i β Finset.range n, b i*(v i:β))/2+energyRecursion n b ΞΌ Ξ½ H := by | |
| induction n generalizing b ΞΌ v H with | |
| | zero => simp [energyRecursion,cascadeRecursion] | |
| | succ n ih => | |
| let F : (I β β) β β := fun a => energyRecursion n (fun i => b (i+1)) | |
| (fun i => ΞΌ (i+1)) Ξ½ (H+a) | |
| have hFm : Measurable F := (measurable_energyRecursion n _ _ Ξ½).comp | |
| (measurable_const.add measurable_id) | |
| have hFg : HasLinearGrowth F := (energyRecursion_linearGrowth n _ _ Ξ½ | |
| (fun i hi => hΞΌ (i+1) (by omega)) (fun i hi => hb (i+1) (by omega))).add_left H | |
| have hFi : Integrable (fun a => Real.exp (b 0*F a)) (ΞΌ 0 : Measure (I β β)) := | |
| integrable_exp_of_linearGrowth _ (hΞΌ 0 (by omega)) hFm hFg _ | |
| have hFsi : Integrable (fun a => Real.exp (b 0*F a)) | |
| (scalarShiftLaw (ΞΌ 0) (v 0) : Measure (I β β)) := | |
| integrable_exp_of_linearGrowth _ (scalarShiftLaw_exponentialNormMoments _ (hΞΌ 0 (by omega)) _) | |
| hFm hFg _ | |
| have hFc (a : I β β) (c : β) : F (fun x => c+a x) = c+F a := by | |
| dsimp [F] | |
| rw [show H+(fun x => c+a x) = (fun x => c+(H+a) x) by ext x; simp [Pi.add_apply]; ring] | |
| exact energyRecursion_add_const _ _ _ Ξ½ (fun i hi => hΞΌ (i+1) (by omega)) | |
| (fun i hi => hb (i+1) (by omega)) _ _ | |
| change logMean (b 0) (scalarShiftLaw (ΞΌ 0) (v 0) : Measure (I β β)) | |
| (fun a => energyRecursion n (fun i => b (i+1)) | |
| (fun i => scalarShiftLaw (ΞΌ (i+1)) (v (i+1))) Ξ½ (H+a)) = _ | |
| simp_rw [ih (fun i => b (i+1)) (fun i => ΞΌ (i+1)) | |
| (fun i hi => hΞΌ (i+1) (by omega)) (fun i hi => hb (i+1) (by omega))] | |
| change logMean (b 0) (scalarShiftLaw (ΞΌ 0) (v 0) : Measure (I β β)) | |
| (fun a => (β i β Finset.range n, b (i+1)*(v (i+1):β))/2+F a) = _ | |
| rw [logMean_const_add _ (hb 0 (by omega)).ne' hFsi, | |
| logMean_scalarShift _ _ _ hFm hFi hFc (hb 0 (by omega)).ne'] | |
| change _ = (β i β Finset.range (n+1), b i*(v i:β))/2+ | |
| logMean (b 0) (ΞΌ 0 : Measure (I β β)) F | |
| rw [Finset.sum_range_succ'] | |
| ring | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| abbrev EnrichedLabeledData (N n : β) (A : Type*) := | |
| EnrichedPoissonRoot N A Γ (LabeledTree n Γ (ForestVertex n β Fin (EnrichedRootSize N) β β)) | |
| def enrichedCoordinateLaw {A : Type*} [MeasurableSpace A] (P : Measure A) | |
| (r : ββ₯0) (N n : β) (b : β β β) : Measure (EnrichedLabeledData N n A) := | |
| ((poissonMeasure r).prod ((Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1)).prod | |
| (Measure.infinitePi (fun _ : β => P)))).prod | |
| ((labeledCascadeLaw n b : Measure (LabeledTree n)).prod (enrichedForestCoordinates N n)) | |
| instance enrichedCoordinateLaw_probability {A : Type*} [MeasurableSpace A] | |
| (P : Measure A) [IsProbabilityMeasure P] (r : ββ₯0) (N n : β) (b : β β β) : | |
| IsProbabilityMeasure (enrichedCoordinateLaw P r N n b) := by | |
| unfold enrichedCoordinateLaw | |
| infer_instance | |
| def enrichedCoordinatePressure {N : β} {A : Type*} (n : β) (h : β β β) | |
| (u : Fin N β β) (Ξ½ : Measure (Spin N)) (Ο : A β Spin N β β) | |
| (p : EnrichedLabeledData N n A) : β := | |
| (labeledEnergyLog n Ξ½ (enrichedPoissonBase n h u Ο p.1) | |
| (p.2.1,enrichedForest N n h u p.2.2) - N*h n/2) / N | |
| def enrichedToNoise {N : β} {A : Type*} (n : β) (h : β β β) (u : Fin N β β) | |
| (p : EnrichedLabeledData N n A) : EnrichedPoissonRoot N A Γ NoiseTree (Spin N β β) n := | |
| (p.1,labeledNoiseJoin (Spin N β β) n (p.2.1,enrichedForest N n h u p.2.2)) | |
| lemma enrichedToNoise_preserving {N : β} {A : Type*} [MeasurableSpace A] | |
| (P : Measure A) [IsProbabilityMeasure P] (r : ββ₯0) (n : β) (b h : β β β) | |
| (u : Fin N β β) : | |
| MeasurePreserving (enrichedToNoise (A := A) n h u) (enrichedCoordinateLaw P r N n b) | |
| (((poissonMeasure r).prod ((Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1)).prod | |
| (Measure.infinitePi (fun _ : β => P)))).prod | |
| (noiseCascadeLaw (Spin N β β) n b (fun i => enrichedIncrementLaw N n h u (i+1)))) := by | |
| have hf : Measurable (fun p : LabeledTree n Γ (ForestVertex n β Fin (EnrichedRootSize N) β β) => | |
| (p.1,enrichedForest N n h u p.2)) := | |
| measurable_fst.prodMk ((measurable_enrichedForest N n h u).comp measurable_snd) | |
| have hp : MeasurePreserving | |
| (fun p : LabeledTree n Γ (ForestVertex n β Fin (EnrichedRootSize N) β β) => | |
| labeledNoiseJoin (Spin N β β) n (p.1,enrichedForest N n h u p.2)) | |
| ((labeledCascadeLaw n b : Measure (LabeledTree n)).prod (enrichedForestCoordinates N n)) | |
| (noiseCascadeLaw (Spin N β β) n b (fun i => enrichedIncrementLaw N n h u (i+1))) := | |
| β¨(measurable_labeledNoiseJoin (Spin N β β) n).comp hf, | |
| labeledEnrichedCoordinates_law N n b h uβ© | |
| exact (MeasurePreserving.id _).prod hp | |
| theorem enrichedCoordinatePressure_eq_noise {N : β} {A : Type*} [MeasurableSpace A] | |
| (P : Measure A) [IsProbabilityMeasure P] (r : ββ₯0) (n : β) (b h : β β β) | |
| (hb : CascadeExponents n b) (u : Fin N β β) (Ξ½ : Measure (Spin N)) [IsProbabilityMeasure Ξ½] | |
| {Ο : A β Spin N β β} (hm : Measurable Ο) : | |
| enrichedCoordinatePressure n h u Ξ½ Ο =α΅[enrichedCoordinateLaw P r N n b] | |
| (fun p => enrichedPoissonLog n b h u Ξ½ Ο (enrichedToNoise n h u p) / N) := by | |
| let Q := (poissonMeasure r).prod | |
| ((Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1)).prod | |
| (Measure.infinitePi (fun _ : β => P))) | |
| let ΞΌ := fun i => enrichedIncrementLaw N n h u (i+1) | |
| have hpF : MeasurePreserving (enrichedForest N n h u) (enrichedForestCoordinates N n) | |
| (markForestLaw (Spin N β β) n ΞΌ) := | |
| β¨measurable_enrichedForest N n h u,enrichedForest_law N n h uβ© | |
| have hpT := (MeasurePreserving.id (labeledCascadeLaw n b : Measure (LabeledTree n))).prod hpF | |
| have hp := (MeasurePreserving.id Q).prod hpT | |
| have he := labeledEnergyLog_eq_cascade_random Q n b hb ΞΌ Ξ½ (measurable_enrichedPoissonBase n h u hm) | |
| have he' : βα΅ p βenrichedCoordinateLaw P r N n b, | |
| labeledEnergyLog n Ξ½ (enrichedPoissonBase n h u Ο p.1) | |
| (p.2.1,enrichedForest N n h u p.2.2) = | |
| cascadeEnergyLog n b ΞΌ Ξ½ (enrichedPoissonBase n h u Ο p.1) | |
| (labeledNoiseJoin (Spin N β β) n (p.2.1,enrichedForest N n h u p.2.2)) := by | |
| apply ae_of_ae_map (p := fun p : EnrichedPoissonRoot N A Γ | |
| (LabeledTree n Γ MarkForest (Spin N β β) n) => | |
| labeledEnergyLog n Ξ½ (enrichedPoissonBase n h u Ο p.1) p.2 = | |
| cascadeEnergyLog n b ΞΌ Ξ½ (enrichedPoissonBase n h u Ο p.1) | |
| (labeledNoiseJoin (Spin N β β) n p.2)) hp.measurable.aemeasurable | |
| rw [show enrichedCoordinateLaw P r N n b = Q.prod | |
| ((labeledCascadeLaw n b : Measure (LabeledTree n)).prod (enrichedForestCoordinates N n)) from rfl, | |
| hp.map_eq] | |
| exact he | |
| filter_upwards [he'] with p he | |
| unfold enrichedCoordinatePressure enrichedPoissonLog enrichedToNoise | |
| dsimp only | |
| rw [he] | |
| theorem enrichedCoordinatePressure_field_cap {N : β} (hN : 0 < N) (n : β) (b : β β β) | |
| (hb : CascadeExponents n b) {h : β β β} (hh : Monotone h) (h0 : 0 β€ h 0) | |
| {H : β} (hH : h n β€ H) (u : Fin N β β) (hu : β j, |u j| β€ 2) | |
| (Ξ½ : Measure (Spin N)) [IsProbabilityMeasure Ξ½] | |
| {A : Type*} [MeasurableSpace A] (P : Measure A) [IsProbabilityMeasure P] | |
| {Ο : A β Spin N β β} (hm : Measurable Ο) {K : β} (hK : 0 β€ K) | |
| (hΟ : β y x, |Ο y x| β€ K) (r : ββ₯0) {Ξ± : β} (hr : (r:β) β€ Ξ±*N) : | |
| let Q := enrichedCoordinateLaw P r N n b | |
| let C := 4*β« T, (Real.log (rawTreeTotal n T).toReal)^2 β(rawCascadeLaw n b : Measure (RawTree n)) | |
| let X := enrichedCoordinatePressure n h u Ξ½ Ο | |
| MemLp X 2 Q β§ Var[X;Q] β€ (C+H+4+5*K^2*Ξ±)/N := by | |
| have hv := enriched_field_cap_variance hN n b hb hh h0 hH u hu Ξ½ P hm hK hΟ r hr | |
| have hp := enrichedToNoise_preserving P r n b h u | |
| have he := enrichedCoordinatePressure_eq_noise P r n b h hb u Ξ½ hm | |
| have hL := hv.1.comp_measurePreserving hp | |
| refine β¨MemLp.ae_eq he.symm hL, ?_β© | |
| have ht := variance_map (X := fun p => enrichedPoissonLog n b h u Ξ½ Ο p / N) | |
| (hp.map_eq.symm βΈ hv.1.aemeasurable) hp.measurable.aemeasurable | |
| rw [hp.map_eq] at ht | |
| simp only [Function.comp_def] at ht | |
| rw [variance_congr he, β ht] | |
| exact hv.2 | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| def nodeAddress : (n : β) β Option (ForestVertex n) β List ChildLabel | |
| | _, none => [] | |
| | 0, some v => v.elim | |
| | n+1, some (m,i,v) => (m,i) :: nodeAddress n v | |
| lemma nodeAddress_injective (n : β) : Function.Injective (nodeAddress n) := by | |
| induction n with | |
| | zero => | |
| intro v w _ | |
| cases v with | |
| | none => cases w with | |
| | none => rfl | |
| | some w => exact w.elim | |
| | some v => exact v.elim | |
| | succ n ih => | |
| intro v w h | |
| cases v with | |
| | none => cases w with | |
| | none => rfl | |
| | some w => simp [nodeAddress] at h | |
| | some v => cases w with | |
| | none => simp [nodeAddress] at h | |
| | some w => | |
| rcases v with β¨m,i,vβ© | |
| rcases w with β¨m',i',wβ© | |
| simp only [nodeAddress,List.cons.injEq,Prod.mk.injEq] at h | |
| rcases h with β¨β¨rfl,rflβ©,hβ© | |
| rw [ih h] | |
| def nodeAt : (n : β) β LabeledLeaf n β Fin (n+1) β Option (ForestVertex n) | |
| | 0, _, _ => none | |
| | n+1, Ξ³, i => Fin.cases none (fun j => some (Ξ³.1.1,Ξ³.1.2,nodeAt n Ξ³.2 j)) i | |
| lemma nodeAddress_nodeAt (n : β) (Ξ³ : LabeledLeaf n) (i : Fin (n+1)) : | |
| nodeAddress n (nodeAt n Ξ³ i) = (labeledAddress n Ξ³).take i := by | |
| induction n with | |
| | zero => simp [nodeAt,nodeAddress,labeledAddress] | |
| | succ n ih => | |
| refine Fin.cases ?_ (fun j => ?_) i | |
| Β· simp [nodeAt,nodeAddress] | |
| Β· simp [nodeAt,nodeAddress,labeledAddress,ih] | |
| lemma nodeAddress_length_some (n : β) (v : ForestVertex n) : | |
| (nodeAddress n (some v)).length = forestVertexDepth n v+1 := by | |
| induction n with | |
| | zero => exact v.elim | |
| | succ n ih => | |
| rcases v with β¨m,i,_ | vβ© | |
| Β· simp [nodeAddress,forestVertexDepth] | |
| Β· simp only [nodeAddress,List.length_cons,ih,forestVertexDepth,Nat.add_assoc] | |
| lemma nodeAddress_nodeAt_length (n : β) (Ξ³ : LabeledLeaf n) (i : Fin (n+1)) : | |
| (nodeAddress n (nodeAt n Ξ³ i)).length = i := by | |
| rw [nodeAddress_nodeAt,List.length_take,labeledAddress_length] | |
| exact Nat.min_eq_left (Nat.le_of_lt_succ i.isLt) | |
| def enrichedNodeTag {N n : β} (v : Option (ForestVertex n)) : EnrichedBlock N β β | |
| | .inl a => Nat.pair 0 (Encodable.encode ((nodeAddress n v).length,nodeAddress n v,a)) | |
| | .inr β¨j,tβ© => Nat.pair (j+1) (Encodable.encode ((nodeAddress n v).length,nodeAddress n v,t)) | |
| lemma enrichedNodeTag_injective (N n : β) : | |
| Function.Injective (fun p : Option (ForestVertex n) Γ EnrichedBlock N => enrichedNodeTag p.1 p.2) := by | |
| rintro β¨v,aβ© β¨w,bβ© h | |
| cases a with | |
| | inl a => cases b with | |
| | inl b => | |
| have he := Encodable.encode_inj.mp (Nat.pair_eq_pair.mp h).2 | |
| have hv : v = w := nodeAddress_injective n (congrArg (fun p => p.2.1) he) | |
| have hab : a = b := congrArg (fun p => p.2.2) he | |
| subst w; subst b; rfl | |
| | inr b => | |
| have h' := (Nat.pair_eq_pair.mp h).1 | |
| omega | |
| | inr a => cases b with | |
| | inl b => | |
| have h' := (Nat.pair_eq_pair.mp h).1 | |
| omega | |
| | inr b => | |
| rcases a with β¨j,tβ© | |
| rcases b with β¨k,sβ© | |
| have hj : j = k := Fin.ext (by have h' := (Nat.pair_eq_pair.mp h).1; exact Nat.add_right_cancel h') | |
| subst k | |
| have he := Encodable.encode_inj.mp (Nat.pair_eq_pair.mp h).2 | |
| have hv : v = w := nodeAddress_injective n (congrArg (fun p => p.2.1) he) | |
| have hts : t = s := congrArg (fun p => p.2.2) he | |
| subst w; subst s; rfl | |
| def enrichedGaussianNodes (N n : β) (g : β β β) | |
| (v : Option (ForestVertex n)) (j : Fin (EnrichedRootSize N)) : β := | |
| g (enrichedNodeTag v ((Fintype.equivFin (EnrichedBlock N)).symm j)) | |
| lemma measurable_enrichedGaussianNodes (N n : β) : | |
| Measurable (enrichedGaussianNodes N n) := by | |
| unfold enrichedGaussianNodes | |
| fun_prop | |
| theorem enrichedGaussianNodes_law (N n : β) : | |
| gaussianCoordinates.map (enrichedGaussianNodes N n) = | |
| Measure.infinitePi (fun _ : Option (ForestVertex n) => | |
| Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1)) := by | |
| let t : Option (ForestVertex n) Γ Fin (EnrichedRootSize N) β β := | |
| fun p => enrichedNodeTag p.1 ((Fintype.equivFin (EnrichedBlock N)).symm p.2) | |
| have ht : Function.Injective t := by | |
| intro p q h | |
| have he := @enrichedNodeTag_injective N n | |
| (p.1,(Fintype.equivFin (EnrichedBlock N)).symm p.2) | |
| (q.1,(Fintype.equivFin (EnrichedBlock N)).symm q.2) h | |
| have he' := Prod.mk.inj he | |
| exact Prod.ext he'.1 ((Fintype.equivFin (EnrichedBlock N)).symm.injective he'.2) | |
| have hp := gaussian_pullback_measurePreserving t ht | |
| change gaussianCoordinates.map | |
| ((MeasurableEquiv.curry (Option (ForestVertex n)) (Fin (EnrichedRootSize N)) β) β | |
| (fun g => fun p => g (t p))) = _ | |
| rw [β Measure.map_map (MeasurableEquiv.curry _ _ _).measurable hp.measurable,hp.map_eq, | |
| Measure.infinitePi_map_curry (fun (_ : Option (ForestVertex n)) (_ : Fin (EnrichedRootSize N)) => gaussianReal 0 1)] | |
| simp only [Measure.infinitePi_eq_pi] | |
| theorem enrichedGaussianRootForest_law (N n : β) : | |
| gaussianCoordinates.map (fun g => | |
| (enrichedGaussianNodes N n g none, fun v => enrichedGaussianNodes N n g (some v))) = | |
| (Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1)).prod | |
| (enrichedForestCoordinates N n) := by | |
| change gaussianCoordinates.map | |
| ((fun q : Option (ForestVertex n) β Fin (EnrichedRootSize N) β β => | |
| (q none,fun v => q (some v))) β enrichedGaussianNodes N n) = _ | |
| rw [β Measure.map_map (by fun_prop) (measurable_enrichedGaussianNodes N n),enrichedGaussianNodes_law] | |
| have he := infinitePi_option_split | |
| (Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1)) | |
| (fun _ : ForestVertex n => Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1)) | |
| have hc : (fun i : Option (ForestVertex n) => i.elim | |
| (Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1)) | |
| (fun _ => Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1))) = | |
| (fun _ => Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1)) := by | |
| funext i; cases i <;> rfl | |
| simpa only [hc,enrichedForestCoordinates] using he | |
| lemma cylinderField_tag (j : β) (a : β ββ β) (g : β β β) : | |
| cylinderField (tagCoefficients j a) g = cylinderField a (fun i => g (Nat.pair j i)) := by | |
| unfold cylinderField tagCoefficients | |
| rw [Finsupp.sum_mapDomain_index_inj (pair_left_injective j)] | |
| lemma cylinderField_feature {J : Type*} [Fintype J] (t : J β β) (a : J β β) (g : β β β) : | |
| cylinderField (featureCoefficients t a) g = β j, a j*g (t j) := by | |
| classical | |
| rw [featureCoefficients,cylinderField_finset_sum] | |
| apply Finset.sum_congr rfl | |
| intro j _ | |
| exact Finsupp.sum_single_index (by simp) | |
| def edgeAt : (n : β) β LabeledLeaf n β Fin n β ForestVertex n | |
| | 0, _, i => i.elim0 | |
| | n+1, Ξ³, i => (Ξ³.1.1,Ξ³.1.2,nodeAt n Ξ³.2 i) | |
| lemma nodeAt_zero (n : β) (Ξ³ : LabeledLeaf n) : nodeAt n Ξ³ 0 = none := by | |
| cases n <;> simp [nodeAt] | |
| lemma nodeAt_succ (n : β) (Ξ³ : LabeledLeaf n) (i : Fin n) : | |
| nodeAt n Ξ³ i.succ = some (edgeAt n Ξ³ i) := by | |
| cases n with | |
| | zero => exact i.elim0 | |
| | succ n => simp [nodeAt,edgeAt] | |
| lemma labeledEnergy_edge_sum {I : Type} (n : β) (g : ForestVertex n β I β β) | |
| (Ξ³ : LabeledLeaf n) (H : I β β) (x : I) : | |
| labeledEnergy n (markForestOfCoords (I β β) n g) Ξ³ H x = | |
| H x + β i : Fin n, g (edgeAt n Ξ³ i) x := by | |
| induction n generalizing H with | |
| | zero => simp [labeledEnergy] | |
| | succ n ih => | |
| rw [labeledEnergy,markForestOfCoords,ih,Fin.sum_univ_succ] | |
| simp only [edgeAt,nodeAt_zero,nodeAt_succ,Pi.add_apply] | |
| ring | |
| lemma labeledEnergy_node_sum {I : Type} (n : β) (g : Option (ForestVertex n) β I β β) | |
| (Ξ³ : LabeledLeaf n) (H : I β β) (x : I) : | |
| labeledEnergy n (markForestOfCoords (I β β) n (fun v => g (some v))) Ξ³ (H+g none) x = | |
| H x + β i : Fin (n+1), g (nodeAt n Ξ³ i) x := by | |
| rw [labeledEnergy_edge_sum,Fin.sum_univ_succ] | |
| simp only [nodeAt_zero,nodeAt_succ,Pi.add_apply] | |
| ring | |
| lemma enrichedIncrement_nodes (N n : β) (h : β β β) (u : Fin N β β) (i : β) | |
| (g : β β β) (v : Option (ForestVertex n)) (x : Spin N) : | |
| enrichedIncrement N n h u i (enrichedGaussianNodes N n g v) x = | |
| β a : EnrichedBlock N, enrichedLevelCoefficient n h u i x a * g (enrichedNodeTag v a) := by | |
| unfold enrichedIncrement enrichedCoefficientsFin enrichedGaussianNodes | |
| exact (Fintype.equivFin (EnrichedBlock N)).symm.sum_comp | |
| (fun a => enrichedLevelCoefficient n h u i x a * g (enrichedNodeTag v a)) | |
| lemma cylinderField_external_nodes {N : β} (n : β) (h : β β β) | |
| (x : Spin N) (Ξ³ : LabeledLeaf n) (g : β β β) : | |
| cylinderField (tagCoefficients 0 (externalFieldCoefficients n h (x,Ξ³))) g = | |
| β i : Fin (n+1), β a : Fin N, | |
| pathAmplitude h i * spinValue (x a) * g (enrichedNodeTag (nodeAt n Ξ³ i) (.inl a)) := by | |
| rw [cylinderField_tag,externalFieldCoefficients,treeFieldCoefficients,cylinderField_feature, | |
| Fintype.sum_prod_type] | |
| simp only [enrichedNodeTag] | |
| simp_rw [nodeAddress_nodeAt_length,nodeAddress_nodeAt] | |
| simp only [treeFeatureTag] | |
| lemma cylinderField_monomial_nodes {N : β} (n : β) (j : Fin N) (c : β) | |
| (x : Spin N) (Ξ³ : LabeledLeaf n) (g : β β β) : | |
| cylinderField (tagCoefficients (j+1) (c β’ monomialCoefficients n (monomialIndex j).1 | |
| (monomialIndex j).2 (x,Ξ³))) g = | |
| β i : Fin (n+1), β a : Fin (monomialIndex j).1 β Fin N, | |
| (c * pathAmplitude (monomialPath n (monomialIndex j).2) i * | |
| tensorFeature (monomialIndex j).1 (spinCoordinate x) a) * | |
| g (enrichedNodeTag (nodeAt n Ξ³ i) (.inr β¨j,aβ©)) := by | |
| rw [cylinderField_tag,cylinderField_smul,monomialCoefficients,treeFieldCoefficients, | |
| cylinderField_feature,Fintype.sum_prod_type,Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| simp only [enrichedNodeTag] | |
| simp_rw [nodeAddress_nodeAt_length,nodeAddress_nodeAt] | |
| simp only [treeFeatureTag] | |
| ring | |
| lemma cylinderField_enriched_nodes {N : β} (n : β) (h : β β β) (u : Fin N β β) | |
| (x : Spin N) (Ξ³ : LabeledLeaf n) (g : β β β) : | |
| cylinderField (enrichedCoefficients n h u (x,Ξ³)) g = | |
| β i : Fin (n+1), β a : EnrichedBlock N, | |
| enrichedLevelCoefficient n h u i x a * g (enrichedNodeTag (nodeAt n Ξ³ i) a) := by | |
| classical | |
| rw [enrichedCoefficients,cylinderField_finset_sum,Fin.sum_univ_succ] | |
| simp only [Fin.cases_zero,Fin.cases_succ,Fin.val_zero,Fin.val_succ, | |
| cylinderField_external_nodes,cylinderField_monomial_nodes] | |
| simp only [Fintype.sum_sum_type,Fintype.sum_sigma,enrichedLevelCoefficient, | |
| Finset.sum_add_distrib] | |
| congr 1 | |
| exact Finset.sum_comm | |
| theorem enrichedEnergy_eq_cylinder {N : β} (n : β) (h : β β β) (u : Fin N β β) | |
| (g : β β β) (H : Spin N β β) (x : Spin N) (Ξ³ : LabeledLeaf n) : | |
| labeledEnergy n (enrichedForest N n h u | |
| (fun v => enrichedGaussianNodes N n g (some v))) Ξ³ | |
| (H+enrichedIncrement N n h u 0 (enrichedGaussianNodes N n g none)) x = | |
| H x + cylinderField (enrichedCoefficients n h u (x,Ξ³)) g := by | |
| let F : Option (ForestVertex n) β Spin N β β := fun v => | |
| enrichedIncrement N n h u (nodeAddress n v).length (enrichedGaussianNodes N n g v) | |
| have he := labeledEnergy_node_sum n F Ξ³ H x | |
| have hf : (fun v => F (some v)) = | |
| (fun v => enrichedIncrement N n h u (forestVertexDepth n v+1) | |
| (enrichedGaussianNodes N n g (some v))) := by | |
| funext v | |
| simp only [F,nodeAddress_length_some] | |
| have h0 : F none = enrichedIncrement N n h u 0 (enrichedGaussianNodes N n g none) := by | |
| simp only [F,nodeAddress,List.length_nil] | |
| rw [hf,h0] at he | |
| rw [cylinderField_enriched_nodes] | |
| simpa only [F,nodeAddress_nodeAt_length,enrichedIncrement_nodes,enrichedForest] using he | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| private lemma preserving_three_rotate {A B C : Type*} | |
| [MeasurableSpace A] [MeasurableSpace B] [MeasurableSpace C] | |
| (ΞΌ : Measure A) (Ξ½ : Measure B) (Ο : Measure C) [SFinite ΞΌ] [SFinite Ξ½] [SFinite Ο] : | |
| MeasurePreserving (fun p : (A Γ B) Γ C => (p.1.1,(p.2,p.1.2))) | |
| ((ΞΌ.prod Ξ½).prod Ο) (ΞΌ.prod (Ο.prod Ξ½)) := | |
| ((MeasurePreserving.id ΞΌ).prod Measure.measurePreserving_swap).comp | |
| (measurePreserving_prodAssoc ΞΌ Ξ½ Ο) | |
| private lemma preserving_four_shuffle {A B C D : Type*} | |
| [MeasurableSpace A] [MeasurableSpace B] [MeasurableSpace C] [MeasurableSpace D] | |
| (ΞΌ : Measure A) (Ξ½ : Measure B) (Ο : Measure C) (Ο : Measure D) | |
| [SFinite ΞΌ] [SFinite Ξ½] [SFinite Ο] [SFinite Ο] : | |
| MeasurePreserving (fun p : (A Γ B) Γ (C Γ D) => ((p.1.1,p.2.1),(p.1.2,p.2.2))) | |
| ((ΞΌ.prod Ξ½).prod (Ο.prod Ο)) ((ΞΌ.prod Ο).prod (Ξ½.prod Ο)) := by | |
| have h1 := (measurePreserving_prodAssoc (ΞΌ.prod Ξ½) Ο Ο).symm MeasurableEquiv.prodAssoc | |
| have h2 := ((measurePreserving_prodAssoc ΞΌ Ο Ξ½).symm MeasurableEquiv.prodAssoc).comp | |
| (preserving_three_rotate ΞΌ Ξ½ Ο) | |
| exact (measurePreserving_prodAssoc (ΞΌ.prod Ο) Ξ½ Ο).comp | |
| ((h2.prod (MeasurePreserving.id Ο)).comp h1) | |
| abbrev EnrichedCylinderBase (n : β) (A : Type*) := (β Γ (β β A)) Γ LabeledTree n | |
| abbrev EnrichedCylinderData (n : β) (A : Type*) := EnrichedCylinderBase n A Γ (β β β) | |
| def enrichedCylinderBaseLaw {A : Type*} [MeasurableSpace A] (P : Measure A) | |
| (r : ββ₯0) (n : β) (b : β β β) : Measure (EnrichedCylinderBase n A) := | |
| ((poissonMeasure r).prod (Measure.infinitePi (fun _ : β => P))).prod (labeledCascadeLaw n b) | |
| def enrichedCylinderLaw {A : Type*} [MeasurableSpace A] (P : Measure A) | |
| (r : ββ₯0) (n : β) (b : β β β) : Measure (EnrichedCylinderData n A) := | |
| (enrichedCylinderBaseLaw P r n b).prod gaussianCoordinates | |
| instance enrichedCylinderBaseLaw_probability {A : Type*} [MeasurableSpace A] | |
| (P : Measure A) [IsProbabilityMeasure P] (r : ββ₯0) (n : β) (b : β β β) : | |
| IsProbabilityMeasure (enrichedCylinderBaseLaw P r n b) := by | |
| unfold enrichedCylinderBaseLaw | |
| infer_instance | |
| instance enrichedCylinderLaw_probability {A : Type*} [MeasurableSpace A] | |
| (P : Measure A) [IsProbabilityMeasure P] (r : ββ₯0) (n : β) (b : β β β) : | |
| IsProbabilityMeasure (enrichedCylinderLaw P r n b) := by | |
| unfold enrichedCylinderLaw | |
| infer_instance | |
| def enrichedCylinderToCoordinates (N n : β) {A : Type*} | |
| (p : EnrichedCylinderData n A) : EnrichedLabeledData N n A := | |
| ((p.1.1.1,(enrichedGaussianNodes N n p.2 none,p.1.1.2)), | |
| (p.1.2,fun v => enrichedGaussianNodes N n p.2 (some v))) | |
| theorem enrichedCylinderToCoordinates_preserving {A : Type*} [MeasurableSpace A] | |
| (P : Measure A) [IsProbabilityMeasure P] (r : ββ₯0) (N n : β) (b : β β β) : | |
| MeasurePreserving (enrichedCylinderToCoordinates (A := A) N n) | |
| (enrichedCylinderLaw P r n b) (enrichedCoordinateLaw P r N n b) := by | |
| let ΞΌ := poissonMeasure r | |
| let Ξ½ := Measure.infinitePi (fun _ : β => P) | |
| let Ο := (labeledCascadeLaw n b : Measure (LabeledTree n)) | |
| let Ξ³ := Measure.pi (fun _ : Fin (EnrichedRootSize N) => gaussianReal 0 1) | |
| let Ο := enrichedForestCoordinates N n | |
| have hn : MeasurePreserving (fun g => | |
| (enrichedGaussianNodes N n g none,fun v => enrichedGaussianNodes N n g (some v))) | |
| gaussianCoordinates (Ξ³.prod Ο) := | |
| β¨(by unfold enrichedGaussianNodes; fun_prop),enrichedGaussianRootForest_law N nβ© | |
| have h1 := (MeasurePreserving.id ((ΞΌ.prod Ξ½).prod Ο)).prod hn | |
| have h2 := preserving_four_shuffle (ΞΌ.prod Ξ½) Ο Ξ³ Ο | |
| have h3 := (preserving_three_rotate ΞΌ Ξ½ Ξ³).prod (MeasurePreserving.id (Ο.prod Ο)) | |
| exact h3.comp (h2.comp h1) | |
| def enrichedCylinderPressure {N : β} {A : Type*} (n : β) (h : β β β) | |
| (u : Fin N β β) (Ξ½ : Measure (Spin N)) (Ο : A β Spin N β β) | |
| (p : EnrichedCylinderData n A) : β := | |
| (Real.log (β« s, Real.exp (patternBase Ο (fun i : Fin p.1.1.1 => p.1.1.2 i) s.1 + | |
| cylinderField (enrichedCoefficients n h u s) p.2) βlabeledSpinReference n Ξ½ p.1.2) - N*h n/2)/N | |
| theorem enrichedCylinderPressure_eq_coordinates {N : β} {A : Type*} | |
| (n : β) (h : β β β) (u : Fin N β β) (Ξ½ : Measure (Spin N)) | |
| (Ο : A β Spin N β β) (p : EnrichedCylinderData n A) : | |
| enrichedCylinderPressure n h u Ξ½ Ο p = | |
| enrichedCoordinatePressure n h u Ξ½ Ο (enrichedCylinderToCoordinates N n p) := by | |
| unfold enrichedCylinderPressure enrichedCoordinatePressure enrichedCylinderToCoordinates | |
| labeledEnergyLog enrichedPoissonBase enrichedBaseEnergy rootPrefix | |
| dsimp only | |
| congr 3 | |
| apply integral_congr_ae | |
| filter_upwards [] with s | |
| congr 1 | |
| exact (enrichedEnergy_eq_cylinder n h u p.2 | |
| (patternBase Ο (fun i : Fin p.1.1.1 => p.1.1.2 i)) s.1 s.2).symm | |
| theorem enrichedCylinderPressure_field_cap {N : β} (hN : 0 < N) (n : β) (b : β β β) | |
| (hb : CascadeExponents n b) {h : β β β} (hh : Monotone h) (h0 : 0 β€ h 0) | |
| {H : β} (hH : h n β€ H) (u : Fin N β β) (hu : β j, |u j| β€ 2) | |
| (Ξ½ : Measure (Spin N)) [IsProbabilityMeasure Ξ½] | |
| {A : Type*} [MeasurableSpace A] (P : Measure A) [IsProbabilityMeasure P] | |
| {Ο : A β Spin N β β} (hm : Measurable Ο) {K : β} (hK : 0 β€ K) | |
| (hΟ : β y x, |Ο y x| β€ K) (r : ββ₯0) {Ξ± : β} (hr : (r:β) β€ Ξ±*N) : | |
| let Q := enrichedCylinderLaw P r n b | |
| let C := 4*β« T, (Real.log (rawTreeTotal n T).toReal)^2 β(rawCascadeLaw n b : Measure (RawTree n)) | |
| let X := enrichedCylinderPressure n h u Ξ½ Ο | |
| MemLp X 2 Q β§ Var[X;Q] β€ (C+H+4+5*K^2*Ξ±)/N := by | |
| have hv := enrichedCoordinatePressure_field_cap hN n b hb hh h0 hH u hu Ξ½ P hm hK hΟ r hr | |
| have hp := enrichedCylinderToCoordinates_preserving P r N n b | |
| have he : enrichedCylinderPressure n h u Ξ½ Ο = | |
| (enrichedCoordinatePressure n h u Ξ½ Ο) β enrichedCylinderToCoordinates N n := by | |
| funext p | |
| exact enrichedCylinderPressure_eq_coordinates n h u Ξ½ Ο p | |
| have hL := hv.1.comp_measurePreserving hp | |
| refine β¨he βΈ hL, ?_β© | |
| have ht := variance_map (X := enrichedCoordinatePressure n h u Ξ½ Ο) | |
| (hp.map_eq.symm βΈ hv.1.aemeasurable) hp.measurable.aemeasurable | |
| rw [hp.map_eq] at ht | |
| rw [he, β ht] | |
| exact hv.2 | |
| end IsingPerceptron | |
| end | |
| end OAI | |