File size: 12,879 Bytes
4a56cd6 | 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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | import OAI.Probability.PosteriorReplicas.Gaussian.RadialIntegrals
import OAI.Probability.PosteriorReplicas.Geometry.BallJacobian
namespace OAI
open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric
open scoped ENNReal NNReal RealInnerProductSpace Topology
noncomputable section
namespace PosteriorReplicas
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace โ E]
[FiniteDimensional โ E] [MeasurableSpace E] [BorelSpace E]
lemma gaussian_orthogonalProjectionOnto (U : Submodule โ E) :
(stdGaussian E).map U.orthogonalProjectionOnto = stdGaussian U := by
apply Measure.ext_of_charFun
ext t
rw [charFun_apply, integral_map (by fun_prop) (by fun_prop)]
have he (x : E) : โชU.orthogonalProjectionOnto x, tโซ = โชx, (t : E)โซ := by
change โชU.starProjection x, (t : E)โซ = _
rw [real_inner_comm, pairing_starProjection U t.2, real_inner_comm]
simp_rw [he]
change charFun (stdGaussian E) (t : E) = _
rw [charFun_stdGaussian, charFun_stdGaussian]
rfl
lemma gaussian_subspace_map (U : Submodule โ E) :
(stdGaussian U).map (Subtype.val : U โ E) = (stdGaussian E).map U.starProjection := by
rw [โ gaussian_orthogonalProjectionOnto U, Measure.map_map (by fun_prop) (by fun_prop)]
rfl
lemma gaussian_subspace_sum (U : Submodule โ E) :
((stdGaussian U).prod (stdGaussian Uแฎ)).map (fun z => (z.1 : E) + (z.2 : E)) =
stdGaussian E := by
rw [โ gaussian_orthogonal_sum U, โ gaussian_subspace_map, โ gaussian_subspace_map,
Measure.map_prod_map _ _ (by fun_prop) (by fun_prop),
Measure.map_map (by fun_prop) (by fun_prop)]
rfl
omit [FiniteDimensional โ E] [MeasurableSpace E] [BorelSpace E] in
lemma subspace_sum_norm_sq [FiniteDimensional โ E] [MeasurableSpace E] [BorelSpace E]
(U : Submodule โ E) (x : U) (z : Uแฎ) :
โ(x : E) + (z : E)โ^2 = โxโ^2 + โzโ^2 := by
have ho : โช(x : E), (z : E)โซ = 0 :=
(real_inner_comm _ _).trans ((Submodule.mem_orthogonal' U (z : E)).mp z.2 _ x.2)
simp [norm_add_sq_real, ho]
omit [FiniteDimensional โ E] [MeasurableSpace E] [BorelSpace E] in
lemma normalDirection_pos_smul [FiniteDimensional โ E] [MeasurableSpace E] [BorelSpace E]
{r : โ} (hr : 0 < r) (x : E) :
normalDirection (r โข x) = normalDirection x := by
simp [normalDirection, norm_smul, Real.norm_eq_abs, abs_of_pos hr,
_root_.mul_inv_rev, smul_smul, hr.ne']
lemma sphere_subspace_gaussian_integral (U : Submodule โ E) [Nontrivial E]
{g : E โ โโฅ0โ} (hg : Measurable g) :
โซโป x, g x โuniformDirection E =
โซโป x : U, โซโป z : Uแฎ, g (normalDirection ((x : E) + (z : E)))
โstdGaussian Uแฎ โstdGaussian U := by
rw [โ gaussian_normalDirection, lintegral_map hg (by fun_prop),
โ gaussian_subspace_sum U, lintegral_map (by fun_prop) (by fun_prop),
lintegral_prod _ (by fun_prop)]
lemma sphere_subspace_polar_integral (U : Submodule โ E) [Nontrivial E] [Nontrivial Uแฎ]
{g : E โ โโฅ0โ} (hg : Measurable g) :
โซโป y, g y โuniformDirection E =
โซโป z : sphere (0 : Uแฎ) 1, โซโป r : Ioi (0 : โ), โซโป x : U,
gaussianRadialDensity (Module.finrank โ U) โxโ *
g (normalDirection ((x : E) + r.1 โข ((z : Uแฎ) : E)))
โvolume โgaussianPolarRadius Uแฎ โ(volume : Measure Uแฎ).toSphere := by
rw [sphere_subspace_gaussian_integral U hg]
have hp (x : U) : (โซโป z : Uแฎ, g (normalDirection ((x : E) + (z : E))) โstdGaussian Uแฎ) =
โซโป z : sphere (0 : Uแฎ) 1, โซโป r : Ioi (0 : โ),
g (normalDirection ((x : E) + r.1 โข ((z : Uแฎ) : E)))
โgaussianPolarRadius Uแฎ โ(volume : Measure Uแฎ).toSphere := by
rw [โ gaussian_polar_reconstruction (E := Uแฎ), lintegral_map (by fun_prop) (by fun_prop),
lintegral_prod _ (by fun_prop)]
rfl
simp_rw [hp]
rw [lintegral_lintegral_swap (by fun_prop)]
apply lintegral_congr
intro z
rw [lintegral_lintegral_swap (by fun_prop)]
apply lintegral_congr
intro r
rw [stdGaussian_density, lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)]
rfl
lemma radial_subspace_integral (U : Submodule โ E) [Nontrivial E] [Nontrivial Uแฎ] (s : โ) :
โซโป r : Ioi (0 : โ), ENNReal.ofReal (r.1 ^ Module.finrank โ U) *
gaussianRadialDensity (Module.finrank โ U) (r.1 * s) โgaussianPolarRadius Uแฎ =
ENNReal.ofReal ((1 + s^2) ^ (-((Module.finrank โ E : โ) : โ) / 2)) *
((volume : Measure E).toSphere univ)โปยน := by
rw [lintegral_gaussianPolarRadius (E := Uแฎ) (g := fun r : โ =>
ENNReal.ofReal (r ^ Module.finrank โ U) *
gaussianRadialDensity (Module.finrank โ U) (r * s)) (by fun_prop)]
calc
_ = โซโป r in Ioi (0 : โ), ENNReal.ofReal (r ^ (Module.finrank โ E - 1)) *
ENNReal.ofReal ((2 * Real.pi) ^ (-((Module.finrank โ E : โ) : โ) / 2) *
Real.exp (-(1 + s^2) * r^2 / 2)) := by
apply setLIntegral_congr_fun measurableSet_Ioi
intro r hr
exact radial_power_gaussian_product Module.finrank_pos U.finrank_add_finrank_orthogonal hr.le s
_ = _ := radial_gaussian_integral (by positivity)
lemma scaled_subspace_integral (U : Submodule โ E) (z : sphere (0 : Uแฎ) 1)
(r : Ioi (0 : โ)) {g : E โ โโฅ0โ} (hg : Measurable g) :
โซโป x : U, gaussianRadialDensity (Module.finrank โ U) โxโ *
g (normalDirection ((x : E) + r.1 โข ((z : Uแฎ) : E))) =
โซโป x : U, ENNReal.ofReal (r.1 ^ Module.finrank โ U) *
gaussianRadialDensity (Module.finrank โ U) (r.1 * โxโ) *
g (normalDirection ((x : E) + ((z : Uแฎ) : E))) := by
rw [lintegral_pos_smul r.2 (by fun_prop), โ lintegral_const_mul _ (by fun_prop)]
apply lintegral_congr
intro x
rw [norm_smul, Real.norm_eq_abs, abs_of_pos r.2]
have he : ((r.1 โข x : U) : E) + r.1 โข ((z : Uแฎ) : E) =
r.1 โข ((x : E) + ((z : Uแฎ) : E)) := by simp [smul_add]
rw [he, normalDirection_pos_smul r.2, mul_assoc]
lemma sphere_subspace_slope_integral (U : Submodule โ E) [Nontrivial E] [Nontrivial Uแฎ]
{g : E โ โโฅ0โ} (hg : Measurable g) :
โซโป y, g y โuniformDirection E =
((volume : Measure E).toSphere univ)โปยน *
โซโป z : sphere (0 : Uแฎ) 1, โซโป x : U,
ENNReal.ofReal ((1 + โxโ^2) ^ (-((Module.finrank โ E : โ) : โ) / 2)) *
g (normalDirection ((x : E) + ((z : Uแฎ) : E)))
โvolume โ(volume : Measure Uแฎ).toSphere := by
rw [sphere_subspace_polar_integral U hg, โ lintegral_const_mul _ (by fun_prop)]
apply lintegral_congr
intro z
simp_rw [scaled_subspace_integral U z _ hg]
rw [lintegral_lintegral_swap (by fun_prop), โ lintegral_const_mul _ (by fun_prop)]
apply lintegral_congr
intro x
rw [lintegral_mul_const _ (by fun_prop), radial_subspace_integral]
ac_rfl
lemma normalDirection_ballStretch (U : Submodule โ E) {x : U}
(hx : x โ ball (0 : U) 1) (z : sphere (0 : Uแฎ) 1) :
normalDirection (((ballStretch x : U) : E) + ((z : Uแฎ) : E)) =
(x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E) := by
have hb := one_sub_norm_sq_pos hx
have hs := Real.sqrt_pos.mpr hb
have hz : โ(z : Uแฎ)โ = 1 := mem_sphere_zero_iff_norm.mp z.2
have hn : โ(x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E)โ = 1 := by
have h := subspace_sum_norm_sq U x (Real.sqrt (1 - โxโ^2) โข (z : Uแฎ))
simp only [Submodule.coe_smul_of_tower, norm_smul, Real.norm_eq_abs,
abs_of_pos hs, hz, mul_one, Real.sq_sqrt hb.le] at h
nlinarith [norm_nonneg ((x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E))]
have he : ((ballStretch x : U) : E) + ((z : Uแฎ) : E) =
(Real.sqrt (1 - โxโ^2))โปยน โข
((x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E)) := by
rw [ballStretch_eq_inv_sqrt hx]
change (Real.sqrt (1 - โxโ^2))โปยน โข (x : E) + ((z : Uแฎ) : E) = _
rw [smul_add, smul_smul, inv_mul_cancelโ hs.ne', one_smul]
rw [he, normalDirection_smul_sphere (inv_pos.mpr hs) hn]
lemma sphere_subspace_surface_integral (U : Submodule โ E) [Nontrivial E] [Nontrivial Uแฎ]
{g : E โ โโฅ0โ} (hg : Measurable g) :
โซโป y, g y โuniformDirection E =
((volume : Measure E).toSphere univ)โปยน *
โซโป x : U in ball 0 1,
ENNReal.ofReal ((1 - โxโ^2) ^ ((((Module.finrank โ Uแฎ : โ) : โ) - 2) / 2)) *
โซโป z : sphere (0 : Uแฎ) 1,
g ((x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E))
โ(volume : Measure Uแฎ).toSphere := by
rw [sphere_subspace_slope_integral U hg]
congr 1
have ht (z : sphere (0 : Uแฎ) 1) :
(โซโป x : U, ENNReal.ofReal ((1 + โxโ^2) ^ (-((Module.finrank โ E : โ) : โ) / 2)) *
g (normalDirection ((x : E) + ((z : Uแฎ) : E)))) =
โซโป x : U in ball 0 1,
ENNReal.ofReal ((1 - โxโ^2) ^ ((((Module.finrank โ Uแฎ : โ) : โ) - 2) / 2)) *
g ((x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E)) := by
rw [lintegral_ballStretch]
apply setLIntegral_congr_fun measurableSet_ball
intro x hx
dsimp only
rw [normalDirection_ballStretch U hx z, โ mul_assoc,
โ U.finrank_add_finrank_orthogonal, ballStretch_weight hx]
simp_rw [ht]
rw [lintegral_lintegral_swap (by fun_prop)]
apply setLIntegral_congr_fun measurableSet_ball
intro x hx
dsimp only
rw [lintegral_const_mul _ (by fun_prop)]
lemma surface_lintegral_eq_gaussian [Nontrivial E] {g : E โ โโฅ0โ} (hg : Measurable g) :
โซโป z : sphere (0 : E) 1, g (z : E) โ(volume : Measure E).toSphere =
(volume : Measure E).toSphere univ * โซโป x, g (normalDirection x) โstdGaussian E := by
have he : (โซโป x, g (normalDirection x) โstdGaussian E) = โซโป x, g x โuniformDirection E := by
rw [โ gaussian_normalDirection, lintegral_map hg (by fun_prop)]
rw [he, uniformDirection, lintegral_map hg (by fun_prop), lintegral_smul_measure]
change _ = (volume : Measure E).toSphere univ *
(((volume : Measure E).toSphere univ)โปยน *
โซโป z : sphere (0 : E) 1, g (z : E) โ(volume : Measure E).toSphere)
rw [โ mul_assoc, ENNReal.mul_inv_cancel
(Measure.measure_univ_ne_zero.mpr (Measure.toSphere_ne_zero volume)) (measure_ne_top _ _), one_mul]
lemma sphere_subspace_gaussian_fiber_integral (U : Submodule โ E)
[Nontrivial E] [Nontrivial Uแฎ] {g : E โ โโฅ0โ} (hg : Measurable g) :
โซโป y, g y โuniformDirection E =
((volume : Measure E).toSphere univ)โปยน * (volume : Measure Uแฎ).toSphere univ *
โซโป x : U in ball 0 1,
ENNReal.ofReal ((1 - โxโ^2) ^ ((((Module.finrank โ Uแฎ : โ) : โ) - 2) / 2)) *
โซโป z : E, g ((x : E) + Real.sqrt (1 - โxโ^2) โข
normalDirection (Uแฎ.starProjection z)) โstdGaussian E := by
rw [sphere_subspace_surface_integral U hg, mul_assoc]
congr 1
rw [โ lintegral_const_mul _ (by fun_prop)]
apply setLIntegral_congr_fun measurableSet_ball
intro x hx
dsimp only
rw [surface_lintegral_eq_gaussian (E := Uแฎ) (g := fun z =>
g ((x : E) + Real.sqrt (1 - โxโ^2) โข (z : E))) (by fun_prop)]
have he : (โซโป z : Uแฎ, g ((x : E) + Real.sqrt (1 - โxโ^2) โข ((normalDirection z : Uแฎ) : E))
โstdGaussian Uแฎ) = โซโป z : E, g ((x : E) + Real.sqrt (1 - โxโ^2) โข
normalDirection (Uแฎ.starProjection z)) โstdGaussian E := by
rw [โ gaussian_orthogonalProjectionOnto Uแฎ, lintegral_map (by fun_prop) (by fun_prop)]
rfl
rw [he]
ac_rfl
lemma sphere_area_ratio (U : Submodule โ E) [Nontrivial E] [Nontrivial Uแฎ] :
((volume : Measure E).toSphere univ)โปยน * (volume : Measure Uแฎ).toSphere univ =
ENNReal.ofReal (Real.Gamma (((Module.finrank โ E : โ) : โ) / 2) /
(Real.pi ^ (((Module.finrank โ U : โ) : โ) / 2) *
Real.Gamma (((Module.finrank โ Uแฎ : โ) : โ) / 2))) := by
have hd : 0 < ((Module.finrank โ E : โ) : โ) := Nat.cast_pos.mpr Module.finrank_pos
have hq : 0 < ((Module.finrank โ Uแฎ : โ) : โ) := Nat.cast_pos.mpr Module.finrank_pos
have he : ((Module.finrank โ E : โ) : โ) =
((Module.finrank โ U : โ) : โ) + ((Module.finrank โ Uแฎ : โ) : โ) := by
exact_mod_cast U.finrank_add_finrank_orthogonal.symm
have hp : Real.pi ^ (((Module.finrank โ E : โ) : โ) / 2) =
Real.pi ^ (((Module.finrank โ U : โ) : โ) / 2) *
Real.pi ^ (((Module.finrank โ Uแฎ : โ) : โ) / 2) := by
rw [he, add_div, Real.rpow_add Real.pi_pos]
rw [sphere_area, sphere_area, โ ENNReal.ofReal_inv_of_pos (by positivity),
โ ENNReal.ofReal_mul (by positivity)]
congr 1
rw [hp]
field_simp
end PosteriorReplicas
end
end OAI
|