math / data /lean /OAI /Probability /IsingPerceptron /SamplingIndependent.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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