Download data/lean/OAI/Probability/IsingPerceptron/SamplingIndependent.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 34.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/IsingPerceptron/SamplingIndependent.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/IsingPerceptron/SamplingIndependent.lean
-
curl -L -o SamplingIndependent.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/IsingPerceptron/SamplingIndependent.lean
34.5 kB
| import Mathlib | |
| import OAI.Probability.IsingPerceptron.RetainedDisplacement | |
| import OAI.Probability.IsingPerceptron.TiltedLabelLaw | |
| namespace OAI | |
| /-! Sampling Independent. -/ | |
| 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 | |
| lemma independent_marks_sampling {Ξ© G X : Type*} [MeasurableSpace Ξ©] [MeasurableSpace G] | |
| [MeasurableSpace X] (P : Measure Ξ©) (Q : Measure G) [IsProbabilityMeasure P] | |
| [IsProbabilityMeasure Q] (K : Kernel Ξ© X) [IsMarkovKernel K] : | |
| ((P.prod Q) ββ K.comap Prod.fst measurable_fst).map (fun p => (p.2,p.1.2)) = | |
| (K ββ P).prod Q := by | |
| apply Measure.ext_of_lintegral | |
| intro F hF | |
| rw [lintegral_map hF (by fun_prop),Measure.lintegral_compProd (by fun_prop)] | |
| simp only [Kernel.comap_apply] | |
| have hI : Measurable (fun p : Ξ© Γ G => β«β» x, F (x,p.2) βK p.1) := | |
| (show Measurable (fun p : (Ξ© Γ G) Γ X => F (p.2,p.1.2)) from by fun_prop).lintegral_kernel_prod_right' (ΞΊ := K.comap Prod.fst measurable_fst) | |
| rw [lintegral_prod _ hI.aemeasurable] | |
| have he (Ο : Ξ©) : (β«β» g, β«β» x, F (x,g) βK Ο βQ) = β«β» x, β«β» g, F (x,g) βQ βK Ο := | |
| lintegral_lintegral_swap (by fun_prop) | |
| simp_rw [he] | |
| rw [lintegral_prod _ hF.aemeasurable] | |
| exact (Measure.lintegral_bind (Kernel.aemeasurable K) (hF.lintegral_prod_right').aemeasurable).symm | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| abbrev PrefixPattern (n r : β) := Fin r β Fin r β Fin n β Bool | |
| def labelPrefixPattern (n r : β) (Ο : Fin r β LabeledLeaf n) : PrefixPattern n r := | |
| fun i j d => if (labeledAddress n (Ο i)).take (d+1) = (labeledAddress n (Ο j)).take (d+1) then true else false | |
| def markPrefixPattern (n r : β) (Ο : Fin r β NoiseLeaf β n) : PrefixPattern n r := | |
| fun i j d => if noiseLeafMark n (Ο i) d = noiseLeafMark n (Ο j) d then true else false | |
| lemma measurable_markPrefixPattern (n r : β) : Measurable (markPrefixPattern n r) := by | |
| unfold markPrefixPattern | |
| apply Measurable.of_eval; intro i | |
| apply Measurable.of_eval; intro j | |
| apply Measurable.of_eval; intro d | |
| apply Measurable.ite _ measurable_const measurable_const | |
| exact measurableSet_eq_fun ((measurable_noiseLeafMark n d).comp (measurable_pi_apply i)) | |
| ((measurable_noiseLeafMark n d).comp (measurable_pi_apply j)) | |
| lemma markPrefixPattern_labeled (n r : β) (Ο : LabeledTree n) (g : ForestVertex n β β) | |
| (hg : Function.Injective g) (Ο : Fin r β LabeledLeaf n) : | |
| markPrefixPattern n r (fun i => labeledNoiseLeaf β n (Ο,markForestOfCoords β n g) (Ο i)) = | |
| labelPrefixPattern n r Ο := by | |
| funext i j d | |
| unfold markPrefixPattern labelPrefixPattern | |
| simp only [noiseLeafMark_eq_iff_prefix n Ο g hg] | |
| lemma noiseLeafProduct_exp_marks (n : β) (E : β β β β β) (v : NoiseLeaf β n) : | |
| noiseLeafProduct n (fun i (p : PUnit Γ β) => Real.exp (E i p.2)) | |
| (fun _ _ => PUnit.unit) PUnit.unit v = | |
| ENNReal.ofReal (Real.exp (β i : Fin n, E i (noiseLeafMark n v i))) := by | |
| induction n generalizing E with | |
| | zero => simp [noiseLeafProduct] | |
| | succ n ih => | |
| rw [noiseLeafProduct,ih,β ENNReal.ofReal_mul (Real.exp_pos _).le,β Real.exp_add, | |
| Fin.sum_univ_succ] | |
| rfl | |
| lemma noiseLeafProduct_retained_labeled (n : β) (b a : β β β) (Ο : LabeledTree n) | |
| (g : ForestVertex n β β) (v : LabeledLeaf n) : | |
| noiseLeafProduct n (fun i (p : PUnit Γ β) => retainedGaussianScale (b i) (a i) p.2) | |
| (fun _ _ => PUnit.unit) PUnit.unit (labeledNoiseLeaf β n (Ο,markForestOfCoords β n g) v) = | |
| ENNReal.ofReal (Real.exp (β i : Fin n, (a i*g (edgeAt n v i)-b i*a i^2/2))) := by | |
| rw [show (fun i (p : PUnit Γ β) => retainedGaussianScale (b i) (a i) p.2) = | |
| (fun i p => Real.exp (a i*p.2-b i*a i^2/2)) by rfl] | |
| rw [noiseLeafProduct_exp_marks n (fun i x => a i*x-b i*a i^2/2)] | |
| simp only [noiseLeafMark_labeled] | |
| lemma noiseLeafProduct_single_level (n : β) (b : β β β) (d : Fin n) (t : β) | |
| (Ο : LabeledTree n) (g : ForestVertex n β β) (v : LabeledLeaf n) : | |
| noiseLeafProduct n (fun i (p : PUnit Γ β) => retainedGaussianScale (b i) (if i = d then t else 0) p.2) | |
| (fun _ _ => PUnit.unit) PUnit.unit (labeledNoiseLeaf β n (Ο,markForestOfCoords β n g) v) = | |
| ENNReal.ofReal (Real.exp (t*g (edgeAt n v d)-b d*t^2/2)) := by | |
| rw [noiseLeafProduct_retained_labeled] | |
| congr 2 | |
| rw [Finset.sum_eq_single d] | |
| Β· simp | |
| Β· intro i _ hi | |
| have hne : (i:β) β d := fun h => hi (Fin.ext h) | |
| simp [hne] | |
| Β· simp | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| lemma measurable_selected_coordinate {X I : Type*} [MeasurableSpace X] [MeasurableSpace I] | |
| [Countable I] [MeasurableSingletonClass I] {e : X β I} (he : Measurable e) : | |
| Measurable (fun p : X Γ (I β β) => p.2 (e p.1)) := by | |
| have hv : Measurable (fun p : (I β β) Γ I => p.1 p.2) := | |
| measurable_from_prod_countable_left (fun i => measurable_pi_apply i) | |
| exact hv.comp (measurable_snd.prodMk (he.comp measurable_fst)) | |
| lemma selected_coordinate_prod_law {X I : Type*} [MeasurableSpace X] [MeasurableSpace I] | |
| [Countable I] [MeasurableSingletonClass I] | |
| (P : Measure X) [IsProbabilityMeasure P] (ΞΌ : I β Measure β) | |
| [β i, IsProbabilityMeasure (ΞΌ i)] {e : X β I} (he : Measurable e) (v : Measure β) [IsProbabilityMeasure v] | |
| (hm : β x, ΞΌ (e x) = v) : | |
| (P.prod (Measure.infinitePi ΞΌ)).map (fun p => (p.1,p.2 (e p.1))) = P.prod v := by | |
| have hT : Measurable (fun p : X Γ (I β β) => (p.1,p.2 (e p.1))) := | |
| measurable_fst.prodMk (measurable_selected_coordinate he) | |
| apply Measure.ext_of_lintegral | |
| intro F hF | |
| rw [lintegral_map hF hT] | |
| have hFT : Measurable (fun p : X Γ (I β β) => F (p.1,p.2 (e p.1))) := hF.comp hT | |
| rw [lintegral_prod _ hFT.aemeasurable] | |
| rw [lintegral_prod _ hF.aemeasurable] | |
| apply lintegral_congr | |
| intro x | |
| have hFx : Measurable (fun y => F (x,y)) := hF.comp (measurable_const.prodMk measurable_id) | |
| rw [β lintegral_map hFx (measurable_pi_apply (e x))] | |
| change (β«β» a, F (x,a) β(Measure.infinitePi ΞΌ).map (fun g => g (e x))) = _ | |
| rw [Measure.infinitePi_map_eval,hm] | |
| lemma selected_gaussian_score {X I : Type*} [MeasurableSpace X] [MeasurableSpace I] | |
| [Countable I] [MeasurableSingletonClass I] | |
| (P : Measure X) [IsProbabilityMeasure P] (mean : I β β) | |
| {e : X β I} (he : Measurable e) (m : β) (hm : β x, mean (e x) = m) | |
| {D : X β β} (hD : Measurable D) : | |
| (β« p : X Γ (I β β), D p.1*p.2 (e p.1) βP.prod (Measure.infinitePi (fun i => gaussianReal (mean i) 1))) = | |
| (β« x, D x βP)*m := by | |
| have hlaw := selected_coordinate_prod_law P (fun i => gaussianReal (mean i) 1) he | |
| (gaussianReal m 1) (fun x => by rw [hm x]) | |
| have hT : Measurable (fun p : X Γ (I β β) => (p.1,p.2 (e p.1))) := | |
| measurable_fst.prodMk (measurable_selected_coordinate he) | |
| have hF : Measurable (fun p : X Γ β => D p.1*p.2) := by fun_prop | |
| rw [β integral_map hT.aemeasurable hF.aestronglyMeasurable,hlaw,integral_prod_mul D (fun y : β => y),integral_id_gaussianReal] | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| def cascadeReplicaLaw (n : β) (b : β β β) : Measure (β β LabeledLeaf n) := | |
| probabilityReplicaKernel (labeledLeafLaw n) (measurable_labeledLeafLaw n) ββ | |
| (labeledCascadeLaw n b : Measure (LabeledTree n)) | |
| instance cascadeReplicaLaw_probability (n : β) (b : β β β) : IsProbabilityMeasure (cascadeReplicaLaw n b) := | |
| inferInstanceAs (IsProbabilityMeasure (_ ββ _)) | |
| def replicaMarkPath {A : Type} (n : β) (Ο : β β NoiseLeaf A n) : β β Fin n β A := | |
| fun i => noiseLeafMark n (Ο i) | |
| lemma measurable_replicaMarkPath {A : Type} [MeasurableSpace A] (n : β) : | |
| Measurable (replicaMarkPath (A := A) n) := by | |
| apply Measurable.of_eval; intro i | |
| apply Measurable.of_eval; intro d | |
| exact (measurable_noiseLeafMark n d).comp (measurable_pi_apply i) | |
| def coordinateMarkPath {A : Type} (n : β) (p : (β β LabeledLeaf n) Γ (ForestVertex n β A)) : β β Fin n β A := | |
| fun i d => p.2 (edgeAt n (p.1 i) d) | |
| lemma measurable_coordinateMarkPath {A : Type} [MeasurableSpace A] (n : β) : | |
| Measurable (coordinateMarkPath (A := A) n) := by | |
| apply Measurable.of_eval; intro i | |
| apply Measurable.of_eval; intro d | |
| have hv : Measurable (fun p : (ForestVertex n β A) Γ LabeledLeaf n => p.1 (edgeAt n p.2 d)) := | |
| measurable_from_prod_countable_left (fun v => measurable_pi_apply (edgeAt n v d)) | |
| exact hv.comp (measurable_snd.prodMk ((measurable_pi_apply i).comp measurable_fst)) | |
| theorem marked_path_law {A : Type} [MeasurableSpace A] [Nonempty A] | |
| (n : β) (b : β β β) (hb : CascadeExponents n b) (ΞΌ : β β ProbabilityMeasure A) : | |
| (markedReplicaLaw n b ΞΌ).map (replicaMarkPath n) = | |
| ((cascadeReplicaLaw n b).prod (Measure.infinitePi | |
| (fun v : ForestVertex n => (ΞΌ (forestVertexDepth n v) : Measure A)))).map (coordinateMarkPath n) := by | |
| let Q := Measure.infinitePi (fun v : ForestVertex n => (ΞΌ (forestVertexDepth n v) : Measure A)) | |
| let P := (labeledCascadeLaw n b : Measure (LabeledTree n)).prod Q | |
| let K := probabilityReplicaKernel (labeledLeafLaw n) (measurable_labeledLeafLaw n) | |
| have hΞ¨ : Measurable (fun p : (LabeledTree n Γ (ForestVertex n β A)) Γ (β β LabeledLeaf n) => | |
| fun i => labeledNoiseLeaf A n (p.1.1,markForestOfCoords A n p.1.2) (p.2 i)) := by | |
| apply Measurable.of_eval; intro i | |
| have hm : Measurable (fun p : (LabeledTree n Γ (ForestVertex n β A)) Γ LabeledLeaf n => | |
| labeledNoiseLeaf A n (p.1.1,markForestOfCoords A n p.1.2) p.2) := by | |
| apply measurable_from_prod_countable_left; intro v | |
| exact (measurable_labeledNoiseLeaf A n v).comp (by fun_prop) | |
| exact hm.comp (measurable_fst.prodMk ((measurable_pi_apply i).comp measurable_snd)) | |
| rw [β labeled_marked_replica_law n b hb ΞΌ,Measure.map_map (measurable_replicaMarkPath n) hΞ¨] | |
| have he := independent_marks_sampling (labeledCascadeLaw n b : Measure (LabeledTree n)) Q K | |
| change (P ββ K.comap Prod.fst measurable_fst).map _ = _ | |
| rw [show (cascadeReplicaLaw n b).prod Q = | |
| (P ββ K.comap Prod.fst measurable_fst).map (fun p => (p.2,p.1.2)) from he.symm, | |
| Measure.map_map (measurable_coordinateMarkPath n) (by fun_prop)] | |
| congr 1 | |
| funext p i d | |
| exact noiseLeafMark_labeled n p.1.1 p.1.2 (p.2 i) d | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| def retainedLabelLeafLaw (n : β) (b a : β β β) : | |
| LabeledTree n Γ (ForestVertex n β β) β Measure (LabeledLeaf n) := | |
| labeledWeightedLeafLaw n (fun i (p : PUnit Γ β) => retainedGaussianScale (b i) (a i) p.2) | |
| (fun _ _ => PUnit.unit) PUnit.unit | |
| instance retainedLabelLeafLaw_probability (n : β) (b a : β β β) | |
| (p : LabeledTree n Γ (ForestVertex n β β)) : IsProbabilityMeasure (retainedLabelLeafLaw n b a p) := | |
| labeledWeightedLeafLaw_probability _ _ _ _ _ | |
| lemma measurable_retainedLabelLeafLaw (n : β) (b a : β β β) : | |
| Measurable (retainedLabelLeafLaw n b a) := | |
| measurable_labeledWeightedLeafLaw n (fun i => by unfold retainedGaussianScale; fun_prop) | |
| (fun _ => measurable_const) PUnit.unit | |
| def retainedLabelBase (n : β) (b : β β β) : Measure (LabeledTree n Γ (ForestVertex n β β)) := | |
| (labeledCascadeLaw n b : Measure (LabeledTree n)).prod | |
| (Measure.infinitePi (fun _ : ForestVertex n => gaussianReal 0 1)) | |
| instance retainedLabelBase_probability (n : β) (b : β β β) : IsProbabilityMeasure (retainedLabelBase n b) := | |
| inferInstanceAs (IsProbabilityMeasure (Measure.prod _ _)) | |
| def retainedLabelJoint (n : β) (b a : β β β) : | |
| Measure ((LabeledTree n Γ (ForestVertex n β β)) Γ (β β LabeledLeaf n)) := | |
| retainedLabelBase n b ββ probabilityReplicaKernel (retainedLabelLeafLaw n b a) | |
| (measurable_retainedLabelLeafLaw n b a) | |
| instance retainedLabelJoint_probability (n : β) (b a : β β β) : IsProbabilityMeasure (retainedLabelJoint n b a) := | |
| inferInstanceAs (IsProbabilityMeasure (_ ββ _)) | |
| def sampledMarkPath (n : β) (p : (LabeledTree n Γ (ForestVertex n β β)) Γ (β β LabeledLeaf n)) : | |
| β β Fin n β β := coordinateMarkPath n (p.2,p.1.2) | |
| lemma measurable_sampledMarkPath (n : β) : Measurable (sampledMarkPath n) := | |
| (measurable_coordinateMarkPath n).comp (measurable_snd.prodMk (measurable_snd.comp measurable_fst)) | |
| theorem retained_joint_path_law (n : β) (b : β β β) (hb : CascadeExponents n b) (a : β β β) : | |
| (retainedLabelJoint n b a).map (sampledMarkPath n) = | |
| (markedReplicaLaw n b (fun i => β¨gaussianReal (b i*a i) 1,inferInstanceβ©)).map (replicaMarkPath n) := by | |
| let ΞΌ : β β ProbabilityMeasure β := fun _ => β¨gaussianReal 0 1,inferInstanceβ© | |
| let Ξ½ : β β ProbabilityMeasure β := fun i => β¨gaussianReal (b i*a i) 1,inferInstanceβ© | |
| let c := fun i (p : PUnit Γ β) => retainedGaussianScale (b i) (a i) p.2 | |
| let u := fun (_ : β) (_ : PUnit Γ β) => PUnit.unit | |
| have hc : β i, Measurable (c i) := fun i => by unfold c retainedGaussianScale; fun_prop | |
| have hu : β i, Measurable (u i) := fun _ => measurable_const | |
| have hm : β i s, β«β» x, ENNReal.ofReal (c i (s,x)^b i) β(ΞΌ i : Measure β) = 1 := | |
| fun i _ => retainedGaussianScale_normalized _ _ | |
| have hL := labeled_weighted_marked_replica_law n b hb ΞΌ hc hu | |
| (fun i s x => Real.exp_pos _) hm PUnit.unit | |
| have hM := noise_mark_replica_transport n b hb ΞΌ Ξ½ | |
| (fun i x => retainedGaussianScale (b i) (a i) x) | |
| (fun i => by unfold retainedGaussianScale; fun_prop) (fun i x => Real.exp_pos _) | |
| (fun i => (retainedGaussianScale_density _ _).symm) | |
| have hΞ¨ : Measurable (fun p : (LabeledTree n Γ (ForestVertex n β β)) Γ (β β LabeledLeaf n) => | |
| fun i => labeledNoiseLeaf β n (p.1.1,markForestOfCoords β n p.1.2) (p.2 i)) := by | |
| apply Measurable.of_eval; intro i | |
| have hΟ : Measurable (fun p : (LabeledTree n Γ (ForestVertex n β β)) Γ LabeledLeaf n => | |
| labeledNoiseLeaf β n (p.1.1,markForestOfCoords β n p.1.2) p.2) := by | |
| apply measurable_from_prod_countable_left; intro v | |
| exact (measurable_labeledNoiseLeaf β n v).comp (by fun_prop) | |
| exact hΟ.comp (measurable_fst.prodMk ((measurable_pi_apply i).comp measurable_snd)) | |
| have he := congrArg (fun P : Measure (β β NoiseLeaf β n) => P.map (replicaMarkPath n)) hL | |
| rw [Measure.map_map (measurable_replicaMarkPath n) hΨ] at he | |
| have hpath : (fun p : (LabeledTree n Γ (ForestVertex n β β)) Γ (β β LabeledLeaf n) => | |
| replicaMarkPath n (fun i => labeledNoiseLeaf β n (p.1.1,markForestOfCoords β n p.1.2) (p.2 i))) = | |
| sampledMarkPath n := by | |
| funext p i d | |
| exact noiseLeafMark_labeled n p.1.1 p.1.2 (p.2 i) d | |
| change (retainedLabelJoint n b a).map _ = _ at he | |
| change (retainedLabelJoint n b a).map _ = _ | |
| rw [show (replicaMarkPath n β (fun p : (LabeledTree n Γ (ForestVertex n β β)) Γ (β β LabeledLeaf n) => | |
| fun i => labeledNoiseLeaf β n (p.1.1,markForestOfCoords β n p.1.2) (p.2 i))) = sampledMarkPath n from hpath] at he | |
| exact he.trans hM | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| lemma tilted_sub_constant {X : Type*} [MeasurableSpace X] | |
| (Ξ½ : Measure X) [IsProbabilityMeasure Ξ½] (H : X β β) | |
| (he : Integrable (fun x => Real.exp (H x)) Ξ½) (c : β) : | |
| Ξ½.tilted (fun x => H x-c) = Ξ½.tilted H := by | |
| have := isProbabilityMeasure_tilted he | |
| have h := tilted_tilted he (fun _ => -c) | |
| simpa only [tilted_const,Pi.add_def,sub_eq_add_neg] using h.symm | |
| lemma retainedLabelLeafLaw_single_tilted (n : β) (b : β β β) (d : Fin n) (t : β) | |
| (p : LabeledTree n Γ (ForestVertex n β β)) | |
| (he : Integrable (fun v => Real.exp (t*p.2 (edgeAt n v d))) (labeledLeafLaw n p.1)) : | |
| retainedLabelLeafLaw n b (fun i => if i = d then t else 0) p = | |
| (labeledLeafLaw n p.1).tilted (fun v => t*p.2 (edgeAt n v d)) := by | |
| have hW : (fun v => labeledWeight n | |
| (fun i (q : PUnit Γ β) => retainedGaussianScale (b i) (if i = d then t else 0) q.2) | |
| (fun _ _ => PUnit.unit) PUnit.unit (p,v)) = | |
| (fun v => ENNReal.ofReal (Real.exp (t*p.2 (edgeAt n v d)-b d*t^2/2))) := by | |
| funext v | |
| exact noiseLeafProduct_single_level n b d t p.1 p.2 v | |
| unfold retainedLabelLeafLaw labeledWeightedLeafLaw labeledWeightedMass | |
| rw [hW] | |
| have hei : Integrable (fun v => Real.exp (t*p.2 (edgeAt n v d)-b d*t^2/2)) (labeledLeafLaw n p.1) := by | |
| simpa only [Real.exp_sub] using he.div_const (Real.exp (b d*t^2/2)) | |
| rw [normalizeMass_exp _ _ (measurable_of_countable _) hei, | |
| tilted_sub_constant _ _ he] | |
| def leafLevelCoefficients (n : β) (d : Fin n) (v : LabeledLeaf n) : β ββ β := | |
| Finsupp.single (edgeGaussianTag n (edgeAt n v d)) 1 | |
| lemma leafLevelCoefficients_field (n : β) (d : Fin n) (v : LabeledLeaf n) (g : β β β) : | |
| cylinderField (leafLevelCoefficients n d v) g = edgeGaussianCoordinates n g (edgeAt n v d) := by | |
| simp [leafLevelCoefficients,cylinderField,Finsupp.sum_single_index,edgeGaussianCoordinates] | |
| lemma leafLevelCoefficients_bound (n : β) (d : Fin n) (v : LabeledLeaf n) : | |
| (leafLevelCoefficients n d v).sum (fun _ c => c^2) β€ 1 := by | |
| simp [leafLevelCoefficients,Finsupp.sum_single_index] | |
| lemma leafLevelCoefficients_diag (n : β) (d : Fin n) (v : LabeledLeaf n) : | |
| cylinderCross (leafLevelCoefficients n d v) (leafLevelCoefficients n d v) = 1 := by | |
| simp [leafLevelCoefficients,cylinderCross_single_left] | |
| lemma leafLevelCoefficients_cross (n : β) (d : Fin n) (v w : LabeledLeaf n) : | |
| cylinderCross (leafLevelCoefficients n d v) (leafLevelCoefficients n d w) = | |
| if (labeledAddress n v).take (d+1) = (labeledAddress n w).take (d+1) then 1 else 0 := | |
| labelLevelCoefficients_cross n d (PUnit.unit,v) (PUnit.unit,w) | |
| def rawLeafGibbs (n : β) (d : Fin n) (t : β) | |
| (p : LabeledTree n Γ (β β β)) : Measure (LabeledLeaf n) := | |
| gibbsProbability (labeledLeafLaw n p.1) (fun v => t*cylinderField (leafLevelCoefficients n d v) p.2) | |
| instance rawLeafGibbs_probability (n : β) (d : Fin n) (t : β) (p : LabeledTree n Γ (β β β)) : | |
| IsProbabilityMeasure (rawLeafGibbs n d t p) := gibbsProbability_probability _ _ | |
| lemma measurable_rawLeafGibbs (n : β) (d : Fin n) (t : β) : Measurable (rawLeafGibbs n d t) := by | |
| have hH : Measurable (fun p : (LabeledTree n Γ (β β β)) Γ LabeledLeaf n => | |
| t*cylinderField (leafLevelCoefficients n d p.2) p.1.2) := | |
| ((measurable_cylinderFields (leafLevelCoefficients n d)).comp | |
| ((measurable_snd.comp measurable_fst).prodMk measurable_snd)).const_mul t | |
| have hΞ½ : Measurable (fun p : LabeledTree n Γ (β β β) => labeledLeafLaw n p.1) := | |
| (measurable_labeledLeafLaw n).comp measurable_fst | |
| exact measurable_gibbsProbability hΞ½ hH | |
| def rawLabelBase (n : β) (b : β β β) : Measure (LabeledTree n Γ (β β β)) := | |
| (labeledCascadeLaw n b : Measure (LabeledTree n)).prod gaussianCoordinates | |
| instance rawLabelBase_probability (n : β) (b : β β β) : IsProbabilityMeasure (rawLabelBase n b) := | |
| inferInstanceAs (IsProbabilityMeasure (Measure.prod _ _)) | |
| def rawLabelJoint (n : β) (b : β β β) (d : Fin n) (t : β) : | |
| Measure ((LabeledTree n Γ (β β β)) Γ (β β LabeledLeaf n)) := | |
| rawLabelBase n b ββ probabilityReplicaKernel (rawLeafGibbs n d t) (measurable_rawLeafGibbs n d t) | |
| instance rawLabelJoint_probability (n : β) (b : β β β) (d : Fin n) (t : β) : | |
| IsProbabilityMeasure (rawLabelJoint n b d t) := inferInstanceAs (IsProbabilityMeasure (_ ββ _)) | |
| lemma rawLeafGibbs_retained (n : β) (b : β β β) (d : Fin n) (t : β) | |
| (p : LabeledTree n Γ (β β β)) | |
| (he : Integrable (fun v => Real.exp (t*cylinderField (leafLevelCoefficients n d v) p.2)) (labeledLeafLaw n p.1)) : | |
| rawLeafGibbs n d t p = | |
| retainedLabelLeafLaw n b (fun i => if i = d then t else 0) (p.1,edgeGaussianCoordinates n p.2) := by | |
| have heq : (fun v => t*cylinderField (leafLevelCoefficients n d v) p.2) = | |
| (fun v => t*edgeGaussianCoordinates n p.2 (edgeAt n v d)) := by | |
| funext v; rw [leafLevelCoefficients_field] | |
| have he' : Integrable (fun v => Real.exp (t*edgeGaussianCoordinates n p.2 (edgeAt n v d))) (labeledLeafLaw n p.1) := by | |
| simpa only [leafLevelCoefficients_field] using he | |
| have hR := retainedLabelLeafLaw_single_tilted n b d t (p.1,edgeGaussianCoordinates n p.2) he' | |
| have hG : rawLeafGibbs n d t p = (labeledLeafLaw n p.1).tilted | |
| (fun v => t*cylinderField (leafLevelCoefficients n d v) p.2) := gibbsProbability_eq_tilted _ _ he | |
| exact hG.trans ((congrArg (fun H => (labeledLeafLaw n p.1).tilted H) heq).trans hR.symm) | |
| lemma rawLeafGibbs_retained_ae (n : β) (b : β β β) (d : Fin n) (t : β) : | |
| βα΅ p βrawLabelBase n b, rawLeafGibbs n d t p = | |
| retainedLabelLeafLaw n b (fun i => if i = d then t else 0) (p.1,edgeGaussianCoordinates n p.2) := by | |
| have ha := random_cylinder_all_exp_ae (P := (labeledCascadeLaw n b : Measure (LabeledTree n))) | |
| (measurable_labeledLeafLaw n) (leafLevelCoefficients n d) (leafLevelCoefficients_bound n d) | |
| exact ha.mono (fun p hp => rawLeafGibbs_retained n b d t p (hp t)) | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| lemma compProd_base_map {Ξ© Ξ©' X : Type*} [MeasurableSpace Ξ©] [MeasurableSpace Ξ©'] | |
| [MeasurableSpace X] (P : Measure Ξ©) [SFinite P] (Q : Measure Ξ©') [SFinite Q] | |
| (K : Kernel Ξ© X) [IsSFiniteKernel K] (L : Kernel Ξ©' X) [IsSFiniteKernel L] | |
| {T : Ξ© β Ξ©'} (hT : Measurable T) (hPQ : P.map T = Q) | |
| (hK : βα΅ Ο βP, K Ο = L (T Ο)) : | |
| (P ββ K).map (fun p => (T p.1,p.2)) = Q ββ L := by | |
| have hS : Measurable (fun p : Ξ© Γ X => (T p.1,p.2)) := (hT.comp measurable_fst).prodMk measurable_snd | |
| apply Measure.ext_of_lintegral | |
| intro F hF | |
| have hFS : Measurable (fun p : Ξ© Γ X => F (T p.1,p.2)) := hF.comp hS | |
| rw [lintegral_map hF hS,Measure.lintegral_compProd hFS, | |
| Measure.lintegral_compProd hF] | |
| calc | |
| _ = β«β» Ο, β«β» x, F (T Ο,x) βL (T Ο) βP := by | |
| apply lintegral_congr_ae | |
| filter_upwards [hK] with Ο hΟ | |
| rw [hΟ] | |
| _ = _ := by | |
| have hI : Measurable (fun Ο' => β«β» x, F (Ο',x) βL Ο') := | |
| Measurable.lintegral_kernel_prod_right (f := fun Ο' x => F (Ο',x)) hF | |
| rw [β lintegral_map hI hT,hPQ] | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| def rawLabelToRetained (n : β) (p : (LabeledTree n Γ (β β β)) Γ (β β LabeledLeaf n)) : | |
| (LabeledTree n Γ (ForestVertex n β β)) Γ (β β LabeledLeaf n) := | |
| ((p.1.1,edgeGaussianCoordinates n p.1.2),p.2) | |
| lemma measurable_rawLabelToRetained (n : β) : Measurable (rawLabelToRetained n) := | |
| (measurable_fst.fst.prodMk ((edgeGaussianCoordinates_preserving n).measurable.comp measurable_fst.snd)).prodMk measurable_snd | |
| lemma raw_retained_joint_preserving (n : β) (b : β β β) (d : Fin n) (t : β) : | |
| MeasurePreserving (rawLabelToRetained n) (rawLabelJoint n b d t) | |
| (retainedLabelJoint n b (fun i => if i = d then t else 0)) := by | |
| have hp : MeasurePreserving (fun p : LabeledTree n Γ (β β β) => (p.1,edgeGaussianCoordinates n p.2)) | |
| (rawLabelBase n b) (retainedLabelBase n b) := | |
| (MeasurePreserving.id _).prod (edgeGaussianCoordinates_preserving n) | |
| refine β¨measurable_rawLabelToRetained n,?_β© | |
| apply compProd_base_map _ _ _ _ hp.measurable hp.map_eq | |
| filter_upwards [rawLeafGibbs_retained_ae n b d t] with p he | |
| change Measure.infinitePi (fun _ : β => rawLeafGibbs n d t p) = | |
| Measure.infinitePi (fun _ : β => retainedLabelLeafLaw n b (fun i => if i = d then t else 0) | |
| (p.1,edgeGaussianCoordinates n p.2)) | |
| rw [he] | |
| lemma rawJoint_integral_reference (n : β) (b : β β β) (d : Fin n) (t : β) (r : β) | |
| (F : (LabeledTree n Γ (β β β)) β (Fin r β LabeledLeaf n) β β) | |
| (hi : Integrable (fun p => F p.1 (fun i => p.2 i)) (rawLabelJoint n b d t)) : | |
| (β« p, F p.1 (fun i => p.2 i) βrawLabelJoint n b d t) = | |
| β« p, referenceReplicaMean (labeledLeafLaw n p.1) | |
| (fun v => t*cylinderField (leafLevelCoefficients n d v) p.2) (F p) βrawLabelBase n b := by | |
| rw [show rawLabelJoint n b d t = rawLabelBase n b ββ | |
| probabilityReplicaKernel (rawLeafGibbs n d t) (measurable_rawLeafGibbs n d t) from rfl, | |
| Measure.integral_compProd hi] | |
| have ha := random_cylinder_all_exp_ae (P := (labeledCascadeLaw n b : Measure (LabeledTree n))) | |
| (measurable_labeledLeafLaw n) (leafLevelCoefficients n d) (leafLevelCoefficients_bound n d) | |
| apply integral_congr_ae | |
| filter_upwards [ha] with p hp | |
| have he := hp t | |
| have hg : rawLeafGibbs n d t p = (labeledLeafLaw n p.1).tilted | |
| (fun v => t*cylinderField (leafLevelCoefficients n d v) p.2) := gibbsProbability_eq_tilted _ _ he | |
| rw [referenceReplicaMean_eq_tilted _ _ he,β hg] | |
| change (β« Ο, F p (fun i => Ο i) βMeasure.infinitePi (fun _ : β => rawLeafGibbs n d t p)) = _ | |
| have hh := (HasLaw.mk (P := Measure.infinitePi (fun _ : β => rawLeafGibbs n d t p)) | |
| (show AEMeasurable (fun Ο : β β LabeledLeaf n => fun i : Fin r => Ο i) _ from (by fun_prop : Measurable _).aemeasurable) | |
| (replica_prefix_map (rawLeafGibbs n d t p) r)).integral_comp | |
| (measurable_of_countable (F p)).aestronglyMeasurable | |
| exact hh | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| def pathPrefixPattern (n r : β) (z : β β Fin n β β) : PrefixPattern n r := | |
| fun i j d => if z i d = z j d then true else false | |
| lemma measurable_pathPrefixPattern (n r : β) : Measurable (pathPrefixPattern n r) := by | |
| unfold pathPrefixPattern | |
| apply Measurable.of_eval; intro i | |
| apply Measurable.of_eval; intro j | |
| apply Measurable.of_eval; intro d | |
| apply Measurable.ite _ measurable_const measurable_const | |
| exact measurableSet_eq_fun ((measurable_pi_apply d).comp (measurable_pi_apply (i:β))) | |
| ((measurable_pi_apply d).comp (measurable_pi_apply (j:β))) | |
| lemma measurable_labelPrefixPattern (n r : β) : Measurable (labelPrefixPattern n r) := | |
| measurable_of_countable _ | |
| lemma measurable_infiniteLabelPattern (n r : β) : | |
| Measurable (fun Ο : β β LabeledLeaf n => labelPrefixPattern n r (fun i => Ο i)) := | |
| (measurable_labelPrefixPattern n r).comp (by fun_prop) | |
| lemma pathPrefixPattern_coordinates (n r : β) (Ο : β β LabeledLeaf n) | |
| (g : ForestVertex n β β) (hg : Function.Injective g) : | |
| pathPrefixPattern n r (coordinateMarkPath n (Ο,g)) = | |
| labelPrefixPattern n r (fun i => Ο i) := by | |
| funext i j d | |
| unfold pathPrefixPattern coordinateMarkPath labelPrefixPattern | |
| simp only [hg.eq_iff,edgeAt_eq_iff_prefix] | |
| def gaussianMarkedPathLaw (n : β) (b m : β β β) : Measure (β β Fin n β β) := | |
| (markedReplicaLaw n b (fun i => β¨gaussianReal (m i) 1,inferInstanceβ©)).map (replicaMarkPath n) | |
| lemma gaussianMarkedPathLaw_eq (n : β) (b : β β β) (hb : CascadeExponents n b) (m : β β β) : | |
| gaussianMarkedPathLaw n b m = | |
| ((cascadeReplicaLaw n b).prod (Measure.infinitePi | |
| (fun v : ForestVertex n => gaussianReal (m (forestVertexDepth n v)) 1))).map (coordinateMarkPath n) := | |
| marked_path_law n b hb _ | |
| lemma path_shape_ae_coordinates (n r : β) (b m : β β β) : | |
| βα΅ p β(cascadeReplicaLaw n b).prod (Measure.infinitePi | |
| (fun v : ForestVertex n => gaussianReal (m (forestVertexDepth n v)) 1)), | |
| pathPrefixPattern n r (coordinateMarkPath n p) = labelPrefixPattern n r (fun i => p.1 i) := by | |
| have ha := gaussian_marks_injective n m | |
| have hp := measurePreserving_snd (ΞΌ := cascadeReplicaLaw n b) | |
| (Ξ½ := Measure.infinitePi (fun v : ForestVertex n => gaussianReal (m (forestVertexDepth n v)) 1)) | |
| filter_upwards [hp.quasiMeasurePreserving.tendsto_ae.eventually ha] with p hp | |
| exact pathPrefixPattern_coordinates n r p.1 p.2 hp | |
| theorem gaussian_marked_shape (n r : β) (b : β β β) (hb : CascadeExponents n b) | |
| (m : β β β) (D : PrefixPattern n r β β) : | |
| (β« z, D (pathPrefixPattern n r z) βgaussianMarkedPathLaw n b m) = | |
| β« Ο, D (labelPrefixPattern n r (fun i => Ο i)) βcascadeReplicaLaw n b := by | |
| have hD := measurable_of_countable D | |
| have hF : Measurable (fun z => D (pathPrefixPattern n r z)) := hD.comp (measurable_pathPrefixPattern n r) | |
| rw [gaussianMarkedPathLaw_eq n b hb m, | |
| integral_map (measurable_coordinateMarkPath n).aemeasurable hF.aestronglyMeasurable] | |
| calc | |
| _ = β« p, D (labelPrefixPattern n r (fun i => p.1 i)) | |
| β(cascadeReplicaLaw n b).prod (Measure.infinitePi | |
| (fun v : ForestVertex n => gaussianReal (m (forestVertexDepth n v)) 1)) := | |
| integral_congr_ae ((path_shape_ae_coordinates n r b m).mono (fun _ h => congrArg D h)) | |
| _ = _ := by | |
| simpa using integral_fun_fst (ΞΌ := cascadeReplicaLaw n b) | |
| (Ξ½ := Measure.infinitePi (fun v : ForestVertex n => gaussianReal (m (forestVertexDepth n v)) 1)) | |
| (fun Ο => D (labelPrefixPattern n r (fun i => Ο i))) | |
| theorem gaussian_marked_shape_score (n r : β) (b : β β β) (hb : CascadeExponents n b) | |
| (m : β β β) (d : Fin n) (D : PrefixPattern n r β β) : | |
| (β« z, D (pathPrefixPattern n r z)*z 0 d βgaussianMarkedPathLaw n b m) = | |
| (β« Ο, D (labelPrefixPattern n r (fun i => Ο i)) βcascadeReplicaLaw n b)*m d := by | |
| have hD := measurable_of_countable D | |
| have hF : Measurable (fun z : β β Fin n β β => D (pathPrefixPattern n r z)*z 0 d) := | |
| (hD.comp (measurable_pathPrefixPattern n r)).mul | |
| ((measurable_pi_apply d).comp (measurable_pi_apply 0)) | |
| rw [gaussianMarkedPathLaw_eq n b hb m, | |
| integral_map (measurable_coordinateMarkPath n).aemeasurable hF.aestronglyMeasurable] | |
| calc | |
| _ = β« p, D (labelPrefixPattern n r (fun i => p.1 i))*p.2 (edgeAt n (p.1 0) d) | |
| β(cascadeReplicaLaw n b).prod (Measure.infinitePi | |
| (fun v : ForestVertex n => gaussianReal (m (forestVertexDepth n v)) 1)) := by | |
| apply integral_congr_ae | |
| filter_upwards [path_shape_ae_coordinates n r b m] with p hp | |
| rw [hp]; rfl | |
| _ = _ := by | |
| let : MeasurableSpace (ForestVertex n) := β€ | |
| let : MeasurableSingletonClass (ForestVertex n) := β¨fun _ => MeasurableSet.of_discreteβ© | |
| exact selected_gaussian_score (cascadeReplicaLaw n b) (fun v => m (forestVertexDepth n v)) | |
| ((measurable_of_countable (fun v : LabeledLeaf n => edgeAt n v d)).comp (measurable_pi_apply 0)) | |
| (m d) (fun Ο => by simp only [Function.comp_apply,forestVertexDepth_edgeAt]) | |
| (hD.comp (measurable_infiniteLabelPattern n r)) | |
| end IsingPerceptron | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped BigOperators Topology ENNReal NNReal | |
| namespace IsingPerceptron | |
| lemma selected_gaussian_score_integrable {X I : Type*} [MeasurableSpace X] [MeasurableSpace I] | |
| [Countable I] [MeasurableSingletonClass I] | |
| (P : Measure X) [IsProbabilityMeasure P] (mean : I β β) | |
| {e : X β I} (he : Measurable e) (m : β) (hm : β x, mean (e x) = m) | |
| {D : X β β} (hD : Measurable D) (hi : Integrable D P) : | |
| Integrable (fun p : X Γ (I β β) => D p.1*p.2 (e p.1)) | |
| (P.prod (Measure.infinitePi (fun i => gaussianReal (mean i) 1))) := by | |
| have hlaw := selected_coordinate_prod_law P (fun i => gaussianReal (mean i) 1) he | |
| (gaussianReal m 1) (fun x => by rw [hm x]) | |
| have hT : Measurable (fun p : X Γ (I β β) => (p.1,p.2 (e p.1))) := | |
| measurable_fst.prodMk (measurable_selected_coordinate he) | |
| have hF : Measurable (fun p : X Γ β => D p.1*p.2) := by fun_prop | |
| have hG : Integrable (fun x : β => x) (gaussianReal m 1) := | |
| (memLp_id_gaussianReal (ΞΌ := m) (v := 1) 1).integrable (by norm_num) | |
| have hiF : Integrable (fun p : X Γ β => D p.1*p.2) (P.prod (gaussianReal m 1)) := hi.mul_prod hG | |
| rw [β hlaw] at hiF | |
| exact (integrable_map_measure hF.aestronglyMeasurable hT.aemeasurable).mp hiF | |
| lemma gaussian_marked_shape_score_integrable (n r : β) (b : β β β) (hb : CascadeExponents n b) | |
| (m : β β β) (d : Fin n) (D : PrefixPattern n r β β) {c : β} (hD : β x, |D x| β€ c) : | |
| Integrable (fun z => D (pathPrefixPattern n r z)*z 0 d) (gaussianMarkedPathLaw n b m) := by | |
| have hDm := measurable_of_countable D | |
| have hF : Measurable (fun z : β β Fin n β β => D (pathPrefixPattern n r z)*z 0 d) := | |
| (hDm.comp (measurable_pathPrefixPattern n r)).mul | |
| ((measurable_pi_apply d).comp (measurable_pi_apply 0)) | |
| rw [gaussianMarkedPathLaw_eq n b hb m] | |
| apply (integrable_map_measure hF.aestronglyMeasurable (measurable_coordinateMarkPath n).aemeasurable).mpr | |
| let : MeasurableSpace (ForestVertex n) := β€ | |
| let : MeasurableSingletonClass (ForestVertex n) := β¨fun _ => MeasurableSet.of_discreteβ© | |
| have hiD : Integrable (fun Ο : β β LabeledLeaf n => D (labelPrefixPattern n r (fun i => Ο i))) | |
| (cascadeReplicaLaw n b) := | |
| integrable_of_measurable_abs_le (hDm.comp (measurable_infiniteLabelPattern n r)) (fun _ => hD _) | |
| have hi := selected_gaussian_score_integrable (cascadeReplicaLaw n b) | |
| (fun v => m (forestVertexDepth n v)) | |
| ((measurable_of_countable (fun v : LabeledLeaf n => edgeAt n v d)).comp (measurable_pi_apply 0)) | |
| (m d) (fun Ο => by simp only [Function.comp_apply,forestVertexDepth_edgeAt]) | |
| (hDm.comp (measurable_infiniteLabelPattern n r)) hiD | |
| apply hi.congr | |
| filter_upwards [path_shape_ae_coordinates n r b m] with p hp | |
| change D (labelPrefixPattern n r (fun i => p.1 i))*p.2 (edgeAt n (p.1 0) d) = _ | |
| rw [β hp]; rfl | |
| end IsingPerceptron | |
| end | |
| end OAI | |