roseking's picture
Add lean source and binary files (part 122)
b317718 verified
Raw History Blame Contribute Delete
11.3 kB
import OAI.Probability.GaussianRegression.Gram
namespace OAI
/-!
Gaussian coordinate domination and replica kernel bounds.
-/
open MeasureTheory ProbabilityTheory Set Filter
open scoped ENNReal NNReal RealInnerProductSpace Topology
open InnerProductSpace
noncomputable section
universe u
namespace NoiselessRegression
section GaussianDomination
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
[FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
lemma orthonormal_gaussian_map {n : ℕ} {u : Fin n → E} (hu : Orthonormal ℝ u) :
(stdGaussian E).map (fun x => fun i => ⟪u i, x⟫) =
Measure.pi (fun _ : Fin n => gaussianReal 0 1) := by
let f : E → EuclideanSpace ℝ (Fin n) := fun x => WithLp.toLp 2 (fun i => ⟪u i, x⟫)
have hf : Measurable f := by dsimp [f]; fun_prop
have he : (stdGaussian E).map f = stdGaussian (EuclideanSpace ℝ (Fin n)) := by
apply Measure.ext_of_charFun
ext t
have hi (x : E) : ⟪f x, t⟫ = ⟪x, ∑ i, t i • u i⟫ := by
simp [f, PiLp.inner_apply, inner_sum, inner_smul_right, real_inner_comm x]
have hn : ‖∑ i, t i • u i‖ ^ 2 = ‖t‖ ^ 2 := by
rw [← real_inner_self_eq_norm_sq, hu.inner_sum, EuclideanSpace.real_norm_sq_eq]
simp [pow_two]
rw [charFun_apply, integral_map hf.aemeasurable (by fun_prop)]
simp_rw [hi]
change charFun (stdGaussian E) (∑ i, t i • u i) = _
rw [charFun_stdGaussian, charFun_stdGaussian]
congr 2
exact_mod_cast congrArg Neg.neg hn
have h := congrArg (Measure.map (WithLp.ofLp : EuclideanSpace ℝ (Fin n) → (Fin n → ℝ))) he
rw [← map_pi_eq_stdGaussian] at h
simpa [Measure.map_map (WithLp.measurable_ofLp _ _) hf,
Measure.map_map (WithLp.measurable_ofLp _ _) (WithLp.measurable_toLp _ _),
Function.comp_def, f, WithLp.ofLp_toLp, Measure.map_id] using h
lemma gaussianReal_le_volume : gaussianReal 0 1 ≤ (volume : Measure ℝ) := by
rw [gaussianReal_of_var_ne_zero _ (by norm_num)]
conv_rhs => rw [← withDensity_one (μ := (volume : Measure ℝ))]
apply withDensity_mono
filter_upwards [] with x
change ENNReal.ofReal (gaussianPDFReal 0 1 x) ≤ 1
rw [← ENNReal.ofReal_one]
apply ENNReal.ofReal_le_ofReal
unfold gaussianPDFReal
have hs : 1 ≤ Real.sqrt (2 * Real.pi * (1 : ℝ≥0)) := by
norm_num only [NNReal.coe_one, mul_one]
apply (Real.le_sqrt (by norm_num) (by positivity)).mpr
nlinarith [Real.pi_gt_three]
have he : Real.exp (-(x - 0)^2 / (2 * (1 : ℝ≥0))) ≤ 1 := by
apply Real.exp_le_one_iff.mpr
exact div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (sq_nonneg _)) (by positivity)
exact (mul_le_of_le_one_left (by positivity) (inv_le_one_of_one_le₀ hs)).trans he
lemma measure_pi_mono {ι : Type*} [Fintype ι] {X : ι → Type*}
[∀ i, MeasurableSpace (X i)] {μ ν : ∀ i, Measure (X i)}
(h : ∀ i, μ i ≤ ν i) : Measure.pi μ ≤ Measure.pi ν := by
have ho : OuterMeasure.pi (fun i => (μ i).toOuterMeasure) ≤
OuterMeasure.pi (fun i => (ν i).toOuterMeasure) := by
apply OuterMeasure.le_pi.mpr
intro s _
exact (OuterMeasure.pi_pi_le _ s).trans (Finset.prod_le_prod fun i _ => h i (s i))
apply Measure.le_iff.mpr
intro s hs
rw [Measure.pi_def, Measure.pi_def, toMeasure_apply _ _ hs, toMeasure_apply _ _ hs]
exact ho s
lemma pi_gaussianReal_le_volume (n : ℕ) :
Measure.pi (fun _ : Fin n => gaussianReal 0 1) ≤ (volume : Measure (Fin n → ℝ)) :=
measure_pi_mono (fun _ => gaussianReal_le_volume)
lemma gaussian_pairings_le {n : ℕ} (v : Fin n → E) (hv : LinearIndependent ℝ v) :
(stdGaussian E).map (fun x => fun i => ⟪v i, x⟫) ≤
ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹) •
(volume : Measure (Fin n → ℝ)) := by
let u := gramSchmidtNormed ℝ v
let R : Matrix (Fin n) (Fin n) ℝ :=
Matrix.diagonal (fun i => ‖gramSchmidt ℝ v i‖) * gsUpper n v
have hu : Orthonormal ℝ u := gramSchmidtNormed_orthonormal hv
have hn (i : Fin n) : ‖gramSchmidt ℝ v i‖ ≠ 0 :=
norm_ne_zero_iff.mpr (gramSchmidt_ne_zero i hv)
have hexp (j : Fin n) : ∑ i, R i j • u i = v j := by
rw [← gsUpper_expansion n v j]
apply Finset.sum_congr rfl
intro i _
simp only [R, u, Matrix.diagonal_mul, gramSchmidtNormed, smul_smul]
congr 1
simp [hn i, mul_comm]
have hdet : R.transpose.det = ∏ i, ‖gramSchmidt ℝ v i‖ := by
dsimp only [R]
rw [Matrix.det_transpose, Matrix.det_mul, Matrix.det_diagonal, gsUpper_det, mul_one]
have hd : R.transpose.det ≠ 0 := by
rw [hdet]
exact Finset.prod_ne_zero_iff.mpr (fun i _ => hn i)
have hpos : 0 ≤ R.transpose.det := by rw [hdet]; positivity
have hf : Measurable (Matrix.toLin' R.transpose) :=
(Matrix.toLin' R.transpose).continuous_of_finiteDimensional.measurable
have heq : (fun x : E => fun j => ⟪v j, x⟫) =
(Matrix.toLin' R.transpose) ∘ (fun x => fun i => ⟪u i, x⟫) := by
funext x j
rw [← hexp j]
simp [Matrix.toLin'_apply, Matrix.mulVec, dotProduct, sum_inner,
inner_smul_left]
rw [heq, ← Measure.map_map hf (by fun_prop), orthonormal_gaussian_map hu]
calc
_ ≤ (volume : Measure (Fin n → ℝ)).map (Matrix.toLin' R.transpose) :=
Measure.map_mono (pi_gaussianReal_le_volume n) hf
_ = _ := by
rw [Real.map_matrix_volume_pi_eq_smul_volume_pi hd,
abs_of_nonneg (inv_nonneg.mpr hpos), hdet]
lemma measure_pi_smul {ι : Type*} [Fintype ι] {X : ι → Type*}
[∀ i, MeasurableSpace (X i)] (μ : ∀ i, Measure (X i)) [∀ i, SigmaFinite (μ i)]
(c : ℝ≥0∞) (hc : c ≠ ∞) :
Measure.pi (fun i => c • μ i) = c ^ Fintype.card ι • Measure.pi μ := by
lift c to ℝ≥0 using hc
simp_rw [Measure.coe_nnreal_smul]
apply Measure.pi_eq
intro s _
simp only [Measure.smul_apply, Measure.pi_pi, ENNReal.smul_def, smul_eq_mul, Finset.prod_mul_distrib,
Finset.prod_const, Finset.card_univ]
lemma gaussian_rows_pairings_le {n : ℕ} (v : Fin n → E) (hv : LinearIndependent ℝ v)
(m : ℕ) :
(Measure.pi (fun _ : Fin m => stdGaussian E)).map
(fun A => fun j i => ⟪v i, A j⟫) ≤
ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹ ^ m) •
(volume : Measure (Fin m → Fin n → ℝ)) := by
rw [Measure.pi_map_pi (fun _ => (by fun_prop : Measurable
(fun x : E => fun i => ⟪v i, x⟫)).aemeasurable)]
have h := measure_pi_mono (fun _ : Fin m => gaussian_pairings_le v hv)
rw [measure_pi_smul _ _ ENNReal.ofReal_ne_top] at h
rw [ENNReal.ofReal_pow (by positivity)]
simpa only [Fintype.card_fin, volume_pi] using h
end GaussianDomination
section ReplicaKernel
variable {X : Type*} [MeasurableSpace X] (μ : Measure X) [SigmaFinite μ]
lemma lintegral_fin_prod (n : ℕ) (f : Fin n → X → ℝ≥0∞) (hf : ∀ i, Measurable (f i)) :
∫⁻ x : Fin n → X, ∏ i, f i (x i) ∂Measure.pi (fun _ => μ) =
∏ i, ∫⁻ x, f i x ∂μ := by
induction n with
| zero => simp
| succ n ih =>
rw [lintegral_pi_snoc μ _ (by fun_prop)]
simp_rw [Fin.prod_univ_castSucc, Fin.snoc_castSucc, Fin.snoc_last]
simp_rw [lintegral_const_mul _ (hf (Fin.last n))]
rw [lintegral_mul_const _ (by fun_prop), ih _ (fun i => hf i.castSucc)]
lemma lintegral_pow_pi (f : X → ℝ≥0∞) (hf : Measurable f) (n : ℕ) :
(∫⁻ x, f x ∂μ)^n =
∫⁻ x : Fin n → X, ∏ i, f (x i) ∂Measure.pi (fun _ => μ) := by
rw [lintegral_fin_prod μ n _ (fun _ => hf)]
simp
lemma lintegral_product_differences (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ)
(hφ1 : ∫⁻ x, φ x = 1) (m n : ℕ) (y : Fin m → ℝ) :
∫⁻ z : Fin m → Fin n → ℝ,
∏ j, φ (y j) * ∏ i, φ (y j - z j i) = ∏ j, φ (y j) := by
rw [volume_pi, lintegral_fin_prod (volume : Measure (Fin n → ℝ)) m
(fun j z => φ (y j) * ∏ i, φ (y j - z i)) (by intro i; fun_prop)]
apply Finset.prod_congr rfl
intro j _
rw [lintegral_const_mul _ (by fun_prop), volume_pi,
lintegral_fin_prod (volume : Measure ℝ) n
(fun _ z => φ (y j - z)) (by intro i; fun_prop)]
simp_rw [lintegral_sub_left_eq_self φ (y j), hφ1]
simp
end ReplicaKernel
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
[FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
lemma gaussian_rows_kernel_bound {n : ℕ} (v : Fin n → E) (hv : LinearIndependent ℝ v)
(φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (hφ1 : ∫⁻ z, φ z = 1)
(m : ℕ) (y : Fin m → ℝ) :
∫⁻ A : Fin m → E, (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫)
∂Measure.pi (fun _ => stdGaussian E) ≤
ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹ ^ m) * ∏ j, φ (y j) := by
let H : (Fin m → Fin n → ℝ) → ℝ≥0∞ :=
fun z => ∏ j, φ (y j) * ∏ i, φ (y j - z j i)
have hH : Measurable H := by dsimp [H]; fun_prop
have heq (A : Fin m → E) :
(∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫) =
H (fun j i => ⟪v i, A j⟫) := by
dsimp [H]
rw [Finset.prod_mul_distrib, Finset.prod_comm]
simp_rw [heq]
rw [← lintegral_map hH (by fun_prop)]
calc
_ ≤ ∫⁻ z, H z ∂(ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹ ^ m) •
(volume : Measure (Fin m → Fin n → ℝ))) :=
lintegral_mono' (gaussian_rows_pairings_le v hv m) (fun _ => le_rfl)
_ = _ := by
rw [lintegral_smul_measure]
change _ * (∫⁻ z : Fin m → Fin n → ℝ, ∏ j, φ (y j) * ∏ i, φ (y j - z j i)) = _
rw [lintegral_product_differences φ hφ hφ1]
lemma gaussian_replica_kernel_bound {n : ℕ} (p : E) (v : Fin n → E)
(hv : LinearIndependent ℝ (fun i => v i - p))
(φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (hφ1 : ∫⁻ z, φ z = 1) (m : ℕ) :
∫⁻ A : Fin m → E, ∫⁻ y : Fin m → ℝ,
(∏ j, φ (y j - ⟪p, A j⟫)) * ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫)
∂volume ∂Measure.pi (fun _ => stdGaussian E) ≤
ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ (fun i => v i - p) i‖)⁻¹ ^ m) := by
have ht (A : Fin m → E) :
(∫⁻ y : Fin m → ℝ, (∏ j, φ (y j - ⟪p, A j⟫)) *
∏ i, ∏ j, φ (y j - ⟪v i, A j⟫)) =
∫⁻ y : Fin m → ℝ, (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i - p, A j⟫) := by
have he (y : Fin m → ℝ) (i : Fin n) (j : Fin m) :
y j - ⟪p, A j⟫ - ⟪v i - p, A j⟫ = y j - ⟪v i, A j⟫ := by
rw [inner_sub_left]
ring
simpa only [Pi.sub_apply, he] using
lintegral_sub_right_eq_self
(fun y : Fin m → ℝ => (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i - p, A j⟫))
(fun j => ⟪p, A j⟫)
simp_rw [ht]
rw [lintegral_lintegral_swap (by fun_prop)]
calc
_ ≤ ∫⁻ y : Fin m → ℝ,
ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ (fun i => v i - p) i‖)⁻¹ ^ m) *
∏ j, φ (y j) := lintegral_mono fun y =>
gaussian_rows_kernel_bound (fun i => v i - p) hv φ hφ hφ1 m y
_ = _ := by
rw [lintegral_const_mul _ (by fun_prop), volume_pi,
lintegral_fin_prod volume m (fun _ => φ) (fun _ => hφ)]
simp [hφ1]
end NoiselessRegression
end
end OAI