Download data/lean/OAI/Probability/GaussianRegression/Support.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 14.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/GaussianRegression/Support.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/GaussianRegression/Support.lean
-
curl -L -o Support.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/GaussianRegression/Support.lean
14.7 kB
| import OAI.Probability.GaussianRegression.Nets | |
| import OAI.Probability.GaussianRegression.Projection | |
| namespace OAI | |
| /-! | |
| Finite-volume enclosures for Gaussian matrix observations. | |
| -/ | |
| open MeasureTheory ProbabilityTheory Set Filter | |
| open scoped ENNReal NNReal RealInnerProductSpace Topology | |
| open InnerProductSpace | |
| noncomputable section | |
| universe u | |
| namespace NoiselessRegression | |
| 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 | |
| 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 NoiselessRegression | |
| end | |
| end OAI | |