Download data/lean/OAI/Probability/FreeIsing/Posterior/GaussianTesting.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.05 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/FreeIsing/Posterior/GaussianTesting.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/FreeIsing/Posterior/GaussianTesting.lean
-
curl -L -o GaussianTesting.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/FreeIsing/Posterior/GaussianTesting.lean
8.05 kB
| import OAI.Probability.FreeIsing.Gaussian.FiniteGaussianPlanted | |
| import OAI.Probability.FreeIsing.Posterior.Fields | |
| namespace OAI | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory | |
| open scoped NNReal ENNReal ProbabilityTheory | |
| namespace Problem367 | |
| theorem gaussianPi_map_sqrt {I : Type*} [Fintype I] | |
| (t : β) (ht : 0 β€ t) : | |
| (Measure.pi (fun _ : I => gaussianReal 0 1)).map | |
| (fun x i => Real.sqrt t * x i) = | |
| Measure.pi (fun _ : I => gaussianReal 0 β¨t, htβ©) := by | |
| rw [Measure.pi_map_pi (ΞΌ := fun _ : I => gaussianReal 0 1) | |
| (f := fun _ (x : β) => Real.sqrt t * x) (fun _ => by fun_prop)] | |
| congr 1 | |
| funext i | |
| rw [gaussianReal_map_const_mul] | |
| congr 1 | |
| Β· simp | |
| Β· apply NNReal.coe_injective | |
| change (Real.sqrt t) ^ 2 * 1 = t | |
| rw [mul_one, Real.sq_sqrt ht] | |
| theorem finiteStandardGaussianPlanted_joint_law | |
| {S I : Type*} [Fintype S] [MeasurableSpace S] [MeasurableSingletonClass S] | |
| [Fintype I] (ΞΌ : Measure S) [IsProbabilityMeasure ΞΌ] | |
| (t : β) (ht : 0 β€ t) (spin : S β I β β) : | |
| (ΞΌ.prod (Measure.pi (fun _ : I => gaussianReal 0 1))).map | |
| (fun z : S Γ (I β β) => | |
| (z.1, fun i => t * spin z.1 i + Real.sqrt t * z.2 i)) = | |
| ΞΌ ββ finiteGaussianObservationKernel β¨t, htβ© spin := by | |
| have : IsMarkovKernel (finiteGaussianObservationKernel β¨t, htβ© spin) := | |
| finiteGaussianObservationKernel_isMarkov β¨t, htβ© spin | |
| apply map_planted_eq_compProd ΞΌ (Measure.pi (fun _ : I => gaussianReal 0 1)) | |
| (finiteGaussianObservationKernel β¨t, htβ© spin) | |
| (fun s x i => t * spin s i + Real.sqrt t * x i) | |
| Β· exact Measurable.of_eval (fun index => | |
| (measurable_const.mul ((measurable_of_finite (fun state => spin state index)).comp | |
| measurable_fst)).add (measurable_const.mul | |
| ((measurable_pi_apply index).comp measurable_snd))) | |
| Β· intro s | |
| have hscale : Measurable (fun x : I β β => fun i => Real.sqrt t * x i) := by | |
| fun_prop | |
| have hshift : Measurable (fun x : I β β => fun i => t * spin s i + x i) := by | |
| fun_prop | |
| rw [show (fun x : I β β => fun i => t * spin s i + Real.sqrt t * x i) = | |
| (fun x : I β β => fun i => t * spin s i + x i) β | |
| (fun x : I β β => fun i => Real.sqrt t * x i) from rfl, | |
| β Measure.map_map hshift hscale, gaussianPi_map_sqrt t ht] | |
| exact gaussianPi_map_signal β¨t, htβ© (spin s) | |
| namespace FinitePosterior | |
| theorem exponential_posterior_eq_fieldMean | |
| {S I : Type*} [Fintype S] [Nonempty S] [Fintype I] | |
| [MeasurableSpace S] (ΞΌ : Measure S) (energy : S β β) | |
| (hprior : β s, ΞΌ.real {s} = Real.exp (energy s) / β a, Real.exp (energy a)) | |
| (spin : S β I β β) (q : S β β) (x : I β β) : | |
| (β s, ΞΌ.real {s} * Real.exp (β i, spin s i * x i) * q s) / | |
| (β s, ΞΌ.real {s} * Real.exp (β i, spin s i * x i)) = | |
| fieldMean energy spin q x := by | |
| let Z := β s, Real.exp (energy s) | |
| have hZ : Z β 0 := ne_of_gt (Finset.sum_pos | |
| (fun s _ => Real.exp_pos (energy s)) Finset.univ_nonempty) | |
| have hw (s : S) : | |
| ΞΌ.real {s} * Real.exp (β i, spin s i * x i) = | |
| Real.exp (fieldEnergy energy spin x s) / Z := by | |
| rw [hprior s] | |
| have hsum : (β i, spin s i * x i) = β i, x i * spin s i := by | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| ring | |
| rw [hsum] | |
| simp only [fieldEnergy, Real.exp_add, Z] | |
| ring | |
| simp_rw [hw, div_mul_eq_mul_div, β Finset.sum_div] | |
| rw [div_div_div_cancel_rightβ hZ] | |
| unfold fieldMean | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| ring | |
| end FinitePosterior | |
| theorem finiteStandardGaussianPlanted_condExp_fieldMean | |
| {S I : Type*} [Fintype S] [MeasurableSpace S] [MeasurableSingletonClass S] | |
| [StandardBorelSpace S] [Nonempty S] [Fintype I] | |
| (ΞΌ : Measure S) [IsProbabilityMeasure ΞΌ] (energy : S β β) | |
| (hprior : β s, ΞΌ.real {s} = Real.exp (energy s) / β a, Real.exp (energy a)) | |
| (t : β) (ht : 0 β€ t) (spin : S β I β β) | |
| (hspin : β s i, spin s i ^ 2 = 1) (q : S β β) : | |
| let Ο := ΞΌ.prod (Measure.pi (fun _ : I => gaussianReal 0 1)) | |
| let Y : S Γ (I β β) β I β β := | |
| fun z i => t * spin z.1 i + Real.sqrt t * z.2 i | |
| Ο[fun z => q z.1 | (inferInstance : MeasurableSpace (I β β)).comap Y] =α΅[Ο] | |
| fun z => FinitePosterior.fieldMean energy spin q (Y z) := by | |
| dsimp only | |
| have : IsMarkovKernel (finiteGaussianObservationKernel β¨t, htβ© spin) := | |
| finiteGaussianObservationKernel_isMarkov β¨t, htβ© spin | |
| apply FiniteBayes.condExp_state_eq_of_posterior_integral | |
| (ΞΌ.prod (Measure.pi (fun _ : I => gaussianReal 0 1))) ΞΌ | |
| (finiteGaussianObservationKernel β¨t, htβ© spin) Prod.fst | |
| (fun z i => t * spin z.1 i + Real.sqrt t * z.2 i) measurable_fst | |
| (by exact Measurable.of_eval (fun index => | |
| (measurable_const.mul ((measurable_of_finite (fun state => spin state index)).comp | |
| measurable_fst)).add (measurable_const.mul | |
| ((measurable_pi_apply index).comp measurable_snd)))) | |
| (finiteStandardGaussianPlanted_joint_law ΞΌ t ht spin) q | |
| filter_upwards [finiteGaussianObservation_posterior_mean ΞΌ β¨t, htβ© spin hspin q] | |
| with x hx | |
| exact hx.trans (FinitePosterior.exponential_posterior_eq_fieldMean | |
| ΞΌ energy hprior spin q x) | |
| theorem finiteStandardGaussianPlanted_integral_test_fieldMean | |
| {S I : Type*} [Fintype S] [MeasurableSpace S] [MeasurableSingletonClass S] | |
| [StandardBorelSpace S] [Nonempty S] [Fintype I] | |
| (ΞΌ : Measure S) [IsProbabilityMeasure ΞΌ] (energy : S β β) | |
| (hprior : β s, ΞΌ.real {s} = Real.exp (energy s) / β a, Real.exp (energy a)) | |
| (t : β) (ht : 0 β€ t) (spin : S β I β β) | |
| (hspin : β s i, spin s i ^ 2 = 1) (q : S β β) | |
| (h : (I β β) β β) (hh : Measurable h) (C : β) | |
| (hbound : β x, βh xβ β€ C) : | |
| let Ο := ΞΌ.prod (Measure.pi (fun _ : I => gaussianReal 0 1)) | |
| let Y : S Γ (I β β) β I β β := | |
| fun z i => t * spin z.1 i + Real.sqrt t * z.2 i | |
| (β« z, h (Y z) * q z.1 βΟ) = | |
| β« z, h (Y z) * FinitePosterior.fieldMean energy spin q (Y z) βΟ := by | |
| let Ο := ΞΌ.prod (Measure.pi (fun _ : I => gaussianReal 0 1)) | |
| let Y : S Γ (I β β) β I β β := | |
| fun z i => t * spin z.1 i + Real.sqrt t * z.2 i | |
| change (β« z, h (Y z) * q z.1 βΟ) = _ | |
| have hY : Measurable Y := by | |
| exact Measurable.of_eval (fun index => | |
| (measurable_const.mul ((measurable_of_finite (fun state => spin state index)).comp | |
| measurable_fst)).add (measurable_const.mul | |
| ((measurable_pi_apply index).comp measurable_snd))) | |
| have hm : (inferInstance : MeasurableSpace (I β β)).comap Y β€ | |
| (inferInstance : MeasurableSpace (S Γ (I β β))) := hY.comap_le | |
| have htest : StronglyMeasurable[(inferInstance : MeasurableSpace (I β β)).comap Y] | |
| (fun z => h (Y z)) := | |
| (hh.comp (comap_measurable Y)).stronglyMeasurable | |
| have hq : Integrable (fun z : S Γ (I β β) => q z.1) Ο := by | |
| apply (integrable_const (β s, |q s|)).mono' | |
| Β· exact ((measurable_of_finite q).comp measurable_fst).aestronglyMeasurable | |
| Β· filter_upwards [] with z | |
| rw [Real.norm_eq_abs] | |
| exact Finset.single_le_sum (fun s _ => abs_nonneg (q s)) (Finset.mem_univ z.1) | |
| have hpull := condExp_stronglyMeasurable_mul_of_bound hm htest hq C | |
| (Filter.Eventually.of_forall (fun z => hbound (Y z))) | |
| have hposterior := finiteStandardGaussianPlanted_condExp_fieldMean | |
| ΞΌ energy hprior t ht spin hspin q | |
| calc | |
| (β« z, h (Y z) * q z.1 βΟ) = | |
| β« z, Ο[(fun z => h (Y z)) * (fun z => q z.1) | (inferInstance : MeasurableSpace (I β β)).comap Y] z βΟ := | |
| (integral_condExp hm).symm | |
| _ = β« z, h (Y z) * Ο[(fun z => q z.1) | (inferInstance : MeasurableSpace (I β β)).comap Y] z βΟ := | |
| integral_congr_ae hpull | |
| _ = β« z, h (Y z) * FinitePosterior.fieldMean energy spin q (Y z) βΟ := by | |
| apply integral_congr_ae | |
| filter_upwards [hposterior] with z hz | |
| rw [hz] | |
| end Problem367 | |
| end | |
| end OAI | |