Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Augmentation graph, spectral contrastive loss, conductance and linear probe error

Definition
SpectralContrastive_Basic

by Xeroth · Nov 23, 2026 · Mathlib 0df444a (Lean v4.33.1)

cheeger-inequalitycontrastive-learninglinear-probeself-supervised-learningspectral-graph-theory

Objects of Sections 3.1-3.3, 4.1 and Appendices B, D.1 of HaoChen, Wei, Gaidon and Ma (2021).

  1. Data model. The natural data form a finite set X‾\overline{\mathcal X}X with population distribution PPP (P(xˉ)≥0P(\bar x)\ge0P(xˉ)≥0, ∑xˉP(xˉ)=1\sum_{\bar x}P(\bar x)=1∑xˉ​P(xˉ)=1). Each xˉ\bar xxˉ has an augmentation distribution A(⋅∣xˉ)\mathcal A(\cdot\mid\bar x)A(⋅∣xˉ) on the finite set X\mathcal XX of augmented data (N=∣X∣N=|\mathcal X|N=∣X∣). The set X\mathcal XX is the union of the supports of the A(⋅∣xˉ)\mathcal A(\cdot\mid\bar x)A(⋅∣xˉ) with P(xˉ)>0P(\bar x)>0P(xˉ)>0. Labels are y:X‾→[r]y:\overline{\mathcal X}\to[r]y:X→[r].
  2. Augmentation graph (eq. 2). wxx′=Exˉ∼P[A(x∣xˉ)A(x′∣xˉ)]w_{xx'}=\mathbb E_{\bar x\sim P}[\mathcal A(x\mid\bar x)\mathcal A(x'\mid\bar x)]wxx′​=Exˉ∼P​[A(x∣xˉ)A(x′∣xˉ)], with degree wx=∑x′wxx′w_x=\sum_{x'}w_{xx'}wx​=∑x′​wxx′​. A general weighted graph (V,w)(V,w)(V,w) has nonnegative symmetric weights and positive degrees.
  3. Spectra (eq. 3, Definition B.1). A‾=D−1/2AD−1/2\overline A=D^{-1/2}AD^{-1/2}A=D−1/2AD−1/2 with Axx′=wxx′A_{xx'}=w_{xx'}Axx′​=wxx′​ and D=diag(wx)D=\mathrm{diag}(w_x)D=diag(wx​), and L=I−A‾\mathcal L=I-\overline AL=I−A. γi\gamma_iγi​ is the iii-th largest eigenvalue of A‾\overline AA and λi\lambda_iλi​ the iii-th smallest eigenvalue of L\mathcal LL (i≥1i\ge1i≥1, with multiplicity).
  4. Conductance (Definitions 3.3, 3.4). For a set SSS, ϕG(S)=∑x∈S,x′∉Swxx′/∑x∈Swx\phi_G(S)=\sum_{x\in S,x'\notin S}w_{xx'}/\sum_{x\in S}w_xϕG​(S)=∑x∈S,x′∈/S​wxx′​/∑x∈S​wx​. For i≥1i\ge1i≥1, ρi=min⁡max⁡jϕG(Sj)\rho_i=\min\max_j\phi_G(S_j)ρi​=minmaxj​ϕG​(Sj​), the minimum over partitions of the vertex set into iii nonempty sets S1,…,SiS_1,\dots,S_iS1​,…,Si​.
  5. Losses (eqs. 4, 6). The spectral contrastive loss is
L(f)=−2 Ex,x+[f(x)⊤f(x+)]+Ex,x−[(f(x)⊤f(x−))2]\mathcal L(f)=-2\,\mathbb E_{x,x^+}[f(x)^\top f(x^+)]+\mathbb E_{x,x^-}[(f(x)^\top f(x^-))^2]L(f)=−2Ex,x+​[f(x)⊤f(x+)]+Ex,x−​[(f(x)⊤f(x−))2]

for f:X→Rkf:\mathcal X\to\mathbb R^kf:X→Rk. Here x,x+∼A(⋅∣xˉ)x,x^+\sim\mathcal A(\cdot\mid\bar x)x,x+∼A(⋅∣xˉ) independently with xˉ∼P\bar x\sim Pxˉ∼P, and x−∼A(⋅∣xˉ′)x^-\sim\mathcal A(\cdot\mid\bar x')x−∼A(⋅∣xˉ′) with an independent xˉ′∼P\bar x'\sim Pxˉ′∼P. The matrix factorization loss is Lmf(F)=∥A‾−FF⊤∥F2\mathcal L_{\mathrm{mf}}(F)=\|\overline A-FF^\top\|_F^2Lmf​(F)=∥A−FF⊤∥F2​ for F∈RN×kF\in\mathbb R^{N\times k}F∈RN×k. 6. Linear probes (eq. 1). A head B∈Rk×rB\in\mathbb R^{k\times r}B∈Rk×r predicts gf,B(x)∈arg⁡max⁡i(f(x)⊤B)ig_{f,B}(x)\in\arg\max_i(f(x)^\top B)_igf,B​(x)∈argmaxi​(f(x)⊤B)i​ on augmented data and gˉf,B(xˉ)∈arg⁡max⁡iPr⁡x∼A(⋅∣xˉ)[gf,B(x)=i]\bar g_{f,B}(\bar x)\in\arg\max_i\Pr_{x\sim\mathcal A(\cdot\mid\bar x)}[g_{f,B}(x)=i]gˉ​f,B​(xˉ)∈argmaxi​Prx∼A(⋅∣xˉ)​[gf,B​(x)=i] on natural data, with ties broken arbitrarily. The error is E(f,B)=Pr⁡xˉ∼P[y(xˉ)≠gˉf,B(xˉ)]\mathcal E(f,B)=\Pr_{\bar x\sim P}[y(\bar x)\ne\bar g_{f,B}(\bar x)]E(f,B)=Prxˉ∼P​[y(xˉ)=gˉ​f,B​(xˉ)], and the linear probe error is E(f)=min⁡BE(f,B)\mathcal E(f)=\min_B\mathcal E(f,B)E(f)=minB​E(f,B). 7. Label quantities (eqs. 18, 19). For y^:X→[r]\hat y:\mathcal X\to[r]y^​:X→[r], ϕy^=∑x,x′wxx′1[y^(x)≠y^(x′)]\phi^{\hat y}=\sum_{x,x'}w_{xx'}\mathbf 1[\hat y(x)\ne\hat y(x')]ϕy^​=∑x,x′​wxx′​1[y^​(x)=y^​(x′)] and Δ(y,y^)=Pr⁡xˉ∼P, x∼A(⋅∣xˉ)(y^(x)≠y(xˉ))\Delta(y,\hat y)=\Pr_{\bar x\sim P,\,x\sim\mathcal A(\cdot\mid\bar x)}(\hat y(x)\ne y(\bar x))Δ(y,y^​)=Prxˉ∼P,x∼A(⋅∣xˉ)​(y^​(x)=y(xˉ)). The squared probe loss is Exˉ,x∥y⃗(xˉ)−B⊤f(x)∥22\mathbb E_{\bar x,x}\|\vec y(\bar x)-B^\top f(x)\|_2^2Exˉ,x​∥y​(xˉ)−B⊤f(x)∥22​, where y⃗\vec yy​ is the one-hot vector, and ∥B∥F\|B\|_F∥B∥F​ is the Frobenius norm. 8. Finite samples (Section 4.1). For a dataset xˉ1,…,xˉn\bar x_1,\dots,\bar x_nxˉ1​,…,xˉn​ the empirical loss is

L^n(f)=−2n∑iEx,x+∼A(⋅∣xˉi)[f(x)⊤f(x+)]+1n(n−1)∑i≠jEx∼A(⋅∣xˉi), x−∼A(⋅∣xˉj)[(f(x)⊤f(x−))2].\widehat{\mathcal L}_n(f)=-\frac2n\sum_i\mathbb E_{x,x^+\sim\mathcal A(\cdot\mid\bar x_i)}[f(x)^\top f(x^+)]+\frac1{n(n-1)}\sum_{i\ne j}\mathbb E_{x\sim\mathcal A(\cdot\mid\bar x_i),\,x^-\sim\mathcal A(\cdot\mid\bar x_j)}[(f(x)^\top f(x^-))^2].Ln​(f)=−n2​i∑​Ex,x+∼A(⋅∣xˉi​)​[f(x)⊤f(x+)]+n(n−1)1​i=j∑​Ex∼A(⋅∣xˉi​),x−∼A(⋅∣xˉj​)​[(f(x)⊤f(x−))2].

The Rademacher complexity is R^m(F)=max⁡x1,…,xmEσ[sup⁡f∈F, i∈[k]1m∑jσjfi(xj)]\widehat{\mathcal R}_m(\mathcal F)=\max_{x_1,\dots,x_m}\mathbb E_\sigma[\sup_{f\in\mathcal F,\,i\in[k]}\frac1m\sum_j\sigma_jf_i(x_j)]Rm​(F)=maxx1​,…,xm​​Eσ​[supf∈F,i∈[k]​m1​∑j​σj​fi​(xj​)] with σ\sigmaσ uniform on {±1}m\{\pm1\}^m{±1}m. Dataset probabilities are taken under P⊗nP^{\otimes n}P⊗n.

Formalization Note Eigenvalues are the roots of the characteristic polynomial, sorted; indices outside 1,…,N1,\dots,N1,…,N give the value 000. The sparsest iii-partition value ρi\rho_iρi​ is likewise 000 for i>Ni>Ni>N (no surjection exists) and equals ϕ(X)=0\phi(\mathcal X)=0ϕ(X)=0 for i=1i=1i=1. Most statements exclude these values by hypothesis; Theorem B.2 (no condition k≤Nk\le Nk≤N, so λk\lambda_kλk​ may be the value 000) and part 2 of Theorem 3.8 (where ρ⌊k/2⌋\rho_{\lfloor k/2\rfloor}ρ⌊k/2⌋​ may be 000) do not, and remain true in those cases. A partition into iii nonempty sets is a surjection X→Fin i\mathcal X\to\mathrm{Fin}\,iX→Fini. Because the paper breaks argmax ties arbitrarily, E(f,B)\mathcal E(f,B)E(f,B) is defined as the largest error over all admissible tie-breaking choices at both levels, so every bound proved for it holds for every tie-breaking rule. Linear heads are k×rk\times rk×r matrices acting by f(x)⊤Bf(x)^\top Bf(x)⊤B as in Section 3; the r×kr\times kr×k heads B∗B^*B∗ of Appendix B are their transposes, with the same Frobenius norm.

Definition code
import Mathlib

/-!
HaoChen, Wei, Gaidon and Ma, *Provable Guarantees for Self-Supervised Deep Learning with Spectral
Contrastive Loss*, arXiv:2106.04156v7 (NeurIPS 2021): the finite natural/augmented data model,
the population augmentation graph, its normalized adjacency and Laplacian matrices and their
eigenvalues, Dirichlet conductance and sparsest partitions, the spectral contrastive and matrix
factorization losses, linear probes and their errors (Sections 3.1-3.3 and Appendix B), and the
empirical loss and Rademacher complexity of Section 4.1 and Appendix D.1.
-/

noncomputable section

namespace SpectralContrastive

section Graph

variable {V : Type*} [Fintype V] [DecidableEq V]

/-- Section 3.1: the total weight (degree) `w_x = ∑_{x'} w_{xx'}` of a vertex. -/
def degree (w : V → V → ℝ) (x : V) : ℝ := ∑ x', w x x'

/-- Lemma B.4 (p. 27): `G = (V, w)` is a weighted graph: the edge weights are nonnegative and
symmetric, and every vertex has positive total weight (so that `D^{-1/2}` exists). -/
def IsWeightedGraph (w : V → V → ℝ) : Prop :=
  (∀ x x', 0 ≤ w x x') ∧ (∀ x x', w x x' = w x' x) ∧ (∀ x, 0 < degree w x)

/-- Eq. (3), p. 7: the normalized adjacency matrix `Ā = D^{-1/2} A D^{-1/2}`, with
`A_{xx'} = w_{xx'}` and `D = diag(w_x)`. -/
def normAdj (w : V → V → ℝ) : Matrix V V ℝ :=
  fun x x' => w x x' / Real.sqrt (degree w x * degree w x')

/-- Definition B.1, p. 26: the normalized Laplacian matrix `L = I - D^{-1/2} A D^{-1/2}`. -/
def normLap (w : V → V → ℝ) : Matrix V V ℝ := 1 - normAdj w

/-- Section 3.1, p. 7: `γ_i`, the `i`-th largest eigenvalue of `Ā` (`i = 1, 2, …`), counted with
multiplicity, as the roots of the characteristic polynomial sorted in decreasing order. Statements
only use `1 ≤ i ≤ |V|`. -/
def adjEig (w : V → V → ℝ) (i : ℕ) : ℝ :=
  ((normAdj w).charpoly.roots.sort (· ≥ ·)).getD (i - 1) 0

/-- Appendix B.1, p. 26: `λ_i`, the `i`-th smallest eigenvalue of `L` (`i = 1, 2, …`), counted
with multiplicity, as the roots of the characteristic polynomial sorted in increasing order.
Statements only use `1 ≤ i ≤ |V|`. -/
def lapEig (w : V → V → ℝ) (i : ℕ) : ℝ :=
  ((normLap w).charpoly.roots.sort (· ≤ ·)).getD (i - 1) 0

/-- Definition 3.3, p. 10: the Dirichlet conductance
`φ_G(S) = (∑_{x ∈ S, x' ∉ S} w_{xx'}) / (∑_{x ∈ S} w_x)`. -/
def conductance (w : V → V → ℝ) (S : Finset V) : ℝ :=
  (∑ x ∈ S, ∑ x' ∈ Sᶜ, w x x') / ∑ x ∈ S, degree w x

/-- Definition 3.4, p. 10: the sparsest `i`-partition
`ρ_i = min_{S_1, …, S_i} max_j φ_G(S_j)`, the minimum over partitions of `V` into `i` nonempty
sets. A partition is encoded by a surjective labelling `σ : V → Fin i`, with `S_j = σ⁻¹(j)`. -/
def sparsestPartition (w : V → V → ℝ) (i : ℕ) : ℝ :=
  ⨅ σ : {σ : V → Fin i // Function.Surjective σ},
    ⨆ j : Fin i, conductance w (Finset.univ.filter fun x => σ.1 x = j)

/-- Eq. (18), p. 26: `φ^ŷ = ∑_{x,x'} w_{xx'} 1[ŷ(x) ≠ ŷ(x')]` for an extended labeling
function `ŷ`. -/
def cutWeight {r : ℕ} (w : V → V → ℝ) (yhat : V → Fin r) : ℝ :=
  ∑ x, ∑ x', w x x' * if yhat x ≠ yhat x' then 1 else 0

end Graph

section Model

variable {Xbar X : Type*} [Fintype Xbar] [Fintype X] [DecidableEq X]

/-- Section 3, pp. 6-7: the finite data model. `P` is the population distribution `P_X̄` on the
natural data, `A x̄ x = 𝒜(x | x̄)` is the augmentation distribution of `x̄`, and the set `X` of
augmented data is the union of the supports of the `𝒜(· | x̄)`, `x̄` in the support of `P`. -/
def IsAugModel (P : Xbar → ℝ) (A : Xbar → X → ℝ) : Prop :=
  (∀ xb, 0 ≤ P xb) ∧ (∑ xb, P xb = 1) ∧ (∀ xb x, 0 ≤ A xb x) ∧ (∀ xb, ∑ x, A xb x = 1) ∧
    (∀ x, ∃ xb, 0 < P xb ∧ 0 < A xb x)

/-- Eq. (2), p. 7: the edge weights of the population augmentation graph,
`w_{xx'} = E_{x̄ ∼ P}[𝒜(x | x̄) 𝒜(x' | x̄)]`. -/
def augWeight (P : Xbar → ℝ) (A : Xbar → X → ℝ) (x x' : X) : ℝ :=
  ∑ xb, P xb * A xb x * A xb x'

/-- Eq. (6), p. 9 (written out on p. 26): the population spectral contrastive loss
`L(f) = -2 E_{x, x⁺}[f(x)ᵀ f(x⁺)] + E_{x, x⁻}[(f(x)ᵀ f(x⁻))²]`, where `x, x⁺ ∼ 𝒜(· | x̄)`
independently for `x̄ ∼ P`, and `x⁻ ∼ 𝒜(· | x̄')` for an independent `x̄' ∼ P`. -/
def scLoss {k : ℕ} (P : Xbar → ℝ) (A : Xbar → X → ℝ) (f : X → Fin k → ℝ) : ℝ :=
  -2 * (∑ xb, P xb * ∑ x, ∑ x', A xb x * A xb x' * ∑ i, f x i * f x' i) +
    ∑ xb, ∑ xb', P xb * P xb' * ∑ x, ∑ x', A xb x * A xb' x' * (∑ i, f x i * f x' i) ^ 2

/-- Eq. (4), p. 8: the matrix factorization loss `L_mf(F) = ‖Ā - F Fᵀ‖_F²` of an embedding
matrix `F ∈ ℝ^{N × k}` (row `x` of `F` is `F x`). -/
def mfLoss {k : ℕ} (w : X → X → ℝ) (F : X → Fin k → ℝ) : ℝ :=
  ∑ x, ∑ x', (normAdj w x x' - ∑ i, F x i * F x' i) ^ 2

/-- Section 3, p. 6: `i` is a prediction of the linear classifier `B ∈ ℝ^{k × r}` on the
representation `f(x)`, i.e. an index maximising `(f(x)ᵀ B)_i`. The paper breaks ties
arbitrarily; `g` is any such choice. -/
def IsProbePred {k r : ℕ} (f : X → Fin k → ℝ) (B : Matrix (Fin k) (Fin r) ℝ)
    (g : X → Fin r) : Prop :=
  ∀ x i, Matrix.vecMul (f x) B i ≤ Matrix.vecMul (f x) B (g x)

/-- Section 3, p. 6: `Pr_{x ∼ 𝒜(·|x̄)}[g(x) = i]`, the vote of the augmentations of `x̄`
for class `i`. -/
def votes {r : ℕ} (A : Xbar → X → ℝ) (g : X → Fin r) (xb : Xbar) (i : Fin r) : ℝ :=
  ∑ x, A xb x * if g x = i then 1 else 0

/-- Section 3, p. 6: `ḡ(x̄) = argmax_i Pr_{x ∼ 𝒜(·|x̄)}[g(x) = i]`, the ensembled prediction on
natural data (ties broken arbitrarily; `gbar` is any such choice). -/
def IsEnsemblePred {r : ℕ} (A : Xbar → X → ℝ) (g : X → Fin r) (gbar : Xbar → Fin r) : Prop :=
  ∀ xb i, votes A g xb i ≤ votes A g xb (gbar xb)

/-- Section 3, p. 6: `Pr_{x̄ ∼ P}[y(x̄) ≠ ḡ(x̄)]`. -/
def ensembleError {r : ℕ} (P : Xbar → ℝ) (y : Xbar → Fin r) (gbar : Xbar → Fin r) : ℝ :=
  ∑ xb, P xb * if gbar xb ≠ y xb then 1 else 0

/-- Section 3, p. 6: the error `E(f, B) = Pr_{x̄ ∼ P}[y(x̄) ≠ ḡ_{f,B}(x̄)]` of the representation
`f` with the linear head `B`. Since the paper breaks ties arbitrarily, this is the largest error
over all tie-breaking choices, so that a bound on it holds for every tie-breaking rule. -/
def probeError {k r : ℕ} (P : Xbar → ℝ) (A : Xbar → X → ℝ) (y : Xbar → Fin r)
    (f : X → Fin k → ℝ) (B : Matrix (Fin k) (Fin r) ℝ) : ℝ :=
  ⨆ c : {c : (X → Fin r) × (Xbar → Fin r) // IsProbePred f B c.1 ∧ IsEnsemblePred A c.1 c.2},
    ensembleError P y c.1.2

/-- Eq. (1), p. 6: the linear probe error `E(f) = min_{B ∈ ℝ^{k × r}} E(f, B)`. -/
def linearProbeError {k r : ℕ} (P : Xbar → ℝ) (A : Xbar → X → ℝ) (y : Xbar → Fin r)
    (f : X → Fin k → ℝ) : ℝ :=
  ⨅ B : Matrix (Fin k) (Fin r) ℝ, probeError P A y f B

/-- Eq. (19), p. 26: `Δ(y, ŷ) = Pr_{x̄ ∼ P, x ∼ 𝒜(·|x̄)}(ŷ(x) ≠ y(x̄))`. With `ŷ = g` this is
also the error of a classifier `g` on augmented data (Assumption 3.6, p. 11). -/
def labelDisagree {r : ℕ} (P : Xbar → ℝ) (A : Xbar → X → ℝ) (y : Xbar → Fin r)
    (yhat : X → Fin r) : ℝ :=
  ∑ xb, P xb * ∑ x, A xb x * if yhat x ≠ y xb then 1 else 0

/-- Theorem B.3, p. 27: the squared error `E_{x̄ ∼ P, x ∼ 𝒜(·|x̄)} ‖y⃗(x̄) - Bᵀ f(x)‖²` of the
linear head on the one-hot label `y⃗(x̄)`. -/
def probeSqLoss {k r : ℕ} (P : Xbar → ℝ) (A : Xbar → X → ℝ) (y : Xbar → Fin r)
    (f : X → Fin k → ℝ) (B : Matrix (Fin k) (Fin r) ℝ) : ℝ :=
  ∑ xb, P xb * ∑ x, A xb x *
    ∑ c, ((if c = y xb then 1 else 0) - Matrix.vecMul (f x) B c) ^ 2

/-- Frobenius norm `‖B‖_F` of a real matrix (Theorem B.3, p. 27). -/
def frobNorm {m n : Type*} [Fintype m] [Fintype n] (B : Matrix m n ℝ) : ℝ :=
  Real.sqrt (∑ i, ∑ j, B i j ^ 2)

/-- Section 4.1, p. 14 (Definition D.1, p. 37): the empirical spectral contrastive loss on a
dataset `x̄_1, …, x̄_n`:
`L̂_n(f) = -(2/n) ∑_i E_{x, x⁺ ∼ 𝒜(·|x̄_i)}[f(x)ᵀ f(x⁺)]
  + (1/(n(n-1))) ∑_{i ≠ j} E_{x ∼ 𝒜(·|x̄_i), x⁻ ∼ 𝒜(·|x̄_j)}[(f(x)ᵀ f(x⁻))²]`. -/
def empLoss {k n : ℕ} (A : Xbar → X → ℝ) (d : Fin n → Xbar) (f : X → Fin k → ℝ) : ℝ :=
  -(2 / n) * (∑ i, ∑ x, ∑ x', A (d i) x * A (d i) x' * ∑ l, f x l * f x' l) +
    (1 / (n * (n - 1) : ℝ)) * ∑ i, ∑ j ∈ Finset.univ.filter (fun j => j ≠ i),
      ∑ x, ∑ x', A (d i) x * A (d j) x' * (∑ l, f x l * f x' l) ^ 2

/-- Section 4.1, p. 14: the Rademacher complexity of a class `ℱ` of maps `X → ℝ^k` on `m` data,
`R̂_m(ℱ) = max_{x_1, …, x_m ∈ X} E_σ[sup_{f ∈ ℱ, i ∈ [k]} (1/m) ∑_j σ_j f_i(x_j)]`, with `σ`
uniform on `{-1, 1}^m` (encoded by `Bool`). -/
def rademacher {k : ℕ} (F : Set (X → Fin k → ℝ)) (m : ℕ) : ℝ :=
  ⨆ xs : Fin m → X, (1 / 2 ^ m : ℝ) * ∑ σ : Fin m → Bool,
    ⨆ p : F × Fin k, (1 / m : ℝ) * ∑ j, (if σ j then 1 else -1) * p.1.1 (xs j) p.2

open Classical in
/-- Section 4.1, p. 14: the probability, under a dataset `x̄_1, …, x̄_n` drawn i.i.d. from `P`,
of an event `E` of the dataset. -/
def datasetProb {n : ℕ} (P : Xbar → ℝ) (E : (Fin n → Xbar) → Prop) : ℝ :=
  ∑ d : Fin n → Xbar, (∏ i, P (d i)) * if E d then 1 else 0

end Model

end SpectralContrastive
Source
HaoChen, Wei, Gaidon and Ma, Provable Guarantees for Self-Supervised Deep Learning with Spectral Contrastive Loss, arXiv:2106.04156v7 (NeurIPS 2021), Sections 3.1-3.3 (eqs. (1)-(6), Definitions 3.3-3.4, Assumptions 3.5-3.7), Section 4.1, Appendix B.1 (Definition B.1, eqs. (18)-(19)), Appendix D.1 (Definition D.1)
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

degree — Let VVV be a finite set with decidable equality and w:V×V→Rw : V \times V \to \mathbb{R}w:V×V→R an arbitrary real-valued function. No nonnegativity or symmetry is assumed. For a vertex x∈Vx \in Vx∈V, the degree is the sum over the second argument:

wx  =  ∑x′∈Vwxx′.w_x \;=\; \sum_{x' \in V} w_{xx'} .wx​=x′∈V∑​wxx′​.

IsWeightedGraph — For a finite set VVV and a function w:V×V→Rw : V \times V \to \mathbb{R}w:V×V→R, the property "www is a weighted graph" holds exactly when all three of the following hold:

  • wxx′≥0w_{xx'} \ge 0wxx′​≥0 for all x,x′∈Vx, x' \in Vx,x′∈V;
  • wxx′=wx′xw_{xx'} = w_{x'x}wxx′​=wx′x​ for all x,x′x, x'x,x′;
  • wx=∑x′wxx′>0w_x = \sum_{x'} w_{xx'} > 0wx​=∑x′​wxx′​>0 for every x∈Vx \in Vx∈V.

Self-loops (wxx>0w_{xx} > 0wxx​>0) are allowed and count toward the degree. If VVV is empty, the property holds vacuously.


normAdj — For a finite set VVV and any w:V×V→Rw : V \times V \to \mathbb{R}w:V×V→R (no graph hypotheses assumed), the normalized adjacency matrix Aˉ∈RV×V\bar A \in \mathbb{R}^{V \times V}Aˉ∈RV×V has entries

Aˉxx′  =  wxx′wx wx′,\bar A_{xx'} \;=\; \frac{w_{xx'}}{\sqrt{w_x\, w_{x'}}},Aˉxx′​=wx​wx′​​wxx′​​,

where wx=∑x′′wxx′′w_x = \sum_{x''} w_{xx''}wx​=∑x′′​wxx′′​ is the degree. Two conventions apply:

  • The square root is taken of the product wxwx′w_x w_{x'}wx​wx′​, and the square root of a negative number is taken to be 000.
  • Division by 000 yields 000.

Hence Aˉxx′=0\bar A_{xx'} = 0Aˉxx′​=0 whenever wxwx′≤0w_x w_{x'} \le 0wx​wx′​≤0, for example when either degree is 000. When both degrees are negative, the product is positive and the entry is wxx′/wxwx′w_{xx'}/\sqrt{w_x w_{x'}}wxx′​/wx​wx′​​.


normLap — For a finite set VVV and any w:V×V→Rw : V \times V \to \mathbb{R}w:V×V→R, the normalized Laplacian is

L=I−Aˉ,L = I - \bar A,L=I−Aˉ,

where III is the V×VV \times VV×V identity matrix and Aˉ\bar AAˉ is the normalized adjacency matrix: Aˉxx′=wxx′/wxwx′\bar A_{xx'} = w_{xx'}/\sqrt{w_x w_{x'}}Aˉxx′​=wxx′​/wx​wx′​​, with wx=∑x′′wxx′′w_x = \sum_{x''} w_{xx''}wx​=∑x′′​wxx′′​, negative:=0\sqrt{\text{negative}} := 0negative​:=0 and division by zero :=0:= 0:=0.


adjEig — For a finite set VVV, any w:V×V→Rw : V \times V \to \mathbb{R}w:V×V→R and a natural number iii, the value γi\gamma_iγi​ is defined as follows:

  1. Take the real roots of the characteristic polynomial of the real matrix Aˉ\bar AAˉ (the normalized adjacency matrix, Aˉxx′=wxx′/wxwx′\bar A_{xx'} = w_{xx'}/\sqrt{w_x w_{x'}}Aˉxx′​=wxx′​/wx​wx′​​ with the conventions negative=0\sqrt{\text{negative}}=0negative​=0 and ⋅/0=0\cdot/0 = 0⋅/0=0).
  2. Count them with multiplicity.
  3. Sort them in non-increasing order: r1≥r2≥⋯≥rmr_1 \ge r_2 \ge \dots \ge r_mr1​≥r2​≥⋯≥rm​.
  4. Set γi=ri\gamma_i = r_iγi​=ri​ if 1≤i≤m1 \le i \le m1≤i≤m, and γi=0\gamma_i = 0γi​=0 if i>mi > mi>m.

Edge cases:

  • Because the index used is i−1i-1i−1 with truncated natural-number subtraction, γ0=γ1\gamma_0 = \gamma_1γ0​=γ1​.
  • Non-real complex roots are discarded, so if Aˉ\bar AAˉ is not symmetric, mmm may be smaller than ∣V∣|V|∣V∣ and the "missing" eigenvalues read as 000.
  • If VVV is empty, the characteristic polynomial is 111 and every γi=0\gamma_i = 0γi​=0.

lapEig — For a finite set VVV, any w:V×V→Rw : V \times V \to \mathbb{R}w:V×V→R and a natural number iii, the value λi\lambda_iλi​ is defined as follows:

  1. Take the real roots of the characteristic polynomial of L=I−AˉL = I - \bar AL=I−Aˉ, the normalized Laplacian (with Aˉxx′=wxx′/wxwx′\bar A_{xx'} = w_{xx'}/\sqrt{w_x w_{x'}}Aˉxx′​=wxx′​/wx​wx′​​ and the conventions negative=0\sqrt{\text{negative}}=0negative​=0, ⋅/0=0\cdot/0=0⋅/0=0).
  2. Count them with multiplicity.
  3. Sort them in non-decreasing order: s1≤s2≤⋯≤sms_1 \le s_2 \le \dots \le s_ms1​≤s2​≤⋯≤sm​.
  4. Set λi=si\lambda_i = s_iλi​=si​ if 1≤i≤m1 \le i \le m1≤i≤m, and λi=0\lambda_i = 0λi​=0 if i>mi > mi>m.

Edge cases:

  • λ0=λ1\lambda_0 = \lambda_1λ0​=λ1​, because of truncated subtraction 0−1=00 - 1 = 00−1=0.
  • Non-real roots are discarded.
  • If VVV is empty, all λi=0\lambda_i = 0λi​=0.

conductance — For a finite set VVV, any w:V×V→Rw : V \times V \to \mathbb{R}w:V×V→R and a finite subset S⊆VS \subseteq VS⊆V, the conductance is

ϕG(S)  =  ∑x∈S∑x′∈V∖Swxx′∑x∈Swx,wx=∑x′′wxx′′.\phi_G(S) \;=\; \frac{\displaystyle\sum_{x \in S}\sum_{x' \in V \setminus S} w_{xx'}}{\displaystyle\sum_{x \in S} w_x}, \qquad w_x = \sum_{x''} w_{xx''}.ϕG​(S)=x∈S∑​wx​x∈S∑​x′∈V∖S∑​wxx′​​,wx​=x′′∑​wxx′′​.

Division by zero yields 000. In particular:

  • ϕG(∅)=0\phi_G(\emptyset) = 0ϕG​(∅)=0;
  • ϕG(V)=0\phi_G(V) = 0ϕG​(V)=0, since the numerator is an empty sum;
  • ϕG(S)=0\phi_G(S) = 0ϕG​(S)=0 whenever the total degree of SSS is 000.

No nonnegativity of www is assumed.


sparsestPartition — For a finite set VVV, any w:V×V→Rw : V \times V \to \mathbb{R}w:V×V→R and a natural number iii, the value is

ρi  =  inf⁡σ:V→{0,…,i−1}σ surjective    max⁡0≤j<i  ϕG(σ−1(j)),\rho_i \;=\; \inf_{\substack{\sigma : V \to \{0,\dots,i-1\}\\ \sigma \text{ surjective}}} \;\; \max_{0 \le j < i} \; \phi_G\big(\sigma^{-1}(j)\big),ρi​=σ:V→{0,…,i−1}σ surjective​inf​0≤j<imax​ϕG​(σ−1(j)),

where ϕG\phi_GϕG​ is the conductance defined above. Each surjective labelling σ\sigmaσ describes an ordered partition of VVV into exactly iii nonempty blocks Sj=σ−1(j)S_j = \sigma^{-1}(j)Sj​=σ−1(j). There are finitely many labellings, so when any exist the infimum is a minimum.

Empty-index conventions (an infimum or supremum over an empty index set is 000):

  • If i>∣V∣i > |V|i>∣V∣, no surjection exists and ρi=0\rho_i = 0ρi​=0.
  • If i=0i = 0i=0, then ρ0=0\rho_0 = 0ρ0​=0, whether or not VVV is empty.

cutWeight — For a finite set VVV, any w:V×V→Rw : V \times V \to \mathbb{R}w:V×V→R, a natural number rrr and a labelling y^:V→{0,…,r−1}\hat y : V \to \{0,\dots,r-1\}y^​:V→{0,…,r−1}, the cut weight is

ϕy^  =  ∑x∈V∑x′∈Vwxx′ 1[y^(x)≠y^(x′)].\phi^{\hat y} \;=\; \sum_{x \in V}\sum_{x' \in V} w_{xx'}\,\mathbf 1[\hat y(x) \ne \hat y(x')].ϕy^​=x∈V∑​x′∈V∑​wxx′​1[y^​(x)=y^​(x′)].

The sum runs over ordered pairs, so for symmetric www each unordered cross-label pair is counted twice. Note also that if r=0r = 0r=0, a labelling exists only when VVV is empty.


IsAugModel — Let Xˉ\bar XXˉ (natural data) and XXX (augmented data) be finite sets, with XXX having decidable equality. Let P:Xˉ→RP : \bar X \to \mathbb{R}P:Xˉ→R and A:Xˉ×X→RA : \bar X \times X \to \mathbb{R}A:Xˉ×X→R, where A(xˉ,x)A(\bar x, x)A(xˉ,x) plays the role of A(x∣xˉ)\mathcal A(x \mid \bar x)A(x∣xˉ). The property holds exactly when all of the following hold:

  • P(xˉ)≥0P(\bar x) \ge 0P(xˉ)≥0 for all xˉ\bar xxˉ, and ∑xˉP(xˉ)=1\sum_{\bar x} P(\bar x) = 1∑xˉ​P(xˉ)=1;
  • A(xˉ,x)≥0A(\bar x, x) \ge 0A(xˉ,x)≥0 for all xˉ,x\bar x, xxˉ,x;
  • ∑x∈XA(xˉ,x)=1\sum_{x \in X} A(\bar x, x) = 1∑x∈X​A(xˉ,x)=1 for every xˉ∈Xˉ\bar x \in \bar Xxˉ∈Xˉ, including those with P(xˉ)=0P(\bar x) = 0P(xˉ)=0;
  • for every x∈Xx \in Xx∈X there exists xˉ\bar xxˉ with P(xˉ)>0P(\bar x) > 0P(xˉ)>0 and A(xˉ,x)>0A(\bar x, x) > 0A(xˉ,x)>0.

These conditions force both Xˉ\bar XXˉ and XXX to be nonempty.


augWeight — For finite sets Xˉ\bar XXˉ, XXX and arbitrary functions P:Xˉ→RP : \bar X \to \mathbb{R}P:Xˉ→R, A:Xˉ×X→RA : \bar X \times X \to \mathbb{R}A:Xˉ×X→R (no probability assumptions are built in), the edge weight between x,x′∈Xx, x' \in Xx,x′∈X is

wxx′  =  ∑xˉ∈XˉP(xˉ) A(xˉ,x) A(xˉ,x′).w_{xx'} \;=\; \sum_{\bar x \in \bar X} P(\bar x)\, A(\bar x, x)\, A(\bar x, x').wxx′​=xˉ∈Xˉ∑​P(xˉ)A(xˉ,x)A(xˉ,x′).

scLoss — Let Xˉ\bar XXˉ, XXX be finite sets, kkk a natural number, P:Xˉ→RP : \bar X \to \mathbb{R}P:Xˉ→R, A:Xˉ×X→RA : \bar X \times X \to \mathbb{R}A:Xˉ×X→R arbitrary, and f:X→Rkf : X \to \mathbb{R}^kf:X→Rk. Write ⟨u,v⟩=∑l=1kulvl\langle u, v\rangle = \sum_{l=1}^k u_l v_l⟨u,v⟩=∑l=1k​ul​vl​. The spectral contrastive loss is

L(f)  =  −2∑xˉP(xˉ)∑x,x′∈XA(xˉ,x)A(xˉ,x′) ⟨f(x),f(x′)⟩  +  ∑xˉ,xˉ′P(xˉ)P(xˉ′)∑x,x′A(xˉ,x)A(xˉ′,x′) ⟨f(x),f(x′)⟩2.\mathcal L(f) \;=\; -2 \sum_{\bar x} P(\bar x) \sum_{x, x' \in X} A(\bar x, x)A(\bar x, x')\,\langle f(x), f(x')\rangle \;+\; \sum_{\bar x, \bar x'} P(\bar x)P(\bar x') \sum_{x, x'} A(\bar x, x)A(\bar x', x')\,\langle f(x), f(x')\rangle^2 .L(f)=−2xˉ∑​P(xˉ)x,x′∈X∑​A(xˉ,x)A(xˉ,x′)⟨f(x),f(x′)⟩+xˉ,xˉ′∑​P(xˉ)P(xˉ′)x,x′∑​A(xˉ,x)A(xˉ′,x′)⟨f(x),f(x′)⟩2.

No normalisation or nonnegativity of PPP or AAA is assumed. When k=0k = 0k=0, L(f)=0\mathcal L(f) = 0L(f)=0.


mfLoss — For a finite set XXX with decidable equality, any w:X×X→Rw : X \times X \to \mathbb{R}w:X×X→R, a natural number kkk and F:X→RkF : X \to \mathbb{R}^kF:X→Rk (row xxx of an ∣X∣×k|X| \times k∣X∣×k matrix), the matrix factorization loss is

Lmf(F)  =  ∑x,x′∈X(Aˉxx′−∑l=1kF(x)lF(x′)l)2  =  ∥Aˉ−FF⊤∥F2.\mathcal L_{\mathrm{mf}}(F) \;=\; \sum_{x, x' \in X}\Big(\bar A_{xx'} - \sum_{l=1}^k F(x)_l F(x')_l\Big)^2 \;=\; \|\bar A - FF^\top\|_F^2 .Lmf​(F)=x,x′∈X∑​(Aˉxx′​−l=1∑k​F(x)l​F(x′)l​)2=∥Aˉ−FF⊤∥F2​.

Here Aˉxx′=wxx′/wxwx′\bar A_{xx'} = w_{xx'}/\sqrt{w_x w_{x'}}Aˉxx′​=wxx′​/wx​wx′​​ is the normalized adjacency of www, with wx=∑x′′wxx′′w_x = \sum_{x''} w_{xx''}wx​=∑x′′​wxx′′​, negative=0\sqrt{\text{negative}} = 0negative​=0 and division by zero =0= 0=0.


IsProbePred — Let XXX be a finite set, k,rk, rk,r natural numbers, f:X→Rkf : X \to \mathbb{R}^kf:X→Rk, B∈Rk×rB \in \mathbb{R}^{k \times r}B∈Rk×r and g:X→{0,…,r−1}g : X \to \{0,\dots,r-1\}g:X→{0,…,r−1}. The property holds exactly when, for every x∈Xx \in Xx∈X and every class ccc,

(f(x)⊤B)c  ≤  (f(x)⊤B)g(x),(f(x)⊤B)c=∑lf(x)lBlc.(f(x)^\top B)_c \;\le\; (f(x)^\top B)_{g(x)}, \qquad (f(x)^\top B)_c = \sum_{l} f(x)_l B_{lc}.(f(x)⊤B)c​≤(f(x)⊤B)g(x)​,(f(x)⊤B)c​=l∑​f(x)l​Blc​.

That is, g(x)g(x)g(x) is some maximizing index, with ties allowed. If r=0r = 0r=0 and XXX is nonempty, no such ggg exists.


votes — For finite sets Xˉ\bar XXˉ, XXX, A:Xˉ×X→RA : \bar X \times X \to \mathbb{R}A:Xˉ×X→R, g:X→{0,…,r−1}g : X \to \{0,\dots,r-1\}g:X→{0,…,r−1}, xˉ∈Xˉ\bar x \in \bar Xxˉ∈Xˉ and a class iii, the vote count is

votes(xˉ,i)  =  ∑x∈XA(xˉ,x) 1[g(x)=i].\mathrm{votes}(\bar x, i) \;=\; \sum_{x \in X} A(\bar x, x)\,\mathbf 1[g(x) = i].votes(xˉ,i)=x∈X∑​A(xˉ,x)1[g(x)=i].

IsEnsemblePred — For finite sets Xˉ\bar XXˉ, XXX, A:Xˉ×X→RA : \bar X \times X \to \mathbb{R}A:Xˉ×X→R, g:X→{0,…,r−1}g : X \to \{0,\dots,r-1\}g:X→{0,…,r−1} and gˉ:Xˉ→{0,…,r−1}\bar g : \bar X \to \{0,\dots,r-1\}gˉ​:Xˉ→{0,…,r−1}, the property holds exactly when, for every xˉ∈Xˉ\bar x \in \bar Xxˉ∈Xˉ (regardless of its probability) and every class iii,

votes(xˉ,i)≤votes(xˉ,gˉ(xˉ)).\mathrm{votes}(\bar x, i) \le \mathrm{votes}(\bar x, \bar g(\bar x)).votes(xˉ,i)≤votes(xˉ,gˉ​(xˉ)).

Here votes(xˉ,i)=∑xA(xˉ,x)1[g(x)=i]\mathrm{votes}(\bar x, i) = \sum_x A(\bar x, x)\mathbf 1[g(x)=i]votes(xˉ,i)=∑x​A(xˉ,x)1[g(x)=i]. That is, gˉ(xˉ)\bar g(\bar x)gˉ​(xˉ) is some vote-maximizing class, with ties allowed.


ensembleError — For a finite set Xˉ\bar XXˉ, P:Xˉ→RP : \bar X \to \mathbb{R}P:Xˉ→R, a label function y:Xˉ→{0,…,r−1}y : \bar X \to \{0,\dots,r-1\}y:Xˉ→{0,…,r−1} and a prediction gˉ:Xˉ→{0,…,r−1}\bar g : \bar X \to \{0,\dots,r-1\}gˉ​:Xˉ→{0,…,r−1}, the ensemble error is

∑xˉP(xˉ) 1[gˉ(xˉ)≠y(xˉ)].\sum_{\bar x} P(\bar x)\,\mathbf 1[\bar g(\bar x) \ne y(\bar x)].xˉ∑​P(xˉ)1[gˉ​(xˉ)=y(xˉ)].

probeError — Let Xˉ\bar XXˉ, XXX be finite sets, P:Xˉ→RP : \bar X \to \mathbb{R}P:Xˉ→R, A:Xˉ×X→RA : \bar X \times X \to \mathbb{R}A:Xˉ×X→R, y:Xˉ→{0,…,r−1}y : \bar X \to \{0,\dots,r-1\}y:Xˉ→{0,…,r−1}, f:X→Rkf : X \to \mathbb{R}^kf:X→Rk and B∈Rk×rB \in \mathbb{R}^{k \times r}B∈Rk×r. The probe error is

E(f,B)  =  sup⁡(g,gˉ)  ∑xˉP(xˉ) 1[gˉ(xˉ)≠y(xˉ)].\mathcal E(f, B) \;=\; \sup_{(g, \bar g)} \; \sum_{\bar x} P(\bar x)\,\mathbf 1[\bar g(\bar x) \ne y(\bar x)].E(f,B)=(g,gˉ​)sup​xˉ∑​P(xˉ)1[gˉ​(xˉ)=y(xˉ)].

The supremum ranges over all pairs (g,gˉ)(g, \bar g)(g,gˉ​) such that:

  • g:X→{0,…,r−1}g : X \to \{0,\dots,r-1\}g:X→{0,…,r−1} satisfies (f(x)⊤B)c≤(f(x)⊤B)g(x)(f(x)^\top B)_c \le (f(x)^\top B)_{g(x)}(f(x)⊤B)c​≤(f(x)⊤B)g(x)​ for all xxx and all classes ccc;
  • gˉ:Xˉ→{0,…,r−1}\bar g : \bar X \to \{0,\dots,r-1\}gˉ​:Xˉ→{0,…,r−1} satisfies ∑xA(xˉ,x)1[g(x)=i]≤∑xA(xˉ,x)1[g(x)=gˉ(xˉ)]\sum_x A(\bar x,x)\mathbf 1[g(x)=i] \le \sum_x A(\bar x,x)\mathbf 1[g(x)=\bar g(\bar x)]∑x​A(xˉ,x)1[g(x)=i]≤∑x​A(xˉ,x)1[g(x)=gˉ​(xˉ)] for all xˉ\bar xxˉ and all classes iii.

So this is the worst case over all tie-breaking choices at both stages. The set of pairs is finite. If it is empty, which happens when r=0r = 0r=0, the value is 000; when r=0r = 0r=0 and both sets are empty, the value is likewise 000.


linearProbeError — With Xˉ\bar XXˉ, XXX, PPP, AAA, yyy and f:X→Rkf : X \to \mathbb{R}^kf:X→Rk as above, the linear probe error is

E(f)  =  inf⁡B∈Rk×rE(f,B).\mathcal E(f) \;=\; \inf_{B \in \mathbb{R}^{k \times r}} \mathcal E(f, B).E(f)=B∈Rk×rinf​E(f,B).

Here E(f,B)\mathcal E(f, B)E(f,B) is the worst-case-over-tie-breaking probe error defined above, and the infimum ranges over all real k×rk \times rk×r matrices. Since E(f,B)\mathcal E(f,B)E(f,B) takes only finitely many values, the infimum is attained. Note that B=0B = 0B=0 is allowed; it makes every class tie for every xxx.


labelDisagree — For finite sets Xˉ\bar XXˉ, XXX, P:Xˉ→RP : \bar X \to \mathbb{R}P:Xˉ→R, A:Xˉ×X→RA : \bar X \times X \to \mathbb{R}A:Xˉ×X→R, labels y:Xˉ→{0,…,r−1}y : \bar X \to \{0,\dots,r-1\}y:Xˉ→{0,…,r−1} and y^:X→{0,…,r−1}\hat y : X \to \{0,\dots,r-1\}y^​:X→{0,…,r−1}, the label disagreement is

Δ(y,y^)  =  ∑xˉP(xˉ)∑xA(xˉ,x) 1[y^(x)≠y(xˉ)].\Delta(y, \hat y) \;=\; \sum_{\bar x} P(\bar x) \sum_{x} A(\bar x, x)\,\mathbf 1[\hat y(x) \ne y(\bar x)].Δ(y,y^​)=xˉ∑​P(xˉ)x∑​A(xˉ,x)1[y^​(x)=y(xˉ)].

probeSqLoss — For finite sets Xˉ\bar XXˉ, XXX, PPP, AAA as above, y:Xˉ→{0,…,r−1}y : \bar X \to \{0,\dots,r-1\}y:Xˉ→{0,…,r−1}, f:X→Rkf : X \to \mathbb{R}^kf:X→Rk and B∈Rk×rB \in \mathbb{R}^{k \times r}B∈Rk×r, the squared probe loss is

∑xˉP(xˉ)∑xA(xˉ,x)∑c=0r−1(1[c=y(xˉ)]−(f(x)⊤B)c)2.\sum_{\bar x} P(\bar x)\sum_{x} A(\bar x, x)\sum_{c=0}^{r-1}\Big(\mathbf 1[c = y(\bar x)] - (f(x)^\top B)_c\Big)^2 .xˉ∑​P(xˉ)x∑​A(xˉ,x)c=0∑r−1​(1[c=y(xˉ)]−(f(x)⊤B)c​)2.

Equivalently, it is the PPP- and AAA-weighted sum of ∥y⃗(xˉ)−B⊤f(x)∥22\|\vec y(\bar x) - B^\top f(x)\|_2^2∥y​(xˉ)−B⊤f(x)∥22​, where y⃗(xˉ)\vec y(\bar x)y​(xˉ) is the one-hot vector of y(xˉ)y(\bar x)y(xˉ).


frobNorm — For finite index sets mmm, nnn and a real matrix B∈Rm×nB \in \mathbb{R}^{m \times n}B∈Rm×n, the Frobenius norm is

∥B∥F=∑i,jBij2.\|B\|_F = \sqrt{\textstyle\sum_{i,j} B_{ij}^2}.∥B∥F​=∑i,j​Bij2​​.

empLoss — Let Xˉ\bar XXˉ, XXX be finite sets, A:Xˉ×X→RA : \bar X \times X \to \mathbb{R}A:Xˉ×X→R, n,kn, kn,k natural numbers, a dataset d=(xˉ1,…,xˉn)∈Xˉnd = (\bar x_1, \dots, \bar x_n) \in \bar X^nd=(xˉ1​,…,xˉn​)∈Xˉn (repetitions allowed) and f:X→Rkf : X \to \mathbb{R}^kf:X→Rk. With ⟨u,v⟩=∑lulvl\langle u,v\rangle = \sum_l u_l v_l⟨u,v⟩=∑l​ul​vl​, the empirical loss is

L^n(f)  =  −2n∑i=1n∑x,x′A(xˉi,x)A(xˉi,x′)⟨f(x),f(x′)⟩  +  1n(n−1)∑i=1n∑j≠i∑x,x′A(xˉi,x)A(xˉj,x′)⟨f(x),f(x′)⟩2.\hat{\mathcal L}_n(f) \;=\; -\frac{2}{n}\sum_{i=1}^n \sum_{x, x'} A(\bar x_i, x)A(\bar x_i, x')\langle f(x), f(x')\rangle \;+\; \frac{1}{n(n-1)}\sum_{i=1}^n\sum_{j \ne i}\sum_{x, x'} A(\bar x_i, x)A(\bar x_j, x')\langle f(x), f(x')\rangle^2 .L^n​(f)=−n2​i=1∑n​x,x′∑​A(xˉi​,x)A(xˉi​,x′)⟨f(x),f(x′)⟩+n(n−1)1​i=1∑n​j=i∑​x,x′∑​A(xˉi​,x)A(xˉj​,x′)⟨f(x),f(x′)⟩2.

The coefficients are computed in the reals, and division by zero yields 000. Consequently:

  • L^0(f)=0\hat{\mathcal L}_0(f) = 0L^0​(f)=0;
  • for n=1n = 1n=1, the second coefficient is 000 (and its sum is empty anyway), so only the first term remains.

rademacher — Let XXX be a finite set, k,mk, mk,m natural numbers and F\mathcal FF any set of maps X→RkX \to \mathbb{R}^kX→Rk. The Rademacher complexity is

R^m(F)  =  sup⁡x1,…,xm∈X  12m∑σ∈{±1}m  sup⁡f∈F,  1≤l≤k  1m∑j=1mσj f(xj)l.\hat R_m(\mathcal F) \;=\; \sup_{x_1,\dots,x_m \in X} \; \frac{1}{2^m}\sum_{\sigma \in \{\pm1\}^m} \; \sup_{f \in \mathcal F,\; 1 \le l \le k} \; \frac{1}{m}\sum_{j=1}^m \sigma_j\, f(x_j)_l .R^m​(F)=x1​,…,xm​∈Xsup​2m1​σ∈{±1}m∑​f∈F,1≤l≤ksup​m1​j=1∑m​σj​f(xj​)l​.

The points xjx_jxj​ may repeat, and the average over σ\sigmaσ is uniform. The suprema follow the real-number conventions, under which:

  • the supremum over an empty index set is 000;
  • the supremum of a set unbounded above is also 000.

In particular:

  • the inner supremum is 000 if F\mathcal FF is empty, if k=0k = 0k=0, or if the values are unbounded above;
  • if XXX is empty and m≥1m \ge 1m≥1, the outer supremum is over nothing and R^m=0\hat R_m = 0R^m​=0;
  • if m=0m = 0m=0, the factor 1/m1/m1/m is 000 and R^0=0\hat R_0 = 0R^0​=0.

datasetProb — For a finite set Xˉ\bar XXˉ, P:Xˉ→RP : \bar X \to \mathbb{R}P:Xˉ→R, a natural number nnn and any property EEE of datasets in Xˉn\bar X^nXˉn, the dataset probability is

Pr⁡[E]  =  ∑d∈Xˉn(∏i=1nP(di)) 1[E(d)].\Pr[E] \;=\; \sum_{d \in \bar X^n} \Big(\prod_{i=1}^n P(d_i)\Big)\,\mathbf 1[E(d)].Pr[E]=d∈Xˉn∑​(i=1∏n​P(di​))1[E(d)].

No probability assumption on PPP is built in. For n=0n = 0n=0 there is exactly one (empty) dataset with weight 111, so the value is 111 if EEE holds of it and 000 otherwise.

Human review
  • Endorsed by Shuze Chen · Nov 23, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 23, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me