ML.Kernel

Roll-up: the abstract RKHS interface, kernel Gram matrices with regularized positive definiteness, the kernel-ridge representer theorem, the Rademacher complexity rate for the L²-ball linear class, and the genuine square

RKHS 1 core · 0 supporting Mathlib has no RKHS hierarchy, so IsRKHS uses a minimal abstract interface: a real inner-product space H of functions on X with an evaluation map and a representer map satisfying the reproducing property f x = ⟪f, kₓ⟫. ★ IsRKHS

Reproducing-kernel Hilbert spaces (abstract interface)

Mathlib has no RKHS hierarchy, so IsRKHS uses a minimal abstract interface: a real inner-product space H of functions on X with an evaluation map and a representer map satisfying the reproducing property f x = ⟪f, kₓ⟫. This is the interface consumed by the representer theorem and RKHS Rademacher bounds.

structure IsRKHS reviewed
Causalean.ML

The candidate reproducing-kernel Hilbert space structure on a real inner-product space H of functions on X, given an evaluation map and a representer map, satisfies the reproducing property: evaluating any function of H at a point equals its inner product with the representer of that point.

Definition (Lean source)
feval :
H → X → ℝ
representer :
X → H
The reproducing identity `f x = ⟪f, kₓ⟫`.
reproducing :
∀ (f : H) (x : X), feval f x = inner ℝ f (representer x)
Causalean.ML.IsRKHS · Causalean/ML/Kernel/RKHS.lean:18
Effective­Dimension 2 core · 7 supporting The effective dimension at regularization level λ > 0 of a positive operator with (summable, nonnegative) eigenvalue family μ : ι → ℝ is N(λ) = ∑ᵢ μᵢ / (μᵢ + λ) = tr(T (T + λ)⁻¹). ★ effectiveDimension★ effectiveDimension_le_trace_div

Effective dimension of a trace-class operator

The effective dimension at regularization level λ > 0 of a positive operator with (summable, nonnegative) eigenvalue family μ : ι → ℝ is

N(λ) = ∑ᵢ μᵢ / (μᵢ + λ) = tr(T (T + λ)⁻¹).

It is the quantity that governs the variance term of kernel ridge regression: the Caponnetto–De Vito optimal-rate analysis expresses the minimax L²(ρ) rate of kernel ridge through N(λ) and the eigenvalue-decay/source-condition exponents. This file provides the definition and its basic structural properties for the trace-class (summable-eigenvalue) regime — the infinite-dimensional RKHS setting.

* effectiveDimension_nonneg0 ≤ N(λ); * summable_effectiveDimension_term — the summand family is summable (so N(λ) is a genuine real number, not the fallback value of a non-summable tsum); * effectiveDimension_le_trace_divN(λ) ≤ (tr T)/λ (the crude dimension-free bound); * effectiveDimension_le_card — over finitely many eigenvalues, N(λ) ≤ #ι; * effectiveDimension_antitoneN is antitone in λ (more regularization ⇒ smaller effective dimension).

The downstream rate theorem (N(λ)/eigenvalue-decay ⇒ the n^{-2rb/(2rb+1)} kernel-ridge rate) additionally requires Hilbert-space operator-concentration machinery (an operator Bernstein inequality for (T+λ)^{-1/2}(T − T̂ₙ)(T+λ)^{-1/2}) that is a separate substrate; this file is the definitional foundation it would build on.

def effectiveDimension reviewed
Causalean.ML

The effective dimension N(λ) = ∑ᵢ μᵢ/(μᵢ+λ) of an operator with eigenvalue family μ at regularization level λ.

Definition (Lean source)
noncomputable def effectiveDimension (μ : ι → ℝ) (lam : ℝ) : ℝ := ∑' i, μ i / (μ i + lam)
Causalean.ML.effectiveDimension · Causalean/ML/Kernel/EffectiveDimension.lean:44
lemma effectiveDimension_le_trace_div reviewed
Causalean.ML

Dimension-free bound. For an eigenvalue family μ and regularization level lam, if every eigenvalue is nonnegative, the regularization level is strictly positive, and the eigenvalues are summable, i.e. the operator is trace-class, then the effective dimension N(lam) = ∑ᵢ μᵢ/(μᵢ+lam) is at most the trace ∑ᵢ μᵢ divided by lam. This is the bound that, with eigenvalue decay μᵢ ≍ i^{-b}, yields N(λ) = O(λ^{-1/b}).

Formal statement
μ :
ι → ℝ
lam :
:
∀ i, 0 ≤ μ i
hlam :
0 < lam
hsum :
effectiveDimension μ lam ≤ (∑' i, μ i) / lam
Proof (Lean source)
lemma effectiveDimension_le_trace_div {μ : ι → ℝ} {lam : ℝ} (hμ : ∀ i, 0 ≤ μ i) (hlam : 0 < lam) (hsum : Summable μ) : effectiveDimension μ lam ≤ (∑' i, μ i) / lam := by have hle : effectiveDimension μ lam ≤ ∑' i, μ i / lam := Summable.tsum_le_tsum (fun i => effectiveDimension_term_le_div hμ hlam i) (summable_effectiveDimension_term hμ hlam hsum) (hsum.div_const lam) rwa [tsum_div_const] at hle
Causalean.ML.effectiveDimension_le_trace_div · Causalean/ML/Kernel/EffectiveDimension.lean:78 · uses effectiveDimension
7 supporting declarations (lemmas, instances)
Gram 3 core · 0 supporting The file defines the Gram matrix gram k x, the positive-semidefinite-kernel predicate IsPSDkernel, and the regularized-Gram positive-definiteness theorem gram_add_lambda_posDef: if k is positive semidefinite and λ > 0, t ★ IsPSDkernel★ gram_add_lambda_posDef

Gram matrices of a kernel

The file defines the Gram matrix gram k x, the positive-semidefinite-kernel predicate IsPSDkernel, and the regularized-Gram positive-definiteness theorem gram_add_lambda_posDef: if k is positive semidefinite and λ > 0, then K + λI ≻ 0. This is the finite-sample invertibility fact used by kernel ridge regression.

def gram reviewed
Causalean.ML

The Gram matrix Kᵢⱼ = k(xᵢ, xⱼ) of a kernel k on a finite sample x.

Definition (Lean source)
def gram {X : Type*} {n : ℕ} (k : X → X → ℝ) (x : Fin n → X) : Matrix (Fin n) (Fin n) ℝ := fun i j => k (x i) (x j)
def IsPSDkernel reviewed
Causalean.ML

A kernel is positive semidefinite when every Gram matrix is PSD.

Definition (Lean source)
def IsPSDkernel {X : Type*} (k : X → X → ℝ) : Prop := ∀ (n : ℕ) (x : Fin n → X), (gram k x).PosSemidef
Causalean.ML.IsPSDkernel · Causalean/ML/Kernel/Gram.lean:27
theorem gram_add_lambda_posDef reviewed
Causalean.ML

For a finite sample x and kernel k, if k is positive semidefinite, i.e. every Gram matrix it produces is PSD and the regularization level lam is strictly positive, then the regularized Gram matrix gram k x + lam·I is positive definite, hence invertible.

Formal statement
X :
Type*
n :
k :
X → X → ℝ
hk :
x :
Fin n → X
lam :
hlam :
0 < lam
(gram k x + lam • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef
Proof (Lean source)
theorem gram_add_lambda_posDef {X : Type*} {n : ℕ} {k : X → X → ℝ} (hk : IsPSDkernel k) (x : Fin n → X) {lam : ℝ} (hlam : 0 < lam) : (gram k x + lam • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef := by have hpsd : (gram k x).PosSemidef := hk n x have hI : (lam • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef := by exact Matrix.PosDef.smul Matrix.PosDef.one hlam exact Matrix.PosDef.posSemidef_add hpsd hI
Causalean.ML.gram_add_lambda_posDef · Causalean/ML/Kernel/Gram.lean:31 · uses IsPSDkernel , gram
Rate 2 core · 0 supporting The statistical rate for empirical risk minimization over an L²-norm-bounded class of linear predictors a ↦ ⟪w, a⟫ (the dual/feature-space view of kernel ridge: the representer theorem puts the estimator in an RKHS ball) ★ rademacherComplexity_l2_ball_le★ kernel_erm_excess_rate

Kernel / L²-ball linear predictors — Rademacher rate

The statistical rate for empirical risk minimization over an -norm-bounded class of linear predictors a ↦ ⟪w, a⟫ (the dual/feature-space view of kernel ridge: the representer theorem puts the estimator in an RKHS ball). The theorem rademacherComplexity_l2_ball_le bounds the expected Rademacher complexity of the W-ball class over Xb-bounded features by Xb·W/√n; kernel_erm_excess_rate combines that bound with the generic ERM oracle inequality (erm_oracle_inequality) to give the O(1/√n) excess-risk rate.

Built on FoML's linear_predictor_l2_bound' (empirical Rademacher bound for the L²-ball, lifted here to the expected rademacherComplexity).

theorem rademacherComplexity_l2_ball_le reviewed
Causalean.ML

Rademacher complexity of the L²-ball linear class. If the feature bound Xb is nonnegative, the weight bound W is nonnegative, and every feature vector has Euclidean norm at most Xb, then the expected Rademacher complexity of the class of linear predictors with weight norm at most W, on a sample of size n, is at most Xb·W/√n.

Formal statement
d n :
Ω :
Xb W :
hXb :
0 ≤ Xb
hW :
0 ≤ W
X :
Ω → EuclideanSpace ℝ (Fin d)
hXbound :
∀ ω, ‖X ω‖ ≤ Xb
rademacherComplexity n (fun w : closedBall (0 : EuclideanSpace ℝ (Fin d)) W => fun a : EuclideanSpace ℝ (Fin d) => inner ℝ (w : EuclideanSpace ℝ (Fin d)) a) μ X
≤ Xb * W / sqrt (n : ℝ)
Proof (Lean source)
theorem rademacherComplexity_l2_ball_le {d n : ℕ} {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] {Xb W : ℝ} (hXb : 0 ≤ Xb) (hW : 0 ≤ W) (X : Ω → EuclideanSpace ℝ (Fin d)) (hXbound : ∀ ω, ‖X ω‖ ≤ Xb) : rademacherComplexity n (fun w : closedBall (0 : EuclideanSpace ℝ (Fin d)) W => fun a : EuclideanSpace ℝ (Fin d) => inner ℝ (w : EuclideanSpace ℝ (Fin d)) a) μ X ≤ Xb * W / sqrt (n : ℝ) := by classical haveI : Nonempty (closedBall (0 : EuclideanSpace ℝ (Fin d)) W) := ⟨⟨0, by simpa [Metric.mem_closedBall, dist_self] using hW⟩⟩ have hpoint : ∀ ω : Fin n → Ω, empiricalRademacherComplexity n (fun w : closedBall (0 : EuclideanSpace ℝ (Fin d)) W => fun a : EuclideanSpace ℝ (Fin d) => inner ℝ (w : EuclideanSpace ℝ (Fin d)) a) (X ∘ ω) ≤ Xb * W / sqrt (n : ℝ) := by intro ω let Y' : Fin n → closedBall (0 : EuclideanSpace ℝ (Fin d)) Xb := fun k => ⟨X (ω k), mem_closedBall_zero_iff.mpr (hXbound (ω k))⟩ simpa [Y', Function.comp_def] using (linear_predictor_l2_bound' (d := d) (n := n) (W := W) (X := Xb) hXb hW Y' id) have hnonneg : ∀ ω : Fin n → Ω, 0 ≤ empiricalRademacherComplexity n (fun w : closedBall (0 : EuclideanSpace ℝ (Fin d)) W => fun a : EuclideanSpace ℝ (Fin d) => inner ℝ (w : EuclideanSpace ℝ (Fin d)) a) (X ∘ ω) := by intro ω unfold empiricalRademacherComplexity refine mul_nonneg ?_ ?_ · positivity · refine sum_nonneg ?_ intro σ _ refine Real.iSup_nonneg ?_ intro w exact abs_nonneg _ unfold rademacherComplexity calc ∫ ω : Fin n → Ω, empiricalRademacherComplexity n (fun w : closedBall (0 : EuclideanSpace ℝ (Fin d)) W => fun a : EuclideanSpace ℝ (Fin d) => inner ℝ (w : EuclideanSpace ℝ (Fin d)) a) (X ∘ ω) ∂(Measure.pi fun _ : Fin n => μ) ≤ ∫ _ω : Fin n → Ω, Xb * W / sqrt (n : ℝ) ∂(Measure.pi fun _ : Fin n => μ) := by apply MeasureTheory.integral_mono_of_nonneg · exact Filter.Eventually.of_forall hnonneg · exact integrable_const _ · exact Filter.Eventually.of_forall hpoint _ = Xb * W / sqrt (n : ℝ) := by simp
Causalean.ML.rademacherComplexity_l2_ball_le · Causalean/ML/Kernel/Rate.lean:26
theorem kernel_erm_excess_rate reviewed
Causalean.ML

Kernel ERM excess-risk rate over the L² ball. For features valued in the closed Xb-ball and linear predictors indexed by the closed W-ball, if the feature bound Xb is nonnegative, the weight bound W is nonnegative, the feature map X is measurable, the constant t satisfies the calibration t·(Xb·W)² ≤ 1/2, the tolerance ε is nonnegative, and the estimator ŵ attains empirical risk no larger than that of the comparator wstar, then the probability that the excess population risk of ŵ over wstar exceeds 4·Xb·W/√n + 2ε is at most exp(-ε²tn).

Formal statement
d n :
Ω :
Xb W :
hXb :
0 ≤ Xb
hW :
0 ≤ W
X :
Ω → closedBall (0 : EuclideanSpace ℝ (Fin d)) Xb
hX :
t :
ht' :
t * (Xb * W) ^ 2 ≤ 1 / 2
ε :
:
0 ≤ ε
ŵ :
(Fin n → Ω) → closedBall (0 : EuclideanSpace ℝ (Fin d)) W
wstar :
closedBall (0 : EuclideanSpace ℝ (Fin d)) W
hERM :
∀ ω : Fin n → Ω,
(n : ℝ)⁻¹ * ∑ k, inner ℝ ((ŵ ω) : EuclideanSpace ℝ (Fin d)) ((X (ω k)) : EuclideanSpace ℝ (Fin d))
≤ (n : ℝ)⁻¹ * ∑ k, inner ℝ (wstar : EuclideanSpace ℝ (Fin d)) ((X (ω k)) : EuclideanSpace ℝ (Fin d))
(Measure.pi (fun _ : Fin n => μ) (fun ω => 4 * (Xb * W / sqrt (n : ℝ)) + 2 * ε < μ[fun ω' => inner ℝ ((ŵ ω) : EuclideanSpace ℝ (Fin d)) ((X ω') : EuclideanSpace ℝ (Fin d))] - μ[fun ω' => inner ℝ (wstar : EuclideanSpace ℝ (Fin d)) ((X ω') : EuclideanSpace ℝ (Fin d))])).toReal
≤ (- ε ^ 2 * t * n).exp
Proof (Lean source)
theorem kernel_erm_excess_rate {d n : ℕ} {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] {Xb W : ℝ} (hXb : 0 ≤ Xb) (hW : 0 ≤ W) (X : Ω → closedBall (0 : EuclideanSpace ℝ (Fin d)) Xb) (hX : Measurable X) {t : ℝ} (ht' : t * (Xb * W) ^ 2 ≤ 1 / 2) {ε : ℝ} (hε : 0 ≤ ε) (ŵ : (Fin n → Ω) → closedBall (0 : EuclideanSpace ℝ (Fin d)) W) (wstar : closedBall (0 : EuclideanSpace ℝ (Fin d)) W) (hERM : ∀ ω : Fin n → Ω, (n : ℝ)⁻¹ * ∑ k, inner ℝ ((ŵ ω) : EuclideanSpace ℝ (Fin d)) ((X (ω k)) : EuclideanSpace ℝ (Fin d)) ≤ (n : ℝ)⁻¹ * ∑ k, inner ℝ (wstar : EuclideanSpace ℝ (Fin d)) ((X (ω k)) : EuclideanSpace ℝ (Fin d))) : (Measure.pi (fun _ : Fin n => μ) (fun ω => 4 * (Xb * W / sqrt (n : ℝ)) + 2 * ε < μ[fun ω' => inner ℝ ((ŵ ω) : EuclideanSpace ℝ (Fin d)) ((X ω') : EuclideanSpace ℝ (Fin d))] - μ[fun ω' => inner ℝ (wstar : EuclideanSpace ℝ (Fin d)) ((X ω') : EuclideanSpace ℝ (Fin d))])).toReal ≤ (- ε ^ 2 * t * n).exp := by classical let 𝒳 := closedBall (0 : EuclideanSpace ℝ (Fin d)) Xb let ι := closedBall (0 : EuclideanSpace ℝ (Fin d)) W let f : ι → 𝒳 → ℝ := fun w a => inner ℝ (w : EuclideanSpace ℝ (Fin d)) (a : EuclideanSpace ℝ (Fin d)) haveI : Nonempty 𝒳 := ⟨⟨0, by simpa [Metric.mem_closedBall, dist_self, 𝒳] using hXb⟩⟩ haveI : Nonempty ι := ⟨⟨0, by simpa [Metric.mem_closedBall, dist_self, ι] using hW⟩⟩ have hb : 0 ≤ Xb * W := mul_nonneg hXb hW have hf : ∀ w : ι, Measurable (f w) := by intro w dsimp [f] fun_prop have hf' : ∀ w : ι, ∀ a : 𝒳, |f w a| ≤ Xb * W := by intro w a have hw : ‖(w : EuclideanSpace ℝ (Fin d))‖ ≤ W := by simpa [ι] using (mem_closedBall_zero_iff.mp w.2) have ha : ‖(a : EuclideanSpace ℝ (Fin d))‖ ≤ Xb := by simpa [𝒳] using (mem_closedBall_zero_iff.mp a.2) calc |f w a| ≤ ‖(w : EuclideanSpace ℝ (Fin d))‖ * ‖(a : EuclideanSpace ℝ (Fin d))‖ := by dsimp [f] exact abs_real_inner_le_norm _ _ _ ≤ W * Xb := mul_le_mul hw ha (norm_nonneg _) hW _ = Xb * W := by ring have hf'' : ∀ a : 𝒳, Continuous fun w : ι => f w a := by intro a dsimp [f] fun_prop have hRC : rademacherComplexity n f μ X ≤ Xb * W / sqrt (n : ℝ) := by have hpoint : ∀ ω : Fin n → Ω, empiricalRademacherComplexity n f (X ∘ ω) ≤ Xb * W / sqrt (n : ℝ) := by intro ω let Y' : Fin n → closedBall (0 : EuclideanSpace ℝ (Fin d)) Xb := X ∘ ω have h := linear_predictor_l2_bound' (d := d) (n := n) (ι := ι) (W := W) (X := Xb) hXb hW Y' id exact h have hnonneg : ∀ ω : Fin n → Ω, 0 ≤ empiricalRademacherComplexity n f (X ∘ ω) := by intro ω unfold empiricalRademacherComplexity refine mul_nonneg ?_ ?_ · positivity · refine sum_nonneg ?_ intro σ _ refine Real.iSup_nonneg ?_ intro w exact abs_nonneg _ unfold rademacherComplexity calc ∫ ω : Fin n → Ω, empiricalRademacherComplexity n f (X ∘ ω) ∂(Measure.pi fun _ : Fin n => μ) ≤ ∫ _ω : Fin n → Ω, Xb * W / sqrt (n : ℝ) ∂(Measure.pi fun _ : Fin n => μ) := by apply MeasureTheory.integral_mono_of_nonneg · exact Filter.Eventually.of_forall hnonneg · exact integrable_const _ · exact Filter.Eventually.of_forall hpoint _ = Xb * W / sqrt (n : ℝ) := by simp have key := erm_oracle_inequality_separable (μ := μ) (n := n) (f := f) hf X hX (b := Xb * W) hb hf' hf'' ht' hε ŵ wstar hERM refine le_trans ?_ key refine ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono ?_) intro ω hω have hthreshold : 4 • rademacherComplexity n f μ X + 2 * ε ≤ 4 * (Xb * W / sqrt (n : ℝ)) + 2 * ε := by simp [nsmul_eq_mul] nlinarith [hRC] exact lt_of_le_of_lt hthreshold hω
Causalean.ML.kernel_erm_excess_rate · Causalean/ML/Kernel/Rate.lean:82
Ridge 2 core · 0 supporting Kernel ridge regression minimizes the regularized empirical risk over an RKHS. ★ representer_theorem

Kernel ridge regression — the representer theorem

Kernel ridge regression minimizes the regularized empirical risk over an RKHS. This file defines krrRisk and proves representer_theorem: under λ > 0, any global minimizer is a finite linear combination of the sample representers k(·, xᵢ). The theorem is the dimension-reduction step from an RKHS-valued optimization problem to a finite coefficient problem.

def krrRisk reviewed
Causalean.ML

The kernel-ridge regularized empirical risk of an RKHS element f: (1/n) ∑ᵢ (f(xᵢ) − yᵢ)² + λ‖f‖².

Definition (Lean source)
noncomputable def krrRisk {X H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H] (feval : H → X → ℝ) {n : ℕ} (x : Fin n → X) (y : Fin n → ℝ) (lam : ℝ) (f : H) : ℝ := (n : ℝ)⁻¹ * ∑ i, (feval f (x i) - y i) ^ 2 + lam * ‖f‖ ^ 2
Causalean.ML.krrRisk · Causalean/ML/Kernel/Ridge.lean:23
theorem representer_theorem reviewed
Causalean.ML

For a complete reproducing-kernel Hilbert space H, if (feval, representer) realizes H as an RKHS on X, i.e. evaluation at each point equals the inner product with its representer, the regularization level lam is strictly positive, and fhat minimizes the regularized empirical risk krrRisk over all of H for the sample (x, y), then fhat lies in the span of the sample representers representer x₁, …, representer xₙ, i.e. it is a finite linear combination of them.

Formal statement
X H :
Type*
H → X → ℝ
X → H
hrkhs :
IsRKHS X H feval representer
n :
x :
Fin n → X
y :
Fin n → ℝ
lam :
hlam :
0 < lam
fhat :
H
hmin :
∀ g : H, krrRisk feval x y lam fhat ≤ krrRisk feval x y lam g
∃ α : Fin n → ℝ, fhat = ∑ i, α i • representer (x i)
Proof (Lean source)
theorem representer_theorem {X H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H] {feval : H → X → ℝ} {representer : X → H} (hrkhs : IsRKHS X H feval representer) {n : ℕ} (x : Fin n → X) (y : Fin n → ℝ) {lam : ℝ} (hlam : 0 < lam) {fhat : H} (hmin : ∀ g : H, krrRisk feval x y lam fhat ≤ krrRisk feval x y lam g) : ∃ α : Fin n → ℝ, fhat = ∑ i, α i • representer (x i) := by classical let M : Submodule ℝ H := span ℝ (Set.range fun i : Fin n => representer (x i)) have : FiniteDimensional ℝ M := FiniteDimensional.span_of_finite ℝ (Set.finite_range _) have : CompleteSpace M := by infer_instance let p : H := M.starProjection fhat have hp_mem : p ∈ M := M.starProjection_apply_mem fhat have hrep_mem : ∀ i : Fin n, representer (x i) ∈ M := by intro i exact Submodule.subset_span ⟨i, rfl⟩ have heval_eq : ∀ i : Fin n, feval fhat (x i) = feval p (x i) := by intro i have horth : inner ℝ (fhat - p) (representer (x i)) = 0 := by exact Submodule.starProjection_inner_eq_zero (K := M) fhat (representer (x i)) (hrep_mem i) rw [hrkhs.reproducing fhat (x i), hrkhs.reproducing p (x i)] calc inner ℝ fhat (representer (x i)) = inner ℝ ((fhat - p) + p) (representer (x i)) := by rw [sub_add_cancel] _ = inner ℝ (fhat - p) (representer (x i)) + inner ℝ p (representer (x i)) := by rw [inner_add_left] _ = inner ℝ p (representer (x i)) := by rw [horth, zero_add] have hdata_eq : (∑ i, (feval fhat (x i) - y i) ^ 2) = ∑ i, (feval p (x i) - y i) ^ 2 := by refine Finset.sum_congr rfl ?_ intro i _ rw [heval_eq i] have hmin_p : krrRisk feval x y lam fhat ≤ krrRisk feval x y lam p := hmin p have hnorm_le : ‖fhat‖ ^ 2 ≤ ‖p‖ ^ 2 := by have hmul_le : lam * ‖fhat‖ ^ 2 ≤ lam * ‖p‖ ^ 2 := by unfold krrRisk at hmin_p rw [hdata_eq] at hmin_p linarith nlinarith have hnorm_decomp : ‖fhat‖ ^ 2 = ‖p‖ ^ 2 + ‖(Mᗮ).starProjection fhat‖ ^ 2 := Submodule.norm_sq_eq_add_norm_sq_starProjection fhat M have hperp_sq : ‖(Mᗮ).starProjection fhat‖ ^ 2 = 0 := by have hnonneg : 0 ≤ ‖(Mᗮ).starProjection fhat‖ ^ 2 := sq_nonneg _ nlinarith have hperp_zero : (Mᗮ).starProjection fhat = 0 := by apply norm_eq_zero.mp have hnonneg : 0 ≤ ‖(Mᗮ).starProjection fhat‖ := norm_nonneg _ nlinarith have hfhat_eq_p : fhat = p := by have hsplit := Submodule.starProjection_add_starProjection_orthogonal (K := M) fhat calc fhat = M.starProjection fhat + (Mᗮ).starProjection fhat := hsplit.symm _ = M.starProjection fhat + 0 := by rw [hperp_zero] _ = p := by rw [add_zero] have hfhat_mem : fhat ∈ M := by simpa [hfhat_eq_p] using hp_mem rcases (Submodule.mem_span_range_iff_exists_fun (R := ℝ) (v := fun i : Fin n => representer (x i)) (x := fhat)).mp hfhat_mem with ⟨α, hα⟩ exact ⟨α, hα.symm⟩
Causalean.ML.representer_theorem · Causalean/ML/Kernel/Ridge.lean:29 · uses IsRKHS , krrRisk
RKHSRademacher 1 core · 1 supporting This file proves the canonical RKHS-ball empirical Rademacher bound Rhat_n({‖f‖_H ≤ r}) ≤ κ * r / sqrt n, where κ² = sup_x K(x,x). ★ rkhs_ball_empiricalRademacher_le

RKHS-ball Rademacher complexity

This file proves the canonical RKHS-ball empirical Rademacher bound Rhat_n({‖f‖_H ≤ r}) ≤ κ * r / sqrt n, where κ² = sup_x K(x,x). The main Hilbert-space theorem is empiricalRademacherComplexity_innerBall_le; the RKHS specialization is rkhs_ball_empiricalRademacher_le, which uses the reproducing identity to turn function evaluation into an inner product. This is the standard worst-case O(1 / sqrt n) kernel learning rate associated with Bartlett--Mendelson style Rademacher complexity bounds.

theorem rkhs_ball_empiricalRademacher_le reviewed
Causalean.ML

In a reproducing-kernel Hilbert space H, if (feval, representer) realizes H as an RKHS on X, κ is a nonnegative bound, r is a nonnegative radius, and every sampled kernel representer representer (xs k) has norm at most κ, then the empirical Rademacher complexity, on the sample xs, of the closed ball of radius r in H is at most κ·r/√n.

Formal statement
X H :
Type*
H → X → ℝ
X → H
hK :
IsRKHS X H feval representer
n :
κ r :
:
0 ≤ κ
hr :
0 ≤ r
xs :
Fin n → X
hbound :
∀ k, ‖representer (xs k)‖ ≤ κ
empiricalRademacherComplexity n (fun (f : {f : H // ‖f‖ ≤ r}) (x : X) => feval (f : H) x) xs
≤ κ * r / sqrt n
Proof (Lean source)
theorem rkhs_ball_empiricalRademacher_le {X H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H] {feval : H → X → ℝ} {representer : X → H} (hK : IsRKHS X H feval representer) {n : ℕ} {κ r : ℝ} (hκ : 0 ≤ κ) (hr : 0 ≤ r) (xs : Fin n → X) (hbound : ∀ k, ‖representer (xs k)‖ ≤ κ) : empiricalRademacherComplexity n (fun (f : {f : H // ‖f‖ ≤ r}) (x : X) => feval (f : H) x) xs ≤ κ * r / sqrt n := by classical let ball := {f : H // ‖f‖ ≤ r} let Y : Fin n → H := fun k => representer (xs k) let w : ball → H := fun f => (f : H) have hw : ∀ f : ball, ‖w f‖ ≤ r := by intro f exact f.2 have hlinear : empiricalRademacherComplexity n (fun (f : ball) (a : H) => inner ℝ (w f) a) Y ≤ κ * r / sqrt n := by exact empiricalRademacherComplexity_innerBall_le κ r hκ hr Y hbound w hw -- Rewrite evaluation into the inner product with the representer; the two -- complexity terms then agree by beta reduction, so close by `exact`. have heval : (fun (f : ball) (x : X) => feval (f : H) x) = fun (f : ball) (x : X) => inner ℝ (w f) (representer x) := by funext f x exact hK.reproducing (f : H) x rw [heval] exact hlinear
Causalean.ML.rkhs_ball_empiricalRademacher_le · Causalean/ML/Kernel/RKHSRademacher.lean:465 · uses IsRKHS
1 supporting declaration (lemmas, instances)
  • empiricalRademacherComplexity_innerBall_le theorem — For a sample of vectors bounded by κ and linear weights bounded by r, the empirical Rademacher complexity of the resulting linear class is at most κ times r divided by the square root of the sample size.
    ι :
    Type*
    n :
    κ r :
    :
    0 ≤ κ
    hr :
    0 ≤ r
    Y :
    Fin n → E
    hY :
    ∀ k, ‖Y k‖ ≤ κ
    w :
    ι → E
    hw :
    ∀ i, ‖w i‖ ≤ r
    empiricalRademacherComplexity n (fun i a => inner ℝ (w i) a) Y ≤ κ * r / sqrt n
    Proof (Lean source)
    theorem empiricalRademacherComplexity_innerBall_le {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {ι : Type*} {n : ℕ} (κ r : ℝ) (hκ : 0 ≤ κ) (hr : 0 ≤ r) (Y : Fin n → E) (hY : ∀ k, ‖Y k‖ ≤ κ) (w : ι → E) (hw : ∀ i, ‖w i‖ ≤ r) : empiricalRademacherComplexity n (fun i a => inner ℝ (w i) a) Y ≤ κ * r / sqrt n := by classical by_cases hι : Nonempty ι · letI : Nonempty ι := hι exact empiricalRademacherComplexity_innerBall_le_nonempty κ r hκ hr Y hY w hw · haveI : IsEmpty ι := not_nonempty_iff.mp hι unfold empiricalRademacherComplexity simp only [Signs.card, Nat.cast_pow, Nat.cast_ofNat, Int.reduceNeg, abs_mul, abs_inv, Nat.abs_cast, iSup_of_isEmpty, Finset.sum_const_zero, mul_zero, ge_iff_le] exact div_nonneg (mul_nonneg hκ hr) (Real.sqrt_nonneg _)
    Causalean.ML.empiricalRademacherComplexity_innerBall_le · Causalean/ML/Kernel/RKHSRademacher.lean:442
Squared­Loss 3 core · 0 supporting The genuine squared-loss statistical rate for empirical risk minimization over an L²-norm-bounded class of linear predictors a ↦ ⟪w, a⟫ (the dual/feature-space view of kernel ridge). ★ kernel_erm_squaredLoss_excess_rate

Kernel / L²-ball linear predictors — squared-loss excess-risk rate

The genuine squared-loss statistical rate for empirical risk minimization over an -norm-bounded class of linear predictors a ↦ ⟪w, a⟫ (the dual/feature-space view of kernel ridge). Unlike the bare-linear-functional version, the loss here is the regression loss (⟪w, x⟩ − y)².

The Rademacher complexity of the squared-loss class is bounded by decomposing the centered loss (⟪w,x⟩ − y)² − y² = ⟪w,x⟩² − 2y⟪w,x⟩:

* the quadratic part ⟪w,x⟩² is handled by the (infinite-index) Ledoux–Talagrand contraction with the clamped square as the Lipschitz surrogate, reducing to the linear L²-ball bound; * the cross part 2y⟪w,x⟩ = ⟪w, 2y·x⟩ is itself a linear class over rescaled features, handled directly by the linear L²-ball bound.

Combined with the generic ERM oracle inequality (erm_oracle_inequality_separable) this gives the O(1/√n) squared-loss excess-risk rate kernel_erm_squaredLoss_excess_rate.

abbrev KFeat reviewed
Causalean.ML

Feature × response data space: Xb-ball features paired with [-Yb, Yb] responses.

Definition (Lean source)
abbrev KFeat (d : ℕ) (Xb Yb : ℝ) : Type := closedBall (0 : EuclideanSpace ℝ (Fin d)) Xb × closedBall (0 : ℝ) Yb
abbrev KWeight reviewed
Causalean.ML

The W-ball of weight vectors.

Definition (Lean source)
abbrev KWeight (d : ℕ) (W : ℝ) : Type := closedBall (0 : EuclideanSpace ℝ (Fin d)) W
theorem kernel_erm_squaredLoss_excess_rate reviewed
Causalean.ML

Kernel ERM squared-loss excess-risk rate over the L² ball. For data pairing features in the closed Xb-ball with responses in [-Yb, Yb], and linear predictors indexed by the closed W-ball, if Xb is nonnegative, Yb is nonnegative, W is nonnegative, the data map X is measurable, the constant t satisfies the calibration t·((Xb·W)² + 2·Yb·Xb·W)² ≤ 1/2, the tolerance ε is nonnegative, and the estimator ŵ attains empirical squared loss no larger than that of the comparator wstar, then for the squared loss (⟪w,x⟩ − y)², the probability that the excess population risk of ŵ over wstar exceeds 4·(4(XbW)² + 2·Yb·Xb·W)/√n + 2ε is at most exp(-ε²tn).

Formal statement
d n :
Ω :
Xb Yb W :
hXb :
0 ≤ Xb
hYb :
0 ≤ Yb
hW :
0 ≤ W
X :
Ω → KFeat d Xb Yb
hX :
t :
ht' :
t * ((Xb * W) ^ 2 + 2 * Yb * (Xb * W)) ^ 2 ≤ 1 / 2
ε :
:
0 ≤ ε
ŵ :
(Fin n → Ω) → KWeight d W
wstar :
hERM :
∀ ω : Fin n → Ω,
(n : ℝ)⁻¹ * ∑ k, (inner ℝ ((ŵ ω) : EuclideanSpace ℝ (Fin d)) ((X (ω k)).1 : EuclideanSpace ℝ (Fin d)) - ((X (ω k)).2 : ℝ)) ^ 2
≤ (n : ℝ)⁻¹ * ∑ k, (inner ℝ (wstar : EuclideanSpace ℝ (Fin d)) ((X (ω k)).1 : EuclideanSpace ℝ (Fin d)) - ((X (ω k)).2 : ℝ)) ^ 2
(Measure.pi (fun _ : Fin n => μ) (fun ω => 4 * ((4 * (Xb * W) ^ 2 + 2 * Yb * Xb * W) / sqrt (n : ℝ)) + 2 * ε < μ[fun ω' => (inner ℝ ((ŵ ω) : EuclideanSpace ℝ (Fin d)) ((X ω').1 : EuclideanSpace ℝ (Fin d)) - ((X ω').2 : ℝ)) ^ 2] - μ[fun ω' => (inner ℝ (wstar : EuclideanSpace ℝ (Fin d)) ((X ω').1 : EuclideanSpace ℝ (Fin d)) - ((X ω').2 : ℝ)) ^ 2])).toReal
≤ (- ε ^ 2 * t * n).exp
Proof (Lean source)
theorem kernel_erm_squaredLoss_excess_rate {d n : ℕ} {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] {Xb Yb W : ℝ} (hXb : 0 ≤ Xb) (hYb : 0 ≤ Yb) (hW : 0 ≤ W) (X : Ω → KFeat d Xb Yb) (hX : Measurable X) {t : ℝ} (ht' : t * ((Xb * W) ^ 2 + 2 * Yb * (Xb * W)) ^ 2 ≤ 1 / 2) {ε : ℝ} (hε : 0 ≤ ε) (ŵ : (Fin n → Ω) → KWeight d W) (wstar : KWeight d W) (hERM : ∀ ω : Fin n → Ω, (n : ℝ)⁻¹ * ∑ k, (inner ℝ ((ŵ ω) : EuclideanSpace ℝ (Fin d)) ((X (ω k)).1 : EuclideanSpace ℝ (Fin d)) - ((X (ω k)).2 : ℝ)) ^ 2 ≤ (n : ℝ)⁻¹ * ∑ k, (inner ℝ (wstar : EuclideanSpace ℝ (Fin d)) ((X (ω k)).1 : EuclideanSpace ℝ (Fin d)) - ((X (ω k)).2 : ℝ)) ^ 2) : (Measure.pi (fun _ : Fin n => μ) (fun ω => 4 * ((4 * (Xb * W) ^ 2 + 2 * Yb * Xb * W) / sqrt (n : ℝ)) + 2 * ε < μ[fun ω' => (inner ℝ ((ŵ ω) : EuclideanSpace ℝ (Fin d)) ((X ω').1 : EuclideanSpace ℝ (Fin d)) - ((X ω').2 : ℝ)) ^ 2] - μ[fun ω' => (inner ℝ (wstar : EuclideanSpace ℝ (Fin d)) ((X ω').1 : EuclideanSpace ℝ (Fin d)) - ((X ω').2 : ℝ)) ^ 2])).toReal ≤ (- ε ^ 2 * t * n).exp := by classical haveI : Nonempty (KFeat d Xb Yb) := ⟨(⟨0, by simpa using hXb⟩, ⟨0, by simpa using hYb⟩)⟩ haveI : Nonempty (KWeight d W) := ⟨⟨0, by simpa using hW⟩⟩ -- linear predictor and squared/centered losses set p : KWeight d W → KFeat d Xb Yb → ℝ := fun w a => inner ℝ (w : EuclideanSpace ℝ (Fin d)) (a.1 : EuclideanSpace ℝ (Fin d)) with hp set φ : ℝ → ℝ := clampedSq (Xb * W) with hφdef set f : KWeight d W → KFeat d Xb Yb → ℝ := fun w a => φ (p w a) - 2 * (a.2 : ℝ) * p w a with hf set sqLoss : KWeight d W → KFeat d Xb Yb → ℝ := fun w a => (p w a - (a.2 : ℝ)) ^ 2 with hsq have hXbW : 0 ≤ Xb * W := mul_nonneg hXb hW -- pointwise bounds on the predictor have hpbound : ∀ (w : KWeight d W) (a : KFeat d Xb Yb), |p w a| ≤ Xb * W := by intro w a have hw : ‖(w : EuclideanSpace ℝ (Fin d))‖ ≤ W := by simpa using (mem_closedBall_zero_iff.mp w.2) have ha : ‖(a.1 : EuclideanSpace ℝ (Fin d))‖ ≤ Xb := by simpa using (mem_closedBall_zero_iff.mp a.1.2) calc |p w a| ≤ ‖(w : EuclideanSpace ℝ (Fin d))‖ * ‖(a.1 : EuclideanSpace ℝ (Fin d))‖ := abs_real_inner_le_norm _ _ _ ≤ W * Xb := mul_le_mul hw ha (norm_nonneg _) hW _ = Xb * W := by ring have hybound : ∀ a : KFeat d Xb Yb, |(a.2 : ℝ)| ≤ Yb := by intro a simpa using (mem_closedBall_zero_iff.mp a.2.2) -- `f` is the centered squared loss: `sqLoss = f + y²` have hsqf : ∀ (w : KWeight d W) (a : KFeat d Xb Yb), sqLoss w a = f w a + ((a.2 : ℝ)) ^ 2 := by intro w a have hclamp : φ (p w a) = (p w a) ^ 2 := by rw [hφdef]; exact clampedSq_eq_sq (hpbound w a) simp only [hsq, hf, hclamp] ring -- uniform bound on `f` have hb0 : (0 : ℝ) ≤ (Xb * W) ^ 2 + 2 * Yb * (Xb * W) := by positivity have hfbound : ∀ (w : KWeight d W) (a : KFeat d Xb Yb), |f w a| ≤ (Xb * W) ^ 2 + 2 * Yb * (Xb * W) := by intro w a have h1 : |φ (p w a)| ≤ (Xb * W) ^ 2 := by rw [hφdef, abs_of_nonneg (clampedSq_nonneg _ _)] exact clampedSq_le_sq hXbW _ have h2 : |2 * (a.2 : ℝ) * p w a| ≤ 2 * Yb * (Xb * W) := by rw [abs_mul, abs_mul, show |(2 : ℝ)| = 2 from by norm_num] nlinarith [hybound a, hpbound w a, abs_nonneg ((a.2 : ℝ)), abs_nonneg (p w a), hYb, hXbW] calc |f w a| = |φ (p w a) - 2 * (a.2 : ℝ) * p w a| := by rw [hf] _ ≤ |φ (p w a)| + |2 * (a.2 : ℝ) * p w a| := abs_sub _ _ _ ≤ (Xb * W) ^ 2 + 2 * Yb * (Xb * W) := add_le_add h1 h2 -- continuity of the predictor and losses have hcont_x1 : Continuous (fun a : KFeat d Xb Yb => (a.1 : EuclideanSpace ℝ (Fin d))) := continuous_subtype_val.comp continuous_fst have hcont_x2 : Continuous (fun a : KFeat d Xb Yb => (a.2 : ℝ)) := continuous_subtype_val.comp continuous_snd have hpcont_a : ∀ w : KWeight d W, Continuous (fun a : KFeat d Xb Yb => p w a) := by intro w exact continuous_const.inner hcont_x1 have hpcont_w : ∀ a : KFeat d Xb Yb, Continuous (fun w : KWeight d W => p w a) := by intro a exact continuous_subtype_val.inner continuous_const have hfcont_a : ∀ w : KWeight d W, Continuous (fun a : KFeat d Xb Yb => f w a) := by intro w exact ((continuous_clampedSq _).comp (hpcont_a w)).sub ((continuous_const.mul hcont_x2).mul (hpcont_a w)) have hfcont_w : ∀ a : KFeat d Xb Yb, Continuous (fun w : KWeight d W => f w a) := by intro a exact ((continuous_clampedSq _).comp (hpcont_w a)).sub (continuous_const.mul (hpcont_w a)) have hfmeas : ∀ w : KWeight d W, Measurable (f w) := fun w => (hfcont_a w).measurable -- Rademacher-complexity bound for the centered squared-loss class set Cf : ℝ := 4 * (Xb * W) ^ 2 + 2 * Yb * Xb * W with hCf have hRC : rademacherComplexity n f μ X ≤ Cf / sqrt (n : ℝ) := by -- uniform empirical bound, over every sample have hemp : ∀ S : Fin n → KFeat d Xb Yb, empiricalRademacherComplexity n f S ≤ Cf / sqrt (n : ℝ) := by intro S -- (1) predictor complexity from the linear L²-ball bound have hpS : empiricalRademacherComplexity n p S ≤ Xb * W / sqrt (n : ℝ) := by have h := linear_predictor_l2_bound' (d := d) (n := n) (ι := KWeight d W) (W := W) (X := Xb) hXb hW (fun k => (S k).1) (fun w => w) rw [hp] exact h -- (2) quadratic part via contraction with the clamped square have hquadbd : ∀ (w : KWeight d W) (a : KFeat d Xb Yb), |φ (p w a)| ≤ (Xb * W) ^ 2 := by intro w a rw [hφdef, abs_of_nonneg (clampedSq_nonneg _ _)] exact clampedSq_le_sq hXbW _ have hcontr := empiricalRademacherComplexity_contraction_abs_of_bddAbove (ι := KWeight d W) φ (L := 2 * (Xb * W)) (by rw [hφdef]; exact lipschitzAt0_clampedSq hXbW) p (M := Xb * W) hXbW hpbound n S have hquad : empiricalRademacherComplexity n (fun (w : KWeight d W) (a : KFeat d Xb Yb) => φ (p w a)) S ≤ 4 * (Xb * W) ^ 2 / sqrt (n : ℝ) := by calc empiricalRademacherComplexity n (fun (w : KWeight d W) (a : KFeat d Xb Yb) => φ (p w a)) S ≤ 2 * (2 * (Xb * W)) * empiricalRademacherComplexity n p S := hcontr _ ≤ 2 * (2 * (Xb * W)) * (Xb * W / sqrt (n : ℝ)) := mul_le_mul_of_nonneg_left hpS (by positivity) _ = 4 * (Xb * W) ^ 2 / sqrt (n : ℝ) := by ring -- (3) cross part: a linear class over rescaled features `2y·x` set featCross : KFeat d Xb Yb → EuclideanSpace ℝ (Fin d) := fun a => (2 * (a.2 : ℝ)) • (a.1 : EuclideanSpace ℝ (Fin d)) with hfeat have hmem : ∀ a : KFeat d Xb Yb, featCross a ∈ closedBall (0 : EuclideanSpace ℝ (Fin d)) (2 * Yb * Xb) := by intro a rw [mem_closedBall_zero_iff, hfeat, norm_smul, Real.norm_eq_abs, abs_mul, show |(2 : ℝ)| = 2 from by norm_num] have hx : ‖(a.1 : EuclideanSpace ℝ (Fin d))‖ ≤ Xb := by simpa using mem_closedBall_zero_iff.mp a.1.2 nlinarith [hybound a, hx, abs_nonneg ((a.2 : ℝ)), norm_nonneg (a.1 : EuclideanSpace ℝ (Fin d)), hYb, hXb] have hcrossfun : (fun (w : KWeight d W) (a : KFeat d Xb Yb) => 2 * (a.2 : ℝ) * p w a) = (fun (w : KWeight d W) (a : KFeat d Xb Yb) => inner ℝ (w : EuclideanSpace ℝ (Fin d)) (featCross a)) := by funext w a rw [hfeat, real_inner_smul_right, hp] have hcrossS : empiricalRademacherComplexity n (fun (w : KWeight d W) (a : KFeat d Xb Yb) => 2 * (a.2 : ℝ) * p w a) S ≤ 2 * Yb * Xb * W / sqrt (n : ℝ) := by rw [hcrossfun] have h := linear_predictor_l2_bound' (d := d) (n := n) (ι := KWeight d W) (W := W) (X := 2 * Yb * Xb) (by positivity) hW (fun k => ⟨featCross (S k), hmem (S k)⟩) (fun w => w) exact h -- (4) combine the two parts via sub-additivity have hcrossbd : ∀ (w : KWeight d W) (a : KFeat d Xb Yb), |2 * (a.2 : ℝ) * p w a| ≤ 2 * Yb * (Xb * W) := by intro w a rw [abs_mul, abs_mul, show |(2 : ℝ)| = 2 from by norm_num] nlinarith [hybound a, hpbound w a, abs_nonneg ((a.2 : ℝ)), abs_nonneg (p w a), hYb, hXbW] have hsub := empiricalRademacherComplexity_sub_le (ι := KWeight d W) (fun (w : KWeight d W) (a : KFeat d Xb Yb) => φ (p w a)) (fun (w : KWeight d W) (a : KFeat d Xb Yb) => 2 * (a.2 : ℝ) * p w a) (MF := (Xb * W) ^ 2) (MG := 2 * Yb * (Xb * W)) (by positivity) (by positivity) hquadbd hcrossbd n S have hfeq : empiricalRademacherComplexity n f S = empiricalRademacherComplexity n (fun (w : KWeight d W) (a : KFeat d Xb Yb) => φ (p w a) - 2 * (a.2 : ℝ) * p w a) S := rfl rw [hfeq] calc empiricalRademacherComplexity n (fun (w : KWeight d W) (a : KFeat d Xb Yb) => φ (p w a) - 2 * (a.2 : ℝ) * p w a) S ≤ empiricalRademacherComplexity n (fun (w : KWeight d W) (a : KFeat d Xb Yb) => φ (p w a)) S + empiricalRademacherComplexity n (fun (w : KWeight d W) (a : KFeat d Xb Yb) => 2 * (a.2 : ℝ) * p w a) S := hsub _ ≤ 4 * (Xb * W) ^ 2 / sqrt (n : ℝ) + 2 * Yb * Xb * W / sqrt (n : ℝ) := add_le_add hquad hcrossS _ = Cf / sqrt (n : ℝ) := by rw [← add_div] -- integrate the uniform empirical bound have hnn : ∀ ω : Fin n → Ω, 0 ≤ empiricalRademacherComplexity n f (X ∘ ω) := by intro ω unfold empiricalRademacherComplexity refine mul_nonneg (by positivity) (sum_nonneg fun σ _ => ?_) exact Real.iSup_nonneg fun i => abs_nonneg _ unfold rademacherComplexity calc ∫ ω, empiricalRademacherComplexity n f (X ∘ ω) ∂(Measure.pi fun _ : Fin n => μ) ≤ ∫ _ω, Cf / sqrt (n : ℝ) ∂(Measure.pi fun _ : Fin n => μ) := by apply integral_mono_of_nonneg (Filter.Eventually.of_forall hnn) (integrable_const _) exact Filter.Eventually.of_forall (fun ω => hemp (X ∘ ω)) _ = Cf / sqrt (n : ℝ) := by simp -- the `f`-ERM hypothesis follows from the squared-loss ERM hypothesis have hERMf : ∀ ω : Fin n → Ω, (n : ℝ)⁻¹ * ∑ k, f (ŵ ω) (X (ω k)) ≤ (n : ℝ)⁻¹ * ∑ k, f wstar (X (ω k)) := by intro ω have hrw : ∀ w : KWeight d W, (n : ℝ)⁻¹ * ∑ k, f w (X (ω k)) = (n : ℝ)⁻¹ * ∑ k, sqLoss w (X (ω k)) - (n : ℝ)⁻¹ * ∑ k, ((X (ω k)).2 : ℝ) ^ 2 := by intro w rw [← mul_sub, ← Finset.sum_sub_distrib] refine congrArg _ (Finset.sum_congr rfl fun k _ => ?_) have := hsqf w (X (ω k)) linarith rw [hrw (ŵ ω), hrw wstar] have hE := hERM ω simp only [hsq, hp] linarith [hE] have key := erm_oracle_inequality_separable (μ := μ) (n := n) (f := f) hfmeas X hX (b := (Xb * W) ^ 2 + 2 * Yb * (Xb * W)) hb0 hfbound hfcont_w ht' hε ŵ wstar hERMf -- transport from `f`-excess to genuine squared-loss excess refine le_trans ?_ key refine ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono ?_) intro ω hω -- population split: `∫ f w = ∫ sqLoss w − ∫ y²` have hsqcont_a : ∀ w : KWeight d W, Continuous (fun a : KFeat d Xb Yb => sqLoss w a) := by intro w exact ((hpcont_a w).sub hcont_x2).pow 2 have hpop : ∀ w : KWeight d W, μ[fun ω' => f w (X ω')] = μ[fun ω' => sqLoss w (X ω')] - μ[fun ω' => ((X ω').2 : ℝ) ^ 2] := by intro w have hInt_sq : Integrable (fun ω' => sqLoss w (X ω')) μ := by refine Integrable.of_bound (((hsqcont_a w).measurable.comp hX).aestronglyMeasurable) ((Xb * W + Yb) ^ 2) ?_ filter_upwards with ω' have hpy : |p w (X ω') - ((X ω').2 : ℝ)| ≤ Xb * W + Yb := (abs_sub _ _).trans (add_le_add (hpbound w (X ω')) (hybound (X ω'))) rw [Real.norm_eq_abs, abs_of_nonneg (by positivity : (0 : ℝ) ≤ sqLoss w (X ω'))] have heq : sqLoss w (X ω') = |p w (X ω') - ((X ω').2 : ℝ)| ^ 2 := by rw [hsq, sq_abs] rw [heq] nlinarith [hpy, abs_nonneg (p w (X ω') - ((X ω').2 : ℝ))] have hInt_y : Integrable (fun ω' => ((X ω').2 : ℝ) ^ 2) μ := by refine Integrable.of_bound ((hcont_x2.pow 2).measurable.comp hX).aestronglyMeasurable (Yb ^ 2) ?_ filter_upwards with ω' rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] nlinarith [hybound (X ω'), sq_abs ((X ω').2 : ℝ), abs_nonneg ((X ω').2 : ℝ)] have hpt : (fun ω' => f w (X ω')) = (fun ω' => sqLoss w (X ω') - ((X ω').2 : ℝ) ^ 2) := by funext ω'; have := hsqf w (X ω'); linarith rw [hpt, integral_sub hInt_sq hInt_y] -- f-excess equals squared-loss excess (the `y²` term cancels) have hexc : μ[fun ω' => f (ŵ ω) (X ω')] - μ[fun ω' => f wstar (X ω')] = μ[fun ω' => sqLoss (ŵ ω) (X ω')] - μ[fun ω' => sqLoss wstar (X ω')] := by rw [hpop (ŵ ω), hpop wstar]; ring have hgoal_eq : μ[fun ω' => (inner ℝ ((ŵ ω) : EuclideanSpace ℝ (Fin d)) ((X ω').1 : EuclideanSpace ℝ (Fin d)) - ((X ω').2 : ℝ)) ^ 2] - μ[fun ω' => (inner ℝ (wstar : EuclideanSpace ℝ (Fin d)) ((X ω').1 : EuclideanSpace ℝ (Fin d)) - ((X ω').2 : ℝ)) ^ 2] = μ[fun ω' => sqLoss (ŵ ω) (X ω')] - μ[fun ω' => sqLoss wstar (X ω')] := by simp only [hsq, hp] have hthr : 4 • rademacherComplexity n f μ X + 2 * ε ≤ 4 * (Cf / sqrt (n : ℝ)) + 2 * ε := by have he : 4 • rademacherComplexity n f μ X = 4 * rademacherComplexity n f μ X := by -- … truncated; follow the source link for the rest …
Causalean.ML.kernel_erm_squaredLoss_excess_rate · Causalean/ML/Kernel/SquaredLoss.lean:42 · uses KFeat , KWeight