import Mathlib /-! # Uniform deviation over a finite class: `E[max_θ |L(θ) - L_M(θ)|] ≤ B √|Θ| / √M` **Stated.** Let `(I, p)` be a finite probability space, `Θ` a finite nonempty parameter class and `ℓ : Θ → I → ℝ` a loss with `|ℓ θ i| ≤ B`. Draw `M ≥ 1` i.i.d. samples `ξ = (ξ 0, …, ξ (M-1)) : Fin M → I` from `p`; the law of `ξ` is the product weight `prodWeight p ξ = ∏ k, p (ξ k)` (defined below), and expectations are the explicit finite weighted sums `∑ ξ, prodWeight p ξ * (…)`. With population loss `L θ = ∑ i, p i * ℓ θ i` and empirical loss `L_M θ ξ = (1/M) ∑ₖ ℓ θ (ξ k)`, the expected uniform deviation satisfies `E[ max_θ |L θ - L_M θ ξ| ] ≤ B · √|Θ| / √M`. **Not stated.** The sample space and the class are finite. The sharper Massart-type bound `B √(2 log (2|Θ|) / M)` (which needs Hoeffding's lemma) is not the target; neither are covering number bounds for neural network classes `Θ_{d,m}` (the audited file replaced these by an assumed capacity hypothesis `B √|Θ| ≤ C d^α m^β`, which is dropped here), nor anything about HJB. -/ open scoped BigOperators namespace NSHJB.FiniteClassGeneralization /-- Product (i.i.d.) weight of a sample `ξ : Fin M → I` under the weights `p`. -/ def prodWeight {I : Type*} {M : ℕ} (p : I → ℝ) (ξ : Fin M → I) : ℝ := ∏ k : Fin M, p (ξ k) /-- Population loss `L θ = ∑ i, p i * ℓ θ i`. -/ def popLoss {Θ I : Type*} [Fintype I] (p : I → ℝ) (ℓ : Θ → I → ℝ) (θ : Θ) : ℝ := ∑ i : I, p i * ℓ θ i /-- Empirical loss `L_M θ ξ = (1/M) ∑ₖ ℓ θ (ξ k)`. -/ noncomputable def empLoss {Θ I : Type*} {M : ℕ} (ℓ : Θ → I → ℝ) (θ : Θ) (ξ : Fin M → I) : ℝ := (M : ℝ)⁻¹ * ∑ k : Fin M, ℓ θ (ξ k) /-- Expected uniform deviation over a finite class. -/ theorem finite_class_uniform_deviation {Θ I : Type*} [Fintype Θ] [Nonempty Θ] [Fintype I] {M : ℕ} (hM : 0 < M) (p : I → ℝ) (hp : ∀ i, 0 ≤ p i) (hp_sum : ∑ i : I, p i = 1) (ℓ : Θ → I → ℝ) (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ θ i, |ℓ θ i| ≤ B) : ∑ ξ : Fin M → I, prodWeight p ξ * (⨆ θ : Θ, |popLoss p ℓ θ - empLoss ℓ θ ξ|) ≤ B * Real.sqrt (Fintype.card Θ) / Real.sqrt M := by sorry end NSHJB.FiniteClassGeneralization