Download data/lean/OAI/Probability/IsingPerceptron/GaussianIntegration.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 60.8 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/IsingPerceptron/GaussianIntegration.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/IsingPerceptron/GaussianIntegration.lean
-
curl -L -o GaussianIntegration.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/IsingPerceptron/GaussianIntegration.lean
60.8 kB
import Mathlib
namespace OAI
/-! Gaussian Integration. -/
noncomputable section
open MeasureTheory ProbabilityTheory Filter Set
open scoped BigOperators Topology ENNReal NNReal BoundedContinuousFunction
namespace IsingPerceptron
lemma hasDerivAt_standardGaussianPDF (x : β) :
HasDerivAt (gaussianPDFReal 0 1) (-x * gaussianPDFReal 0 1 x) x := by
have h := (((hasDerivAt_id x).pow 2).neg.div_const 2).exp.const_mul
(Real.sqrt (2 * Real.pi))β»ΒΉ
convert h using 1 <;> try rfl
Β· ext y
simp [gaussianPDFReal]
Β· norm_num [gaussianPDFReal]
ring
lemma integrable_gaussian_iff {f : β β β} :
Integrable f (gaussianReal 0 1) β
Integrable (fun x => gaussianPDFReal 0 1 x * f x) := by
rw [gaussianReal_of_var_ne_zero 0 (by norm_num : (1 : ββ₯0) β 0)]
rw [integrable_withDensity_iff_integrable_smul']
Β· simp [gaussianPDF, ENNReal.toReal_ofReal, gaussianPDFReal_nonneg]
Β· exact measurable_gaussianPDF _ _
Β· exact ae_of_all _ (fun x => by simp [gaussianPDF])
lemma gaussian_integration_by_parts {f f' : β β β} (hd : β x, HasDerivAt f (f' x) x)
(hf : Integrable f (gaussianReal 0 1))
(hf' : Integrable f' (gaussianReal 0 1))
(hxf : Integrable (fun x => x * f x) (gaussianReal 0 1)) :
(β« x, x * f x βgaussianReal 0 1) = β« x, f' x βgaussianReal 0 1 := by
have hh := integral_mul_deriv_eq_deriv_mul_of_integrable
(u := f) (u' := f') (v := gaussianPDFReal 0 1)
(v' := fun x => -x * gaussianPDFReal 0 1 x)
(fun x _ => hd x) (fun x _ => hasDerivAt_standardGaussianPDF x)
have h1 : Integrable (fun x => f x * (-x * gaussianPDFReal 0 1 x)) := by
convert (integrable_gaussian_iff.mp hxf).neg using 1
ext x; dsimp; ring
have h2 : Integrable (fun x => f' x * gaussianPDFReal 0 1 x) := by
simpa [mul_comm] using integrable_gaussian_iff.mp hf'
have h3 : Integrable (fun x => f x * gaussianPDFReal 0 1 x) := by
simpa [mul_comm] using integrable_gaussian_iff.mp hf
specialize hh h1 h2 h3
rw [integral_gaussianReal_eq_integral_smul (by norm_num : (1 : ββ₯0) β 0),
integral_gaussianReal_eq_integral_smul (by norm_num : (1 : ββ₯0) β 0)]
simp only [smul_eq_mul] at *
have heq : (fun x => f x * (-x * gaussianPDFReal 0 1 x)) =
fun x => -(gaussianPDFReal 0 1 x * (x * f x)) := by ext x; ring
rw [heq, integral_neg] at hh
simpa [mul_comm] using neg_injective hh
lemma gaussian_integration_by_parts_bounded {f f' : β β β}
(hd : β x, HasDerivAt f (f' x) x) (hm' : Measurable f')
{K K' : β} (hb : β x, |f x| β€ K) (hb' : β x, |f' x| β€ K') :
(β« x, x * f x βgaussianReal 0 1) = β« x, f' x βgaussianReal 0 1 := by
have hm : Measurable f := (continuous_iff_continuousAt.mpr
(fun x => (hd x).continuousAt)).measurable
have hif : Integrable f (gaussianReal 0 1) :=
(MemLp.of_bound hm.aestronglyMeasurable K
(ae_of_all _ (fun x => by simpa using hb x)) (p := 1)).integrable le_rfl
have hif' : Integrable f' (gaussianReal 0 1) :=
(MemLp.of_bound hm'.aestronglyMeasurable K'
(ae_of_all _ (fun x => by simpa using hb' x)) (p := 1)).integrable le_rfl
apply gaussian_integration_by_parts hd hif hif'
exact ((memLp_id_gaussianReal 1).integrable le_rfl).mul_bdd
hm.aestronglyMeasurable (ae_of_all _ (fun x => by simpa using hb x))
lemma gaussian_pi_integration_by_parts {n : β} (i : Fin (n + 1))
{F F' : (Fin (n + 1) β β) β β} (hm : Measurable F) (hm' : Measurable F')
(hd : β (g : Fin n β β) (x : β),
HasDerivAt (fun y => F (i.insertNth y g)) (F' (i.insertNth x g)) x)
{K K' : β} (hb : β g, |F g| β€ K) (hb' : β g, |F' g| β€ K') :
(β« g, g i * F g βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)) =
β« g, F' g βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1) := by
let ΞΌ := Measure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)
let Ξ½ := Measure.pi (fun _ : Fin n => gaussianReal 0 1)
let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n + 1) => β) i
have he : MeasurePreserving e.symm ((gaussianReal 0 1).prod Ξ½) ΞΌ :=
(measurePreserving_piFinSuccAbove (fun _ : Fin (n + 1) => gaussianReal 0 1) i).symm
have hF' : Integrable F' ΞΌ :=
(MemLp.of_bound hm'.aestronglyMeasurable K'
(ae_of_all _ (fun g => by simpa using hb' g)) (p := 1)).integrable le_rfl
have hFi : Integrable (fun g => g i * F g) ΞΌ := by
have hc : Integrable (fun g : Fin (n + 1) β β => g i) ΞΌ :=
(measurePreserving_eval (fun _ : Fin (n + 1) => gaussianReal 0 1) i).integrable_comp_of_integrable
((memLp_id_gaussianReal 1).integrable le_rfl)
exact hc.mul_bdd hm.aestronglyMeasurable
(ae_of_all _ (fun g => by simpa using hb g))
change (β« g, g i * F g βΞΌ) = β« g, F' g βΞΌ
rw [β he.integral_comp' (fun g => g i * F g), β he.integral_comp' F']
have hi1 : Integrable (fun v => e.symm v i * F (e.symm v))
((gaussianReal 0 1).prod Ξ½) := he.integrable_comp_of_integrable hFi
have hi2 : Integrable (fun v => F' (e.symm v))
((gaussianReal 0 1).prod Ξ½) := he.integrable_comp_of_integrable hF'
rw [integral_prod_symm _ hi1, integral_prod_symm _ hi2]
apply integral_congr_ae
apply ae_of_all
intro g
simp only [e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv,
Equiv.coe_fn_mk, Fin.insertNth_apply_same]
apply gaussian_integration_by_parts_bounded (hd g)
Β· exact hm'.comp (measurable_pi_iff.mpr (i.forall_iff_succAbove.mpr
β¨by simp only [Fin.insertNth_apply_same]; exact measurable_id,
fun j => by simpβ©))
Β· exact fun x => hb _
Β· exact fun x => hb' _
section FiniteGibbs
variable {S : Type*} [Fintype S]
def finitePartition (w H : S β β) : β := β x, w x * Real.exp (H x)
def finiteGibbs (w H : S β β) (x : S) : β :=
w x * Real.exp (H x) / finitePartition w H
def GibbsReference (w : S β β) : Prop := (β x, 0 β€ w x) β§ β x, 0 < w x
lemma finitePartition_pos {w : S β β} (hw : GibbsReference w) (H : S β β) :
0 < finitePartition w H := by
obtain β¨x, hxβ© := hw.2
exact Finset.sum_pos' (fun y _ => mul_nonneg (hw.1 y) (Real.exp_pos _).le)
β¨x, Finset.mem_univ _, mul_pos hx (Real.exp_pos _)β©
lemma finiteGibbs_nonneg {w : S β β} (hw : GibbsReference w) (H : S β β) (x : S) :
0 β€ finiteGibbs w H x :=
div_nonneg (mul_nonneg (hw.1 x) (Real.exp_pos _).le) (finitePartition_pos hw H).le
lemma finiteGibbs_sum {w : S β β} (hw : GibbsReference w) (H : S β β) :
β x, finiteGibbs w H x = 1 := by
simp only [finiteGibbs, β Finset.sum_div]
exact div_self (finitePartition_pos hw H).ne'
lemma finiteGibbs_le_one {w : S β β} (hw : GibbsReference w) (H : S β β) (x : S) :
finiteGibbs w H x β€ 1 := by
rw [β finiteGibbs_sum hw H]
exact Finset.single_le_sum (fun y _ => finiteGibbs_nonneg hw H y) (Finset.mem_univ x)
lemma finiteGibbs_average_bound {w : S β β} (hw : GibbsReference w)
(H A : S β β) {K : β} (hA : β x, |A x| β€ K) :
|β x, finiteGibbs w H x * A x| β€ K := by
calc
_ β€ β x, |finiteGibbs w H x * A x| := Finset.abs_sum_le_sum_abs _ _
_ = β x, finiteGibbs w H x * |A x| := by
congr 1; ext x; rw [abs_mul, abs_of_nonneg (finiteGibbs_nonneg hw H x)]
_ β€ β x, finiteGibbs w H x * K := Finset.sum_le_sum
(fun x _ => mul_le_mul_of_nonneg_left (hA x) (finiteGibbs_nonneg hw H x))
_ = K := by rw [β Finset.sum_mul, finiteGibbs_sum hw H, one_mul]
lemma hasDerivAt_finitePartition {H : β β S β β} {dH : S β β} {t : β}
(hH : β x, HasDerivAt (fun s => H s x) (dH x) t) (w : S β β) :
HasDerivAt (fun s => finitePartition w (H s))
(β x, w x * Real.exp (H t x) * dH x) t := by
simpa only [finitePartition, mul_assoc] using
(HasDerivAt.fun_sum (u := Finset.univ) (fun x _ => (hH x).exp.const_mul (w x)))
lemma hasDerivAt_finiteGibbs {w : S β β} (hw : GibbsReference w)
{H : β β S β β} {dH : S β β} {t : β}
(hH : β x, HasDerivAt (fun s => H s x) (dH x) t) (x : S) :
HasDerivAt (fun s => finiteGibbs w (H s) x)
(finiteGibbs w (H t) x *
(dH x - β y, finiteGibbs w (H t) y * dH y)) t := by
have hd := ((hH x).exp.const_mul (w x)).div
(hasDerivAt_finitePartition hH w) (finitePartition_pos hw (H t)).ne'
convert hd using 1 <;> try rfl
simp only [finiteGibbs, div_mul_eq_mul_div, β Finset.sum_div]
field_simp [(finitePartition_pos hw (H t)).ne']
lemma hasDerivAt_log_finitePartition {w : S β β} (hw : GibbsReference w)
{H : β β S β β} {dH : S β β} {t : β}
(hH : β x, HasDerivAt (fun s => H s x) (dH x) t) :
HasDerivAt (fun s => Real.log (finitePartition w (H s)))
(β x, finiteGibbs w (H t) x * dH x) t := by
convert (hasDerivAt_finitePartition hH w).log (finitePartition_pos hw (H t)).ne' using 1
simp only [finiteGibbs, div_mul_eq_mul_div, Finset.sum_div]
end FiniteGibbs
section GaussianGibbs
variable {S : Type*} [Fintype S]
def linearGaussian {n : β} (C : S β Fin n β β) (g : Fin n β β) (x : S) : β :=
β j, C x j * g j
def gaussianGibbs {n : β} (w B : S β β) (C : S β Fin n β β)
(g : Fin n β β) (x : S) : β :=
finiteGibbs w (fun y => B y + linearGaussian C g y) x
lemma continuous_gaussianGibbs {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin n β β) (x : S) :
Continuous (fun g => gaussianGibbs w B C g x) := by
unfold gaussianGibbs finiteGibbs
apply Continuous.div
Β· unfold linearGaussian; fun_prop
Β· unfold finitePartition linearGaussian; fun_prop
Β· exact fun g => (finitePartition_pos hw _).ne'
omit [Fintype S] in
lemma hasDerivAt_linearGaussian_insert {n : β} (C : S β Fin (n + 1) β β)
(i : Fin (n + 1)) (g : Fin n β β) (x : S) (t : β) :
HasDerivAt (fun y => linearGaussian C (i.insertNth y g) x) (C x i) t := by
have he : (fun y => linearGaussian C (i.insertNth y g) x) =
fun y => C x i * y + β j : Fin n, C x (i.succAbove j) * g j := by
funext y
simp only [linearGaussian, i.sum_univ_succAbove, Fin.insertNth_apply_same,
Fin.insertNth_apply_succAbove]
rw [he]
simpa using ((hasDerivAt_id t).const_mul (C x i)).add_const
(β j : Fin n, C x (i.succAbove j) * g j)
lemma hasDerivAt_gaussianGibbs_insert {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin (n + 1) β β) (i : Fin (n + 1))
(g : Fin n β β) (x : S) (t : β) :
HasDerivAt (fun y => gaussianGibbs w B C (i.insertNth y g) x)
(gaussianGibbs w B C (i.insertNth t g) x *
(C x i - β z, gaussianGibbs w B C (i.insertNth t g) z * C z i)) t := by
apply hasDerivAt_finiteGibbs hw
intro z
exact (hasDerivAt_linearGaussian_insert C i g z t).const_add (B z)
lemma gaussian_gibbs_coordinate_insertion {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin (n + 1) β β) (i : Fin (n + 1)) (x : S) :
(β« g, g i * gaussianGibbs w B C g x
βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)) =
β« g, gaussianGibbs w B C g x * (C x i - β z, gaussianGibbs w B C g z * C z i)
βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1) := by
apply gaussian_pi_integration_by_parts i (K := 1) (K' := |C x i| + β z, |C z i|)
(continuous_gaussianGibbs hw B C x).measurable
Β· exact ((continuous_gaussianGibbs hw B C x).mul
(continuous_const.sub (continuous_finsetSum _
(fun z _ => (continuous_gaussianGibbs hw B C z).mul continuous_const)))).measurable
Β· exact fun g t => hasDerivAt_gaussianGibbs_insert hw B C i g x t
Β· intro g
change |finiteGibbs w (fun z => B z + linearGaussian C g z) x| β€ 1
rw [abs_of_nonneg (finiteGibbs_nonneg hw _ x)]
exact finiteGibbs_le_one hw _ x
Β· intro g
let K := β z, |C z i|
have hK (z : S) : |C z i| β€ K :=
Finset.single_le_sum (fun y _ => abs_nonneg (C y i)) (Finset.mem_univ z)
have ha := finiteGibbs_average_bound hw (fun z => B z + linearGaussian C g z)
(fun z => C z i) hK
change |gaussianGibbs w B C g x * _| β€ |C x i| + K
rw [abs_mul, abs_of_nonneg (show 0 β€ gaussianGibbs w B C g x from finiteGibbs_nonneg hw _ x)]
calc
_ β€ 1 * |C x i - β z, gaussianGibbs w B C g z * C z i| :=
mul_le_mul_of_nonneg_right (finiteGibbs_le_one hw _ x) (abs_nonneg _)
_ β€ |C x i| + K := by
rw [one_mul]
exact (abs_sub _ _).trans (add_le_add le_rfl ha)
end GaussianGibbs
section Replicas
variable {S : Type*} [Fintype S]
def replicaGibbs {n r : β} (w B : S β β) (C : S β Fin n β β)
(g : Fin n β β) (Ο : Fin r β S) : β :=
β l, gaussianGibbs w B C g (Ο l)
lemma replicaGibbs_nonneg {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin n β β) (g : Fin n β β) (Ο : Fin r β S) :
0 β€ replicaGibbs w B C g Ο :=
Finset.prod_nonneg (fun l _ => finiteGibbs_nonneg hw _ (Ο l))
lemma replicaGibbs_le_one {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin n β β) (g : Fin n β β) (Ο : Fin r β S) :
replicaGibbs w B C g Ο β€ 1 := by
exact Finset.prod_le_oneβ (fun replica _ => finiteGibbs_nonneg hw _ (Ο replica))
(fun l _ => finiteGibbs_le_one hw _ (Ο l))
lemma replicaGibbs_sum {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin n β β) (g : Fin n β β) :
β Ο : Fin r β S, replicaGibbs w B C g Ο = 1 := by
classical
unfold replicaGibbs
rw [β Fintype.prod_sum]
simp only [gaussianGibbs, finiteGibbs_sum hw, Finset.prod_const_one]
lemma continuous_replicaGibbs {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin n β β) (Ο : Fin r β S) :
Continuous (fun g => replicaGibbs w B C g Ο) := by
exact continuous_finsetProd _ (fun l _ => continuous_gaussianGibbs hw B C (Ο l))
lemma hasDerivAt_replicaGibbs_insert {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin (n + 1) β β) (i : Fin (n + 1))
(g : Fin n β β) (Ο : Fin r β S) (t : β) :
HasDerivAt (fun y => replicaGibbs w B C (i.insertNth y g) Ο)
(replicaGibbs w B C (i.insertNth t g) Ο *
(β l, (C (Ο l) i - β z, gaussianGibbs w B C (i.insertNth t g) z * C z i))) t := by
have hd := HasDerivAt.fun_finsetProd (u := Finset.univ)
(fun l _ => hasDerivAt_gaussianGibbs_insert hw B C i g (Ο l) t)
convert hd using 1 <;> try rfl
simp only [smul_eq_mul, Finset.mul_sum]
apply Finset.sum_congr rfl
intro l hl
rw [β mul_assoc, Finset.prod_erase_mul _ _ hl]
rfl
lemma gaussian_replica_coordinate_insertion {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin (n + 1) β β) (i : Fin (n + 1)) (Ο : Fin r β S) :
(β« g, g i * replicaGibbs w B C g Ο
βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)) =
β« g, replicaGibbs w B C g Ο *
(β l, (C (Ο l) i - β z, gaussianGibbs w B C g z * C z i))
βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1) := by
let K := β z, |C z i|
have hK (z : S) : |C z i| β€ K :=
Finset.single_le_sum (fun y _ => abs_nonneg (C y i)) (Finset.mem_univ z)
apply gaussian_pi_integration_by_parts i (K := 1) (K' := β l, (|C (Ο l) i| + K))
(continuous_replicaGibbs hw B C Ο).measurable
Β· exact ((continuous_replicaGibbs hw B C Ο).mul
(continuous_finsetSum _ (fun l _ => continuous_const.sub
(continuous_finsetSum _ (fun z _ =>
(continuous_gaussianGibbs hw B C z).mul continuous_const))))).measurable
Β· exact fun g t => hasDerivAt_replicaGibbs_insert hw B C i g Ο t
Β· intro g
rw [abs_of_nonneg (replicaGibbs_nonneg hw B C g Ο)]
exact replicaGibbs_le_one hw B C g Ο
Β· intro g
rw [abs_mul, abs_of_nonneg (replicaGibbs_nonneg hw B C g Ο)]
calc
_ β€ 1 * |β l, (C (Ο l) i - β z, gaussianGibbs w B C g z * C z i)| :=
mul_le_mul_of_nonneg_right (replicaGibbs_le_one hw B C g Ο) (abs_nonneg _)
_ β€ β l, (|C (Ο l) i| + K) := by
rw [one_mul]
apply (Finset.abs_sum_le_sum_abs _ _).trans
apply Finset.sum_le_sum
intro l _
exact (abs_sub _ _).trans (add_le_add le_rfl
(finiteGibbs_average_bound hw (fun z => B z + linearGaussian C g z)
(fun z => C z i) hK))
lemma integrable_gaussian_coordinate_mul {n : β} (i : Fin n)
{F : (Fin n β β) β β} (hm : Measurable F) {K : β} (hK : β g, |F g| β€ K) :
Integrable (fun g => g i * F g) (Measure.pi (fun _ : Fin n => gaussianReal 0 1)) := by
have hc : Integrable (fun g : Fin n β β => g i)
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)) :=
(measurePreserving_eval (fun _ : Fin n => gaussianReal 0 1) i).integrable_comp_of_integrable
((memLp_id_gaussianReal 1).integrable le_rfl)
exact hc.mul_bdd hm.aestronglyMeasurable (ae_of_all _ (fun g => by simpa using hK g))
omit [Fintype S] in
lemma gaussian_pi_linear_insertion {n : β} (a : Fin (n + 1) β β)
{F : (Fin (n + 1) β β) β β} {F' : Fin (n + 1) β (Fin (n + 1) β β) β β}
(hm : Measurable F) (hm' : β i, Measurable (F' i))
(hd : β i g x, HasDerivAt (fun y => F (i.insertNth y g)) (F' i (i.insertNth x g)) x)
{K : β} {K' : Fin (n + 1) β β}
(hb : β g, |F g| β€ K) (hb' : β i g, |F' i g| β€ K' i) :
(β« g, (β i, a i * g i) * F g βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)) =
β« g, β i, a i * F' i g βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1) := by
have hi i : Integrable (F' i) (Measure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)) :=
(MemLp.of_bound (hm' i).aestronglyMeasurable (K' i)
(ae_of_all _ (fun g => by simpa using hb' i g)) (p := 1)).integrable le_rfl
simp_rw [Finset.sum_mul, mul_assoc]
rw [integral_finsetSum _ (fun i _ => (integrable_gaussian_coordinate_mul i hm hb).const_mul _),
integral_finsetSum _ (fun i _ => (hi i).const_mul _)]
apply Finset.sum_congr rfl
intro i _
rw [integral_const_mul, integral_const_mul,
gaussian_pi_integration_by_parts i hm (hm' i) (hd i) hb (hb' i)]
omit [Fintype S] in
def gaussianCross {n : β} (A C : S β Fin n β β) (x y : S) : β :=
β i, A x i * C y i
lemma gaussian_replica_insertion {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A C : S β Fin (n + 1) β β) (x : S) (Ο : Fin r β S) :
(β« g, linearGaussian A g x * replicaGibbs w B C g Ο
βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)) =
β« g, replicaGibbs w B C g Ο *
(β l, (gaussianCross A C x (Ο l) -
β z, gaussianGibbs w B C g z * gaussianCross A C x z))
βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1) := by
have hd := gaussian_pi_linear_insertion (A x) (continuous_replicaGibbs hw B C Ο).measurable
(F' := fun i g => replicaGibbs w B C g Ο *
β l, (C (Ο l) i - β z, gaussianGibbs w B C g z * C z i))
(fun i => ((continuous_replicaGibbs hw B C Ο).mul
(continuous_finsetSum _ (fun l _ => continuous_const.sub
(continuous_finsetSum _ (fun z _ =>
(continuous_gaussianGibbs hw B C z).mul continuous_const))))).measurable)
(fun i g t => hasDerivAt_replicaGibbs_insert hw B C i g Ο t)
(K := 1) (K' := fun i => β l, (|C (Ο l) i| + β z, |C z i|))
(fun g => by rw [abs_of_nonneg (replicaGibbs_nonneg hw B C g Ο)];
exact replicaGibbs_le_one hw B C g Ο)
have hb i g : |replicaGibbs w B C g Ο *
β l, (C (Ο l) i - β z, gaussianGibbs w B C g z * C z i)| β€
β l, (|C (Ο l) i| + β z, |C z i|) := by
rw [abs_mul, abs_of_nonneg (replicaGibbs_nonneg hw B C g Ο)]
apply (mul_le_mul_of_nonneg_right (replicaGibbs_le_one hw B C g Ο) (abs_nonneg _)).trans
rw [one_mul]
apply (Finset.abs_sum_le_sum_abs _ _).trans
apply Finset.sum_le_sum
intro l _
exact (abs_sub _ _).trans (add_le_add le_rfl
(finiteGibbs_average_bound hw (fun z => B z + linearGaussian C g z)
(fun z => C z i) (fun z => Finset.single_le_sum (fun y _ => abs_nonneg (C y i))
(Finset.mem_univ z))))
rw [show linearGaussian A = fun g x => β i, A x i * g i from rfl, hd hb]
apply integral_congr_ae
apply ae_of_all
intro g
simp only [gaussianCross, Finset.mul_sum, mul_sub]
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro l _
simp only [Finset.sum_sub_distrib]
congr 1
Β· apply Finset.sum_congr rfl; intro i _; ring
Β· rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro z _
apply Finset.sum_congr rfl
intro i _
ring
end Replicas
section Perturbation
variable {S : Type*} [Fintype S]
lemma log_finitePartition_le_add {w : S β β} (hw : GibbsReference w)
{H J : S β β} {K : β} (h : β x, H x β€ J x + K) :
Real.log (finitePartition w H) β€ Real.log (finitePartition w J) + K := by
rw [β Real.log_exp K, β Real.log_mul (finitePartition_pos hw J).ne' (Real.exp_pos K).ne']
apply Real.log_le_log (finitePartition_pos hw H)
unfold finitePartition
rw [Finset.sum_mul]
apply Finset.sum_le_sum
intro x _
rw [mul_assoc, β Real.exp_add]
exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr (h x)) (hw.1 x)
lemma log_finitePartition_lipschitz {w : S β β} (hw : GibbsReference w)
{H J : S β β} {K : β} (h : β x, |H x - J x| β€ K) :
|Real.log (finitePartition w H) - Real.log (finitePartition w J)| β€ K := by
apply abs_le.mpr
constructor
Β· have hh := log_finitePartition_le_add hw (H := J) (J := H) (K := K)
(fun x => by have := (abs_le.mp (h x)).1; linarith)
linarith
Β· have hh := log_finitePartition_le_add hw (H := H) (J := J) (K := K)
(fun x => by have := (abs_le.mp (h x)).2; linarith)
linarith
omit [Fintype S] in
lemma integrable_linearGaussian {n : β} (A : S β Fin n β β) (x : S) :
Integrable (fun g => linearGaussian A g x)
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)) := by
apply integrable_finsetSum
intro i _
exact ((measurePreserving_eval (fun _ : Fin n => gaussianReal 0 1) i).integrable_comp_of_integrable
((memLp_id_gaussianReal 1).integrable le_rfl)).const_mul _
lemma continuous_log_finitePartition {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A : S β Fin n β β) (t : β) :
Continuous (fun g => Real.log (finitePartition w (fun x => B x + t * linearGaussian A g x))) := by
apply Continuous.log
Β· unfold finitePartition linearGaussian; fun_prop
Β· exact fun g => (finitePartition_pos hw _).ne'
lemma integrable_log_finitePartition {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A : S β Fin n β β) (t : β) :
Integrable (fun g => Real.log (finitePartition w (fun x => B x + t * linearGaussian A g x)))
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)) := by
have hi : Integrable (fun g => |Real.log (finitePartition w B)| +
|t| * β x, |linearGaussian A g x|)
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)) :=
(integrable_const _).add ((integrable_finsetSum _
(fun x _ => (integrable_linearGaussian A x).abs)).const_mul _)
apply hi.mono' (continuous_log_finitePartition hw B A t).aestronglyMeasurable
apply ae_of_all
intro g
rw [Real.norm_eq_abs]
have hh := log_finitePartition_lipschitz hw (H := fun x => B x + t * linearGaussian A g x)
(J := B) (K := |t| * β x, |linearGaussian A g x|) (fun x => by
simp only [add_sub_cancel_left, abs_mul]
exact mul_le_mul_of_nonneg_left
(Finset.single_le_sum (fun y _ => abs_nonneg (linearGaussian A g y)) (Finset.mem_univ x))
(abs_nonneg t))
have := abs_le.mp hh
have hz := abs_le.mp (le_refl |Real.log (finitePartition w B)|)
exact abs_le.mpr β¨by linarith, by linarithβ©
lemma hasDerivAt_expected_log_finitePartition {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A : S β Fin n β β) (t : β) :
HasDerivAt (fun s => β« g, Real.log (finitePartition w (fun x => B x + s * linearGaussian A g x))
βMeasure.pi (fun _ : Fin n => gaussianReal 0 1))
(β« g, β x, finiteGibbs w (fun z => B z + t * linearGaussian A g z) x * linearGaussian A g x
βMeasure.pi (fun _ : Fin n => gaussianReal 0 1)) t := by
let ΞΌ := Measure.pi (fun _ : Fin n => gaussianReal 0 1)
have hc (s : β) (x : S) : Continuous (fun g =>
finiteGibbs w (fun z => B z + s * linearGaussian A g z) x) := by
unfold finiteGibbs
apply Continuous.div
Β· unfold linearGaussian; fun_prop
Β· unfold finitePartition linearGaussian; fun_prop
Β· exact fun g => (finitePartition_pos hw _).ne'
apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le (ΞΌ := ΞΌ) (s := Set.univ)
(F' := fun s g => β x, finiteGibbs w (fun z => B z + s * linearGaussian A g z) x *
linearGaussian A g x)
(bound := fun g => β x, |linearGaussian A g x|) (Filter.univ_mem)
(Filter.Eventually.of_forall (fun s => (continuous_log_finitePartition hw B A s).aestronglyMeasurable))
(integrable_log_finitePartition hw B A t) ?_ ?_ ?_ ?_).2
Β· apply Continuous.aestronglyMeasurable
apply continuous_finsetSum
intro x _
exact (hc t x).mul (by unfold linearGaussian; fun_prop)
Β· apply ae_of_all
intro g s _
rw [Real.norm_eq_abs]
exact finiteGibbs_average_bound hw _ _ (fun x =>
Finset.single_le_sum (fun y _ => abs_nonneg (linearGaussian A g y)) (Finset.mem_univ x))
Β· exact integrable_finsetSum _ (fun x _ => (integrable_linearGaussian A x).abs)
Β· apply ae_of_all
intro g s _
exact hasDerivAt_log_finitePartition hw (fun x => by simpa using
((hasDerivAt_id s).mul_const (linearGaussian A g x)).const_add (B x))
omit [Fintype S] in
lemma linearGaussian_scale {n : β} (A : S β Fin n β β) (t : β) (g : Fin n β β) (x : S) :
linearGaussian (fun y i => t * A y i) g x = t * linearGaussian A g x := by
simp only [linearGaussian, Finset.mul_sum, mul_assoc]
omit [Fintype S] in
lemma gaussianCross_scale {n : β} (A : S β Fin n β β) (t : β) (x y : S) :
gaussianCross A (fun z i => t * A z i) x y = t * gaussianCross A A x y := by
simp only [gaussianCross, Finset.mul_sum]
apply Finset.sum_congr rfl
intro i _
ring
lemma gaussian_gibbs_insertion {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A C : S β Fin (n + 1) β β) (x : S) :
(β« g, linearGaussian A g x * gaussianGibbs w B C g x
βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)) =
β« g, gaussianGibbs w B C g x *
(gaussianCross A C x x - β z, gaussianGibbs w B C g z * gaussianCross A C x z)
βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1) := by
simpa [replicaGibbs, Fin.prod_univ_one, Fin.sum_univ_one] using
gaussian_replica_insertion (r := 1) hw B A C x (fun _ => x)
lemma integrable_linearGaussian_mul_gibbs {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A C : S β Fin n β β) (x y : S) :
Integrable (fun g => linearGaussian A g x * gaussianGibbs w B C g y)
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)) := by
apply (integrable_linearGaussian A x).mul_bdd
(continuous_gaussianGibbs hw B C y).aestronglyMeasurable (c := 1)
apply ae_of_all
intro g
rw [Real.norm_eq_abs, abs_of_nonneg (show 0 β€ gaussianGibbs w B C g y from finiteGibbs_nonneg hw _ y)]
exact finiteGibbs_le_one hw _ y
lemma hasDerivAt_expected_log_gaussian {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A : S β Fin (n + 1) β β) (t : β) :
HasDerivAt (fun s => β« g, Real.log (finitePartition w (fun x => B x + s * linearGaussian A g x))
βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1))
(β x, β« g, gaussianGibbs w B (fun y i => t * A y i) g x *
(gaussianCross A (fun y i => t * A y i) x x -
β z, gaussianGibbs w B (fun y i => t * A y i) g z *
gaussianCross A (fun y i => t * A y i) x z)
βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)) t := by
convert hasDerivAt_expected_log_finitePartition hw B A t using 1
have he : β g x, finiteGibbs w (fun z => B z + t * linearGaussian A g z) x =
gaussianGibbs w B (fun y i => t * A y i) g x := by
intro g x
simp only [gaussianGibbs, linearGaussian_scale]
simp_rw [he, mul_comm (gaussianGibbs _ _ _ _ _) (linearGaussian _ _ _)]
rw [integral_finsetSum _ (fun x _ => integrable_linearGaussian_mul_gibbs hw B A _ x x)]
apply Finset.sum_congr rfl
intro x _
exact (gaussian_gibbs_insertion hw B A _ x).symm
lemma gaussian_covariance_difference_bound {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A : S β Fin n β β) (t : β) {K : β}
(hK : β x y, |gaussianCross A A x y| β€ K) (g : Fin n β β) (x : S) :
|gaussianCross A (fun y i => t * A y i) x x -
β z, gaussianGibbs w B (fun y i => t * A y i) g z *
gaussianCross A (fun y i => t * A y i) x z| β€ 2 * |t| * K := by
have hb : β y, |gaussianCross A (fun z i => t * A z i) x y| β€ |t| * K := by
intro y
rw [gaussianCross_scale, abs_mul]
exact mul_le_mul_of_nonneg_left (hK x y) (abs_nonneg t)
have hh := finiteGibbs_average_bound hw (fun y => B y + linearGaussian (fun z i => t * A z i) g y)
(fun y => gaussianCross A (fun z i => t * A z i) x y) hb
exact (abs_sub _ _).trans (by dsimp only [gaussianGibbs] at *; linarith [hb x])
lemma integrable_gaussian_covariance_insertion {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A : S β Fin n β β) (t : β) {K : β}
(hK : β x y, |gaussianCross A A x y| β€ K) (x : S) :
Integrable (fun g => gaussianGibbs w B (fun y i => t * A y i) g x *
(gaussianCross A (fun y i => t * A y i) x x -
β z, gaussianGibbs w B (fun y i => t * A y i) g z *
gaussianCross A (fun y i => t * A y i) x z))
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)) := by
apply (MemLp.of_bound (p := 1) (C := 2 * |t| * K) ?_ ?_).integrable le_rfl
Β· apply Continuous.aestronglyMeasurable
apply (continuous_gaussianGibbs hw B _ x).mul
exact continuous_const.sub (continuous_finsetSum _ (fun y _ =>
(continuous_gaussianGibbs hw B _ y).mul continuous_const))
Β· apply ae_of_all
intro g
rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (show 0 β€ gaussianGibbs w B (fun y i => t * A y i) g x from finiteGibbs_nonneg hw _ x)]
exact (mul_le_mul_of_nonneg_right (finiteGibbs_le_one hw _ x) (abs_nonneg _)).trans
(by simpa only [one_mul] using gaussian_covariance_difference_bound hw B A t hK g x)
def expectedGaussianLog {n : β} (w B : S β β) (A : S β Fin n β β) (t : β) : β :=
β« g, Real.log (finitePartition w (fun x => B x + t * linearGaussian A g x))
βMeasure.pi (fun _ : Fin n => gaussianReal 0 1)
def gaussianLogDerivative {n : β} (w B : S β β) (A : S β Fin n β β) (t : β) : β :=
β x, β« g, gaussianGibbs w B (fun y i => t * A y i) g x *
(gaussianCross A (fun y i => t * A y i) x x -
β z, gaussianGibbs w B (fun y i => t * A y i) g z *
gaussianCross A (fun y i => t * A y i) x z)
βMeasure.pi (fun _ : Fin n => gaussianReal 0 1)
lemma gaussianLogDerivative_bound {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A : S β Fin n β β) (t : β) {K : β}
(hK : β x y, |gaussianCross A A x y| β€ K) :
|gaussianLogDerivative w B A t| β€ 2 * |t| * K := by
unfold gaussianLogDerivative
rw [β integral_finsetSum _ (fun x _ => integrable_gaussian_covariance_insertion hw B A t hK x)]
simpa only [Real.norm_eq_abs, probReal_univ, mul_one] using
(norm_integral_le_of_norm_le_const (ΞΌ := Measure.pi (fun _ : Fin n => gaussianReal 0 1))
(f := fun g => β x, gaussianGibbs w B (fun y i => t * A y i) g x *
(gaussianCross A (fun y i => t * A y i) x x -
β z, gaussianGibbs w B (fun y i => t * A y i) g z *
gaussianCross A (fun y i => t * A y i) x z))
(C := 2 * |t| * K) (ae_of_all _ (fun g => by
rw [Real.norm_eq_abs]
exact finiteGibbs_average_bound hw (fun x => B x + linearGaussian (fun y i => t * A y i) g x) _
(gaussian_covariance_difference_bound hw B A t hK g))))
theorem gaussian_perturbation_cost {n : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A : S β Fin (n+1) β β) {K s : β} (hs : 0 β€ s)
(hK : β x y, |gaussianCross A A x y| β€ K) :
|expectedGaussianLog w B A s - Real.log (finitePartition w B)| β€ K * s ^ 2 := by
have hd (t : β) : HasDerivAt (expectedGaussianLog w B A) (gaussianLogDerivative w B A t) t :=
hasDerivAt_expected_log_gaussian hw B A t
have hc : Continuous (expectedGaussianLog w B A) := continuous_iff_continuousAt.mpr
(fun t => (hd t).continuousAt)
have h0 : expectedGaussianLog w B A 0 = Real.log (finitePartition w B) := by
simp [expectedGaussianLog]
have hu : AntitoneOn (fun t => expectedGaussianLog w B A t - K * t ^ 2) (Set.Ici 0) := by
apply antitoneOn_of_hasDerivWithinAt_nonpos (convex_Ici (0 : β))
((hc.sub (continuous_const.mul (continuous_id.pow 2))).continuousOn)
(fun t _ => ((hd t).sub (((hasDerivAt_id t).pow 2).const_mul K)).hasDerivWithinAt)
intro t ht
have ht0 : 0 β€ t := (interior_subset ht)
have hb := (abs_le.mp (gaussianLogDerivative_bound hw B A t hK)).2
rw [abs_of_nonneg ht0] at hb
simp only [Nat.cast_ofNat, id_eq, Nat.add_one_sub_one, pow_one, mul_one]
nlinarith
have hl : MonotoneOn (fun t => expectedGaussianLog w B A t + K * t ^ 2) (Set.Ici 0) := by
apply monotoneOn_of_hasDerivWithinAt_nonneg (convex_Ici (0 : β))
((hc.add (continuous_const.mul (continuous_id.pow 2))).continuousOn)
(fun t _ => ((hd t).add (((hasDerivAt_id t).pow 2).const_mul K)).hasDerivWithinAt)
intro t ht
have ht0 : 0 β€ t := (interior_subset ht)
have hb := (abs_le.mp (gaussianLogDerivative_bound hw B A t hK)).1
rw [abs_of_nonneg ht0] at hb
simp only [Nat.cast_ofNat, id_eq, Nat.add_one_sub_one, pow_one, mul_one]
nlinarith
have huu := hu (Set.mem_Ici.mpr (le_refl (0 : β))) hs hs
have hll := hl (Set.mem_Ici.mpr (le_refl (0 : β))) hs hs
dsimp only at huu hll
rw [h0] at huu hll
simp only [zero_pow (by decide : 2 β 0), mul_zero, add_zero, sub_zero] at huu hll
exact abs_le.mpr β¨by linarith, by linarithβ©
end Perturbation
section Thermal
variable {S : Type*} [Fintype S]
lemma hasDerivAt_finiteGibbs_mean {w : S β β} (hw : GibbsReference w)
(B Y : S β β) (t : β) :
HasDerivAt (fun s => β x, finiteGibbs w (fun y => B y+s*Y y) x * Y x)
(β x, finiteGibbs w (fun y => B y+t*Y y) x *
(Y x-β z, finiteGibbs w (fun y => B y+t*Y y) z*Y z)^2) t := by
have hd x := (hasDerivAt_finiteGibbs hw
(fun y => (hasDerivAt_const t (B y)).add ((hasDerivAt_id t).mul_const (Y y))) x).mul_const (Y x)
have hsum := HasDerivAt.fun_sum (u := Finset.univ) (fun x _ => hd x)
convert hsum using 1 <;> try rfl
let p := finiteGibbs w (fun y => B y+t*Y y)
let m := β z, p z*Y z
have hp : β x, p x = 1 := finiteGibbs_sum hw _
change (β x, p x * (Y x-m)^2) = β x, (p x * ((0+1*Y x)-β y, p y*(0+1*Y y)))*Y x
simp only [zero_add, one_mul]
change (β x, p x * (Y x-m)^2) = β x, p x*(Y x-m)*Y x
have he x : p x * (Y x-m)^2 = p x*(Y x-m)*Y x - m*(p x*Y x)+m^2*p x := by ring
simp_rw [he]
rw [Finset.sum_add_distrib, Finset.sum_sub_distrib, β Finset.mul_sum, β Finset.mul_sum, hp]
change (β x, p x*(Y x-m)*Y x) - m*m + m^2*1 = _
ring
lemma convexOn_log_finitePartition {w : S β β} (hw : GibbsReference w)
(B Y : S β β) :
ConvexOn β Set.univ (fun s => Real.log (finitePartition w (fun y => B y+s*Y y))) := by
have h1 t := hasDerivAt_log_finitePartition hw
(fun y => (hasDerivAt_const t (B y)).add ((hasDerivAt_id t).mul_const (Y y)))
simp only [zero_add, one_mul] at h1
apply convexOn_of_hasDerivWithinAt2_nonneg convex_univ
(continuous_iff_continuousAt.mpr (fun t => (h1 t).continuousAt)).continuousOn
(fun t _ => (h1 t).hasDerivWithinAt)
(fun t _ => (hasDerivAt_finiteGibbs_mean hw B Y t).hasDerivWithinAt)
intro t _
exact Finset.sum_nonneg (fun x _ => mul_nonneg (finiteGibbs_nonneg hw _ x) (sq_nonneg _))
end Thermal
abbrev Spin (N : β) := Fin N β Fin 2
abbrev Patterns (M N : β) := (Fin M Γ Fin N) β β
def spinValue (x : Fin 2) : β := if x = 0 then -1 else 1
def patternCount (Ξ± : β) (N : β) : β := βΞ± * (N : β)ββ
def projection {M N : β} (g : Patterns M N) (a : Fin M) (x : Spin N) : β :=
(β i : Fin N, g (a, i) * spinValue (x i)) / Real.sqrt (N : β)
def partitionFunction (Ξ± : β) (f : β β β) (N : β)
(g : Patterns (patternCount Ξ± N) N) : β :=
(β x : Spin N, Real.exp (β a : Fin (patternCount Ξ± N), f (projection g a x))) /
(2 : β) ^ N
def pressure (Ξ± : β) (f : β β β) (N : β)
(g : Patterns (patternCount Ξ± N) N) : β :=
Real.log (partitionFunction Ξ± f N g) / (N : β)
def gaussianPatterns (M N : β) : Measure (Patterns M N) :=
Measure.pi (fun _ : Fin M Γ Fin N => gaussianReal 0 1)
def spinOverlap {N : β} (x y : Spin N) : β :=
(β i, spinValue (x i)*spinValue (y i))/(N : β)
def spinTensor {N : β} (p : β) (x : Spin N) (a : Fin p β Fin N) : β :=
β l, spinValue (x (a l))/Real.sqrt (N : β)
lemma abs_spinValue (x : Fin 2) : |spinValue x| = 1 := by
unfold spinValue
split <;> norm_num
lemma spinOverlap_diag {N : β} (hN : 0 < N) (x : Spin N) : spinOverlap x x = 1 := by
have hv (i : Fin N) : spinValue (x i)*spinValue (x i) = 1 := by
have := abs_spinValue (x i)
nlinarith [sq_abs (spinValue (x i))]
simp [spinOverlap, hv, ne_of_gt hN]
lemma abs_spinOverlap_le {N : β} (hN : 0 < N) (x y : Spin N) :
|spinOverlap x y| β€ 1 := by
have hn : (0:β) < N := by exact_mod_cast hN
rw [spinOverlap, abs_div, abs_of_pos hn, div_le_one hn]
calc
_ β€ β i, |spinValue (x i)*spinValue (y i)| := Finset.abs_sum_le_sum_abs _ _
_ = N := by simp [abs_mul, abs_spinValue]
lemma spinTensor_covariance {N : β} (p : β) (x y : Spin N) :
(β a : Fin p β Fin N, spinTensor p x a * spinTensor p y a) = (spinOverlap x y)^p := by
have hs : Real.sqrt (N : β)*Real.sqrt (N : β) = N := by
rw [β sq, Real.sq_sqrt (Nat.cast_nonneg N)]
unfold spinTensor
simp_rw [β Finset.prod_mul_distrib, div_mul_div_comm, hs]
have he := Finset.sum_pow' (Finset.univ : Finset (Fin N))
(fun i => spinValue (x i)*spinValue (y i)/(N : β)) p
simpa [spinOverlap, Finset.sum_div] using he.symm
abbrev BulkCoordinate (N : β) := Ξ£ j : Fin N, (Fin (j.val+1) β Fin N)
def bulkCoefficient {N : β} (v : β β β) (x : Spin N) (a : BulkCoordinate N) : β :=
(v (a.1.val+1)/(2:β)^(a.1.val+1))*spinTensor (a.1.val+1) x a.2
def bulkCovariance (N : β) (v : β β β) (r : β) : β :=
β j : Fin N, (v (j.val+1)/(2:β)^(j.val+1))^2*r^(j.val+1)
lemma bulkCoefficient_covariance {N : β} (v : β β β) (x y : Spin N) :
(β a : BulkCoordinate N, bulkCoefficient v x a*bulkCoefficient v y a) =
bulkCovariance N v (spinOverlap x y) := by
rw [Fintype.sum_sigma]
unfold bulkCovariance
apply Finset.sum_congr rfl
intro j _
have he (a : Fin (j.val+1) β Fin N) :
bulkCoefficient v x β¨j,aβ©*bulkCoefficient v y β¨j,aβ© =
(v (j.val+1)/(2:β)^(j.val+1))^2*(spinTensor (j.val+1) x a*spinTensor (j.val+1) y a) := by
unfold bulkCoefficient; ring
simp_rw [he, β Finset.mul_sum, spinTensor_covariance]
lemma bulkCovariance_abs_le (N : β) (v : β β β) (hv : β j, |v j| β€ 2)
{r : β} (hr : |r| β€ 1) : |bulkCovariance N v r| β€ 4/3 := by
have ha (j : β) : (v j/(2:β)^j)^2 β€ 4*(1/4:β)^j := by
have hv2 : (v j)^2 β€ 4 := by nlinarith [sq_abs (v j), hv j, abs_nonneg (v j)]
have he : ((2:β)^j)^2 = (4:β)^j := by rw [β pow_mul, Nat.mul_comm j 2, pow_mul]; norm_num
rw [div_pow, he, one_div_pow]
simpa [div_eq_mul_inv] using div_le_div_of_nonneg_right hv2 (pow_nonneg (by norm_num : (0:β) β€ 4) j)
calc
_ β€ β j : Fin N, |(v (j.val+1)/(2:β)^(j.val+1))^2*r^(j.val+1)| := Finset.abs_sum_le_sum_abs _ _
_ β€ β j : Fin N, 4*(1/4:β)^(j.val+1) := by
apply Finset.sum_le_sum
intro j _
rw [abs_mul, abs_of_nonneg (sq_nonneg _), abs_pow]
calc
_ β€ (v (j.val+1)/(2:β)^(j.val+1))^2*1 := mul_le_mul_of_nonneg_left
(pow_le_oneβ (abs_nonneg r) hr) (sq_nonneg _)
_ β€ _ := by simpa using ha (j.val+1)
_ = β j β Finset.range N, (1/4:β)^j := by
rw [Fin.sum_univ_eq_sum_range (fun j => 4*(1/4:β)^(j+1))]
apply Finset.sum_congr rfl
intro j _
rw [pow_succ]; ring
_ β€ 4/3 := by
have hh := geom_sum_Ico_le_of_lt_one (m := 0) (n := N)
(by norm_num : (0:β) β€ 1/4) (by norm_num : (1/4:β) < 1)
norm_num at hh β’
simpa using hh
def indexedBulkCoefficient (N : β) (v : β β β) (x : Spin N) :
Fin (Fintype.card (BulkCoordinate N)+1) β β :=
Fin.cons 0 (fun i => bulkCoefficient v x ((Fintype.equivFin (BulkCoordinate N)).symm i))
lemma indexedBulkCoefficient_covariance (N : β) (v : β β β) (x y : Spin N) :
gaussianCross (indexedBulkCoefficient N v) (indexedBulkCoefficient N v) x y =
bulkCovariance N v (spinOverlap x y) := by
unfold gaussianCross indexedBulkCoefficient
rw [Fin.sum_univ_succ]
simp only [Fin.cons_zero, mul_zero, zero_add, Fin.cons_succ]
rw [Equiv.sum_comp (Fintype.equivFin (BulkCoordinate N)).symm
(fun a => bulkCoefficient v x a*bulkCoefficient v y a)]
exact bulkCoefficient_covariance v x y
lemma bulk_gaussian_perturbation_cost {N : β} (hN : 0 < N)
{w : Spin N β β} (hw : GibbsReference w) (B : Spin N β β)
(v : β β β) (hv : β j, |v j| β€ 2) {s : β} (hs : 0 β€ s) :
|expectedGaussianLog w B (indexedBulkCoefficient N v) s -
Real.log (finitePartition w B)| β€ (4/3)*s^2 := by
apply gaussian_perturbation_cost hw B (indexedBulkCoefficient N v) hs
intro x y
rw [indexedBulkCoefficient_covariance]
exact bulkCovariance_abs_le N v hv (abs_spinOverlap_le hN x y)
lemma coordinatewise_lipschitz_sum (n : β) {F : (Fin n β β) β β} {L : Fin n β β}
(hL : β i, 0 β€ L i)
(hF : β i x y, (β j, j β i β x j = y j) β |F x-F y| β€ L i*|x i-y i|)
(x y : Fin n β β) : |F x-F y| β€ β i, L i*|x i-y i| := by
induction n with
| zero =>
have he : x = y := Subsingleton.elim _ _
simp [he]
| succ n ih =>
let G := fun z : Fin n β β => F (Fin.cons (y 0) z)
have hG : β i a b, (β j, j β i β a j = b j) β
|G a-G b| β€ L i.succ*|a i-b i| := by
intro i a b hab
apply hF i.succ
intro j
refine Fin.cases (fun _ => rfl) (fun k hk => ?_) j
simpa only [Fin.cons_succ] using hab k (fun h => hk (congrArg Fin.succ h))
have hg := ih (fun i => hL i.succ) hG (Fin.tail x) (Fin.tail y)
have hh := hF 0 x (Fin.cons (y 0) (Fin.tail x)) (fun j hj => by
obtain β¨k, hkβ© := Fin.exists_succ_eq_of_ne_zero hj
rw [β hk]; rfl)
calc
_ β€ |F x-F (Fin.cons (y 0) (Fin.tail x))|+
|F (Fin.cons (y 0) (Fin.tail x))-F y| := abs_sub_le _ _ _
_ β€ L 0*|x 0-y 0|+β i : Fin n, L i.succ*|x i.succ-y i.succ| := by
apply add_le_add
Β· simpa using hh
Β· simpa [G, Fin.cons_self_tail, Fin.tail] using hg
_ = _ := by rw [Fin.sum_univ_succ]
lemma memLp_gaussian_coordinatewise {n : β} {F : (Fin n β β) β β} {L : Fin n β β}
(hm : Measurable F) (hL : β i, 0 β€ L i)
(hF : β i x y, (β j, j β i β x j = y j) β |F x-F y| β€ L i*|x i-y i|)
(p : ββ₯0) :
MemLp F p (Measure.pi (fun _ : Fin n => gaussianReal 0 1)) := by
have hg i : MemLp (fun g : Fin n β β => |g i|) p
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)) := by
exact ((memLp_id_gaussianReal p).comp_measurePreserving
(measurePreserving_eval (fun _ : Fin n => gaussianReal 0 1) i)).norm
have hsum := MemLp.add (memLp_const (|F 0|))
(memLp_finsetSum' Finset.univ (fun i _ => (hg i).const_mul (L i)))
apply hsum.mono' hm.aestronglyMeasurable
apply ae_of_all
intro x
have hh := coordinatewise_lipschitz_sum n hL hF x 0
simp only [Pi.zero_apply, sub_zero] at hh
simp only [Real.norm_eq_abs, Pi.add_apply, Finset.sum_apply]
have ha := abs_add_le (F x-F 0) (F 0)
calc
|F x| β€ |F x-F 0|+|F 0| := by simpa using ha
_ β€ |F 0|+β i, L i*|x i| := by linarith
lemma memLp_gaussian_lipschitz {F : β β β} {L : β} (hm : Measurable F)
(hF : β x, |F x-F 0| β€ L*|x|) (p : ββ₯0) :
MemLp F p (gaussianReal 0 1) := by
have hg : MemLp (fun x : β => |F 0|+L*|x|) p (gaussianReal 0 1) :=
(memLp_const (|F 0|)).add ((memLp_id_gaussianReal p).norm.const_mul L)
apply hg.mono' hm.aestronglyMeasurable
apply ae_of_all
intro x
simp only [Real.norm_eq_abs]
have := abs_add_le (F x-F 0) (F 0)
have := hF x
simp only [sub_add_cancel] at *
linarith
lemma variance_gaussian_lipschitz {F : β β β} {L : β} (hm : Measurable F)
(hL : 0 β€ L) (hF : β x, |F x-F 0| β€ L*|x|) :
variance F (gaussianReal 0 1) β€ L^2 := by
have hLp := memLp_gaussian_lipschitz hm hF 2
have hsq := (hLp.sub (memLp_const (F 0))).integrable_sq
have hid : Integrable (fun x : β => L^2*x^2) (gaussianReal 0 1) :=
(memLp_id_gaussianReal 2).integrable_sq.const_mul _
have hb := integral_mono hsq hid (fun x => by
have := sq_le_sq.mpr (show |F x-F 0| β€ |L*(|x|)| by
rw [abs_of_nonneg (mul_nonneg hL (abs_nonneg x))]; exact hF x)
simpa only [Pi.sub_apply, Pi.pow_apply, mul_pow, sq_abs] using this)
have hz : (β« x : β, x^2 βgaussianReal 0 1) = 1 := by
have hv := variance_eq_sub (memLp_id_gaussianReal 2 (ΞΌ := 0) (v := 1))
simpa using hv.symm
rw [integral_const_mul, hz, mul_one] at hb
calc
_ = variance (fun x => F x-F 0) (gaussianReal 0 1) :=
(variance_sub_const hm.aestronglyMeasurable (F 0)).symm
_ β€ β« x, (F x-F 0)^2 βgaussianReal 0 1 :=
variance_le_expectation_sq (hm.aestronglyMeasurable.sub aestronglyMeasurable_const)
_ β€ L^2 := hb
lemma variance_prod_section_bound {A B : Type*} [MeasurableSpace A] [MeasurableSpace B]
{ΞΌ : Measure A} {Ξ½ : Measure B} [IsProbabilityMeasure ΞΌ] [IsProbabilityMeasure Ξ½]
{F : A Γ B β β} {c : β} (hF : MemLp F 2 (ΞΌ.prod Ξ½))
(hG : MemLp (fun b => β« a, F (a,b) βΞΌ) 2 Ξ½)
(hsec : β b, MemLp (fun a => F (a,b)) 2 ΞΌ)
(hv : β b, variance (fun a => F (a,b)) ΞΌ β€ c) :
variance F (ΞΌ.prod Ξ½) β€ c+variance (fun b => β« a, F (a,b) βΞΌ) Ξ½ := by
have hpoint b : (β« a, F (a,b)^2 βΞΌ) β€ c+(β« a, F (a,b) βΞΌ)^2 := by
have h := hv b
rw [variance_eq_sub (hsec b)] at h
simp only [Pi.pow_apply] at h
linarith
have hs := integral_mono hF.integrable_sq.integral_prod_right
((integrable_const c).add hG.integrable_sq) hpoint
simp only [Pi.add_apply] at hs
rw [integral_add (integrable_const _) hG.integrable_sq, integral_const,
probReal_univ, one_smul] at hs
rw [variance_eq_sub hF, variance_eq_sub hG]
simp only [Pi.pow_apply]
rw [integral_prod_symm _ hF.integrable_sq,
integral_prod_symm _ (hF.integrable (by norm_num))]
linarith
lemma variance_gaussian_coordinatewise (n : β) {F : (Fin n β β) β β} {L : Fin n β β}
(hm : Measurable F) (hL : β i, 0 β€ L i)
(hF : β i x y, (β j, j β i β x j = y j) β |F x-F y| β€ L i*|x i-y i|) :
variance F (Measure.pi (fun _ : Fin n => gaussianReal 0 1)) β€ β i, (L i)^2 := by
induction n with
| zero =>
have he : F = fun _ => F 0 := by ext x; congr 1; exact Subsingleton.elim _ _
rw [he, variance_eq_integral measurable_const.aemeasurable]
simp
| succ n ih =>
let ΞΌ := gaussianReal 0 1
let Ξ½ := Measure.pi (fun _ : Fin n => ΞΌ)
let C := fun z : β Γ (Fin n β β) => F (Fin.cons z.1 z.2)
let G := fun x : Fin n β β => β« a, C (a,x) βΞΌ
have hcons : Measurable (fun z : β Γ (Fin n β β) => (Fin.cons z.1 z.2 : Fin (n+1) β β)) := by
apply Measurable.of_eval
intro i
refine Fin.cases ?_ (fun j => ?_) i
Β· simpa only [Fin.cons_zero] using (measurable_fst : Measurable (Prod.fst : β Γ (Fin n β β) β β))
Β· simpa only [Fin.cons_succ, Function.comp_def] using (measurable_pi_apply j).comp
(measurable_snd : Measurable (Prod.snd : β Γ (Fin n β β) β (Fin n β β)))
have hCm : Measurable C := hm.comp hcons
have hGm : Measurable G := hCm.stronglyMeasurable.integral_prod_left'.measurable
have hhead x a : |C (a,x)-C (0,x)| β€ L 0*|a| := by
have hh := hF 0 (Fin.cons a x) (Fin.cons 0 x) (fun j hj => by
obtain β¨k, hkβ© := Fin.exists_succ_eq_of_ne_zero hj
rw [β hk]; rfl)
simpa [C] using hh
have hsec x : MemLp (fun a => C (a,x)) 2 ΞΌ :=
memLp_gaussian_lipschitz
(hCm.comp (measurable_id.prodMk measurable_const)) (hhead x) 2
have hGlip : β i x y, (β j, j β i β x j = y j) β
|G x-G y| β€ L i.succ*|x i-y i| := by
intro i x y hxy
have hb a : |C (a,x)-C (a,y)| β€ L i.succ*|x i-y i| := by
apply hF i.succ
intro j
refine Fin.cases (fun _ => rfl) (fun k hk => ?_) j
simpa only [Fin.cons_succ] using hxy k (fun he => hk (congrArg Fin.succ he))
have hh := norm_integral_le_of_norm_le_const (ΞΌ := ΞΌ) (f := fun a => C (a,x)-C (a,y))
(ae_of_all ΞΌ (fun a => by simpa only [Real.norm_eq_abs] using hb a))
rw [integral_sub ((hsec x).integrable (by norm_num)) ((hsec y).integrable (by norm_num))] at hh
simpa [G] using hh
have hG2 := memLp_gaussian_coordinatewise hGm (fun i => hL i.succ) hGlip 2
have hF2 := memLp_gaussian_coordinatewise hm hL hF 2
have he := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => ΞΌ) 0).symm
have hC2 : MemLp C 2 (ΞΌ.prod Ξ½) := by
have hh := hF2.comp_measurePreserving he
simpa only [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv,
Fin.insertNth_zero, Equiv.coe_fn_mk, Fin.zero_succAbove, cast_eq, Function.comp_def, C, Ξ½, ENNReal.coe_ofNat] using hh
have hp := variance_prod_section_bound hC2 hG2 hsec
(fun x => variance_gaussian_lipschitz
(hCm.comp (measurable_id.prodMk measurable_const)) (hL 0) (hhead x))
have hi := ih hGm (fun i => hL i.succ) hGlip
have heq : variance C (ΞΌ.prod Ξ½) = variance F (Measure.pi (fun _ : Fin (n+1) => ΞΌ)) := by
have hh := he.variance_fun_comp hm.aemeasurable
simpa only [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv,
Fin.insertNth_zero, Equiv.coe_fn_mk, Fin.zero_succAbove, cast_eq] using hh
rw [heq] at hp
rw [Fin.sum_univ_succ]
exact hp.trans (add_le_add le_rfl hi)
section GaussianConcentration
variable {S : Type*} [Fintype S]
lemma log_finitePartition_coordinate_lipschitz {n : β} {w : S β β}
(hw : GibbsReference w) (B : S β β) (A : S β Fin n β β)
(L : Fin n β β) (hA : β x i, |A x i| β€ L i) (t : β)
(i : Fin n) (g h : Fin n β β) (hgh : β j, j β i β g j = h j) :
|Real.log (finitePartition w (fun x => B x+t*linearGaussian A g x))-
Real.log (finitePartition w (fun x => B x+t*linearGaussian A h x))| β€
(|t| *L i)*|g i-h i| := by
apply log_finitePartition_lipschitz hw
intro x
have he : linearGaussian A g x-linearGaussian A h x = A x i*(g i-h i) := by
unfold linearGaussian
rw [β Finset.sum_sub_distrib]
rw [Finset.sum_eq_single i]
Β· ring
Β· intro j _ hji
rw [hgh j hji]; ring
Β· simp
have he' : B x+t*linearGaussian A g x-(B x+t*linearGaussian A h x) =
t*(linearGaussian A g x-linearGaussian A h x) := by ring
rw [he', he, abs_mul, abs_mul]
calc
_ β€ |t| *(L i*|g i-h i|) := mul_le_mul_of_nonneg_left
(mul_le_mul_of_nonneg_right (hA x i) (abs_nonneg _)) (abs_nonneg _)
_ = _ := by ring
lemma variance_gaussian_log_finitePartition {n : β} {w : S β β}
(hw : GibbsReference w) (B : S β β) (A : S β Fin n β β)
(L : Fin n β β) (hL : β i, 0 β€ L i) (hA : β x i, |A x i| β€ L i) (t : β) :
variance (fun g => Real.log (finitePartition w (fun x => B x+t*linearGaussian A g x)))
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)) β€ t^2*β i, (L i)^2 := by
have hb := variance_gaussian_coordinatewise n
(continuous_log_finitePartition hw B A t).measurable
(L := fun i => |t| *L i) (fun i => mul_nonneg (abs_nonneg _) (hL i))
(log_finitePartition_coordinate_lipschitz hw B A L hA t)
have he : (β i, (|t| *L i)^2) = t^2*β i, (L i)^2 := by
simp_rw [mul_pow, sq_abs, Finset.mul_sum]
rwa [he] at hb
end GaussianConcentration
lemma abs_spinTensor_independent {N : β} (p : β) (x y : Spin N)
(a : Fin p β Fin N) : |spinTensor p x a| = |spinTensor p y a| := by
unfold spinTensor
simp_rw [Finset.abs_prod, abs_div, abs_spinValue]
lemma abs_bulkCoefficient_independent {N : β} (v : β β β) (x y : Spin N)
(a : BulkCoordinate N) : |bulkCoefficient v x a| = |bulkCoefficient v y a| := by
unfold bulkCoefficient
rw [abs_mul, abs_mul, abs_spinTensor_independent _ x y]
lemma abs_indexedBulkCoefficient_independent {N : β} (v : β β β) (x y : Spin N)
(i : Fin (Fintype.card (BulkCoordinate N)+1)) :
|indexedBulkCoefficient N v x i| = |indexedBulkCoefficient N v y i| := by
refine Fin.cases rfl (fun j => ?_) i
exact abs_bulkCoefficient_independent v x y _
lemma bulk_gaussian_variance {N : β} (hN : 0 < N)
{w : Spin N β β} (hw : GibbsReference w) (B : Spin N β β)
(v : β β β) (hv : β j, |v j| β€ 2) (s : β) :
variance (fun g => Real.log (finitePartition w
(fun x => B x+s*linearGaussian (indexedBulkCoefficient N v) g x)))
(Measure.pi (fun _ : Fin (Fintype.card (BulkCoordinate N)+1) => gaussianReal 0 1)) β€
(4/3)*s^2 := by
let xβ : Spin N := fun _ => 0
have hb := variance_gaussian_log_finitePartition hw B (indexedBulkCoefficient N v)
(fun i => |indexedBulkCoefficient N v xβ i|) (fun _ => abs_nonneg _)
(fun x i => (abs_indexedBulkCoefficient_independent v x xβ i).le) s
have he : (β i, |indexedBulkCoefficient N v xβ i|^2) = bulkCovariance N v 1 := by
simp_rw [sq_abs, pow_two]
change gaussianCross (indexedBulkCoefficient N v) (indexedBulkCoefficient N v) xβ xβ = _
rw [indexedBulkCoefficient_covariance, spinOverlap_diag hN]
rw [he] at hb
have hc := (le_abs_self (bulkCovariance N v 1)).trans
(bulkCovariance_abs_le N v hv (by norm_num))
calc
_ β€ s^2*bulkCovariance N v 1 := hb
_ β€ s^2*(4/3) := mul_le_mul_of_nonneg_left hc (sq_nonneg _)
_ = _ := by ring
variable {S : Type*} [Fintype S]
def replicaMean {n r : β} (w B : S β β) (C : S β Fin n β β)
(D : (Fin r β S) β β) (g : Fin n β β) : β :=
β Ο, replicaGibbs w B C g Ο*D Ο
def expectedReplica {n r : β} (w B : S β β) (C : S β Fin n β β)
(D : (Fin r β S) β β) : β :=
β« g, replicaMean w B C D g βMeasure.pi (fun _ : Fin n => gaussianReal 0 1)
lemma replicaMean_abs_le {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin n β β) {D : (Fin r β S) β β}
{K : β} (hD : β Ο, |D Ο| β€ K) (g : Fin n β β) :
|replicaMean w B C D g| β€ K := by
calc
_ β€ β Ο, replicaGibbs w B C g Ο*|D Ο| := by
apply (Finset.abs_sum_le_sum_abs _ _).trans
apply Finset.sum_le_sum
intro Ο _
rw [abs_mul, abs_of_nonneg (replicaGibbs_nonneg hw B C g Ο)]
_ β€ β Ο : Fin r β S, replicaGibbs w B C g Ο*K := by
apply Finset.sum_le_sum
intro Ο _
exact mul_le_mul_of_nonneg_left (hD Ο) (replicaGibbs_nonneg hw B C g Ο)
_ = K := by rw [β Finset.sum_mul, replicaGibbs_sum hw, one_mul]
lemma integrable_replicaMean {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin n β β) (D : (Fin r β S) β β) :
Integrable (replicaMean w B C D) (Measure.pi (fun _ : Fin n => gaussianReal 0 1)) := by
apply Integrable.of_bound
(continuous_finsetSum _ (fun Ο _ => (continuous_replicaGibbs hw B C Ο).mul continuous_const)).aestronglyMeasurable
(β Ο, |D Ο|)
apply ae_of_all
intro g
exact replicaMean_abs_le hw B C (fun Ο =>
Finset.single_le_sum (fun Ο _ => abs_nonneg (D Ο)) (Finset.mem_univ Ο)) g
lemma integrable_linear_mul_replica {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A C : S β Fin n β β) (x : S) (Ο : Fin r β S) :
Integrable (fun g => linearGaussian A g x*replicaGibbs w B C g Ο)
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)) := by
apply (integrable_linearGaussian A x).mul_bdd
(continuous_replicaGibbs hw B C Ο).aestronglyMeasurable (c := 1)
apply ae_of_all
intro g
rw [Real.norm_eq_abs, abs_of_nonneg (replicaGibbs_nonneg hw B C g Ο)]
exact replicaGibbs_le_one hw B C g Ο
lemma integrable_replica_covariance {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A C : S β Fin n β β) (x : S) (Ο : Fin r β S) :
Integrable (fun g => replicaGibbs w B C g Ο*
(β l, (gaussianCross A C x (Ο l)-β z, gaussianGibbs w B C g z*gaussianCross A C x z)))
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)) := by
let K := β z, |gaussianCross A C x z|
apply Integrable.of_bound
((continuous_replicaGibbs hw B C Ο).mul
(continuous_finsetSum _ (fun l _ => continuous_const.sub
(continuous_finsetSum _ (fun z _ =>
(continuous_gaussianGibbs hw B C z).mul continuous_const))))).aestronglyMeasurable
(β l, (|gaussianCross A C x (Ο l)|+K))
apply ae_of_all
intro g
simp only [Pi.mul_apply, Pi.sub_apply]
rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (replicaGibbs_nonneg hw B C g Ο)]
calc
_ β€ 1*|β l, (gaussianCross A C x (Ο l)-β z, gaussianGibbs w B C g z*gaussianCross A C x z)| :=
mul_le_mul_of_nonneg_right (replicaGibbs_le_one hw B C g Ο) (abs_nonneg _)
_ β€ _ := by
rw [one_mul]
apply (Finset.abs_sum_le_sum_abs _ _).trans
apply Finset.sum_le_sum
intro l _
exact (abs_sub _ _).trans (add_le_add le_rfl
(finiteGibbs_average_bound hw _ _ (fun z =>
show |gaussianCross A C x z| β€ β y, |gaussianCross A C x y| from
Finset.single_le_sum (fun y _ => abs_nonneg (gaussianCross A C x y)) (Finset.mem_univ z))))
lemma gaussian_replica_test_insertion {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (A C : S β Fin (n+1) β β) (D : (Fin (r+1) β S) β β) :
(β« g, β Ο : Fin (r+1) β S,
D Ο*(linearGaussian A g (Ο 0)*replicaGibbs w B C g Ο)
βMeasure.pi (fun _ : Fin (n+1) => gaussianReal 0 1)) =
β« g, β Ο : Fin (r+1) β S, D Ο*(replicaGibbs w B C g Ο*
(β l, (gaussianCross A C (Ο 0) (Ο l)-
β z, gaussianGibbs w B C g z*gaussianCross A C (Ο 0) z)))
βMeasure.pi (fun _ : Fin (n+1) => gaussianReal 0 1) := by
rw [integral_finsetSum _ (fun Ο _ => (integrable_linear_mul_replica hw B A C (Ο 0) Ο).const_mul (D Ο)),
integral_finsetSum _ (fun Ο _ => (integrable_replica_covariance hw B A C (Ο 0) Ο).const_mul (D Ο))]
apply Finset.sum_congr rfl
intro Ο _
rw [integral_const_mul, integral_const_mul, gaussian_replica_insertion hw]
lemma replicaMean_marginal_zero {n r : β} {w : S β β} (hw : GibbsReference w)
(B : S β β) (C : S β Fin n β β) (F : S β β) (g : Fin n β β) :
replicaMean w B C (fun Ο : Fin (r+1) β S => F (Ο 0)) g =
β x, gaussianGibbs w B C g x*F x := by
classical
unfold replicaMean
rw [β Equiv.sum_comp (Fin.consEquiv (fun _ : Fin (r+1) => S))]
rw [Fintype.sum_prod_type]
apply Finset.sum_congr rfl
intro x _
have he (Ο : Fin r β S) :
replicaGibbs w B C g ((Fin.consEquiv (fun _ : Fin (r+1) => S)) (x,Ο))*
F (((Fin.consEquiv (fun _ : Fin (r+1) => S)) (x,Ο)) 0) =
gaussianGibbs w B C g x*F x*replicaGibbs w B C g Ο := by
simp [replicaGibbs, Fin.consEquiv, Fin.prod_univ_succ]
ring
simp_rw [he]
rw [β Finset.mul_sum, replicaGibbs_sum hw, mul_one]
end IsingPerceptron
end
end OAI
import Mathlib
namespace OAI
/-! Gaussian Integration. -/
noncomputable section
open MeasureTheory ProbabilityTheory Filter Set
open scoped BigOperators Topology ENNReal NNReal BoundedContinuousFunction
namespace IsingPerceptron
lemma hasDerivAt_standardGaussianPDF (x : β) :
HasDerivAt (gaussianPDFReal 0 1) (-x * gaussianPDFReal 0 1 x) x := by
have h := (((hasDerivAt_id x).pow 2).neg.div_const 2).exp.const_mul
(Real.sqrt (2 * Real.pi))β»ΒΉ
convert h using 1 <;> try rfl
Β· ext y
simp [gaussianPDFReal]
Β· norm_num [gaussianPDFReal]
ring
lemma integrable_gaussian_iff {f : β β β} :
Integrable f (gaussianReal 0 1) β
Integrable (fun x => gaussianPDFReal 0 1 x * f x) := by
rw [gaussianReal_of_var_ne_zero 0 (by norm_num : (1 : ββ₯0) β 0)]
rw [integrable_withDensity_iff_integrable_smul']
Β· simp [gaussianPDF, ENNReal.toReal_ofReal, gaussianPDFReal_nonneg]
Β· exact measurable_gaussianPDF _ _
Β· exact ae_of_all _ (fun x => by simp [gaussianPDF])
lemma gaussian_integration_by_parts {f f' : β β β} (hd : β x, HasDerivAt f (f' x) x)
(hf : Integrable f (gaussianReal 0 1))
(hf' : Integrable f' (gaussianReal 0 1))
(hxf : Integrable (fun x => x * f x) (gaussianReal 0 1)) :
(β« x, x * f x βgaussianReal 0 1) = β« x, f' x βgaussianReal 0 1 := by
have hh := integral_mul_deriv_eq_deriv_mul_of_integrable
(u := f) (u' := f') (v := gaussianPDFReal 0 1)
(v' := fun x => -x * gaussianPDFReal 0 1 x)
(fun x _ => hd x) (fun x _ => hasDerivAt_standardGaussianPDF x)
have h1 : Integrable (fun x => f x * (-x * gaussianPDFReal 0 1 x)) := by
convert (integrable_gaussian_iff.mp hxf).neg using 1
ext x; dsimp; ring
have h2 : Integrable (fun x => f' x * gaussianPDFReal 0 1 x) := by
simpa [mul_comm] using integrable_gaussian_iff.mp hf'
have h3 : Integrable (fun x => f x * gaussianPDFReal 0 1 x) := by
simpa [mul_comm] using integrable_gaussian_iff.mp hf
specialize hh h1 h2 h3
rw [integral_gaussianReal_eq_integral_smul (by norm_num : (1 : ββ₯0) β 0),
integral_gaussianReal_eq_integral_smul (by norm_num : (1 : ββ₯0) β 0)]
simp only [smul_eq_mul] at *
have heq : (fun x => f x * (-x * gaussianPDFReal 0 1 x)) =
fun x => -(gaussianPDFReal 0 1 x * (x * f x)) := by ext x; ring
rw [heq, integral_neg] at hh
simpa [mul_comm] using neg_injective hh
lemma gaussian_integration_by_parts_bounded {f f' : β β β}
(hd : β x, HasDerivAt f (f' x) x) (hm' : Measurable f')
{K K' : β} (hb : β x, |f x| β€ K) (hb' : β x, |f' x| β€ K') :
(β« x, x * f x βgaussianReal 0 1) = β« x, f' x βgaussianReal 0 1 := by
have hm : Measurable f := (continuous_iff_continuousAt.mpr
(fun x => (hd x).continuousAt)).measurable
have hif : Integrable f (gaussianReal 0 1) :=
(MemLp.of_bound hm.aestronglyMeasurable K
(ae_of_all _ (fun x => by simpa using hb x)) (p := 1)).integrable le_rfl
have hif' : Integrable f' (gaussianReal 0 1) :=
(MemLp.of_bound hm'.aestronglyMeasurable K'
(ae_of_all _ (fun x => by simpa using hb' x)) (p := 1)).integrable le_rfl
apply gaussian_integration_by_parts hd hif hif'
exact ((memLp_id_gaussianReal 1).integrable le_rfl).mul_bdd
hm.aestronglyMeasurable (ae_of_all _ (fun x => by simpa using hb x))
lemma gaussian_pi_integration_by_parts {n : β} (i : Fin (n + 1))
{F F' : (Fin (n + 1) β β) β β} (hm : Measurable F) (hm' : Measurable F')
(hd : β (g : Fin n β β) (x : β),
HasDerivAt (fun y => F (i.insertNth y g)) (F' (i.insertNth x g)) x)
{K K' : β} (hb : β g, |F g| β€ K) (hb' : β g, |F' g| β€ K') :
(β« g, g i * F g βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)) =
β« g, F' g βMeasure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1) := by
let ΞΌ := Measure.pi (fun _ : Fin (n + 1) => gaussianReal 0 1)
let Ξ½ := Measure.pi (fun _ : Fin n => gaussianReal 0 1)
let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n + 1) => β) i
have he : MeasurePreserving e.symm ((gaussianReal 0 1).prod Ξ½) ΞΌ :=
(measurePreserving_piFinSuccAbove (fun _ : Fin (n + 1) => gaussianReal 0 1) i).symm
have hF' : Integrable F' ΞΌ :=
(MemLp.of_bound hm'.aestronglyMeasurable K'
(ae_of_all _ (fun g => by simpa using hb' g)) (p := 1)).integrable le_rfl
have hFi : Integrable (fun g => g i * F g) ΞΌ := by
have hc : Integrable (fun g : Fin (n + 1) β β => g i) ΞΌ :=
(measurePreserving_eval (fun _ : Fin (n + 1) => gaussianReal 0 1) i).integrable_comp_of_integrable
((memLp_id_gaussianReal 1).integrable le_rfl)
exact hc.mul_bdd hm.aestronglyMeasurable
(ae_of_all _ (fun g => by simpa using hb g))
change (β« g, g i * F g βΞΌ) = β« g, F' g βΞΌ
rw [β he.integral_comp' (fun g => g i * F g), β he.integral_comp' F']
have hi1 : Integrable (fun v => e.symm v i * F (e.symm v))
((gaussianReal 0 1).prod Ξ½) := he.integrable_comp_of_integrable hFi
have hi2 : Integrable (fun v => F' (e.symm v))
((gaussianReal 0 1).prod Ξ½) := he.integrable_comp_of_integrable hF'
rw [integral_prod_symm _ hi1, integral_prod_symm _ hi2]