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 trades expected squared loss against coefficient shrinkage. It evaluates a coefficient vector and finite feature map at penalty level under a joint covariate--response law.

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

The population ridge normal equations require each residual--feature moment to equal its penalty term. They evaluate a coefficient vector and finite feature map at penalty level under a joint covariate--response law.

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

Population ridge normal equations guarantee objective optimality, for the candidate and comparator coefficients under the joint law and finite feature map on the covariate and feature-coordinate spaces. The guarantee requires a nonnegative penalty, the regularized normal equations, finite risks for both predictors, and integrable residual--feature products.

Formal statement
X' :
Type u_1
shared
K :
Type u_2
shared
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 (Finset.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. ★ ridgeCoef_normalEq★ ridgeCoef_unique

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. Here λ is the penalty on the unnormalized sum-of-squares objective: for the average-loss convention with penalty λavg, pass λ = |Obs| · λavg.

def ridgeCoef reviewed
Causalean.ML

The closed-form ridge coefficient applies the inverse regularized Gram to the design--outcome cross-product. It uses a design matrix and outcome vector over finite observation and decidable coefficient indices with ridge penalty weight. The inverse is ordinary when the regularized matrix is invertible; the unnormalized convention makes an averaged-loss penalty equal to this weight divided by the observation count.

Definition (Lean source)
Obs :
Type u_1
shared
Param :
Type u_2
shared
X :
Matrix Obs Param ℝ
y :
Obs → ℝ
lam :
ℝ
ridgeCoef X y lam :
Param → ℝ
((Xᵀ * X) + lam • (1 : Matrix Param Param ℝ))⁻¹ *ᵥ (Xᵀ *ᵥ y)
Causalean.ML.ridgeCoef · Causalean/ML/Ridge/ClosedForm.lean:29
theorem ridgeCoef_normalEq reviewed
Causalean.ML

The closed-form ridge coefficient satisfies the ridge normal equations for the finite design and outcome vectors over the observation and coefficient indices when the ridge penalty is strictly positive.

Formal statement
Obs :
Type u_1
shared
Param :
Type u_2
shared
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:54 · uses ridgeCoef
theorem ridgeCoef_unique reviewed
Causalean.ML

The closed-form ridge coefficient uniquely solves the normal equations: any candidate coefficient vector for the finite design and response vectors over the observation and coefficient indices must equal it when the ridge penalty is strictly positive and the candidate satisfies the equations.

Formal statement
Obs :
Type u_1
shared
Param :
Type u_2
shared
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:69 · uses ridgeCoef
1 supporting declaration (lemmas, instances)
  • ridgeGram_posDef theorem — A positive ridge penalty makes the design Gram positive definite for the finite design matrix over the observation and coefficient indices, because the penalty is positive.
    Obs :
    Type u_1
    shared
    Param :
    Type u_2
    shared
    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:41
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 trades residual squares against coefficient shrinkage. It evaluates a coefficient vector at penalty weight using a design matrix and outcome vector over finite observation and coefficient indices.

Definition (Lean source)
Obs :
Type u_1
shared
Param :
Type u_2
shared
X :
Matrix Obs Param ℝ
y :
Obs → ℝ
lam :
ℝ
β :
Param → ℝ
ridgeObjective X y lam β :
ℝ
olsObjective X y β + lam * (β ⬝ᵥ β)
Causalean.ML.ridgeObjective · Causalean/ML/Ridge/Finite.lean:27
theorem ridge_is_regularized_squaredLoss_ERM_of_normalEq reviewed
Causalean.ML

A ridge normal-equation solution globally minimizes the objective. This holds for a candidate coefficient vector under the normal equations with a nonnegative penalty, using the design and outcome vectors over finite observation and coefficient indices.

Formal statement
Obs :
Type u_1
shared
Param :
Type u_2
shared
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 Finset.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 (Finset.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:35 · 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 fixed-penalty population ridge minimizer. This is a penalized pseudo-true linear predictor, not in general the conditional mean E[Y|X]; identifying the two requires additional assumptions or a vanishing-penalty argument. 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

The empirical feature Gram matrix is average feature outer product, the design second moment used by ridge regression. It is computed from sample-indexed observations at sample size and realized sample state, using a finite feature map on the sample and covariate spaces.

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

The empirical feature--response cross moment is average response times feature, the right side of the ridge normal equations. It uses from sample-indexed observations at sample size and realized sample state, using a finite feature map on the sample and covariate spaces.

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

The sample ridge coefficient vector is inverse regularized Gram times the feature--response moment. It uses sample-indexed observations, a finite decidable feature map, penalty level, and sample size and realized state on the sample and covariate spaces. No nonsingularity condition is imposed.

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

The sample ridge predictor maps each covariate to the sample-coefficient linear feature score. Those coefficients come from sample-indexed observations, a finite decidable feature map, penalty level, and sample size and realized state on the sample and covariate spaces.

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

The population feature Gram matrix records every expected feature-coordinate product, the population design second moment. It uses a finite feature map on a measurable covariate space under a joint covariate--response law, defined entrywise to avoid a matrix-valued integral.

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

Ridge root-n rate toward the penalized pseudo-true predictor. 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 pseudo-true coefficient vector βstar satisfies the regularized population ridge normal equations, each feature coordinate is measurable, the fourth moment of the 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; this fixed-λ target is not asserted to equal the conditional mean.

Formal statement
Ω :
Type u_1
shared
γ :
Type u_2
shared
K :
Type u_3
shared
μ :
shared
φ :
P :
S :
IIDSample Ω (γ × ℝ) μ P
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 : ℝ))⁻¹) μ
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 refine IsBigOp.of_abs_le (Yn := fun n ω => C * ‖sampleRidgeCoef φ S.Z lam n ω - βstar‖) ?_ (IsBigOp.const_mul C hcoef) intro n ω rw [abs_of_nonneg ENNReal.toReal_nonneg, abs_of_nonneg (mul_nonneg hC_nonneg (norm_nonneg _))] simpa [sampleRidgePredictor] using hC_bound (sampleRidgeCoef φ S.Z lam n ω)
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.
    γ :
    Type u_2
    shared
    K :
    Type u_3
    shared
    φ :
    P :
    hφ :
    ∀ 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) := Finset.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 := Finset.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 Finset.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:94
  • empiricalGram_posSemidef theorem — The empirical Gram is positive semidefinite (average of rank-one φφᵀ).
    Ω :
    Type u_1
    shared
    γ :
    Type u_2
    shared
    K :
    Type u_3
    shared
    φ :
    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:201
  • sampleRidgeCoef_sub_eq theorem — The ridge coefficient error factors through the regularized empirical Gram inverse and the centered empirical score Ŝₙ − λ β⋆ = (Ĉₙ − Ĝₙ β⋆) − λ β⋆.
    Ω :
    Type u_1
    shared
    γ :
    Type u_2
    shared
    K :
    Type u_3
    shared
    φ :
    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:217
  • 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.
    Ω :
    Type u_1
    shared
    γ :
    Type u_2
    shared
    K :
    Type u_3
    shared
    μ :
    shared
    φ :
    P :
    S :
    IIDSample Ω (γ × ℝ) μ P
    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 : ℝ))⁻¹) μ
    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 (Finset.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 let A : ℝ := ∫ z, (g k z) ^ 2 ∂P have hA_nonneg : 0 ≤ A := by dsimp [A] exact integral_nonneg fun z => sq_nonneg _ 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] by_cases hA_pos : 0 < A · have hk0 := S.sampleMean_sub_isBigOp (hg_meas k) (by simpa [g] using hscore k) (by simpa [A] using hA_pos) 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 hrate_le hk0 exact scale_rate (rn := fun n => (sqrt (n : ℝ))⁻¹) (by linarith [Real.sqrt_nonneg A]) hk1 · have hA_zero : A = 0 := le_antisymm (le_of_not_gt hA_pos) hA_nonneg intro δ hδ refine ⟨1, one_pos, ?_⟩ filter_upwards [Filter.eventually_gt_atTop (0 : ℕ)] with n hn have hsq := S.sampleMean_sub_sq_lintegral_le (hg_meas k) (by simpa [g] using hscore k) hn have hlintegral_zero : ∫⁻ ω, ofReal ((S.sampleMean (g k) n ω - ∫ z, g k z ∂P) ^ 2) ∂μ = 0 := by apply le_antisymm · simpa [A, hA_zero] using hsq · exact bot_le have hae_sq : (fun ω => ofReal ((S.sampleMean (g k) n ω - ∫ z, g k z ∂P) ^ 2)) =ᵐ[μ] 0 := (lintegral_eq_zero_iff' (by fun_prop)).mp hlintegral_zero have hae_zero : (fun ω => S.sampleMean (g k) n ω - ∫ z, g k z ∂P) =ᵐ[μ] 0 := by filter_upwards [hae_sq] with ω hω simp only [Pi.zero_apply] at hω have hsquare_zero : (S.sampleMean (g k) n ω - ∫ z, g k z ∂P) ^ 2 = 0 := le_antisymm (ENNReal.ofReal_eq_zero.mp hω) (sq_nonneg _) exact sq_eq_zero_iff.mp hsquare_zero have hrate_pos : 0 < (sqrt (n : ℝ))⁻¹ := inv_pos.mpr (Real.sqrt_pos.mpr (by exact_mod_cast hn)) have hevent_zero : μ {ω | (1 : ℝ) * (sqrt (n : ℝ))⁻¹ ≤ ‖S.sampleMean (g k) n ω - ∫ z, g k z ∂P‖} = 0 := by rw [measure_eq_zero_iff_ae_notMem] filter_upwards [hae_zero] with ω hω simp [hω, not_le.mpr hrate_pos] calc μ {ω | (1 : ℝ) * (sqrt (n : ℝ))⁻¹ ≤ ‖S.sampleMean (g k) n ω - ∫ z, g k z ∂P‖} = 0 := hevent_zero _ ≤ δ := bot_le have hcoord_abs : ∀ k, IsBigOp (fun n ω => |D n ω k|) (fun n => (sqrt (n : ℝ))⁻¹) μ := by intro k simpa only [IsBigOp, BoundedInProbability, Real.norm_eq_abs, abs_abs] using hcoord_big k have hroot_pos : ∀ᶠ n : ℕ in atTop, 0 < (sqrt (n : ℝ))⁻¹ := (Filter.eventually_gt_atTop (0 : ℕ)).mono fun n hn => inv_pos.mpr (Real.sqrt_pos.mpr (by exact_mod_cast hn)) 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|) hroot_pos (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| := Finset.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:249
  • continuousAt_matrixInv_entry theorem — Continuity of an inverse-matrix entry. At any matrix with nonzero determinant, the map M ↦ (M⁻¹)ₖₗ is continuous.
    K :
    Type u_3
    Matrix K K ℝ
    shared
    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:427
  • 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}).
    Ω :
    Type u_1
    shared
    γ :
    Type u_2
    shared
    K :
    Type u_3
    shared
    μ :
    shared
    φ :
    P :
    S :
    IIDSample Ω (γ × ℝ) μ P
    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 : ℝ))⁻¹) μ
    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 hrn_pos : ∀ᶠ n : ℕ in atTop, 0 < rn n := (Filter.eventually_gt_atTop (0 : ℕ)).mono fun n hn => inv_pos.mpr (Real.sqrt_pos.mpr (by exact_mod_cast hn)) 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) := Finset.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 := Finset.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 Finset.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, Modes.TendstoInProbability (fun _ : ℕ => μ) (fun n ω => empiricalGram φ S.Z n ω i j) atTop (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' : Modes.TendstoInProbability (fun _ : ℕ => μ) (S.sampleMean fun z : γ × ℝ => φ.φ z.1 i * φ.φ z.1 j) atTop (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 : Modes.TendstoInProbability (fun _ : ℕ => μ) (fun n ω => Inv n ω k l) atTop (fun _ _ => ((populationGram φ P + lam • (1 : Matrix K K ℝ))⁻¹) k l) := by simpa [Inv] using (Modes.TendstoInProbability.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 Modes.TendstoInProbability.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) (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) hrn_pos 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 only [IsBigOp, BoundedInProbability, Real.norm_eq_abs, 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|) hrn_pos (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| := Finset.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:443
  • 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.
    γ :
    Type u_2
    shared
    K :
    Type u_3
    shared
    φ :
    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)
    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) := Finset.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 := Finset.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 (Finset.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) := (Finset.measurable_sum _ (fun k _ => measurable_const.mul (hφ k))).sub (Finset.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:627
  • 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 ‖δ‖.
    γ :
    Type u_2
    shared
    K :
    Type u_3
    shared
    φ :
    P :
    hφ :
    ∀ k, Measurable (fun x => φ.φ x k)
    h4 :
    Integrable (fun z => (∑ k, (φ.φ z.1 k) ^ 2) ^ 2) P
    βstar :
    K → ℝ
    ∃ C : ℝ,
    0 ≤ C
    conclusion 1
    β :
    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) := Finset.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 := Finset.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 (Finset.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 Finset.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) := (Finset.measurable_sum _ (fun k _ => measurable_const.mul (hφ k))).sub (Finset.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:679