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