ML.Ridge

Ridge (L²-penalized) regression: the penalized least-squares objective and its normal equations (XᵀX + λI)β̂ = Xᵀy, the closed-form solution β̂ = (XᵀX + λI)⁻¹Xᵀy for λ > 0 (no full-rank assumption on X needed), the shrunk population target, and the root-n L² estimation rate of the sample ridge predictor toward that target (the learning-theory result the causal layer uses to discharge the DML nuisance-rate condition).

Population 3 core · 0 supporting This file defines the population ridge objective populationRidgeObjective, the population squared prediction risk plus the L² penalty λ‖β‖², and the normal-equation predicate IsPopulationRidge. ★ IsPopulationRidge★ populationRidge_minimizes

Ridge regression — population target

This file defines the population ridge objective populationRidgeObjective, the population squared prediction risk plus the L² penalty λ‖β‖², and the normal-equation predicate IsPopulationRidge. The main theorem, populationRidge_minimizes, proves that a coefficient vector satisfying E[(Y - ⟪β,φ⟫) φₖ] = λ βₖ for every feature coordinate minimizes the population ridge objective when λ ≥ 0 and the required integrability hypotheses hold. This is a penalized coefficient target in the chosen finite feature span, not a separate claim that the predictor equals the conditional regression function.

def populationRidgeObjective reviewed
Causalean.ML

The population ridge objective: population squared risk plus λ‖β‖².

Definition (Lean source)
noncomputable def populationRidgeObjective (P : Measure (X' × ℝ)) (φ : FeatureMap X' K) (lam : ℝ) (β : K → ℝ) : ℝ := populationRisk squaredLoss P (fun x => ∑ k, β k * φ.φ x k) + lam * ∑ k, β k ^ 2
Causalean.ML.populationRidgeObjective · Causalean/ML/Ridge/Population.lean:28 · uses FeatureMap
def IsPopulationRidge reviewed
Causalean.ML

The regularized population normal equations: E[(Y − ⟪βstar,φ⟫) φₖ] = λ · βstarₖ for every feature k.

Definition (Lean source)
def IsPopulationRidge (P : Measure (X' × ℝ)) (φ : FeatureMap X' K) (lam : ℝ) (βstar : K → ℝ) : Prop := ∀ k, ∫ z, (z.2 - ∑ j, βstar j * φ.φ z.1 j) * φ.φ z.1 k ∂P = lam * βstar k
Causalean.ML.IsPopulationRidge · Causalean/ML/Ridge/Population.lean:33 · uses FeatureMap
theorem populationRidge_minimizes reviewed
Causalean.ML

With a nonnegative ridge penalty λ, for a probability measure P on features and outcome and a finite feature map φ, if the coefficient vector βstar satisfies the regularized population normal equations E[(Y − ⟪βstar,φ⟫)φₖ] = λβstarₖ for every feature k, the population squared-loss risks of the βstar- and β-predictors are both finite, and each feature is integrable against that residual, then the population ridge objective at βstar is at most its value at any other coefficient vector β.

Formal statement
P :
Measure (X' × ℝ)
φ :
lam :
hlam :
0 ≤ lam
βstar :
K → ℝ
hreg :
IsPopulationRidge P φ lam βstar
β :
K → ℝ
hint_star :
HasFinitePopulationRisk squaredLoss P (fun x => ∑ k, βstar k * φ.φ x k)
hint_β :
HasFinitePopulationRisk squaredLoss P (fun x => ∑ k, β k * φ.φ x k)
hcross :
∀ k, Integrable (fun z => (z.2 - ∑ j, βstar j * φ.φ z.1 j) * φ.φ z.1 k) P
populationRidgeObjective P φ lam βstar ≤ populationRidgeObjective P φ lam β
Proof (Lean source)
theorem populationRidge_minimizes (P : Measure (X' × ℝ)) (φ : FeatureMap X' K) {lam : ℝ} (hlam : 0 ≤ lam) {βstar : K → ℝ} (hreg : IsPopulationRidge P φ lam βstar) (β : K → ℝ) (hint_star : HasFinitePopulationRisk squaredLoss P (fun x => ∑ k, βstar k * φ.φ x k)) (hint_β : HasFinitePopulationRisk squaredLoss P (fun x => ∑ k, β k * φ.φ x k)) (hcross : ∀ k, Integrable (fun z => (z.2 - ∑ j, βstar j * φ.φ z.1 j) * φ.φ z.1 k) P) : populationRidgeObjective P φ lam βstar ≤ populationRidgeObjective P φ lam β := by let m : X' → ℝ := fun x => ∑ k, βstar k * φ.φ x k let h : X' → ℝ := fun x => ∑ k, β k * φ.φ x k have hint_m' : Integrable (fun z : X' × ℝ => (z.2 - m z.1) ^ 2) P := by simpa [HasFinitePopulationRisk, squaredLoss, m] using hint_star have hint_h' : Integrable (fun z : X' × ℝ => (z.2 - h z.1) ^ 2) P := by simpa [HasFinitePopulationRisk, squaredLoss, h] using hint_β have hdiff : Integrable (fun z : X' × ℝ => (z.2 - h z.1) ^ 2 - (z.2 - m z.1) ^ 2) P := hint_h'.sub hint_m' have hmh_expand : ∀ z : X' × ℝ, m z.1 - h z.1 = ∑ k, (βstar k - β k) * φ.φ z.1 k := by intro z calc m z.1 - h z.1 = (∑ k, βstar k * φ.φ z.1 k) - ∑ k, β k * φ.φ z.1 k := rfl _ = ∑ k, (βstar k * φ.φ z.1 k - β k * φ.φ z.1 k) := by rw [Finset.sum_sub_distrib] _ = ∑ k, (βstar k - β k) * φ.φ z.1 k := by exact Finset.sum_congr rfl (fun k _ => by ring) have hcross_mh : Integrable (fun z : X' × ℝ => (z.2 - m z.1) * (m z.1 - h z.1)) P := by have hsum_int : Integrable (fun z : X' × ℝ => ∑ k, (βstar k - β k) * ((z.2 - m z.1) * φ.φ z.1 k)) P := by exact integrable_finset_sum (s := univ) (fun k _ => (hcross k).const_mul (βstar k - β k)) refine hsum_int.congr ?_ filter_upwards with z rw [hmh_expand z] rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro k _ ring have hcross_val : ∫ z, (z.2 - m z.1) * (m z.1 - h z.1) ∂P = -lam * ∑ k, (β k - βstar k) * βstar k := by calc ∫ z, (z.2 - m z.1) * (m z.1 - h z.1) ∂P = ∫ z, ∑ k, (βstar k - β k) * ((z.2 - m z.1) * φ.φ z.1 k) ∂P := by apply integral_congr_ae filter_upwards with z rw [hmh_expand z] rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro k _ ring _ = ∑ k, ∫ z, (βstar k - β k) * ((z.2 - m z.1) * φ.φ z.1 k) ∂P := by rw [integral_finset_sum] intro k _ exact (hcross k).const_mul (βstar k - β k) _ = ∑ k, (βstar k - β k) * ∫ z, (z.2 - m z.1) * φ.φ z.1 k ∂P := by refine Finset.sum_congr rfl ?_ intro k _ rw [integral_const_mul] _ = ∑ k, (βstar k - β k) * (lam * βstar k) := by refine Finset.sum_congr rfl ?_ intro k _ rw [hreg k] _ = -lam * ∑ k, (β k - βstar k) * βstar k := by rw [Finset.mul_sum] exact Finset.sum_congr rfl (fun k _ => by ring) have hsq_int : Integrable (fun z : X' × ℝ => (m z.1 - h z.1) ^ 2) P := by have htmp : Integrable (fun z : X' × ℝ => ((z.2 - h z.1) ^ 2 - (z.2 - m z.1) ^ 2) - 2 * ((z.2 - m z.1) * (m z.1 - h z.1))) P := hdiff.sub (hcross_mh.const_mul 2) convert htmp using 1 funext z ring have hrisk_diff : populationRisk squaredLoss P h - populationRisk squaredLoss P m = 2 * ∫ z, (z.2 - m z.1) * (m z.1 - h z.1) ∂P + ∫ z, (m z.1 - h z.1) ^ 2 ∂P := by change (∫ z, (z.2 - h z.1) ^ 2 ∂P) - (∫ z, (z.2 - m z.1) ^ 2 ∂P) = 2 * ∫ z, (z.2 - m z.1) * (m z.1 - h z.1) ∂P + ∫ z, (m z.1 - h z.1) ^ 2 ∂P rw [← integral_sub hint_h' hint_m'] calc ∫ z, ((z.2 - h z.1) ^ 2 - (z.2 - m z.1) ^ 2) ∂P = ∫ z, 2 * ((z.2 - m z.1) * (m z.1 - h z.1)) + (m z.1 - h z.1) ^ 2 ∂P := by apply integral_congr_ae filter_upwards with z ring _ = ∫ z, 2 * ((z.2 - m z.1) * (m z.1 - h z.1)) ∂P + ∫ z, (m z.1 - h z.1) ^ 2 ∂P := by rw [integral_add] · exact hcross_mh.const_mul 2 · exact hsq_int _ = 2 * ∫ z, (z.2 - m z.1) * (m z.1 - h z.1) ∂P + ∫ z, (m z.1 - h z.1) ^ 2 ∂P := by rw [integral_const_mul] have hpenalty_diff : (∑ k, β k ^ 2) - ∑ k, βstar k ^ 2 = (∑ k, (β k - βstar k) ^ 2) + 2 * ∑ k, (β k - βstar k) * βstar k := by calc (∑ k, β k ^ 2) - ∑ k, βstar k ^ 2 = ∑ k, (β k ^ 2 - βstar k ^ 2) := by rw [Finset.sum_sub_distrib] _ = ∑ k, ((β k - βstar k) ^ 2 + 2 * ((β k - βstar k) * βstar k)) := by exact Finset.sum_congr rfl (fun k _ => by ring) _ = (∑ k, (β k - βstar k) ^ 2) + ∑ k, 2 * ((β k - βstar k) * βstar k) := by rw [Finset.sum_add_distrib] _ = (∑ k, (β k - βstar k) ^ 2) + 2 * ∑ k, (β k - βstar k) * βstar k := by rw [Finset.mul_sum] have hobj_diff : populationRidgeObjective P φ lam β - populationRidgeObjective P φ lam βstar = ∫ z, (m z.1 - h z.1) ^ 2 ∂P + lam * ∑ k, (β k - βstar k) ^ 2 := by calc populationRidgeObjective P φ lam β - populationRidgeObjective P φ lam βstar = (populationRisk squaredLoss P h - populationRisk squaredLoss P m) + lam * ((∑ k, β k ^ 2) - ∑ k, βstar k ^ 2) := by simp [populationRidgeObjective, m, h] ring _ = (2 * ∫ z, (z.2 - m z.1) * (m z.1 - h z.1) ∂P + ∫ z, (m z.1 - h z.1) ^ 2 ∂P) + lam * ((∑ k, (β k - βstar k) ^ 2) + 2 * ∑ k, (β k - βstar k) * βstar k) := by rw [hrisk_diff, hpenalty_diff] _ = (2 * (-lam * ∑ k, (β k - βstar k) * βstar k) + ∫ z, (m z.1 - h z.1) ^ 2 ∂P) + lam * ((∑ k, (β k - βstar k) ^ 2) + 2 * ∑ k, (β k - βstar k) * βstar k) := by rw [hcross_val] _ = ∫ z, (m z.1 - h z.1) ^ 2 ∂P + lam * ∑ k, (β k - βstar k) ^ 2 := by ring have hdiff_nonneg : 0 ≤ populationRidgeObjective P φ lam β - populationRidgeObjective P φ lam βstar := by rw [hobj_diff] exact add_nonneg (integral_nonneg (fun z => sq_nonneg _)) (mul_nonneg hlam (sum_nonneg (fun k _ => sq_nonneg _))) linarith
Closed­Form 3 core · 1 supporting For λ > 0 the ridge Gram matrix XᵀX + λI is positive definite, hence invertible, so the ridge coefficient β̂ = (XᵀX + λI)⁻¹ Xᵀy is the unique solution of the ridge normal equations — no full-rank assumption on X needed. ★ ridgeGram_posDef★ ridgeCoef_normalEq

Ridge regression — closed form

For λ > 0 the ridge Gram matrix XᵀX + λI is positive definite, hence invertible, so the ridge coefficient β̂ = (XᵀX + λI)⁻¹ Xᵀy is the unique solution of the ridge normal equations — no full-rank assumption on X needed.

def ridgeCoef reviewed
Causalean.ML

The ridge closed-form coefficient (XᵀX + λI)⁻¹ Xᵀy.

Definition (Lean source)
noncomputable def ridgeCoef (X : Matrix Obs Param ℝ) (y : Obs → ℝ) (lam : ℝ) : Param → ℝ := ((Xᵀ * X) + lam • (1 : Matrix Param Param ℝ))⁻¹ *ᵥ (Xᵀ *ᵥ y)
Causalean.ML.ridgeCoef · Causalean/ML/Ridge/ClosedForm.lean:23
theorem ridgeGram_posDef reviewed
Causalean.ML

For a strictly positive ridge penalty λ, the ridge Gram matrix XᵀX + λI built from a finite design matrix X is positive definite.

Formal statement
X :
Matrix Obs Param ℝ
lam :
hlam :
0 < lam
((Xᵀ * X) + lam • (1 : Matrix Param Param ℝ)).PosDef
Proof (Lean source)
theorem ridgeGram_posDef (X : Matrix Obs Param ℝ) {lam : ℝ} (hlam : 0 < lam) : ((Xᵀ * X) + lam • (1 : Matrix Param Param ℝ)).PosDef := by have hpsd : (Xᵀ * X).PosSemidef := by simpa [Matrix.conjTranspose_eq_transpose_of_trivial] using (Matrix.posSemidef_conjTranspose_mul_self X) have hI : (lam • (1 : Matrix Param Param ℝ)).PosDef := by exact Matrix.PosDef.smul Matrix.PosDef.one hlam exact Matrix.PosDef.posSemidef_add hpsd hI
Causalean.ML.ridgeGram_posDef · Causalean/ML/Ridge/ClosedForm.lean:29
theorem ridgeCoef_normalEq reviewed
Causalean.ML

For a strictly positive ridge penalty λ, the closed-form ridge coefficient (XᵀX + λI)⁻¹Xᵀy, built from a finite design matrix X and outcome vector y, satisfies the ridge normal equations (XᵀX + λI)β̂ = Xᵀy.

Formal statement
X :
Matrix Obs Param ℝ
y :
Obs → ℝ
lam :
hlam :
0 < lam
((Xᵀ * X) + lam • (1 : Matrix Param Param ℝ)) *ᵥ ridgeCoef X y lam = Xᵀ *ᵥ y
Proof (Lean source)
theorem ridgeCoef_normalEq (X : Matrix Obs Param ℝ) (y : Obs → ℝ) {lam : ℝ} (hlam : 0 < lam) : ((Xᵀ * X) + lam • (1 : Matrix Param Param ℝ)) *ᵥ ridgeCoef X y lam = Xᵀ *ᵥ y := by let G : Matrix Param Param ℝ := (Xᵀ * X) + lam • (1 : Matrix Param Param ℝ) have hGpos : G.PosDef := by dsimp [G] exact ridgeGram_posDef X hlam have hGdet : IsUnit G.det := (Matrix.isUnit_iff_isUnit_det G).mp hGpos.isUnit dsimp [ridgeCoef, G] rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv _ hGdet, Matrix.one_mulVec]
Causalean.ML.ridgeCoef_normalEq · Causalean/ML/Ridge/ClosedForm.lean:41 · uses ridgeCoef
1 supporting declaration (lemmas, instances)
  • ridgeCoef_unique theorem — For λ > 0, every solution of the ridge normal equations is the closed-form ridge coefficient.
    X :
    Matrix Obs Param ℝ
    y :
    Obs → ℝ
    lam :
    hlam :
    0 < lam
    β :
    Param → ℝ
    hNE :
    ((Xᵀ * X) + lam • (1 : Matrix Param Param ℝ)) *ᵥ β = Xᵀ *ᵥ y
    β = ridgeCoef X y lam
    Proof (Lean source)
    theorem ridgeCoef_unique (X : Matrix Obs Param ℝ) (y : Obs → ℝ) {lam : ℝ} (hlam : 0 < lam) {β : Param → ℝ} (hNE : ((Xᵀ * X) + lam • (1 : Matrix Param Param ℝ)) *ᵥ β = Xᵀ *ᵥ y) : β = ridgeCoef X y lam := by let G : Matrix Param Param ℝ := (Xᵀ * X) + lam • (1 : Matrix Param Param ℝ) have hGpos : G.PosDef := by dsimp [G] exact ridgeGram_posDef X hlam have hGdet : IsUnit G.det := (Matrix.isUnit_iff_isUnit_det G).mp hGpos.isUnit have hclosed : G *ᵥ ridgeCoef X y lam = Xᵀ *ᵥ y := by dsimp [G] exact ridgeCoef_normalEq X y hlam have hsame : G *ᵥ β = G *ᵥ ridgeCoef X y lam := by dsimp [G] at hclosed ⊢ rw [hNE, hclosed] have hcancel := congrArg (fun v : Param → ℝ => G⁻¹ *ᵥ v) hsame simpa [Matrix.mulVec_mulVec, Matrix.nonsing_inv_mul _ hGdet, Matrix.one_mulVec] using hcancel
    Causalean.ML.ridgeCoef_unique · Causalean/ML/Ridge/ClosedForm.lean:55
Finite 2 core · 0 supporting This file defines the finite-sample ridge objective ridgeObjective, the ordinary least-squares error plus the L² penalty λ‖β‖². ★ ridge_is_regularized_squaredLoss_ERM_of_normalEq

Ridge regression — finite design-matrix layer

This file defines the finite-sample ridge objective ridgeObjective, the ordinary least-squares error plus the L² penalty λ‖β‖². Its main theorem, ridge_is_regularized_squaredLoss_ERM_of_normalEq, proves that any coefficient vector satisfying the ridge normal equations (XᵀX + λI) β̂ = Xᵀy with λ ≥ 0 minimizes this penalized objective.

def ridgeObjective reviewed
Causalean.ML

The ridge objective: least-squares error plus the L² penalty λ‖β‖².

Definition (Lean source)
noncomputable def ridgeObjective (X : Matrix Obs Param ℝ) (y : Obs → ℝ) (lam : ℝ) (β : Param → ℝ) : ℝ := olsObjective X y β + lam * (β ⬝ᵥ β)
Causalean.ML.ridgeObjective · Causalean/ML/Ridge/Finite.lean:23
theorem ridge_is_regularized_squaredLoss_ERM_of_normalEq reviewed
Causalean.ML

With a nonnegative ridge penalty λ, for any coefficient vector β̂ satisfying the ridge normal equations (XᵀX + λI)β̂ = Xᵀy built from a finite design matrix X and outcome vector y, that vector minimizes the ridge objective — the sum of squared residuals plus λ‖β‖² — over every coefficient vector β.

Formal statement
X :
Matrix Obs Param ℝ
y :
Obs → ℝ
lam :
hlam :
0 ≤ lam
βhat :
Param → ℝ
hNE :
((Xᵀ * X) + lam • (1 : Matrix Param Param ℝ)) *ᵥ βhat = Xᵀ *ᵥ y
∀ β : Param → ℝ, ridgeObjective X y lam βhat ≤ ridgeObjective X y lam β
Proof (Lean source)
theorem ridge_is_regularized_squaredLoss_ERM_of_normalEq (X : Matrix Obs Param ℝ) (y : Obs → ℝ) {lam : ℝ} (hlam : 0 ≤ lam) (βhat : Param → ℝ) (hNE : ((Xᵀ * X) + lam • (1 : Matrix Param Param ℝ)) *ᵥ βhat = Xᵀ *ᵥ y) : ∀ β : Param → ℝ, ridgeObjective X y lam βhat ≤ ridgeObjective X y lam β := by intro β let δ : Param → ℝ := β - βhat let r : Obs → ℝ := y - X *ᵥ βhat let z : Obs → ℝ := X *ᵥ δ have hβ : β = βhat + δ := by ext j simp [δ] have hcross : Xᵀ *ᵥ r = lam • βhat := by dsimp [r] ext j have hj := congrFun hNE j simp [Matrix.add_mulVec, Matrix.smul_mulVec, Matrix.one_mulVec, Matrix.mulVec_sub, Matrix.mulVec_mulVec] at hj ⊢ linarith have hcross_dot : r ⬝ᵥ z = lam * (βhat ⬝ᵥ δ) := by calc r ⬝ᵥ z = (Xᵀ *ᵥ r) ⬝ᵥ δ := by dsimp [z] rw [Matrix.dotProduct_mulVec, Matrix.mulVec_transpose] _ = (lam • βhat) ⬝ᵥ δ := by rw [hcross] _ = lam * (βhat ⬝ᵥ δ) := by exact smul_dotProduct lam βhat δ have hsq (r z : Obs → ℝ) : (∑ i, (r i - z i) ^ 2) - (∑ i, (r i) ^ 2) = (∑ i, (z i) ^ 2) - 2 * (r ⬝ᵥ z) := by calc (∑ i, (r i - z i) ^ 2) - (∑ i, (r i) ^ 2) = ∑ i, ((r i - z i) ^ 2 - (r i) ^ 2) := by rw [Finset.sum_sub_distrib] _ = ∑ i, ((z i) ^ 2 - 2 * (r i * z i)) := by apply Finset.sum_congr rfl intro i _ ring _ = (∑ i, (z i) ^ 2) - ∑ i, 2 * (r i * z i) := by rw [Finset.sum_sub_distrib] _ = (∑ i, (z i) ^ 2) - 2 * (r ⬝ᵥ z) := by simp [dotProduct, Finset.mul_sum] have hdot (a d : Param → ℝ) : (a + d) ⬝ᵥ (a + d) - a ⬝ᵥ a = 2 * (a ⬝ᵥ d) + d ⬝ᵥ d := by calc (a + d) ⬝ᵥ (a + d) - a ⬝ᵥ a = ∑ i, (((a i + d i) * (a i + d i)) - a i * a i) := by simp [dotProduct, Finset.sum_sub_distrib] _ = ∑ i, (2 * (a i * d i) + d i * d i) := by apply Finset.sum_congr rfl intro i _ ring _ = 2 * (a ⬝ᵥ d) + d ⬝ᵥ d := by simp [dotProduct, Finset.sum_add_distrib, Finset.mul_sum] have hols : olsObjective X y β - olsObjective X y βhat = (∑ i, z i ^ 2) - 2 * (r ⬝ᵥ z) := by rw [hβ] dsimp [olsObjective, r, z] rw [Matrix.mulVec_add] convert hsq (y - X *ᵥ βhat) (X *ᵥ δ) using 2 · congr 1 ext i simp ring · rfl have hpen : lam * (β ⬝ᵥ β) - lam * (βhat ⬝ᵥ βhat) = lam * (2 * (βhat ⬝ᵥ δ) + δ ⬝ᵥ δ) := by rw [hβ] nlinarith [hdot βhat δ] have hdiff : ridgeObjective X y lam β - ridgeObjective X y lam βhat = (∑ i, z i ^ 2) + lam * (δ ⬝ᵥ δ) := by dsimp [ridgeObjective] calc olsObjective X y β + lam * (β ⬝ᵥ β) - (olsObjective X y βhat + lam * (βhat ⬝ᵥ βhat)) = (olsObjective X y β - olsObjective X y βhat) + (lam * (β ⬝ᵥ β) - lam * (βhat ⬝ᵥ βhat)) := by ring _ = ((∑ i, z i ^ 2) - 2 * (r ⬝ᵥ z)) + lam * (2 * (βhat ⬝ᵥ δ) + δ ⬝ᵥ δ) := by rw [hols, hpen] _ = (∑ i, z i ^ 2) + lam * (δ ⬝ᵥ δ) := by rw [hcross_dot] ring have hdot_nonneg : 0 ≤ δ ⬝ᵥ δ := by simpa [dotProduct, pow_two] using sum_nonneg (s := univ) (fun i _ => mul_self_nonneg (δ i)) have hnonneg : 0 ≤ ridgeObjective X y lam β - ridgeObjective X y lam βhat := by rw [hdiff] exact add_nonneg (sum_nonneg fun _ _ => sq_nonneg _) (mul_nonneg hlam hdot_nonneg) linarith
Causalean.ML.ridge_is_regularized_squaredLoss_ERM_of_normalEq · Causalean/ML/Ridge/Finite.lean:28 · uses ridgeObjective
Rate 6 core · 8 supporting This file builds the sample ridge estimator from the first n points of an i.i.d. ★ ridge_achievesL2Rate

Ridge regression — estimation rate (root-n)

This file builds the sample ridge estimator from the first n points of an i.i.d. sample and proves a root-n L²-estimation rate toward the population ridge minimizer. It defines the empirical Gram empiricalGram, empirical cross moment empiricalCross, sample coefficient sampleRidgeCoef, sample predictor sampleRidgePredictor, and population feature Gram populationGram.

The main algebraic step is sampleRidgeCoef_sub_eq: the coefficient error factors through (Ĝₙ + λI)⁻¹ times the centered empirical score (Ĉₙ - Ĝₙ β⋆) - λ β⋆. The population ridge normal equation centers that score; centered_score_mean_isBigOp gives its O_p(n^{-1/2}) rate, while sampleRidgeCoef_isBigOp combines this with entrywise convergence of the regularized Gram inverse. The final theorem ridge_achievesL2Rate transfers the coefficient rate to an L²-rate for the sample ridge predictor.

def empiricalGram reviewed
Causalean.ML

Empirical feature Gram over the first n sample points: Ĝₙ = n⁻¹ Σ_{i<n} φ(xᵢ) φ(xᵢ)ᵀ.

Definition (Lean source)
noncomputable def empiricalGram (φ : FeatureMap γ K) (Z : ℕ → Ω → γ × ℝ) (n : ℕ) (ω : Ω) : Matrix K K ℝ := (n : ℝ)⁻¹ • ∑ i ∈ range n, vecMulVec (φ.φ (Z i ω).1) (φ.φ (Z i ω).1)
Causalean.ML.empiricalGram · Causalean/ML/Ridge/Rate.lean:42 · uses FeatureMap
def empiricalCross reviewed
Causalean.ML

Empirical feature–response cross moment: Ĉₙ = n⁻¹ Σ_{i<n} yᵢ φ(xᵢ).

Definition (Lean source)
noncomputable def empiricalCross (φ : FeatureMap γ K) (Z : ℕ → Ω → γ × ℝ) (n : ℕ) (ω : Ω) : K → ℝ := (n : ℝ)⁻¹ • ∑ i ∈ range n, (Z i ω).2 • φ.φ (Z i ω).1
Causalean.ML.empiricalCross · Causalean/ML/Ridge/Rate.lean:49 · uses FeatureMap
def sampleRidgeCoef reviewed
Causalean.ML

The sample ridge coefficient β̂ₙ = (Ĝₙ + λI)⁻¹ Ĉₙ.

Definition (Lean source)
noncomputable def sampleRidgeCoef (φ : FeatureMap γ K) (Z : ℕ → Ω → γ × ℝ) (lam : ℝ) (n : ℕ) (ω : Ω) : K → ℝ := (empiricalGram φ Z n ω + lam • (1 : Matrix K K ℝ))⁻¹ *ᵥ empiricalCross φ Z n ω
Causalean.ML.sampleRidgeCoef · Causalean/ML/Ridge/Rate.lean:54 · uses FeatureMap
def sampleRidgePredictor reviewed
Causalean.ML

The sample ridge predictor x ↦ ⟨β̂ₙ, φ(x)⟩.

Definition (Lean source)
noncomputable def sampleRidgePredictor (φ : FeatureMap γ K) (Z : ℕ → Ω → γ × ℝ) (lam : ℝ) (n : ℕ) (ω : Ω) : γ → ℝ := fun x => ∑ k, sampleRidgeCoef φ Z lam n ω k * φ.φ x k
Causalean.ML.sampleRidgePredictor · Causalean/ML/Ridge/Rate.lean:59 · uses FeatureMap
def populationGram reviewed
Causalean.ML

The population feature Gram, defined entrywise (avoids matrix-valued Bochner integration): Gₖₗ = ∫ φ(x)ₖ φ(x)ₗ dP.

Definition (Lean source)
noncomputable def populationGram (φ : FeatureMap γ K) (P : Measure (γ × ℝ)) : Matrix K K ℝ := of fun k l => ∫ z, φ.φ z.1 k * φ.φ z.1 l ∂P
Causalean.ML.populationGram · Causalean/ML/Ridge/Rate.lean:64 · uses FeatureMap
theorem ridge_achievesL2Rate reviewed
Causalean.ML

Ridge root-n estimation rate. For a strictly positive ridge penalty λ, a finite feature map φ, and an i.i.d. sample S from a distribution P on features and outcome, if the true coefficient vector βstar satisfies the regularized population ridge normal equations, each feature coordinate is measurable, the fourth moment of the squared feature norm is finite, and each per-coordinate score function is square-integrable, then the sample ridge predictor converges to the population ridge predictor at the root-n rate in the L²(P) sense.

Formal statement
φ :
P :
S :
IIDSample Ω (γ × ℝ) μ P
lam :
hlam :
0 < lam
βstar :
K → ℝ
hpop :
IsPopulationRidge P φ lam βstar
:
∀ k, Measurable (fun x => φ.φ x k)
h4 :
Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P
hscore :
∀ k, MemLp (fun z => (z.2 - ∑ j, βstar j * φ.φ z.1 j) * φ.φ z.1 k) 2 P
AchievesL2Rate (sampleRidgePredictor φ S.Z lam) (fun x => ∑ k, βstar k * φ.φ x k) P (fun n => (sqrt (n : ℝ))⁻¹) μ
Proof (Lean source)
theorem ridge_achievesL2Rate (φ : FeatureMap γ K) (P : Measure (γ × ℝ)) [IsProbabilityMeasure P] (S : IIDSample Ω (γ × ℝ) μ P) [IsProbabilityMeasure μ] {lam : ℝ} (hlam : 0 < lam) (βstar : K → ℝ) (hpop : IsPopulationRidge P φ lam βstar) (hφ : ∀ k, Measurable (fun x => φ.φ x k)) (h4 : Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P) (hscore : ∀ k, MemLp (fun z => (z.2 - ∑ j, βstar j * φ.φ z.1 j) * φ.φ z.1 k) 2 P) : AchievesL2Rate (sampleRidgePredictor φ S.Z lam) (fun x => ∑ k, βstar k * φ.φ x k) P (fun n => (sqrt (n : ℝ))⁻¹) μ := by classical rcases eLpNorm_predictor_sub_le φ P hφ h4 βstar with ⟨C, hC_nonneg, hC_bound⟩ have hGramPosDef : (populationGram φ P + lam • (1 : Matrix K K ℝ)).PosDef := Matrix.PosDef.posSemidef_add (populationGram_posSemidef φ P hφ h4) (Matrix.PosDef.smul Matrix.PosDef.one hlam) have hcoef := sampleRidgeCoef_isBigOp φ P S hlam βstar hpop hφ h4 hscore hGramPosDef unfold AchievesL2Rate constructor · intro n ω simpa [sampleRidgePredictor] using (linear_predictor_sub_memLp_of_l4 φ P hφ h4 (sampleRidgeCoef φ S.Z lam n ω) βstar).eLpNorm_ne_top intro ε hε rcases hcoef ε hε with ⟨M0, hM0⟩ let M : ℝ := max M0 0 have hM0_le_M : M0 ≤ M := le_max_left M0 0 have hM_nonneg : 0 ≤ M := le_max_right M0 0 refine ⟨C * M, ?_⟩ have hlim_M : limsup (fun n : ℕ => μ {ω | M * (sqrt (n : ℝ))⁻¹ < |‖sampleRidgeCoef φ S.Z lam n ω - βstar‖|}) atTopofReal ε := by refine le_trans (Filter.limsup_le_limsup (Filter.Eventually.of_forall ?_)) hM0 intro n apply measure_mono intro ω hω have hr_nonneg : 0 ≤ (sqrt (n : ℝ))⁻¹ := inv_nonneg.mpr (Real.sqrt_nonneg _) exact lt_of_le_of_lt (mul_le_mul_of_nonneg_right hM0_le_M hr_nonneg) hω refine le_trans (Filter.limsup_le_limsup (Filter.Eventually.of_forall ?_)) hlim_M intro n apply measure_mono intro ω hω by_cases hC_zero : C = 0 · have hpred_le_zero : (eLpNorm (fun x => sampleRidgePredictor φ S.Z lam n ω x - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)).toReal ≤ 0 := by simpa [sampleRidgePredictor, hC_zero] using hC_bound (sampleRidgeCoef φ S.Z lam n ω) have hpred_nonneg : 0 ≤ (eLpNorm (fun x => sampleRidgePredictor φ S.Z lam n ω x - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)).toReal := ENNReal.toReal_nonneg have hpred_abs : |(eLpNorm (fun x => sampleRidgePredictor φ S.Z lam n ω x - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)).toReal| = 0 := by rw [abs_of_nonneg hpred_nonneg] exact le_antisymm hpred_le_zero hpred_nonneg rw [hC_zero, zero_mul, zero_mul] at hω have hpred_abs' : |(fun n ω => (eLpNorm (fun x => sampleRidgePredictor φ S.Z lam n ω x - (fun x => ∑ k, βstar k * φ.φ x k) x) 2 (P.map fst)).toReal) n ω| = 0 := by simpa using hpred_abs exfalso have hωlt : 0 < |(fun n ω => (eLpNorm (fun x => sampleRidgePredictor φ S.Z lam n ω x - (fun x => ∑ k, βstar k * φ.φ x k) x) 2 (P.map fst)).toReal) n ω| := by simpa using hω rw [hpred_abs'] at hωlt exact (lt_irrefl (0 : ℝ)) hωlt · have hC_pos : 0 < C := lt_of_le_of_ne hC_nonneg (Ne.symm hC_zero) have hpred_bound : (eLpNorm (fun x => sampleRidgePredictor φ S.Z lam n ω x - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)).toReal ≤ C * ‖sampleRidgeCoef φ S.Z lam n ω - βstar‖ := by simpa [sampleRidgePredictor] using hC_bound (sampleRidgeCoef φ S.Z lam n ω) have hpred_nonneg : 0 ≤ (eLpNorm (fun x => sampleRidgePredictor φ S.Z lam n ω x - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)).toReal := ENNReal.toReal_nonneg have hnorm_nonneg : 0 ≤ ‖sampleRidgeCoef φ S.Z lam n ω - βstar‖ := norm_nonneg _ have hr_nonneg : 0 ≤ (sqrt (n : ℝ))⁻¹ := inv_nonneg.mpr (Real.sqrt_nonneg _) have hlt : C * (M * (sqrt (n : ℝ))⁻¹) < C * ‖sampleRidgeCoef φ S.Z lam n ω - βstar‖ := by calc C * (M * (sqrt (n : ℝ))⁻¹) = (C * M) * (sqrt (n : ℝ))⁻¹ := by ring _ < |(eLpNorm (fun x => sampleRidgePredictor φ S.Z lam n ω x - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)).toReal| := hω _ = (eLpNorm (fun x => sampleRidgePredictor φ S.Z lam n ω x - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)).toReal := by rw [abs_of_nonneg hpred_nonneg] _ ≤ C * ‖sampleRidgeCoef φ S.Z lam n ω - βstar‖ := hpred_bound have hlt' : M * (sqrt (n : ℝ))⁻¹ < ‖sampleRidgeCoef φ S.Z lam n ω - βstar‖ := by nlinarith [hC_pos, hlt] simpa [abs_of_nonneg hnorm_nonneg] using hlt'
8 supporting declarations (lemmas, instances)
  • populationGram_posSemidef theorem — The population feature Gram is positive semidefinite whenever the feature coordinates are measurable and the fourth moment of the feature norm is finite.
    φ :
    P :
    :
    ∀ k, Measurable (fun x => φ.φ x k)
    h4 :
    Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P
    Proof (Lean source)
    theorem populationGram_posSemidef (φ : FeatureMap γ K) (P : Measure (γ × ℝ)) [IsFiniteMeasure P] (hφ : ∀ k, Measurable (fun x => φ.φ x k)) (h4 : Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P) : (populationGram φ P).PosSemidef := by classical have hφ_prod : ∀ k, Measurable (fun z : γ × ℝ => φ.φ z.1 k) := fun k => (hφ k).comp measurable_fst have hsum_meas : Measurable (fun z : γ × ℝ => ∑ k, (φ.φ z.1 k) ^ 2) := measurable_sum _ (fun k _ => (hφ_prod k).pow_const 2) have hsumsq_int : Integrable (fun z : γ × ℝ => ∑ k, (φ.φ z.1 k) ^ 2) P := by refine Integrable.mono' (g := fun z => 1 + (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) ((integrable_const (1 : ℝ)).add h4) hsum_meas.aestronglyMeasurable ?_ refine Filter.Eventually.of_forall (fun z => ?_) have hnn : (0 : ℝ) ≤ ∑ k, (φ.φ z.1 k) ^ 2 := sum_nonneg (fun k _ => sq_nonneg _) rw [Real.norm_of_nonneg hnn] nlinarith [sq_nonneg ((∑ k, (φ.φ z.1 k) ^ 2) - 1)] have hprod_int : ∀ i j, Integrable (fun z : γ × ℝ => φ.φ z.1 i * φ.φ z.1 j) P := by intro i j refine Integrable.mono hsumsq_int ((hφ_prod i).mul (hφ_prod j)).aestronglyMeasurable ?_ refine Filter.Eventually.of_forall (fun z => ?_) let a : ℝ := φ.φ z.1 i let b : ℝ := φ.φ z.1 j let s : ℝ := ∑ k, (φ.φ z.1 k) ^ 2 have hs_nonneg : 0 ≤ s := by dsimp [s] exact sum_nonneg (fun k _ => sq_nonneg _) rw [Real.norm_eq_abs, Real.norm_of_nonneg hs_nonneg] have hi_le : a ^ 2 ≤ s := by dsimp [a, s] exact Finset.single_le_sum (f := fun k => (φ.φ z.1 k) ^ 2) (fun k _ => sq_nonneg _) (Finset.mem_univ i) have hj_le : b ^ 2 ≤ s := by dsimp [b, s] exact Finset.single_le_sum (f := fun k => (φ.φ z.1 k) ^ 2) (fun k _ => sq_nonneg _) (Finset.mem_univ j) have hab_half : |a| * |b| ≤ (a ^ 2 + b ^ 2) / 2 := by have h := two_mul_le_add_sq |a| |b| have hsqa : |a| ^ 2 = a ^ 2 := by rw [sq_abs] have hsqb : |b| ^ 2 = b ^ 2 := by rw [sq_abs] nlinarith have hab_sum : (a ^ 2 + b ^ 2) / 2 ≤ s := by nlinarith calc |φ.φ z.1 i * φ.φ z.1 j| = |a| * |b| := by dsimp [a, b] rw [abs_mul] _ ≤ (a ^ 2 + b ^ 2) / 2 := hab_half _ ≤ s := hab_sum refine Matrix.PosSemidef.of_dotProduct_mulVec_nonneg ?_ ?_ · apply Matrix.IsHermitian.ext intro i j simp [populationGram, mul_comm] · intro x have hterm_int : ∀ i j, Integrable (fun z : γ × ℝ => (x i * x j) * (φ.φ z.1 i * φ.φ z.1 j)) P := by intro i j simpa [mul_assoc] using (hprod_int i j).const_mul (x i * x j) have hquad : star x ⬝ᵥ (populationGram φ P *ᵥ x) = ∫ z, (∑ i, x i * φ.φ z.1 i) ^ 2 ∂P := by calc star x ⬝ᵥ (populationGram φ P *ᵥ x) = ∑ i, ∑ j, x i * ((∫ z, φ.φ z.1 i * φ.φ z.1 j ∂P) * x j) := by simp [dotProduct, mulVec, populationGram, Finset.mul_sum] _ = ∑ i, ∑ j, ∫ z, (x i * x j) * (φ.φ z.1 i * φ.φ z.1 j) ∂P := by refine Finset.sum_congr rfl ?_ intro i _ refine Finset.sum_congr rfl ?_ intro j _ calc x i * ((∫ z, φ.φ z.1 i * φ.φ z.1 j ∂P) * x j) = (x i * x j) * ∫ z, φ.φ z.1 i * φ.φ z.1 j ∂P := by ring _ = ∫ z, (x i * x j) * (φ.φ z.1 i * φ.φ z.1 j) ∂P := by rw [integral_const_mul] _ = ∫ z, ∑ i, ∑ j, (x i * x j) * (φ.φ z.1 i * φ.φ z.1 j) ∂P := by rw [integral_finset_sum univ] · refine Finset.sum_congr rfl ?_ intro i _ rw [integral_finset_sum univ] intro j _ exact hterm_int i j · intro i _ exact integrable_finset_sum univ (fun j _ => hterm_int i j) _ = ∫ z, (∑ i, x i * φ.φ z.1 i) ^ 2 ∂P := by congr 1 funext z rw [sq, Finset.sum_mul_sum] refine Finset.sum_congr rfl ?_ intro i _ refine Finset.sum_congr rfl ?_ intro j _ ring rw [hquad] exact integral_nonneg fun z => sq_nonneg _
    Causalean.ML.populationGram_posSemidef · Causalean/ML/Ridge/Rate.lean:71
  • empiricalGram_posSemidef theorem — The empirical Gram is positive semidefinite (average of rank-one φφᵀ).
    φ :
    Z :
    ℕ → Ω → γ × ℝ
    n :
    ω :
    Ω
    Proof (Lean source)
    theorem empiricalGram_posSemidef (φ : FeatureMap γ K) (Z : ℕ → Ω → γ × ℝ) (n : ℕ) (ω : Ω) : (empiricalGram φ Z n ω).PosSemidef := by unfold empiricalGram apply Matrix.PosSemidef.smul · refine Finset.sum_induction (fun i => vecMulVec (φ.φ (Z i ω).1) (φ.φ (Z i ω).1)) (fun A : Matrix K K ℝ => A.PosSemidef) (fun _ _ hA hB => hA.add hB) Matrix.PosSemidef.zero ?_ intro i _ simpa using (Matrix.posSemidef_vecMulVec_self_star (φ.φ (Z i ω).1) : (vecMulVec (φ.φ (Z i ω).1) (star (φ.φ (Z i ω).1))).PosSemidef) · exact inv_nonneg.mpr (Nat.cast_nonneg n)
    Causalean.ML.empiricalGram_posSemidef · Causalean/ML/Ridge/Rate.lean:178
  • sampleRidgeCoef_sub_eq theorem — The ridge coefficient error factors through the regularized empirical Gram inverse and the centered empirical score Ŝₙ − λ β⋆ = (Ĉₙ − Ĝₙ β⋆) − λ β⋆.
    φ :
    Z :
    ℕ → Ω → γ × ℝ
    lam :
    hlam :
    0 < lam
    βstar :
    K → ℝ
    n :
    ω :
    Ω
    sampleRidgeCoef φ Z lam n ω - βstar
    = (empiricalGram φ Z n ω + lam • (1 : Matrix K K ℝ))⁻¹ *ᵥ (empiricalCross φ Z n ω - empiricalGram φ Z n ω *ᵥ βstar - lam • βstar)
    Proof (Lean source)
    theorem sampleRidgeCoef_sub_eq (φ : FeatureMap γ K) (Z : ℕ → Ω → γ × ℝ) {lam : ℝ} (hlam : 0 < lam) (βstar : K → ℝ) (n : ℕ) (ω : Ω) : sampleRidgeCoef φ Z lam n ω - βstar = (empiricalGram φ Z n ω + lam • (1 : Matrix K K ℝ))⁻¹ *ᵥ (empiricalCross φ Z n ω - empiricalGram φ Z n ω *ᵥ βstar - lam • βstar) := by let G : Matrix K K ℝ := empiricalGram φ Z n ω + lam • (1 : Matrix K K ℝ) have hGpos : G.PosDef := by dsimp [G] exact Matrix.PosDef.posSemidef_add (empiricalGram_posSemidef φ Z n ω) (Matrix.PosDef.smul Matrix.PosDef.one hlam) have hGdet : IsUnit G.det := (Matrix.isUnit_iff_isUnit_det G).mp hGpos.isUnit have hG_mul : empiricalGram φ Z n ω *ᵥ βstar + lam • βstar = G *ᵥ βstar := by dsimp [G] rw [Matrix.add_mulVec, Matrix.smul_mulVec, Matrix.one_mulVec] calc sampleRidgeCoef φ Z lam n ω - βstar = G⁻¹ *ᵥ empiricalCross φ Z n ω - βstar := by rfl _ = G⁻¹ *ᵥ empiricalCross φ Z n ω - G⁻¹ *ᵥ (G *ᵥ βstar) := by rw [Matrix.mulVec_mulVec, Matrix.nonsing_inv_mul _ hGdet, Matrix.one_mulVec] _ = G⁻¹ *ᵥ (empiricalCross φ Z n ω - G *ᵥ βstar) := by rw [Matrix.mulVec_sub] _ = G⁻¹ *ᵥ (empiricalCross φ Z n ω - empiricalGram φ Z n ω *ᵥ βstar - lam • βstar) := by rw [← hG_mul] abel_nf
    Causalean.ML.sampleRidgeCoef_sub_eq · Causalean/ML/Ridge/Rate.lean:194
  • centered_score_mean_isBigOp theorem — The centered empirical score mean Ŝₙ − λβ⋆ = (Ĉₙ − Ĝₙβ⋆) − λβ⋆ = n⁻¹ Σ (φᵢ(yᵢ−⟨β⋆,φᵢ⟩) − λβ⋆) is O_p(n^{-1/2}). The population normal equations make the summands centered.
    φ :
    P :
    S :
    IIDSample Ω (γ × ℝ) μ P
    lam :
    βstar :
    K → ℝ
    hpop :
    IsPopulationRidge P φ lam βstar
    :
    ∀ k, Measurable (fun x => φ.φ x k)
    hscore :
    ∀ k, MemLp (fun z => (z.2 - ∑ j, βstar j * φ.φ z.1 j) * φ.φ z.1 k) 2 P
    IsBigOp (fun n ω => ‖empiricalCross φ S.Z n ω - empiricalGram φ S.Z n ω *ᵥ βstar - lam • βstar‖) (fun n => (sqrt (n : ℝ))⁻¹) μ
    Proof (Lean source)
    theorem centered_score_mean_isBigOp (φ : FeatureMap γ K) (P : Measure (γ × ℝ)) [IsProbabilityMeasure P] (S : IIDSample Ω (γ × ℝ) μ P) [IsProbabilityMeasure μ] {lam : ℝ} (βstar : K → ℝ) (hpop : IsPopulationRidge P φ lam βstar) (hφ : ∀ k, Measurable (fun x => φ.φ x k)) (hscore : ∀ k, MemLp (fun z => (z.2 - ∑ j, βstar j * φ.φ z.1 j) * φ.φ z.1 k) 2 P) : IsBigOp (fun n ω => ‖empiricalCross φ S.Z n ω - empiricalGram φ S.Z n ω *ᵥ βstar - lam • βstar‖) (fun n => (sqrt (n : ℝ))⁻¹) μ := by classical let g : K → γ × ℝ → ℝ := fun k z => (z.2 - ∑ j, βstar j * φ.φ z.1 j) * φ.φ z.1 k let D : ℕ → Ω → K → ℝ := fun n ω => empiricalCross φ S.Z n ω - empiricalGram φ S.Z n ω *ᵥ βstar - lam • βstar have hφ_prod : ∀ k, Measurable (fun z : γ × ℝ => φ.φ z.1 k) := fun k => (hφ k).comp measurable_fst have hg_meas : ∀ k, Measurable (g k) := by intro k dsimp [g] exact (measurable_snd.sub (measurable_sum _ fun j _ => measurable_const.mul (hφ_prod j))).mul (hφ_prod k) have hcoord : ∀ n ω k, D n ω k = S.sampleMean (g k) n ω - ∫ z, g k z ∂P := by intro n ω k dsimp [D, g, IIDSample.sampleMean, empiricalCross, empiricalGram] rw [hpop k] simp only [smul_eq_mul, mulVec, dotProduct, Matrix.smul_apply, Matrix.sum_apply, Matrix.vecMulVec_apply] simp [Finset.sum_apply] have hgram_sum : (∑ x, (((n : ℝ)⁻¹ * ∑ i ∈ range n, φ.φ (S.Z i ω).1 k * φ.φ (S.Z i ω).1 x) * βstar x)) = (n : ℝ)⁻¹ * ∑ i ∈ range n, (∑ x, βstar x * φ.φ (S.Z i ω).1 x) * φ.φ (S.Z i ω).1 k := by calc (∑ x, (((n : ℝ)⁻¹ * ∑ i ∈ range n, φ.φ (S.Z i ω).1 k * φ.φ (S.Z i ω).1 x) * βstar x)) = ∑ x, (n : ℝ)⁻¹ * ((∑ i ∈ range n, φ.φ (S.Z i ω).1 k * φ.φ (S.Z i ω).1 x) * βstar x) := by refine Finset.sum_congr rfl ?_ intro x _ ring _ = (n : ℝ)⁻¹ * ∑ x, (∑ i ∈ range n, φ.φ (S.Z i ω).1 k * φ.φ (S.Z i ω).1 x) * βstar x := by rw [Finset.mul_sum] _ = (n : ℝ)⁻¹ * ∑ x, ∑ i ∈ range n, (φ.φ (S.Z i ω).1 k * φ.φ (S.Z i ω).1 x) * βstar x := by congr 1 refine Finset.sum_congr rfl ?_ intro x _ rw [Finset.sum_mul] _ = (n : ℝ)⁻¹ * ∑ i ∈ range n, ∑ x, (φ.φ (S.Z i ω).1 k * φ.φ (S.Z i ω).1 x) * βstar x := by congr 1 rw [Finset.sum_comm] _ = (n : ℝ)⁻¹ * ∑ i ∈ range n, (∑ x, βstar x * φ.φ (S.Z i ω).1 x) * φ.φ (S.Z i ω).1 k := by congr 1 refine Finset.sum_congr rfl ?_ intro i _ rw [Finset.sum_mul] refine Finset.sum_congr rfl ?_ intro x _ ring rw [hgram_sum] rw [← mul_sub, ← Finset.sum_sub_distrib] refine congrArg (fun t : ℝ => (n : ℝ)⁻¹ * t) ?_ refine Finset.sum_congr rfl ?_ intro i _ ring have hcoord_big : ∀ k, IsBigOp (fun n ω => D n ω k) (fun n => (sqrt (n : ℝ))⁻¹) μ := by intro k have hk0 := S.sampleMean_sub_isBigOp (hg_meas k) (by simpa [g] using hscore k) let A : ℝ := ∫ z, (g k z) ^ 2 ∂P have hA_nonneg : 0 ≤ A := by dsimp [A] exact integral_nonneg fun z => sq_nonneg _ have hrate_le : ∀ n : ℕ, sqrt (A / (n : ℝ)) ≤ (sqrt A + 1) * (sqrt (n : ℝ))⁻¹ := by intro n calc sqrt (A / (n : ℝ)) = sqrt A * (sqrt (n : ℝ))⁻¹ := by rw [Real.sqrt_div hA_nonneg, div_eq_mul_inv] _ ≤ (sqrt A + 1) * (sqrt (n : ℝ))⁻¹ := by exact mul_le_mul_of_nonneg_right (by linarith [Real.sqrt_nonneg A]) (inv_nonneg.mpr (Real.sqrt_nonneg (n : ℝ))) have hk1 : IsBigOp (fun n ω => S.sampleMean (g k) n ω - ∫ z, g k z ∂P) (fun n => (sqrt A + 1) * (sqrt (n : ℝ))⁻¹) μ := by exact mono_rate (fun n => Real.sqrt_nonneg (A / (n : ℝ))) hrate_le hk0 have hk2 : IsBigOp (fun n ω => S.sampleMean (g k) n ω - ∫ z, g k z ∂P) (fun n => (sqrt (n : ℝ))⁻¹) μ := by exact scale_rate (rn := fun n => (sqrt (n : ℝ))⁻¹) (by linarith [Real.sqrt_nonneg A]) hk1 have hfun : (fun n ω => D n ω k) = (fun n ω => S.sampleMean (g k) n ω - ∫ z, g k z ∂P) := by funext n ω exact hcoord n ω k rw [hfun] exact hk2 have hcoord_abs : ∀ k, IsBigOp (fun n ω => |D n ω k|) (fun n => (sqrt (n : ℝ))⁻¹) μ := by intro k simpa [IsBigOp, abs_abs] using hcoord_big k have hsum_abs : IsBigOp (fun n ω => ∑ k, |D n ω k|) (fun n => (sqrt (n : ℝ))⁻¹) μ := by simpa using (IsBigOp.finset_sum (μ := μ) (s := (Finset.univ : Finset K)) (X := fun k n ω => |D n ω k|) (fun k _ => hcoord_abs k)) refine IsBigOp.of_abs_le (Xn := fun n ω => ‖empiricalCross φ S.Z n ω - empiricalGram φ S.Z n ω *ᵥ βstar - lam • βstar‖) (Yn := fun n ω => ∑ k, |D n ω k|) ?_ hsum_abs intro n ω have hD_eq : D n ω = empiricalCross φ S.Z n ω - empiricalGram φ S.Z n ω *ᵥ βstar - lam • βstar := rfl have hsum_nonneg : 0 ≤ ∑ k, |D n ω k| := sum_nonneg fun k _ => abs_nonneg _ rw [abs_of_nonneg (norm_nonneg _), abs_of_nonneg hsum_nonneg, ← hD_eq] refine (pi_norm_le_iff_of_nonneg hsum_nonneg).2 (fun k => ?_) rw [Real.norm_eq_abs] exact Finset.single_le_sum (f := fun j => |D n ω j|) (fun j _ => abs_nonneg _) (Finset.mem_univ k)
    Causalean.ML.centered_score_mean_isBigOp · Causalean/ML/Ridge/Rate.lean:226
  • continuousAt_matrixInv_entry theorem — Continuity of an inverse-matrix entry. At any matrix with nonzero determinant, the map M ↦ (M⁻¹)ₖₗ is continuous.
    G₀ :
    Matrix K K ℝ
    hdet :
    G₀.det ≠ 0
    k l :
    K
    ContinuousAt (fun M : Matrix K K ℝ => (M⁻¹) k l) G₀
    Proof (Lean source)
    theorem continuousAt_matrixInv_entry {G₀ : Matrix K K ℝ} (hdet : G₀.det ≠ 0) (k l : K) : ContinuousAt (fun M : Matrix K K ℝ => (M⁻¹) k l) G₀ := by have hdet_cont : ContinuousAt (fun M : Matrix K K ℝ => M.det) G₀ := (Continuous.matrix_det continuous_id).continuousAt have hadj : ContinuousAt (fun M : Matrix K K ℝ => M.adjugate k l) G₀ := (Continuous.matrix_elem (Continuous.matrix_adjugate continuous_id) k l).continuousAt have hfun : ContinuousAt (fun M : Matrix K K ℝ => (M.det)⁻¹ * M.adjugate k l) G₀ := (hdet_cont.inv₀ hdet).mul hadj convert hfun using 1 funext M rw [Matrix.inv_def] simp [smul_eq_mul]
    Causalean.ML.continuousAt_matrixInv_entry · Causalean/ML/Ridge/Rate.lean:367
  • sampleRidgeCoef_isBigOp theorem — The ridge coefficient error is O_p(n^{-1/2}): the regularized empirical-Gram inverse is O_p(1) (entrywise matrix LLN + inverse continuity at the PosDef limit) times the centered score mean O_p(n^{-1/2}).
    φ :
    P :
    S :
    IIDSample Ω (γ × ℝ) μ P
    lam :
    hlam :
    0 < lam
    βstar :
    K → ℝ
    hpop :
    IsPopulationRidge P φ lam βstar
    :
    ∀ k, Measurable (fun x => φ.φ x k)
    h4 :
    Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P
    hscore :
    ∀ k, MemLp (fun z => (z.2 - ∑ j, βstar j * φ.φ z.1 j) * φ.φ z.1 k) 2 P
    hGramPosDef :
    (populationGram φ P + lam • (1 : Matrix K K ℝ)).PosDef
    IsBigOp (fun n ω => ‖sampleRidgeCoef φ S.Z lam n ω - βstar‖) (fun n => (sqrt (n : ℝ))⁻¹) μ
    Proof (Lean source)
    theorem sampleRidgeCoef_isBigOp (φ : FeatureMap γ K) (P : Measure (γ × ℝ)) [IsProbabilityMeasure P] (S : IIDSample Ω (γ × ℝ) μ P) [IsProbabilityMeasure μ] {lam : ℝ} (hlam : 0 < lam) (βstar : K → ℝ) (hpop : IsPopulationRidge P φ lam βstar) (hφ : ∀ k, Measurable (fun x => φ.φ x k)) (h4 : Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P) (hscore : ∀ k, MemLp (fun z => (z.2 - ∑ j, βstar j * φ.φ z.1 j) * φ.φ z.1 k) 2 P) (hGramPosDef : (populationGram φ P + lam • (1 : Matrix K K ℝ)).PosDef) : IsBigOp (fun n ω => ‖sampleRidgeCoef φ S.Z lam n ω - βstar‖) (fun n => (sqrt (n : ℝ))⁻¹) μ := by classical let rn : ℕ → ℝ := fun n => (sqrt (n : ℝ))⁻¹ let D : ℕ → Ω → K → ℝ := fun n ω => empiricalCross φ S.Z n ω - empiricalGram φ S.Z n ω *ᵥ βstar - lam • βstar let Inv : ℕ → Ω → Matrix K K ℝ := fun n ω => (empiricalGram φ S.Z n ω + lam • (1 : Matrix K K ℝ))⁻¹ have hrn_nonneg : ∀ n, 0 ≤ rn n := fun n => inv_nonneg.mpr (Real.sqrt_nonneg (n : ℝ)) have hDnorm : IsBigOp (fun n ω => ‖D n ω‖) rn μ := by simpa [D, rn] using (centered_score_mean_isBigOp φ P S βstar hpop hφ hscore) have hDcoord : ∀ l, IsBigOp (fun n ω => D n ω l) rn μ := by intro l refine IsBigOp.of_abs_le (Yn := fun n ω => ‖D n ω‖) ?_ hDnorm intro n ω have hcoord := norm_le_pi_norm (D n ω) l simpa [Real.norm_eq_abs, abs_of_nonneg (norm_nonneg _)] using hcoord have hφ_prod : ∀ k, Measurable (fun z : γ × ℝ => φ.φ z.1 k) := fun k => (hφ k).comp measurable_fst have hsum_meas : Measurable (fun z : γ × ℝ => ∑ k, (φ.φ z.1 k) ^ 2) := measurable_sum _ (fun k _ => (hφ_prod k).pow_const 2) have hsumsq_int : Integrable (fun z : γ × ℝ => ∑ k, (φ.φ z.1 k) ^ 2) P := by refine Integrable.mono' (g := fun z => 1 + (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) ((integrable_const (1 : ℝ)).add h4) hsum_meas.aestronglyMeasurable ?_ refine Filter.Eventually.of_forall (fun z => ?_) have hnn : (0 : ℝ) ≤ ∑ k, (φ.φ z.1 k) ^ 2 := sum_nonneg (fun k _ => sq_nonneg _) rw [Real.norm_of_nonneg hnn] nlinarith [sq_nonneg ((∑ k, (φ.φ z.1 k) ^ 2) - 1)] have hprod_int : ∀ i j, Integrable (fun z : γ × ℝ => φ.φ z.1 i * φ.φ z.1 j) P := by intro i j refine Integrable.mono hsumsq_int ((hφ_prod i).mul (hφ_prod j)).aestronglyMeasurable ?_ refine Filter.Eventually.of_forall (fun z => ?_) let a : ℝ := φ.φ z.1 i let b : ℝ := φ.φ z.1 j let s : ℝ := ∑ k, (φ.φ z.1 k) ^ 2 have hs_nonneg : 0 ≤ s := by dsimp [s] exact sum_nonneg (fun k _ => sq_nonneg _) rw [Real.norm_eq_abs, Real.norm_of_nonneg hs_nonneg] have hi_le : a ^ 2 ≤ s := by dsimp [a, s] exact Finset.single_le_sum (f := fun k => (φ.φ z.1 k) ^ 2) (fun k _ => sq_nonneg _) (Finset.mem_univ i) have hj_le : b ^ 2 ≤ s := by dsimp [b, s] exact Finset.single_le_sum (f := fun k => (φ.φ z.1 k) ^ 2) (fun k _ => sq_nonneg _) (Finset.mem_univ j) have hab_half : |a| * |b| ≤ (a ^ 2 + b ^ 2) / 2 := by have h := two_mul_le_add_sq |a| |b| have hsqa : |a| ^ 2 = a ^ 2 := by rw [sq_abs] have hsqb : |b| ^ 2 = b ^ 2 := by rw [sq_abs] nlinarith have hab_sum : (a ^ 2 + b ^ 2) / 2 ≤ s := by nlinarith calc |φ.φ z.1 i * φ.φ z.1 j| = |a| * |b| := by dsimp [a, b] rw [abs_mul] _ ≤ (a ^ 2 + b ^ 2) / 2 := hab_half _ ≤ s := hab_sum have hGram_entry : ∀ i j, Tendsto_inProb (fun n ω => empiricalGram φ S.Z n ω i j) (fun _ => populationGram φ P i j) μ := by intro i j have hmean := S.sampleMean_tendsto_inProb ((hφ_prod i).mul (hφ_prod j)) (hprod_int i j) have hfun : (fun n ω => empiricalGram φ S.Z n ω i j) = S.sampleMean (fun z : γ × ℝ => φ.φ z.1 i * φ.φ z.1 j) := by funext n ω simp [empiricalGram, IIDSample.sampleMean, smul_eq_mul, Matrix.smul_apply, Matrix.sum_apply, Matrix.vecMulVec_apply, Finset.mul_sum] rw [hfun] -- `MemLp.mul` now concludes about the point-free product `f * g`; restate it -- in the (definitionally equal) lambda form the goal is phrased with. have hmean' : Tendsto_inProb (S.sampleMean fun z : γ × ℝ => φ.φ z.1 i * φ.φ z.1 j) (fun _ => ∫ z : γ × ℝ, φ.φ z.1 i * φ.φ z.1 j ∂P) μ := hmean simpa [populationGram] using hmean' have hInv_entry : ∀ k l, IsBigOp (fun n ω => Inv n ω k l) (fun _ => (1 : ℝ)) μ := by intro k l have hconv : Tendsto_inProb (fun n ω => Inv n ω k l) (fun _ => ((populationGram φ P + lam • (1 : Matrix K K ℝ))⁻¹) k l) μ := by simpa [Inv] using (Tendsto_inProb.matrix_comp_continuousAt (Mn := fun n ω => empiricalGram φ S.Z n ω) (M₀ := populationGram φ P) (g := fun M : Matrix K K ℝ => ((M + lam • (1 : Matrix K K ℝ))⁻¹) k l) (by have hshift : ContinuousAt (fun M : Matrix K K ℝ => M + lam • (1 : Matrix K K ℝ)) (populationGram φ P) := (continuous_id.add continuous_const).continuousAt have hbase : ContinuousAt (fun A : Matrix K K ℝ => (A⁻¹) k l) (populationGram φ P + lam • (1 : Matrix K K ℝ)) := continuousAt_matrixInv_entry (hdet := (Matrix.PosDef.det_pos hGramPosDef).ne') k l simpa [Function.comp_def] using (ContinuousAt.comp (f := fun M : Matrix K K ℝ => M + lam • (1 : Matrix K K ℝ)) (g := fun A : Matrix K K ℝ => (A⁻¹) k l) hbase hshift)) hGram_entry) exact Tendsto_inProb.isBigOp_one hconv have hcoef_coord : ∀ k, IsBigOp (fun n ω => (sampleRidgeCoef φ S.Z lam n ω - βstar) k) rn μ := by intro k have hsummand : ∀ l ∈ (Finset.univ : Finset K), IsBigOp (fun n ω => Inv n ω k l * D n ω l) rn μ := by intro l _ simpa [rn] using (IsBigOp.mul (μ := μ) (rn := fun _ => (1 : ℝ)) (sn := rn) (Xn := fun n ω => Inv n ω k l) (Yn := fun n ω => D n ω l) (fun _ => zero_le_one) hrn_nonneg (hInv_entry k l) (hDcoord l)) have hsum : IsBigOp (fun n ω => ∑ l ∈ (Finset.univ : Finset K), Inv n ω k l * D n ω l) rn μ := IsBigOp.finset_sum (μ := μ) (s := (Finset.univ : Finset K)) (X := fun l n ω => Inv n ω k l * D n ω l) hsummand refine IsBigOp.of_abs_le (Yn := fun n ω => ∑ l ∈ (Finset.univ : Finset K), Inv n ω k l * D n ω l) ?_ hsum intro n ω have hsub := sampleRidgeCoef_sub_eq φ S.Z hlam βstar n ω have hcoord : (sampleRidgeCoef φ S.Z lam n ω - βstar) k = ∑ l ∈ (Finset.univ : Finset K), Inv n ω k l * D n ω l := by rw [hsub] dsimp [Inv, D] simp [mulVec, dotProduct] rw [hcoord] have hcoord_abs : ∀ k, IsBigOp (fun n ω => |(sampleRidgeCoef φ S.Z lam n ω - βstar) k|) rn μ := by intro k simpa [IsBigOp, abs_abs] using hcoef_coord k have hsum_abs : IsBigOp (fun n ω => ∑ k, |(sampleRidgeCoef φ S.Z lam n ω - βstar) k|) rn μ := by simpa using (IsBigOp.finset_sum (μ := μ) (s := (Finset.univ : Finset K)) (X := fun k n ω => |(sampleRidgeCoef φ S.Z lam n ω - βstar) k|) (fun k _ => hcoord_abs k)) refine IsBigOp.of_abs_le (Xn := fun n ω => ‖sampleRidgeCoef φ S.Z lam n ω - βstar‖) (Yn := fun n ω => ∑ k, |(sampleRidgeCoef φ S.Z lam n ω - βstar) k|) ?_ hsum_abs intro n ω let v : K → ℝ := sampleRidgeCoef φ S.Z lam n ω - βstar have hsum_nonneg : 0 ≤ ∑ k, |v k| := sum_nonneg fun k _ => abs_nonneg _ rw [abs_of_nonneg (norm_nonneg _), abs_of_nonneg hsum_nonneg] change ‖v‖ ≤ ∑ k, |v k| refine (pi_norm_le_iff_of_nonneg hsum_nonneg).2 (fun k => ?_) rw [Real.norm_eq_abs] exact Finset.single_le_sum (f := fun j => |v j|) (fun j _ => abs_nonneg _) (Finset.mem_univ k)
    Causalean.ML.sampleRidgeCoef_isBigOp · Causalean/ML/Ridge/Rate.lean:383
  • linear_predictor_sub_memLp_of_l4 lemma — A finite linear combination of features has finite L² norm under the covariate marginal whenever the feature vector has a finite fourth moment under the joint law.
    φ :
    P :
    :
    ∀ k, Measurable (fun x => φ.φ x k)
    h4 :
    Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P
    β βstar :
    K → ℝ
    MemLp (fun x : γ => (∑ k, β k * φ.φ x k) - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)
    Proof (Lean source)
    lemma linear_predictor_sub_memLp_of_l4 (φ : FeatureMap γ K) (P : Measure (γ × ℝ)) [IsProbabilityMeasure P] (hφ : ∀ k, Measurable (fun x => φ.φ x k)) (h4 : Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P) (β βstar : K → ℝ) : MemLp (fun x : γ => (∑ k, β k * φ.φ x k) - ∑ k, βstar k * φ.φ x k) 2 (P.map fst) := by classical have hmeasP : ∀ k, Measurable (fun z : γ × ℝ => φ.φ z.1 k) := fun k => (hφ k).comp measurable_fst have hsum_meas : Measurable (fun z : γ × ℝ => ∑ k, (φ.φ z.1 k) ^ 2) := measurable_sum _ (fun k _ => (hmeasP k).pow_const 2) have hsumsq_int : Integrable (fun z : γ × ℝ => ∑ k, (φ.φ z.1 k) ^ 2) P := by refine Integrable.mono' (g := fun z => 1 + (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) ((integrable_const (1 : ℝ)).add h4) hsum_meas.aestronglyMeasurable ?_ refine Filter.Eventually.of_forall (fun z => ?_) have hnn : (0 : ℝ) ≤ ∑ k, (φ.φ z.1 k) ^ 2 := sum_nonneg (fun k _ => sq_nonneg _) rw [Real.norm_of_nonneg hnn] nlinarith [sq_nonneg ((∑ k, (φ.φ z.1 k) ^ 2) - 1)] have hphisq_int : ∀ k, Integrable (fun z : γ × ℝ => (φ.φ z.1 k) ^ 2) P := by intro k refine Integrable.mono hsumsq_int ((hmeasP k).pow_const 2).aestronglyMeasurable ?_ refine Filter.Eventually.of_forall (fun z => ?_) rw [Real.norm_of_nonneg (sq_nonneg _), Real.norm_of_nonneg (sum_nonneg (fun k _ => sq_nonneg _))] exact Finset.single_le_sum (f := fun k => (φ.φ z.1 k) ^ 2) (fun i _ => sq_nonneg _) (Finset.mem_univ k) have hmemLp : ∀ k, MemLp (fun z : γ × ℝ => φ.φ z.1 k) 2 P := fun k => (memLp_two_iff_integrable_sq (hmeasP k).aestronglyMeasurable).mpr (hphisq_int k) set δ : K → ℝ := β - βstar with hδ have hlin_mem : MemLp (fun z : γ × ℝ => ∑ k, δ k * φ.φ z.1 k) 2 P := by exact memLp_finset_sum (s := (Finset.univ : Finset K)) (fun k _ => (hmemLp k).const_mul (δ k)) have hF_meas : Measurable (fun x : γ => (∑ k, β k * φ.φ x k) - ∑ k, βstar k * φ.φ x k) := (measurable_sum _ (fun k _ => measurable_const.mul (hφ k))).sub (measurable_sum _ (fun k _ => measurable_const.mul (hφ k))) have hmap : (fun z : γ × ℝ => (∑ k, β k * φ.φ z.1 k) - ∑ k, βstar k * φ.φ z.1 k) = fun z : γ × ℝ => ∑ k, δ k * φ.φ z.1 k := by funext z rw [← Finset.sum_sub_distrib] exact Finset.sum_congr rfl (fun k _ => by rw [hδ]; simp [sub_mul]) rw [memLp_map_measure_iff hF_meas.aestronglyMeasurable measurable_fst.aemeasurable] simpa [Function.comp_def, hmap] using hlin_mem
    Causalean.ML.linear_predictor_sub_memLp_of_l4 · Causalean/ML/Ridge/Rate.lean:561
  • eLpNorm_predictor_sub_le theorem — Deterministic predictor Lipschitz bound. The prediction L²(P_X) error is bounded by a finite constant times the coefficient error: ‖∑ₖ δₖ φ·ₖ‖_{L²} ≤ C ‖δ‖.
    φ :
    P :
    :
    ∀ k, Measurable (fun x => φ.φ x k)
    h4 :
    Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P
    βstar :
    K → ℝ
    ∃ C : ℝ,
    0 ≤ C ∧
    ∀ (β : K → ℝ),
    (eLpNorm (fun x => (∑ k, β k * φ.φ x k) - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)).toReal
    ≤ C * ‖β - βstar‖
    Proof (Lean source)
    theorem eLpNorm_predictor_sub_le (φ : FeatureMap γ K) (P : Measure (γ × ℝ)) [IsProbabilityMeasure P] (hφ : ∀ k, Measurable (fun x => φ.φ x k)) (h4 : Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P) (βstar : K → ℝ) : ∃ C : ℝ, 0 ≤ C ∧ ∀ (β : K → ℝ), (eLpNorm (fun x => (∑ k, β k * φ.φ x k) - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)).toReal ≤ C * ‖β - βstar‖ := by classical -- Coordinate measurability on the product space. have hmeasP : ∀ k, Measurable (fun z : γ × ℝ => φ.φ z.1 k) := fun k => (hφ k).comp measurable_fst -- Features are square-integrable under `P` (from the L⁴ feature moment `h4`). have hsum_meas : Measurable (fun z : γ × ℝ => ∑ k, (φ.φ z.1 k) ^ 2) := measurable_sum _ (fun k _ => (hmeasP k).pow_const 2) have hsumsq_int : Integrable (fun z : γ × ℝ => ∑ k, (φ.φ z.1 k) ^ 2) P := by refine Integrable.mono' (g := fun z => 1 + (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) ((integrable_const (1 : ℝ)).add h4) hsum_meas.aestronglyMeasurable ?_ refine Filter.Eventually.of_forall (fun z => ?_) have hnn : (0 : ℝ) ≤ ∑ k, (φ.φ z.1 k) ^ 2 := sum_nonneg (fun k _ => sq_nonneg _) rw [Real.norm_of_nonneg hnn] nlinarith [sq_nonneg ((∑ k, (φ.φ z.1 k) ^ 2) - 1)] have hphisq_int : ∀ k, Integrable (fun z : γ × ℝ => (φ.φ z.1 k) ^ 2) P := by intro k refine Integrable.mono hsumsq_int ((hmeasP k).pow_const 2).aestronglyMeasurable ?_ refine Filter.Eventually.of_forall (fun z => ?_) rw [Real.norm_of_nonneg (sq_nonneg _), Real.norm_of_nonneg (sum_nonneg (fun k _ => sq_nonneg _))] exact Finset.single_le_sum (f := fun k => (φ.φ z.1 k) ^ 2) (fun i _ => sq_nonneg _) (Finset.mem_univ k) have hmemLp : ∀ k, MemLp (fun z : γ × ℝ => φ.φ z.1 k) 2 P := fun k => (memLp_two_iff_integrable_sq (hmeasP k).aestronglyMeasurable).mpr (hphisq_int k) have hCk_ne_top : ∀ k, eLpNorm (fun z : γ × ℝ => φ.φ z.1 k) 2 P ≠ ⊤ := fun k => (hmemLp k).2.ne refine ⟨∑ k, (eLpNorm (fun z : γ × ℝ => φ.φ z.1 k) 2 P).toReal, ?_, ?_⟩ · exact sum_nonneg (fun k _ => ENNReal.toReal_nonneg) intro β set δ : K → ℝ := β - βstar with hδ -- Push the L²(P_X) norm back to `P` via the coordinate projection. have hF_meas : Measurable (fun x : γ => (∑ k, β k * φ.φ x k) - ∑ k, βstar k * φ.φ x k) := (measurable_sum _ (fun k _ => measurable_const.mul (hφ k))).sub (measurable_sum _ (fun k _ => measurable_const.mul (hφ k))) have hmap : eLpNorm (fun x => (∑ k, β k * φ.φ x k) - ∑ k, βstar k * φ.φ x k) 2 (P.map fst) = eLpNorm (fun z : γ × ℝ => ∑ k, δ k * φ.φ z.1 k) 2 P := by rw [eLpNorm_map_measure hF_meas.aestronglyMeasurable measurable_fst.aemeasurable] congr 1 funext z simp only [Function.comp_apply] rw [← Finset.sum_sub_distrib] exact Finset.sum_congr rfl (fun k _ => by rw [hδ]; simp [sub_mul]) -- Triangle inequality + scalar pull-out, coordinatewise. have hsum_le : eLpNorm (fun z : γ × ℝ => ∑ k, δ k * φ.φ z.1 k) 2 P ≤ ∑ k, ‖δ k‖ₑ * eLpNorm (fun z : γ × ℝ => φ.φ z.1 k) 2 P := by have hbound : eLpNorm (fun z : γ × ℝ => ∑ k, δ k * φ.φ z.1 k) 2 P ≤ ∑ k, eLpNorm (fun z : γ × ℝ => δ k * φ.φ z.1 k) 2 P := by have hfun : (fun z : γ × ℝ => ∑ k, δ k * φ.φ z.1 k) = ∑ k, (fun z : γ × ℝ => δ k * φ.φ z.1 k) := by funext z; rw [Finset.sum_apply] rw [hfun] exact eLpNorm_sum_le (μ := P) (p := 2) (f := fun k => fun z : γ × ℝ => δ k * φ.φ z.1 k) (s := (Finset.univ : Finset K)) (fun k _ => ((hmeasP k).const_mul (δ k)).aestronglyMeasurable) (by norm_num) refine hbound.trans (le_of_eq ?_) refine Finset.sum_congr rfl (fun k _ => ?_) rw [show (fun z : γ × ℝ => δ k * φ.φ z.1 k) = δ k • (fun z : γ × ℝ => φ.φ z.1 k) from rfl, eLpNorm_const_smul] -- Replace each coordinate factor by the sup norm `‖δ‖`. have hcoord_le : ∀ k, ‖δ k‖ₑ * eLpNorm (fun z : γ × ℝ => φ.φ z.1 k) 2 P ≤ ‖δ‖ₑ * eLpNorm (fun z : γ × ℝ => φ.φ z.1 k) 2 P := by intro k have hk : ‖δ k‖ₑ ≤ ‖δ‖ₑ := by have : ‖δ k‖ ≤ ‖δ‖ := norm_le_pi_norm δ k simpa [enorm_eq_nnnorm] using ENNReal.coe_le_coe.mpr (by exact_mod_cast this) gcongr have hfinal_le : eLpNorm (fun x => (∑ k, β k * φ.φ x k) - ∑ k, βstar k * φ.φ x k) 2 (P.map fst) ≤ ‖δ‖ₑ * ∑ k, eLpNorm (fun z : γ × ℝ => φ.φ z.1 k) 2 P := by rw [hmap, Finset.mul_sum] exact hsum_le.trans (Finset.sum_le_sum (fun k _ => hcoord_le k)) have hrhs_ne_top : ‖δ‖ₑ * ∑ k, eLpNorm (fun z : γ × ℝ => φ.φ z.1 k) 2 P ≠ ⊤ := by apply ENNReal.mul_ne_top · exact enorm_ne_top · exact (ENNReal.sum_ne_top).mpr (fun k _ => hCk_ne_top k) calc (eLpNorm (fun x => (∑ k, β k * φ.φ x k) - ∑ k, βstar k * φ.φ x k) 2 (P.map fst)).toReal ≤ (‖δ‖ₑ * ∑ k, eLpNorm (fun z : γ × ℝ => φ.φ z.1 k) 2 P).toReal := ENNReal.toReal_mono hrhs_ne_top hfinal_le _ = ‖δ‖ * ∑ k, (eLpNorm (fun z : γ × ℝ => φ.φ z.1 k) 2 P).toReal := by rw [ENNReal.toReal_mul, ENNReal.toReal_sum (fun k _ => hCk_ne_top k)] congr 1 _ = (∑ k, (eLpNorm (fun z : γ × ℝ => φ.φ z.1 k) 2 P).toReal) * ‖β - βstar‖ := by rw [hδ]; ring
    Causalean.ML.eLpNorm_predictor_sub_le · Causalean/ML/Ridge/Rate.lean:613