introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
14.7 kB
import OAI.Probability.PosteriorReplicas.Regression.ProjectionCoupling
namespace OAI
open MeasureTheory ProbabilityTheory Set Filter
open scoped ENNReal NNReal RealInnerProductSpace
noncomputable section
universe u
namespace PosteriorRegression
open scoped Topology
open InnerProductSpace
section SupportVolume
open scoped Pointwise
def coordinateNorm {m : β„•} (y : Fin m β†’ ℝ) : ℝ := β€–WithLp.toLp 2 yβ€–
@[fun_prop] lemma continuous_coordinateNorm {m : β„•} :
Continuous (coordinateNorm (m := m)) := by
unfold coordinateNorm
fun_prop
lemma coordinateNorm_sq {m : β„•} (y : Fin m β†’ ℝ) :
coordinateNorm y ^ 2 = βˆ‘ j, (y j)^2 := by
exact EuclideanSpace.real_norm_sq_eq (WithLp.toLp 2 y)
lemma coordinateNorm_smul {m : β„•} (c : ℝ) (y : Fin m β†’ ℝ) :
coordinateNorm (c β€’ y) = |c| * coordinateNorm y := by
simp [coordinateNorm, WithLp.toLp_smul, norm_smul, Real.norm_eq_abs]
def coordinateBall (m : β„•) (r : ℝ) : Set (Fin m β†’ ℝ) :=
{y | coordinateNorm y ≀ r}
lemma measurableSet_coordinateBall (m : β„•) (r : ℝ) :
MeasurableSet (coordinateBall m r) :=
measurableSet_le continuous_coordinateNorm.measurable measurable_const
lemma coordinateBall_smul (m : β„•) (c r : ℝ) (hc : 0 < c) :
coordinateBall m (c * r) = c β€’ coordinateBall m r := by
ext y
constructor
Β· intro hy
refine ⟨c⁻¹ β€’ y, ?_, by simp [hc.ne']⟩
change coordinateNorm (c⁻¹ β€’ y) ≀ r
rw [coordinateNorm_smul, abs_of_pos (inv_pos.mpr hc)]
exact (inv_mul_le_iffβ‚€ hc).mpr hy
· rintro ⟨y, hy, rfl⟩
change coordinateNorm (c β€’ y) ≀ c * r
rw [coordinateNorm_smul, abs_of_pos hc]
exact mul_le_mul_of_nonneg_left hy hc.le
lemma volume_coordinateBall_smul (m : β„•) (c r : ℝ) (hc : 0 < c) :
volume (coordinateBall m (c * r)) =
ENNReal.ofReal (c^m) * volume (coordinateBall m r) := by
rw [coordinateBall_smul m c r hc, Measure.addHaar_smul_of_nonneg volume hc.le]
simp
lemma gaussianPDF_le_exp (x : ℝ) :
gaussianPDF 0 1 x ≀ ENNReal.ofReal (Real.exp (-(x^2)/2)) := by
apply ENNReal.ofReal_le_ofReal
unfold gaussianPDFReal
simp only [NNReal.coe_one, mul_one, sub_zero]
apply mul_le_of_le_one_left (Real.exp_nonneg _)
apply inv_le_one_of_one_leβ‚€
apply (Real.le_sqrt (by norm_num) (by positivity)).mpr
nlinarith [Real.pi_gt_three]
lemma lintegral_quarterGaussian_le :
(∫⁻ x : ℝ, ENNReal.ofReal (Real.exp (-(x^2)/4))) ≀ 4 := by
have he : (fun x : ℝ => Real.exp (-(x^2)/4)) =
(fun x : ℝ => Real.exp (-(1/4 : ℝ) * x^2)) := by
ext x
congr 1
ring
simp_rw [show βˆ€ x : ℝ, Real.exp (-(x^2)/4) = Real.exp (-(1/4 : ℝ) * x^2) from congrFun he]
rw [← ofReal_integral_eq_lintegral_ofReal
(integrable_exp_neg_mul_sq (by norm_num)) (by filter_upwards [] with x; positivity),
integral_gaussian]
have hs : Real.sqrt (Real.pi / (1/4 : ℝ)) ≀ 4 := by
apply (Real.sqrt_le_iff).mpr
constructor
Β· norm_num
Β· nlinarith [Real.pi_lt_four]
exact (ENNReal.ofReal_le_ofReal hs).trans_eq (by norm_num)
lemma gaussian_density_pair_bound {m : β„•} (x y : Fin m β†’ ℝ)
(h : coordinateNorm y ≀ coordinateNorm x) :
(∏ j, gaussianPDF 0 1 (x j)) ≀
(∏ j, ENNReal.ofReal (Real.exp (-(x j)^2/4))) *
∏ j, ENNReal.ofReal (Real.exp (-(y j)^2/4)) := by
calc
_ ≀ ∏ j, ENNReal.ofReal (Real.exp (-(x j)^2/2)) :=
Finset.prod_le_prod fun j _ => gaussianPDF_le_exp (x j)
_ = ENNReal.ofReal (Real.exp (- (βˆ‘ j, (x j)^2) / 2)) := by
rw [← ENNReal.ofReal_prod_of_nonneg (fun j _ => Real.exp_nonneg _), ← Real.exp_sum]
congr 2
rw [← Finset.sum_div, Finset.sum_neg_distrib]
_ ≀ ENNReal.ofReal (Real.exp (- (βˆ‘ j, (x j)^2)/4 - (βˆ‘ j, (y j)^2)/4)) := by
apply ENNReal.ofReal_le_ofReal
apply Real.exp_le_exp.mpr
have hn : 0 ≀ coordinateNorm y := norm_nonneg _
have hs := pow_le_pow_leftβ‚€ hn h 2
rw [coordinateNorm_sq, coordinateNorm_sq] at hs
linarith
_ = _ := by
rw [← ENNReal.ofReal_prod_of_nonneg (fun j _ => Real.exp_nonneg _),
← ENNReal.ofReal_prod_of_nonneg (fun j _ => Real.exp_nonneg _),
← Real.exp_sum, ← Real.exp_sum, ← ENNReal.ofReal_mul (Real.exp_nonneg _),
← Real.exp_add]
congr 2
simp only [← Finset.sum_div, Finset.sum_neg_distrib]
ring
lemma measurable_coordinateVolume (m : β„•) : Measurable (fun x : Fin m β†’ ℝ => volume (coordinateBall m (coordinateNorm x))) := by
have : Measurable (fun z : (Fin m β†’ ℝ) Γ— (Fin m β†’ ℝ) =>
({z | coordinateNorm z.2 ≀ coordinateNorm z.1} : Set _).indicator
(fun _ => (1 : ℝβ‰₯0∞)) z) :=
measurable_const.indicator (measurableSet_le (by fun_prop) (by fun_prop))
change Measurable (Function.uncurry (fun x y : Fin m β†’ ℝ =>
(coordinateBall m (coordinateNorm x)).indicator (fun _ => (1 : ℝβ‰₯0∞)) y)) at this
convert this.lintegral_prod_right (Ξ½ := (volume : Measure (Fin m β†’ ℝ))) using 1
ext x
rw [lintegral_indicator (measurableSet_coordinateBall m _)]
simp
lemma gaussian_expected_coordinate_volume (m : β„•) :
(∫⁻ x : Fin m β†’ ℝ, volume (coordinateBall m (coordinateNorm x))
βˆ‚Measure.pi (fun _ => gaussianReal 0 1)) ≀ (16 : ℝβ‰₯0∞)^m := by
have hB := measurable_coordinateVolume m
rw [pi_gaussian_withDensity m 1 (by norm_num),
lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) hB]
have hi (x : Fin m β†’ ℝ) :
(∏ j, gaussianPDF 0 1 (x j)) * volume (coordinateBall m (coordinateNorm x)) =
∫⁻ y : Fin m β†’ ℝ, (coordinateBall m (coordinateNorm x)).indicator
(fun _ => ∏ j, gaussianPDF 0 1 (x j)) y := by
rw [lintegral_indicator (measurableSet_coordinateBall m _)]
simp
simp only [Pi.mul_apply]
simp_rw [hi]
calc
_ ≀ ∫⁻ x : Fin m β†’ ℝ, ∫⁻ y : Fin m β†’ ℝ,
(∏ j, ENNReal.ofReal (Real.exp (-(x j)^2/4))) *
∏ j, ENNReal.ofReal (Real.exp (-(y j)^2/4)) := by
apply lintegral_mono
intro x
apply lintegral_mono
intro y
by_cases hy : y ∈ coordinateBall m (coordinateNorm x)
Β· rw [Set.indicator_of_mem hy]
exact gaussian_density_pair_bound x y hy
Β· rw [Set.indicator_of_notMem hy]
exact zero_le
_ = ((∫⁻ z : ℝ, ENNReal.ofReal (Real.exp (-(z^2)/4)))^m)^2 := by
have hJ : (∫⁻ y : Fin m β†’ ℝ, ∏ j, ENNReal.ofReal (Real.exp (-(y j)^2/4))) =
(∫⁻ z : ℝ, ENNReal.ofReal (Real.exp (-(z^2)/4)))^m := by
rw [volume_pi, lintegral_fin_prod volume m
(fun _ => fun z : ℝ => ENNReal.ofReal (Real.exp (-(z^2)/4))) (fun _ => by fun_prop)]
simp
have hj (x : Fin m β†’ ℝ) := lintegral_const_mul (ΞΌ := volume)
(∏ j, ENNReal.ofReal (Real.exp (-(x j)^2/4)))
(by fun_prop : Measurable (fun y : Fin m β†’ ℝ =>
∏ j, ENNReal.ofReal (Real.exp (-(y j)^2/4))))
simp_rw [hj, hJ]
rw [lintegral_mul_const _ (by fun_prop), hJ, pow_two]
_ ≀ ((4 : ℝβ‰₯0∞)^m)^2 := pow_le_pow_leftβ‚€ (by positivity)
(pow_le_pow_leftβ‚€ (by positivity) lintegral_quarterGaussian_le m) 2
_ = _ := by rw [← pow_mul, Nat.mul_comm, pow_mul]; norm_num
section Rows
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
[FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
lemma stdGaussian_inner_map (u : E) :
(stdGaussian E).map (fun x => βŸͺu, x⟫) =
gaussianReal 0 (NNReal.mk (β€–uβ€–^2) (sq_nonneg β€–uβ€–)) := by
have h := IsGaussian.map_eq_gaussianReal (ΞΌ := stdGaussian E) (innerSL ℝ u)
have he : (⇑(innerSL ℝ u)) = (fun x => βŸͺu, x⟫) := by
ext x
exact innerSL_apply_apply ℝ u x
simp only [integral_strongDual_stdGaussian, variance_dual_stdGaussian, innerSL_apply_norm] at h
rw [he] at h
have hh : (β€–uβ€–^2).toNNReal = NNReal.mk (β€–uβ€–^2) (sq_nonneg β€–uβ€–) := by
ext
simp
simpa only [integral_strongDual_stdGaussian, variance_dual_stdGaussian,
innerSL_apply_norm, hh] using h
lemma rows_inner_map (u : E) (m : β„•) :
(Measure.pi (fun _ : Fin m => stdGaussian E)).map
(fun A => fun j => βŸͺu, A j⟫) =
(Measure.pi (fun _ : Fin m => gaussianReal 0 1)).map
(fun x => β€–uβ€– β€’ x) := by
rw [Measure.pi_map_pi (f := fun _ : Fin m => fun x : E => βŸͺu, x⟫)
(fun _ => (by fun_prop : Measurable (fun x : E => βŸͺu, x⟫)).aemeasurable)]
simp_rw [stdGaussian_inner_map]
exact (pi_gaussian_map_scale m β€–uβ€–).symm
lemma rows_expected_coordinate_volume (u : E) (hu : β€–uβ€– ≀ 1) (m : β„•) :
(∫⁻ A : Fin m β†’ E, volume (coordinateBall m (coordinateNorm (fun j => βŸͺu, A j⟫)))
βˆ‚Measure.pi (fun _ => stdGaussian E)) ≀ (16 : ℝβ‰₯0∞)^m := by
have h := congrArg (fun ΞΌ : Measure (Fin m β†’ ℝ) =>
∫⁻ y, volume (coordinateBall m (coordinateNorm y)) βˆ‚ΞΌ) (rows_inner_map u m)
rw [lintegral_map (measurable_coordinateVolume m) (by fun_prop),
lintegral_map (measurable_coordinateVolume m) (by fun_prop)] at h
rw [h]
apply le_trans _ (gaussian_expected_coordinate_volume m)
apply lintegral_mono
intro x
apply measure_mono
intro y hy
change coordinateNorm y ≀ coordinateNorm x
apply le_trans hy
rw [coordinateNorm_smul, abs_of_nonneg (norm_nonneg _)]
exact mul_le_of_le_one_left (norm_nonneg _) hu
def rowOperator {m : β„•} (A : Fin m β†’ E) : E β†’L[ℝ] EuclideanSpace ℝ (Fin m) :=
(PiLp.continuousLinearEquiv 2 ℝ (fun _ : Fin m => ℝ)).symm.toContinuousLinearMap.comp
(ContinuousLinearMap.pi (fun j => innerSL ℝ (A j)))
omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in
lemma rowOperator_apply {m : β„•} (A : Fin m β†’ E) (t : E) :
rowOperator A t = WithLp.toLp 2 (fun j => βŸͺt, A j⟫) := by
ext j
exact real_inner_comm _ _
def netProjectionSupport (s : Finset E) (m : β„•) :
Set ((Fin m β†’ E) Γ— (Fin m β†’ ℝ)) :=
⋃ u ∈ s, {z | coordinateNorm z.2 ≀ 2 * coordinateNorm (fun j => βŸͺu, z.1 j⟫)}
lemma measurableSet_netProjectionSupport (s : Finset E) (m : β„•) :
MeasurableSet (netProjectionSupport s m) := by
apply MeasurableSet.biUnion s.countable_toSet
intro u _
exact measurableSet_le (by fun_prop) (by fun_prop)
lemma netProjectionSupport_volume (s : Finset E) (hs : βˆ€ u ∈ s, β€–uβ€– ≀ 1) (m : β„•) :
matrixLabelReference (E := E) m (netProjectionSupport s m) ≀
(s.card : ℝβ‰₯0∞) * (32 : ℝβ‰₯0∞)^m := by
classical
apply (measure_biUnion_finset_le s _).trans
calc
_ ≀ βˆ‘ _u ∈ s, (32 : ℝβ‰₯0∞)^m := by
apply Finset.sum_le_sum
intro u hu
rw [matrixLabelReference, Measure.prod_apply (measurableSet_le (by fun_prop) (by fun_prop))]
change (∫⁻ A : Fin m β†’ E,
volume (coordinateBall m (2 * coordinateNorm (fun j => βŸͺu, A j⟫)))
βˆ‚Measure.pi (fun _ => stdGaussian E)) ≀ _
simp_rw [volume_coordinateBall_smul m 2 _ (by norm_num)]
have hme : Measurable (fun A : Fin m β†’ E =>
volume (coordinateBall m (coordinateNorm (fun j => βŸͺu, A j⟫)))) :=
(measurable_coordinateVolume m).comp (by fun_prop)
rw [lintegral_const_mul _ hme]
calc
_ ≀ ENNReal.ofReal ((2 : ℝ)^m) * (16 : ℝβ‰₯0∞)^m :=
mul_le_mul' le_rfl (rows_expected_coordinate_volume u (hs u hu) m)
_ = _ := by rw [ENNReal.ofReal_pow (by norm_num)]; norm_num [← mul_pow]
_ = _ := by simp
end Rows
section NetNorm
variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F]
lemma opNorm_le_twice_net (f : E β†’L[ℝ] F) (s : Finset E)
(hnet : βˆ€ x : E, β€–xβ€– ≀ 1 β†’ βˆƒ y ∈ s, dist x y ≀ 1/2) :
β€–fβ€– ≀ 2 * (s.sup (fun u => β€–f uβ€–β‚Š) : ℝβ‰₯0) := by
classical
let K : ℝ := (s.sup (fun u => β€–f uβ€–β‚Š) : ℝβ‰₯0)
have hK : 0 ≀ K := NNReal.coe_nonneg _
have hbound : β€–fβ€– ≀ K + β€–fβ€–/2 := by
apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity)
intro x hx
obtain ⟨y, hy, hxy⟩ := hnet x hx.le
have hfy : β€–f yβ€– ≀ K := by
exact_mod_cast (Finset.le_sup (f := fun u => β€–f uβ€–β‚Š) hy)
calc
β€–f xβ€– = β€–f y + f (x-y)β€– := by rw [map_sub]; congr 1; abel
_ ≀ β€–f yβ€– + β€–f (x-y)β€– := norm_add_le _ _
_ ≀ K + β€–fβ€– * (1/2) := add_le_add hfy
((f.le_opNorm (x-y)).trans (mul_le_mul_of_nonneg_left
(by simpa [dist_eq_norm] using hxy) (norm_nonneg _)))
_ = _ := by ring
dsimp [K] at hbound
linarith
end NetNorm
section SupportExistence
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
[FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
theorem exists_projection_support (m : β„•) (hm : m ≀ Module.finrank ℝ E) :
βˆƒ D : Set ((Fin m β†’ E) Γ— (Fin m β†’ ℝ)), MeasurableSet D ∧
(βˆ€ A t, β€–tβ€– ≀ 1 β†’ (A, fun j => βŸͺt, A j⟫) ∈ D) ∧
matrixLabelReference (E := E) m D ≀ (192 : ℝβ‰₯0∞)^(Module.finrank ℝ E) := by
classical
obtain ⟨s, hs, hc, hnet⟩ := exists_unit_ball_net (E := E)
(by norm_num : (0 : ℝ) < 1/2) (by norm_num : (1/2 : ℝ) ≀ 1)
have hsne : s.Nonempty := by
obtain ⟨u, hu, _⟩ := hnet 0 (by simp)
exact ⟨u, hu⟩
refine ⟨netProjectionSupport s m, measurableSet_netProjectionSupport s m, ?_, ?_⟩
Β· intro A t ht
obtain ⟨u, hu, he⟩ := s.exists_mem_eq_sup hsne (fun u => β€–rowOperator A uβ€–β‚Š)
refine Set.mem_iUnion.mpr ⟨u, Set.mem_iUnion.mpr ⟨hu, ?_⟩⟩
change coordinateNorm (fun j => βŸͺt, A j⟫) ≀
2 * coordinateNorm (fun j => βŸͺu, A j⟫)
change β€–WithLp.toLp 2 (fun j => βŸͺt, A j⟫)β€– ≀
2 * β€–WithLp.toLp 2 (fun j => βŸͺu, A j⟫)β€–
rw [← rowOperator_apply, ← rowOperator_apply]
calc
_ ≀ β€–rowOperator Aβ€– * β€–tβ€– := (rowOperator A).le_opNorm t
_ ≀ β€–rowOperator Aβ€– := mul_le_of_le_one_right (norm_nonneg _) ht
_ ≀ _ := by simpa [he] using opNorm_le_twice_net (rowOperator A) s hnet
Β· apply (netProjectionSupport_volume s hs m).trans
have hcard : (s.card : ℝβ‰₯0∞) ≀ (6 : ℝβ‰₯0∞)^(Module.finrank ℝ E) := by
have h : (s.card : ℝ) ≀ (6 : ℝ)^(Module.finrank ℝ E) := by norm_num at hc ⊒; exact hc
simpa using ENNReal.ofReal_le_ofReal h
calc
_ ≀ (6 : ℝβ‰₯0∞)^Module.finrank ℝ E * (32 : ℝβ‰₯0∞)^Module.finrank ℝ E :=
mul_le_mul' hcard (pow_le_pow_rightβ‚€ (by norm_num) hm)
_ = _ := by rw [← mul_pow]; norm_num
end SupportExistence
end SupportVolume
end PosteriorRegression
end
end OAI