File size: 8,369 Bytes
dd14c26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import Mathlib
import OAI.Probability.LogConcave.Model
import OAI.Probability.LogConcave.Sampling.LintegralFinNatProd

namespace OAI

section
section
noncomputable section
open MeasureTheory Filter
open scoped ENNReal NNReal Topology

section UpperProof
namespace LogConcaveSampling

theorem map_withDensity_of_measurePreserving {E F : Type*}
    [MeasurableSpace E] [MeasurableSpace F] {μ : Measure E} {ν : Measure F}
    (e : E ≃ᵐ F) (he : MeasurePreserving e μ ν) {f : E → ℝ≥0∞} (hf : Measurable f) :
    (μ.withDensity f).map e = ν.withDensity (fun y => f (e.symm y)) := by
  ext s hs
  rw [Measure.map_apply e.measurable hs, withDensity_apply _ (hs.preimage e.measurable),
    withDensity_apply _ hs]
  have h := he.setLIntegral_comp_preimage hs (hf.comp e.symm.measurable)
  simpa only [Function.comp_apply, MeasurableEquiv.symm_apply_apply] using h

end LogConcaveSampling

namespace LogConcaveSampling
namespace EulerDensity
open ProbabilityTheory MeasureTheory WithLp
open scoped ENNReal NNReal RealInnerProductSpace

def gaussianCoefficient (d : ℕ) : ℝ≥0∞ :=
  ∏ _ : Fin d, ENNReal.ofReal ((Real.sqrt (2*Real.pi))⁻¹)

lemma standard_pi_density (d : ℕ) :
    Measure.pi (fun _ : Fin d => gaussianReal 0 1) =
      (volume : Measure (Fin d → ℝ)).withDensity
        (fun x => gaussianCoefficient d*ENNReal.ofReal (Real.exp (-(∑ k, (x k)^2)/2))) := by
  have hg : gaussianReal 0 1 = volume.withDensity (gaussianPDF 0 1) :=
    gaussianReal_of_var_ne_zero _ (by norm_num)
  have : IsProbabilityMeasure (volume.withDensity (gaussianPDF 0 1)) := by rw [← hg]; infer_instance
  simp_rw [hg]
  rw [pi_withDensity_fin _ _ (fun _ => measurable_gaussianPDF _ _)]
  congr 1
  ext x
  have he (z : ℝ) : gaussianPDF 0 1 z =
      ENNReal.ofReal ((Real.sqrt (2*Real.pi))⁻¹)*ENNReal.ofReal (Real.exp (-z^2/2)) := by
    simp [gaussianPDF,gaussianPDFReal]
  simp_rw [he]
  rw [Finset.prod_mul_distrib]
  congr 1
  rw [← ENNReal.ofReal_prod_of_nonneg (fun _ _ => (Real.exp_pos _).le),← Real.exp_sum]
  congr 2
  rw [← Finset.sum_div,Finset.sum_neg_distrib]

theorem standard_density (d : ℕ) :
    stdGaussian (Point d) = gaussianCoefficient d •
      (volume : Measure (Point d)).withDensity
        (fun z => ENNReal.ofReal (Real.exp (-‖z‖^2/2))) := by
  rw [← map_pi_eq_stdGaussian,standard_pi_density]
  let e : (Fin d → ℝ) ≃ᵐ Point d := MeasurableEquiv.toLp 2 (Fin d → ℝ)
  change Measure.map e _ = _
  rw [map_withDensity_of_measurePreserving e (PiLp.volume_preserving_toLp (Fin d)) (by fun_prop)]
  have he : (fun y : Point d => gaussianCoefficient d*
      ENNReal.ofReal (Real.exp (-(∑ k, (e.symm y k)^2)/2))) =
      gaussianCoefficient d • (fun z : Point d => ENNReal.ofReal (Real.exp (-‖z‖^2/2))) := by
    funext y
    simp only [Pi.smul_apply,smul_eq_mul]
    congr 3
    change -(∑ k, (y k)^2)/2 = -‖y‖^2/2
    rw [EuclideanSpace.norm_sq_eq]
    simp [Real.norm_eq_abs,sq_abs]
  rw [he,withDensity_smul]
  fun_prop

lemma gaussianCoefficient_positive (d : ℕ) : 0 < gaussianCoefficient d := by
  apply pos_iff_ne_zero.mpr
  apply Finset.prod_ne_zero_iff.mpr
  intro i _
  exact ENNReal.ofReal_ne_zero_iff.mpr (by positivity)

lemma gaussianCoefficient_finite (d : ℕ) : gaussianCoefficient d ≠ ⊤ := by
  exact ENNReal.prod_ne_top (fun _ _ => ENNReal.ofReal_ne_top)

lemma standard_partition (d : ℕ) :
    (gaussianCoefficient d).toReal*(∫ z : Point d, Real.exp (-‖z‖^2/2)) = 1 := by
  have he := congrArg (fun μ : Measure (Point d) => μ Set.univ) (standard_density d)
  rw [measure_univ,Measure.smul_apply,withDensity_apply _ MeasurableSet.univ,
    Measure.restrict_univ,smul_eq_mul] at he
  have hh := congrArg ENNReal.toReal he
  rw [ENNReal.toReal_one,ENNReal.toReal_mul] at hh
  rw [integral_eq_lintegral_of_nonneg_ae (Filter.Eventually.of_forall (fun _ => (Real.exp_pos _).le))
    (by fun_prop)]
  exact hh.symm

def shear {d : ℕ} (T : Point d → Point d) (hT : Measurable T) :
    Point d × Point d ≃ᵐ Point d × Point d where
  toFun p := (p.1,T p.1+p.2)
  invFun p := (p.1,p.2-T p.1)
  left_inv p := by ext <;> simp
  right_inv p := by ext <;> simp
  measurable_toFun := measurable_fst.prodMk ((hT.comp measurable_fst).add measurable_snd)
  measurable_invFun := measurable_fst.prodMk (measurable_snd.sub (hT.comp measurable_fst))

lemma shear_measurePreserving {d : ℕ} {T : Point d → Point d} (hT : Measurable T) :
    MeasurePreserving (shear T hT) ((volume : Measure (Point d)).prod volume)
      ((volume : Measure (Point d)).prod volume) := by
  exact (MeasurePreserving.id volume).skew_product ((hT.comp measurable_fst).add measurable_snd)
    (Filter.Eventually.of_forall (fun x => map_add_left_eq_self volume (T x)))

end EulerDensity
end LogConcaveSampling

namespace LogConcaveSampling
namespace EulerDensity
open MeasureTheory ProbabilityTheory
open scoped ENNReal NNReal RealInnerProductSpace

lemma map_withDensity_equiv {E F : Type*} [MeasurableSpace E] [MeasurableSpace F]
    (μ : Measure E) (e : E ≃ᵐ F) {f : E → ℝ≥0∞} (hf : Measurable f) :
    (μ.withDensity f).map e = (μ.map e).withDensity (fun y => f (e.symm y)) :=
  map_withDensity_of_measurePreserving e ⟨e.measurable,rfl⟩ hf

def noiseCoefficient (d : ℕ) (σ : ℝ) : ℝ≥0∞ :=
  gaussianCoefficient d*ENNReal.ofReal |(σ^d)⁻¹|

lemma scaled_standard_density (d : ℕ) {σ : ℝ} (hσ : σ ≠ 0) :
    (stdGaussian (Point d)).map (fun z => σ • z) =
      noiseCoefficient d σ • (volume : Measure (Point d)).withDensity
        (fun z => ENNReal.ofReal (Real.exp (-‖z‖^2/(2*σ^2)))) := by
  let e := (Homeomorph.smulOfNeZero (α := Point d) σ hσ).toMeasurableEquiv
  rw [standard_density,Measure.map_smul _ (by fun_prop)]
  change gaussianCoefficient d • (Measure.map e _) = _
  rw [map_withDensity_equiv volume e (by fun_prop)]
  have he : (volume : Measure (Point d)).map e =
      ENNReal.ofReal |(σ^d)⁻¹| • volume := by
    convert! Measure.map_addHaar_smul (volume : Measure (Point d)) hσ using 1
    simp [Point]
  rw [he,withDensity_smul_measure,smul_smul]
  congr 2
  funext z
  have hz : e.symm z = σ⁻¹ • z := by
    exact congrFun (Homeomorph.smulOfNeZero_symm_apply hσ) z
  rw [hz,norm_smul,Real.norm_eq_abs,mul_pow,sq_abs]
  congr 2
  field_simp

lemma noiseCoefficient_positive (d : ℕ) {σ : ℝ} (hσ : σ ≠ 0) :
    0 < noiseCoefficient d σ := by
  apply ENNReal.mul_pos_iff.mpr
  exact ⟨gaussianCoefficient_positive d,ENNReal.ofReal_pos.mpr (abs_pos.mpr (inv_ne_zero (pow_ne_zero _ hσ)))⟩

lemma noiseCoefficient_finite (d : ℕ) (σ : ℝ) : noiseCoefficient d σ ≠ ⊤ :=
  ENNReal.mul_ne_top (gaussianCoefficient_finite d) ENNReal.ofReal_ne_top

theorem joint_density {d : ℕ} {H : Point d → ℝ} (hH : Measurable H)
    (T : Point d → Point d) (hT : Measurable T) {σ : ℝ} (hσ : σ ≠ 0) :
    ((gibbs H).prod (stdGaussian (Point d))).map (fun p => (p.1,T p.1+σ • p.2)) =
      ((partition H)⁻¹*noiseCoefficient d σ) •
        ((volume : Measure (Point d)).prod volume).withDensity
          (fun p => ENNReal.ofReal (Real.exp (-H p.1-‖p.2-T p.1‖^2/(2*σ^2)))) := by
  have : SFinite (gibbs H) := by unfold gibbs; infer_instance
  have hmap : ((gibbs H).prod (stdGaussian (Point d))).map
      (fun p => (p.1,T p.1+σ • p.2)) =
      (((gibbs H).prod ((stdGaussian (Point d)).map (fun z => σ • z))).map (shear T hT)) := by
    have hj := Measure.map_prod_map (gibbs H) (stdGaussian (Point d)) measurable_id
      (show Measurable (fun z : Point d => σ • z) by fun_prop)
    simp only [Measure.map_id] at hj
    rw [hj,Measure.map_map (shear T hT).measurable (by fun_prop)]
    rfl
  rw [hmap,scaled_standard_density d hσ]
  unfold gibbs
  rw [Measure.prod_smul_left,Measure.prod_smul_right,smul_smul,
    prod_withDensity (by unfold gibbsDensity; fun_prop) (by fun_prop),
    Measure.map_smul _ (shear T hT).measurable.aemeasurable,
    map_withDensity_of_measurePreserving (shear T hT) (shear_measurePreserving hT) (by unfold gibbsDensity; fun_prop)]
  congr 2
  funext p
  change ENNReal.ofReal (Real.exp (-H p.1))*
    ENNReal.ofReal (Real.exp (-‖p.2-T p.1‖^2/(2*σ^2))) = _
  rw [← ENNReal.ofReal_mul (Real.exp_pos _).le,← Real.exp_add]
  congr 2
  ring

end EulerDensity
end LogConcaveSampling

end UpperProof
end
end
end

end OAI