cfahlgren1's picture
download
raw
7.78 kB
import OAI.Probability.PosteriorReplicas.Gaussian.GaussianFiber
import OAI.Probability.PosteriorReplicas.Measures.DensityTools
namespace OAI
open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace
open scoped ENNReal NNReal RealInnerProductSpace
noncomputable section
namespace PosteriorReplicas
def matrixLinearEquiv {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) (hd : M.det ≠ 0) :
(Fin n → ℝ) ≃ₗ[ℝ] (Fin n → ℝ) :=
{ Matrix.toLin' M with
invFun := Matrix.toLin' M⁻¹
left_inv := by
intro x
change M⁻¹ *ᵥ (M *ᵥ x) = x
rw [Matrix.mulVec_mulVec, Matrix.nonsing_inv_mul _ (isUnit_iff_ne_zero.mpr hd),
Matrix.one_mulVec]
right_inv := by
intro x
change M *ᵥ (M⁻¹ *ᵥ x) = x
rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv _ (isUnit_iff_ne_zero.mpr hd),
Matrix.one_mulVec] }
lemma gaussian_linear_image_density {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ)
(hd : M.det ≠ 0) :
(Measure.pi (fun _ : Fin n => gaussianReal 0 1)).map (Matrix.toLin' M) =
(volume : Measure (Fin n → ℝ)).withDensity (fun y =>
ENNReal.ofReal |M.det⁻¹| * ∏ i, gaussianPDF 0 1 ((M⁻¹ *ᵥ y) i)) := by
let e := (matrixLinearEquiv M hd).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv
have he : (e : (Fin n → ℝ) → (Fin n → ℝ)) = Matrix.toLin' M := rfl
have hi : (e.symm : (Fin n → ℝ) → (Fin n → ℝ)) = Matrix.toLin' M⁻¹ := rfl
rw [pi_gaussian_density, ← he, map_withDensity_equiv _ e (by fun_prop), he,
Real.map_matrix_volume_pi_eq_smul_volume_pi hd, withDensity_smul_measure,
← withDensity_smul _ (by fun_prop)]
rfl
lemma gaussian_density_product {n : ℕ} (z : Fin n → ℝ) :
(∏ i, gaussianPDF 0 1 (z i)) = ENNReal.ofReal
((2 * Real.pi) ^ (-(n : ℝ) / 2) * Real.exp (-(∑ i, (z i)^2) / 2)) := by
have hconst : (Real.sqrt (2 * Real.pi))⁻¹ ^ n =
(2 * Real.pi) ^ (-(n : ℝ) / 2) := by
rw [inv_pow, Real.sqrt_eq_rpow, ← Real.rpow_natCast,
← Real.rpow_mul (by positivity), ← Real.rpow_neg (by positivity)]
congr 1
ring
simp only [gaussianPDF_def]
rw [← ENNReal.ofReal_prod_of_nonneg (fun i _ => gaussianPDFReal_nonneg 0 1 (z i))]
congr 1
simp only [gaussianPDFReal, NNReal.coe_one, mul_one, sub_zero,
Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin]
rw [hconst, ← Real.exp_sum]
congr 2
rw [← Finset.sum_div, Finset.sum_neg_distrib]
section PairingsDensity
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
def pairingTriangular {n : ℕ} (v : Fin n → E) : Matrix (Fin n) (Fin n) ℝ :=
Matrix.diagonal (fun i => ‖gramSchmidt ℝ v i‖) * PosteriorRegression.gsUpper n v
lemma pairingTriangular_expansion [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
{n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v)
(j : Fin n) : ∑ i, pairingTriangular v i j • gramSchmidtNormed ℝ v i = v j := by
have hn (i : Fin n) : ‖gramSchmidt ℝ v i‖ ≠ 0 :=
norm_ne_zero_iff.mpr (gramSchmidt_ne_zero i hv)
rw [← PosteriorRegression.gsUpper_expansion n v j]
apply Finset.sum_congr rfl
intro i _
simp only [pairingTriangular, Matrix.diagonal_mul, gramSchmidtNormed, smul_smul]
congr 1
simp [hn i, mul_comm]
lemma pairingTriangular_det [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
{n : ℕ} (v : Fin n → E) :
(pairingTriangular v).transpose.det = Real.sqrt (Matrix.gram ℝ v).det := by
rw [pairingTriangular, Matrix.det_transpose, Matrix.det_mul, Matrix.det_diagonal,
PosteriorRegression.gsUpper_det, mul_one, PosteriorRegression.sqrt_det_gram]
variable [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
lemma pairingTriangular_det_pos {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) :
0 < (pairingTriangular v).transpose.det := by
rw [pairingTriangular_det]
exact Real.sqrt_pos.mpr (Matrix.posDef_gram_of_linearIndependent hv).det_pos
lemma pairings_eq_triangular {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) :
(fun x : E => fun j => ⟪v j, x⟫) =
(Matrix.toLin' (pairingTriangular v).transpose) ∘
(fun x => fun i => ⟪gramSchmidtNormed ℝ v i, x⟫) := by
funext x j
rw [← pairingTriangular_expansion hv j]
simp [Matrix.toLin'_apply, Matrix.mulVec, dotProduct, sum_inner, inner_smul_left]
lemma gaussian_pairings_density_coordinates {n : ℕ} {v : Fin n → E}
(hv : LinearIndependent ℝ v) :
(stdGaussian E).map (fun x => fun i => ⟪v i, x⟫) =
(volume : Measure (Fin n → ℝ)).withDensity (fun y =>
ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ v).det)⁻¹) *
∏ i, gaussianPDF 0 1 (((pairingTriangular v).transpose⁻¹ *ᵥ y) i)) := by
rw [pairings_eq_triangular hv, ← Measure.map_map (by fun_prop) (by fun_prop),
PosteriorRegression.orthonormal_gaussian_map (gramSchmidtNormed_orthonormal hv),
gaussian_linear_image_density _ (ne_of_gt (pairingTriangular_det_pos hv)),
abs_of_pos (inv_pos.mpr (pairingTriangular_det_pos hv)), pairingTriangular_det]
lemma orthonormal_pairings_eq_inverse {n : ℕ} {v : Fin n → E}
(hv : LinearIndependent ℝ v) (x : E) :
(fun i => ⟪gramSchmidtNormed ℝ v i, x⟫) =
(pairingTriangular v).transpose⁻¹ *ᵥ (fun i => ⟪v i, x⟫) := by
have he := congrFun (pairings_eq_triangular hv) x
change (fun i => ⟪v i, x⟫) =
(pairingTriangular v).transpose *ᵥ (fun i => ⟪gramSchmidtNormed ℝ v i, x⟫) at he
rw [he, Matrix.mulVec_mulVec,
Matrix.nonsing_inv_mul _ (isUnit_iff_ne_zero.mpr (ne_of_gt (pairingTriangular_det_pos hv))),
Matrix.one_mulVec]
lemma pairingLift_energy {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v)
(y : Fin n → ℝ) :
‖pairingLift v y‖^2 = ∑ i, (((pairingTriangular v).transpose⁻¹ *ᵥ y) i)^2 := by
have hu := gramSchmidtNormed_orthonormal hv
have hs : Submodule.span ℝ (Set.range (gramSchmidtNormed ℝ v)) =
Submodule.span ℝ (Set.range v) :=
(span_gramSchmidtNormed_range v).trans (span_gramSchmidt ℝ v)
have hexp := orthonormal_starProjection hu (pairingLift v y)
rw [hs, (Submodule.span ℝ (Set.range v)).starProjection_eq_self_iff.mpr
(pairingLift_mem v y)] at hexp
have hc := orthonormal_pairings_eq_inverse hv (pairingLift v y)
rw [pairings_pairingLift hv y] at hc
simp_rw [congrFun hc] at hexp
rw [hexp, ← real_inner_self_eq_norm_sq, hu.inner_sum]
simp [pow_two]
lemma gaussian_pairings_density {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) :
(stdGaussian E).map (fun x => fun i => ⟪v i, x⟫) =
(volume : Measure (Fin n → ℝ)).withDensity (fun y => ENNReal.ofReal
((2 * Real.pi) ^ (-(n : ℝ) / 2) * Real.exp (-‖pairingLift v y‖^2 / 2) /
Real.sqrt (Matrix.gram ℝ v).det)) := by
rw [gaussian_pairings_density_coordinates hv]
congr 1
funext y
rw [gaussian_density_product, ← pairingLift_energy hv,
← ENNReal.ofReal_mul (by positivity)]
congr 1
ring
lemma gaussian_fiber_integral {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v)
{g : E → ℝ≥0∞} (hg : Measurable g) :
∫⁻ x, g x ∂stdGaussian E = ∫⁻ y, ENNReal.ofReal
((2 * Real.pi) ^ (-(n : ℝ) / 2) * Real.exp (-‖pairingLift v y‖^2 / 2) /
Real.sqrt (Matrix.gram ℝ v).det) *
∫⁻ r, g (pairingLift v y + r)
∂((stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection) := by
rw [gaussian_pairings_integral hv hg, gaussian_pairings_density hv,
lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)]
rfl
end PairingsDensity
end PosteriorReplicas
end
end OAI

Xet Storage Details

Size:
7.78 kB
·
Xet hash:
86da3f9541d7900a21b73ca1cf80c2e73d7c5c0bbea897e72a00d487ac195aeb

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.