Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Relation matrices, graph Laplacians, VICReg and SimCLR losses, and linear-probe objects

Definition
SSLSpectralEmbedding_Basic

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

graph-laplacianmatrix-analysisself-supervised-learningspectral-embeddingvicreg

Objects of Sections 2, 3, 4.1 and 6 and Appendix A.15 of Balestriero and LeCun (2022). A data set has NNN samples; a representation is a matrix Z∈RN×KZ\in\mathbb{R}^{N\times K}Z∈RN×K whose iii-th row Zi,.Z_{i,.}Zi,.​ is the embedding of sample iii.

  1. Relation matrix and Laplacian. A relation matrix G∈RN×NG\in\mathbb{R}^{N\times N}G∈RN×N is symmetric, has nonnegative entries and zero diagonal. D=diag⁡(G1)D=\operatorname{diag}(G\mathbf 1)D=diag(G1) is its degree matrix and L=D−GL=D-GL=D−G its graph Laplacian. H=I−1N11⊤H=I-\frac1N\mathbf 1\mathbf 1^\topH=I−N1​11⊤ is the centring matrix, and Cov⁡(Z)=1NZ⊤HZ\operatorname{Cov}(Z)=\frac1N Z^\top HZCov(Z)=N1​Z⊤HZ.
  2. VICReg (eq. 2). Lvar(Z)=∑kmax⁡(0,1−Cov⁡(Z)k,k)\mathcal L_{\rm var}(Z)=\sum_k\max(0,1-\sqrt{\operatorname{Cov}(Z)_{k,k}})Lvar​(Z)=∑k​max(0,1−Cov(Z)k,k​​), Lcov(Z)=∑k∑j≠kCov⁡(Z)k,j2\mathcal L_{\rm cov}(Z)=\sum_k\sum_{j\ne k}\operatorname{Cov}(Z)_{k,j}^2Lcov​(Z)=∑k​∑j=k​Cov(Z)k,j2​, Linv(Z)=γN∑i,jGi,j∥Zi,.−Zj,.∥22\mathcal L_{\rm inv}(Z)=\frac{\gamma}{N}\sum_{i,j}G_{i,j}\|Z_{i,.}-Z_{j,.}\|_2^2Linv​(Z)=Nγ​∑i,j​Gi,j​∥Zi,.​−Zj,.​∥22​, and Lvic=αLvar+βLcov+Linv\mathcal L_{\rm vic}=\alpha\mathcal L_{\rm var}+\beta\mathcal L_{\rm cov}+\mathcal L_{\rm inv}Lvic​=αLvar​+βLcov​+Linv​. The squared variant (Section 3.1) replaces Lvar\mathcal L_{\rm var}Lvar​ by ∑k(1−Cov⁡(Z)k,k)2\sum_k(1-\operatorname{Cov}(Z)_{k,k})^2∑k​(1−Cov(Z)k,k​)2.
  3. Spectral data of VICReg (eq. 8). Mα,γ=H−γαL=Pdiag⁡(λ)P⊤M_{\alpha,\gamma}=H-\frac{\gamma}{\alpha}L=P\operatorname{diag}(\lambda)P^\topMα,γ​=H−αγ​L=Pdiag(λ)P⊤ with PPP orthogonal and λ1≥⋯≥λN\lambda_1\ge\dots\ge\lambda_Nλ1​≥⋯≥λN​. The candidate optimum is Zα,γ∗=(P(diag⁡(λ)N)1/2):,1:KZ^*_{\alpha,\gamma}=(P(\operatorname{diag}(\lambda)N)^{1/2})_{:,1:K}Zα,γ∗​=(P(diag(λ)N)1/2):,1:K​.
  4. Laplacian Eigenmaps (eq. 11). ZLE∗Z^*_{\rm LE}ZLE∗​ minimises Tr⁡(Z⊤LZ)\operatorname{Tr}(Z^\top LZ)Tr(Z⊤LZ) over ZZZ with Z⊤DZ=IZ^\top DZ=IZ⊤DZ=I and columns of zero mean.
  5. Linear VICReg (eq. 12). For data X∈RN×DX\in\mathbb{R}^{N\times D}X∈RN×D, B=Cov⁡(X)−γαNX⊤LXB=\operatorname{Cov}(X)-\frac{\gamma}{\alpha N}X^\top LXB=Cov(X)−αNγ​X⊤LX.
  6. Graph estimation (eqs. 14-16, 3). For a dissimilarity ddd on embeddings, (D)i,j=d(Zi,.,Zj,.)(\mathbf D)_{i,j}=d(Z_{i,.},Z_{j,.})(D)i,j​=d(Zi,.​,Zj,.​). The objective is ∑i,jDi,jWi,j+R(W)\sum_{i,j}\mathbf D_{i,j}W_{i,j}+\mathcal R(W)∑i,j​Di,j​Wi,j​+R(W) with Rlog⁡(W)=∑i≠jτWi,j(log⁡Wi,j−1)\mathcal R_{\log}(W)=\sum_{i\ne j}\tau W_{i,j}(\log W_{i,j}-1)Rlog​(W)=∑i=j​τWi,j​(logWi,j​−1) (and 0log⁡0=00\log0=00log0=0). G\mathcal GG is the set of symmetric nonnegative matrices with zero diagonal, and Grsto\mathcal G_{\rm rsto}Grsto​ its right-stochastic elements. The kernels are e−Di,j/τ1{i≠j}e^{-\mathbf D_{i,j}/\tau}1_{\{i\ne j\}}e−Di,j​/τ1{i=j}​ and its row-normalised version. The cosine distance is 1−CosSim⁡1-\operatorname{CosSim}1−CosSim, and the SimCLR estimate is G^(Z)i,j=eCosSim⁡(zi,zj)/τ/∑k≠ieCosSim⁡(zi,zk)/τ\widehat G(Z)_{i,j}=e^{\operatorname{CosSim}(z_i,z_j)/\tau}/\sum_{k\ne i}e^{\operatorname{CosSim}(z_i,z_k)/\tau}G(Z)i,j​=eCosSim(zi​,zj​)/τ/∑k=i​eCosSim(zi​,zk​)/τ for i≠ji\ne ji=j, 000 on the diagonal.
  7. Linear probe (Section 6.1). L(W)=12∥Y−ZW∥F2\mathcal L(W)=\frac12\|Y-ZW\|_F^2L(W)=21​∥Y−ZW∥F2​ for a target Y∈RN×CY\in\mathbb{R}^{N\times C}Y∈RN×C.
  8. LDA scatter matrices (Appendix A.15). For labels y∈{1,…,C}Ny\in\{1,\dots,C\}^Ny∈{1,…,C}N with class sizes NcN_cNc​, Gi,j=1/NcG_{i,j}=1/N_cGi,j​=1/Nc​ if yi=yj=cy_i=y_j=cyi​=yj​=c and 000 otherwise. Then Σw=X⊤(I−G)X\Sigma_w=X^\top(I-G)XΣw​=X⊤(I−G)X and Σb=X⊤GX\Sigma_b=X^\top GXΣb​=X⊤GX.

Formalization Note Cov⁡\operatorname{Cov}Cov is normalised by NNN, as in the proofs of Appendix A.7-A.9 and the code for eq. (12). The code for eq. (2) uses torch.cov, which normalises by N−1N-1N−1. The sum in Lcov\mathcal L_{\rm cov}Lcov​ runs over all ordered off-diagonal pairs, as in the code for eq. (2). The indicator in eq. (3) is printed as 1{i=j}1_{\{i=j\}}1{i=j}​ and in eq. (16) as 1{1≠j}1_{\{1\ne j\}}1{1=j}​; both are read as 1{i≠j}1_{\{i\ne j\}}1{i=j}​. For zero vectors the cosine similarity takes Lean's value 0/0=00/0=00/0=0.

Definition code
import Mathlib

/-!
Balestriero and LeCun, *Contrastive and Non-Contrastive Self-Supervised Learning Recover Global
and Local Spectral Embedding Methods*, arXiv:2205.11508v3 (NeurIPS 2022): the relation matrix,
graph Laplacian and VICReg losses of Sections 2 and 3, the Laplacian-Eigenmaps problem of
Section 3.2, the graph estimates of SimCLR in Section 4.1, the linear-probe loss of Section 6.1
and the scatter matrices of the LDA argument in Appendix A.15.

A data set of `N` samples with `K`-dimensional embeddings is a matrix `Z : Matrix (Fin N) (Fin K) ℝ`
whose `i`-th row is the embedding of sample `i`.
-/

noncomputable section

namespace SSLSpectralEmbedding

open Matrix

variable {N K : ℕ}

/-- Section 2, p. 3 and Fig. 1: a relation matrix `G` is symmetric, has nonnegative entries and
zero diagonal; `G i j > 0` marks samples `i` and `j` as a positive pair. -/
def IsRelationMatrix (G : Matrix (Fin N) (Fin N) ℝ) : Prop :=
  G.IsSymm ∧ (∀ i j, 0 ≤ G i j) ∧ ∀ i, G i i = 0

/-- Section 3.1, below eq. (7), p. 6: the diagonal degree matrix `D` of `G`, `D i i = ∑ j, G i j`. -/
def degMat (G : Matrix (Fin N) (Fin N) ℝ) : Matrix (Fin N) (Fin N) ℝ :=
  Matrix.diagonal fun i => ∑ j, G i j

/-- Section 3.1, below eq. (7), p. 6: the graph Laplacian `L = D - G`. -/
def laplacian (G : Matrix (Fin N) (Fin N) ℝ) : Matrix (Fin N) (Fin N) ℝ :=
  degMat G - G

/-- Eq. (8), p. 6 and Appendix A.7: the centring matrix `H = I - (1/N) 1 1ᵀ` (the Laplacian of the
complete graph, scaled by `1/N`). -/
def centering (N : ℕ) : Matrix (Fin N) (Fin N) ℝ :=
  1 - Matrix.of fun _ _ => (1 / (N : ℝ))

/-- Appendix A.7–A.9: the covariance matrix of the columns of `Z`, `Cov(Z) = (1/N) Zᵀ H Z`
(normalised by `N`). -/
def cov (Z : Matrix (Fin N) (Fin K) ℝ) : Matrix (Fin K) (Fin K) ℝ :=
  (1 / (N : ℝ)) • (Zᵀ * centering N * Z)

/-- Eq. (2) and eq. (7): the pairwise sum `∑_{i,j} G i j ‖Z_{i,.} - Z_{j,.}‖²` of the invariance
term. -/
def pairSum (G : Matrix (Fin N) (Fin N) ℝ) (Z : Matrix (Fin N) (Fin K) ℝ) : ℝ :=
  ∑ i, ∑ j, G i j * ∑ k, (Z i k - Z j k) ^ 2

/-- Eq. (2): the invariance term `L_inv(Z) = (γ/N) ∑_{i,j} G i j ‖Z_{i,.} - Z_{j,.}‖²`. -/
def invTerm (γ : ℝ) (G : Matrix (Fin N) (Fin N) ℝ) (Z : Matrix (Fin N) (Fin K) ℝ) : ℝ :=
  γ / N * pairSum G Z

/-- Eq. (2): the variance (hinge) term `L_var(Z) = ∑_k max(0, 1 - √Cov(Z)_{k,k})`. -/
def varTerm (Z : Matrix (Fin N) (Fin K) ℝ) : ℝ :=
  ∑ k, max 0 (1 - Real.sqrt (cov Z k k))

/-- Eq. (2): the covariance term `L_cov(Z) = ∑_k ∑_{j ≠ k} Cov(Z)_{k,j}²`. -/
def covTerm (Z : Matrix (Fin N) (Fin K) ℝ) : ℝ :=
  ∑ k, ∑ j, if j = k then 0 else cov Z k j ^ 2

/-- Eq. (2), p. 4: the VICReg loss `α L_var + β L_cov + L_inv`. -/
def vicLoss (α β γ : ℝ) (G : Matrix (Fin N) (Fin N) ℝ) (Z : Matrix (Fin N) (Fin K) ℝ) : ℝ :=
  α * varTerm Z + β * covTerm Z + invTerm γ G Z

/-- Section 3.1, p. 5: the VICReg loss with the hinge variance term replaced by the squared loss
`∑_k (1 - Cov(Z)_{k,k})²`. -/
def vicLossSq (α β γ : ℝ) (G : Matrix (Fin N) (Fin N) ℝ) (Z : Matrix (Fin N) (Fin K) ℝ) : ℝ :=
  α * ∑ k, (1 - cov Z k k) ^ 2 + β * covTerm Z + invTerm γ G Z

/-- Eq. (8), p. 6: the matrix `I - (1/N) 1 1ᵀ - (γ/α)(D - G)` whose eigendecomposition gives the
optimal VICReg representation. -/
def vicMat (α γ : ℝ) (G : Matrix (Fin N) (Fin N) ℝ) : Matrix (Fin N) (Fin N) ℝ :=
  centering N - (γ / α) • laplacian G

/-- Eq. (8): `M = P diag(λ) Pᵀ` with `P` orthogonal and the eigenvalues `λ` in descending order. -/
def IsDescEigendecomp (M P : Matrix (Fin N) (Fin N) ℝ) (lam : Fin N → ℝ) : Prop :=
  Pᵀ * P = 1 ∧ M = P * Matrix.diagonal lam * Pᵀ ∧ Antitone lam

/-- Theorem 1, p. 7: `Z*_{α,γ} = (P (diag(λ) N)^{1/2})_{:,1:K}`, the first `K` columns of `P`
scaled by `√(N λ_k)`. -/
def vicOpt (P : Matrix (Fin N) (Fin N) ℝ) (lam : Fin N → ℝ) (hKN : K ≤ N) :
    Matrix (Fin N) (Fin K) ℝ :=
  fun i k => P i (Fin.castLE hKN k) * Real.sqrt (lam (Fin.castLE hKN k) * N)

/-- Eq. (11), p. 9 and Section 3.2: an optimal Laplacian-Eigenmaps representation `Z*_LE`: it
minimises `Tr(Zᵀ (D - G) Z)` subject to `Zᵀ D Z = I`, among representations whose columns have
zero mean (LE discards the eigenvector of the eigenvalue `0`). -/
def IsLESolution (G : Matrix (Fin N) (Fin N) ℝ) (Z : Matrix (Fin N) (Fin K) ℝ) : Prop :=
  (Zᵀ * degMat G * Z = 1 ∧ ∀ k, ∑ i, Z i k = 0) ∧
    ∀ Z' : Matrix (Fin N) (Fin K) ℝ, Z'ᵀ * degMat G * Z' = 1 → (∀ k, ∑ i, Z' i k = 0) →
      (Zᵀ * laplacian G * Z).trace ≤ (Z'ᵀ * laplacian G * Z').trace

/-- Eq. (12), p. 10: `B = Cov(X) - (γ/(α N)) Xᵀ L X`, whose square root gives the optimal weights of
linear VICReg. -/
def linB {D : ℕ} (α γ : ℝ) (G : Matrix (Fin N) (Fin N) ℝ) (X : Matrix (Fin N) (Fin D) ℝ) :
    Matrix (Fin D) (Fin D) ℝ :=
  cov X - (γ / (α * N)) • (Xᵀ * laplacian G * X)

/-- Section 4.1, p. 11: the matrix of pairwise distances `(D)_{i,j} = d(f(x_i), f(x_j))` of the
embeddings (rows of `Z`). -/
def distMat (d : (Fin K → ℝ) → (Fin K → ℝ) → ℝ) (Z : Matrix (Fin N) (Fin K) ℝ) :
    Matrix (Fin N) (Fin N) ℝ :=
  fun i j => d (Z i) (Z j)

/-- Eq. (14), p. 11: the graph-estimation objective `∑_{i,j} (D)_{i,j} (G)_{i,j} + R(G)`. -/
def graphObjective (Dm : Matrix (Fin N) (Fin N) ℝ) (R : Matrix (Fin N) (Fin N) ℝ → ℝ)
    (W : Matrix (Fin N) (Fin N) ℝ) : ℝ :=
  ∑ i, ∑ j, Dm i j * W i j + R W

/-- Eq. (15), p. 11: the entropic regulariser `R_log(G) = ∑_{i≠j} τ G_{i,j} (log G_{i,j} - 1)`
(with `0 log 0 = 0`). -/
def entropyReg (τ : ℝ) (W : Matrix (Fin N) (Fin N) ℝ) : ℝ :=
  ∑ i, ∑ j, if i = j then 0 else τ * W i j * (Real.log (W i j) - 1)

/-- Section 4.1, p. 11: `𝒢`, the symmetric matrices with nonnegative entries and zero diagonal. -/
def graphSet (N : ℕ) : Set (Matrix (Fin N) (Fin N) ℝ) :=
  {W | W.IsSymm ∧ (∀ i j, 0 ≤ W i j) ∧ ∀ i, W i i = 0}

/-- Section 4.1, p. 11: `𝒢_rsto = {G ∈ 𝒢 : G 1 = 1}`, the right-stochastic elements of `𝒢`. -/
def rstoSet (N : ℕ) : Set (Matrix (Fin N) (Fin N) ℝ) :=
  {W | W ∈ graphSet N ∧ ∀ i, ∑ j, W i j = 1}

/-- Appendix A.10, p. 27: the set over which the proof of Theorem 4 solves the `𝒢_rsto` problem:
nonnegative, zero-diagonal, right-stochastic matrices (the proof does not impose symmetry). -/
def rowStochSet (N : ℕ) : Set (Matrix (Fin N) (Fin N) ℝ) :=
  {W | (∀ i j, 0 ≤ W i j) ∧ (∀ i, W i i = 0) ∧ ∀ i, ∑ j, W i j = 1}

/-- Eq. (16), first line: `(Ĝ)_{i,j} = exp(-(D)_{i,j}/τ) 1_{i≠j}`. -/
def expKernel (τ : ℝ) (Dm : Matrix (Fin N) (Fin N) ℝ) : Matrix (Fin N) (Fin N) ℝ :=
  fun i j => if i = j then 0 else Real.exp (-Dm i j / τ)

/-- Eq. (16), second line: `(Ĝ)_{i,j} = exp(-(D)_{i,j}/τ) / ∑_{k≠i} exp(-(D)_{i,k}/τ) 1_{i≠j}`. -/
def softmaxKernel (τ : ℝ) (Dm : Matrix (Fin N) (Fin N) ℝ) : Matrix (Fin N) (Fin N) ℝ :=
  fun i j => if i = j then 0 else
    Real.exp (-Dm i j / τ) / ∑ k, (if k = i then 0 else Real.exp (-Dm i k / τ))

/-- Section 2, p. 4: the cosine similarity `⟨u, v⟩ / (‖u‖₂ ‖v‖₂)`. -/
def cosSim (u v : Fin K → ℝ) : ℝ :=
  (∑ k, u k * v k) / (Real.sqrt (∑ k, u k ^ 2) * Real.sqrt (∑ k, v k ^ 2))

/-- Appendix A.10, p. 28: the cosine distance `1 - ⟨u, v⟩ / (‖u‖ ‖v‖)`. -/
def cosineDist (u v : Fin K → ℝ) : ℝ :=
  1 - cosSim u v

/-- Eq. (3), p. 4: the SimCLR similarity estimate
`(Ĝ(Z))_{i,j} = exp(CosSim(z_i,z_j)/τ) / ∑_{k≠i} exp(CosSim(z_i,z_k)/τ)` for `i ≠ j`, and `0` on the
diagonal. -/
def simclrSim (τ : ℝ) (Z : Matrix (Fin N) (Fin K) ℝ) : Matrix (Fin N) (Fin N) ℝ :=
  fun i j => if i = j then 0 else
    Real.exp (cosSim (Z i) (Z j) / τ) / ∑ k, (if k = i then 0 else Real.exp (cosSim (Z i) (Z k) / τ))

/-- Squared Frobenius norm `‖A‖_F²`. -/
def frobSq {m n : ℕ} (A : Matrix (Fin m) (Fin n) ℝ) : ℝ :=
  ∑ i, ∑ j, A i j ^ 2

/-- Section 6.1, p. 15: the linear-probe loss `L(W) = (1/2) ‖Y - Z W‖_F²`. -/
def lsLoss {C : ℕ} (Y : Matrix (Fin N) (Fin C) ℝ) (Z : Matrix (Fin N) (Fin K) ℝ)
    (W : Matrix (Fin K) (Fin C) ℝ) : ℝ :=
  (1 / 2) * frobSq (Y - Z * W)

/-- Appendix A.15, p. 30: the supervised relation matrix normalised to degree `I`:
`(G)_{i,j} = 1/N_c` if samples `i` and `j` both belong to class `c` (with `N_c` samples), else `0`. -/
def ldaRelation {C : ℕ} (y : Fin N → Fin C) : Matrix (Fin N) (Fin N) ℝ :=
  fun i j => if y i = y j then 1 / ((Finset.univ.filter fun k => y k = y i).card : ℝ) else 0

/-- Appendix A.15, p. 30: the within-class scatter `Σ_w = Xᵀ (I - G) X`. -/
def withinScatter {D C : ℕ} (X : Matrix (Fin N) (Fin D) ℝ) (y : Fin N → Fin C) :
    Matrix (Fin D) (Fin D) ℝ :=
  Xᵀ * (1 - ldaRelation y) * X

/-- Appendix A.15, p. 30: the between-class scatter `Σ_b = Xᵀ G X`. -/
def betweenScatter {D C : ℕ} (X : Matrix (Fin N) (Fin D) ℝ) (y : Fin N → Fin C) :
    Matrix (Fin D) (Fin D) ℝ :=
  Xᵀ * ldaRelation y * X

end SSLSpectralEmbedding
Source
Balestriero and LeCun, Contrastive and Non-Contrastive Self-Supervised Learning Recover Global and Local Spectral Embedding Methods, arXiv:2205.11508v3 (NeurIPS 2022), Sections 2, 3.1-3.3, 4.1, 6.1 and Appendix A.15
Read-back

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

Throughout, NNN and KKK are arbitrary natural numbers (including 000). All matrices are real, and rows and columns are indexed by {1,…,N}\{1,\dots,N\}{1,…,N} or {1,…,K}\{1,\dots,K\}{1,…,K}. A data matrix Z∈RN×KZ \in \mathbb{R}^{N\times K}Z∈RN×K has iii-th row zi∈RKz_i \in \mathbb{R}^Kzi​∈RK. Several conventions of the underlying system matter below:

  • division by zero returns 000;
  • the square root of a negative number returns 000;
  • log⁡0=0\log 0 = 0log0=0, and log⁡x=log⁡∣x∣\log x = \log|x|logx=log∣x∣ for x<0x<0x<0.

Relation matrix. A matrix G∈RN×NG \in \mathbb{R}^{N\times N}G∈RN×N is called a relation matrix when it satisfies all three of the following:

  • G⊤=GG^\top = GG⊤=G;
  • Gij≥0G_{ij} \ge 0Gij​≥0 for all i,ji,ji,j;
  • Gii=0G_{ii} = 0Gii​=0 for all iii.

No other condition is imposed. In particular, GGG need not be nonzero, need not be connected, and need not have positive row sums. For N=0N=0N=0 the condition holds trivially.

Degree matrix. For any G∈RN×NG \in \mathbb{R}^{N\times N}G∈RN×N (no assumptions), the degree matrix D(G)D(G)D(G) is the N×NN\times NN×N diagonal matrix of row sums of GGG:

D(G)ii=∑j=1NGij,D(G)ij=0 (i≠j).D(G)_{ii} = \sum_{j=1}^N G_{ij}, \qquad D(G)_{ij} = 0 \ (i\ne j).D(G)ii​=j=1∑N​Gij​,D(G)ij​=0 (i=j).

Graph Laplacian. For any G∈RN×NG \in \mathbb{R}^{N\times N}G∈RN×N (no assumptions), the Laplacian is

L(G)=D(G)−G.L(G) = D(G) - G.L(G)=D(G)−G.

Centring matrix. For a natural number NNN, HNH_NHN​ is the N×NN\times NN×N matrix

HN=IN−1N 11⊤,H_N = I_N - \tfrac{1}{N}\,\mathbf{1}\mathbf{1}^\top,HN​=IN​−N1​11⊤,

that is, (HN)ij=δij−1/N(H_N)_{ij} = \delta_{ij} - 1/N(HN​)ij​=δij​−1/N. For N=0N=0N=0 it is the empty matrix.

Covariance. For Z∈RN×KZ \in \mathbb{R}^{N\times K}Z∈RN×K,

Cov⁡(Z)=1N Z⊤HNZ∈RK×K.\operatorname{Cov}(Z) = \tfrac{1}{N}\, Z^\top H_N Z \in \mathbb{R}^{K\times K}.Cov(Z)=N1​Z⊤HN​Z∈RK×K.

The normalisation is by NNN, not N−1N-1N−1. When N=0N=0N=0, the factor 1/N1/N1/N is 000, and Cov⁡(Z)\operatorname{Cov}(Z)Cov(Z) is the zero K×KK\times KK×K matrix.

Pairwise sum. For any G∈RN×NG \in \mathbb{R}^{N\times N}G∈RN×N and Z∈RN×KZ \in \mathbb{R}^{N\times K}Z∈RN×K,

S(G,Z)=∑i=1N∑j=1NGij∑k=1K(Zik−Zjk)2=∑i,jGij ∥zi−zj∥22.S(G,Z) = \sum_{i=1}^N\sum_{j=1}^N G_{ij}\sum_{k=1}^K (Z_{ik}-Z_{jk})^2 = \sum_{i,j} G_{ij}\,\|z_i - z_j\|_2^2.S(G,Z)=i=1∑N​j=1∑N​Gij​k=1∑K​(Zik​−Zjk​)2=i,j∑​Gij​∥zi​−zj​∥22​.

The sum runs over all ordered pairs (i,j)(i,j)(i,j), including i=ji=ji=j (those terms vanish).

Invariance term. For a real γ\gammaγ, any GGG, and any ZZZ,

Linvγ(G,Z)=γN S(G,Z).L_{\mathrm{inv}}^{\gamma}(G,Z) = \frac{\gamma}{N}\, S(G,Z).Linvγ​(G,Z)=Nγ​S(G,Z).

When N=0N=0N=0, this is 000.

Variance term. For Z∈RN×KZ \in \mathbb{R}^{N\times K}Z∈RN×K,

Lvar(Z)=∑k=1Kmax⁡ ⁣(0, 1−Cov⁡(Z)kk).L_{\mathrm{var}}(Z) = \sum_{k=1}^K \max\!\Big(0,\ 1 - \sqrt{\operatorname{Cov}(Z)_{kk}}\Big).Lvar​(Z)=k=1∑K​max(0, 1−Cov(Z)kk​​).

The square root is taken with the convention x=0\sqrt{x} = 0x​=0 for x<0x<0x<0. For K=0K=0K=0, Lvar(Z)=0L_{\mathrm{var}}(Z) = 0Lvar​(Z)=0.

Covariance term. For Z∈RN×KZ \in \mathbb{R}^{N\times K}Z∈RN×K,

Lcov(Z)=∑k=1K∑j=1j≠kKCov⁡(Z)kj2.L_{\mathrm{cov}}(Z) = \sum_{k=1}^K \sum_{\substack{j=1\\ j\ne k}}^K \operatorname{Cov}(Z)_{kj}^2.Lcov​(Z)=k=1∑K​j=1j=k​∑K​Cov(Z)kj2​.

The sum is over ordered pairs, so each unordered off-diagonal pair {j,k}\{j,k\}{j,k} is counted twice.

VICReg loss. For arbitrary reals α,β,γ\alpha,\beta,\gammaα,β,γ (no sign constraints), any G∈RN×NG \in \mathbb{R}^{N\times N}G∈RN×N (not required to be a relation matrix), and any Z∈RN×KZ \in \mathbb{R}^{N\times K}Z∈RN×K,

Lα,β,γ(G,Z)=α Lvar(Z)+β Lcov(Z)+γN∑i,jGij∥zi−zj∥22.\mathcal{L}_{\alpha,\beta,\gamma}(G,Z) = \alpha\, L_{\mathrm{var}}(Z) + \beta\, L_{\mathrm{cov}}(Z) + \frac{\gamma}{N}\sum_{i,j} G_{ij}\|z_i-z_j\|_2^2.Lα,β,γ​(G,Z)=αLvar​(Z)+βLcov​(Z)+Nγ​i,j∑​Gij​∥zi​−zj​∥22​.

Squared-variance VICReg loss. For arbitrary reals α,β,γ\alpha,\beta,\gammaα,β,γ, any GGG, and any ZZZ,

Lα,β,γsq(G,Z)=α∑k=1K(1−Cov⁡(Z)kk)2+β Lcov(Z)+γN∑i,jGij∥zi−zj∥22.\mathcal{L}^{\mathrm{sq}}_{\alpha,\beta,\gamma}(G,Z) = \alpha\sum_{k=1}^K \big(1 - \operatorname{Cov}(Z)_{kk}\big)^2 + \beta\, L_{\mathrm{cov}}(Z) + \frac{\gamma}{N}\sum_{i,j} G_{ij}\|z_i-z_j\|_2^2.Lα,β,γsq​(G,Z)=αk=1∑K​(1−Cov(Z)kk​)2+βLcov​(Z)+Nγ​i,j∑​Gij​∥zi​−zj​∥22​.

This is the same as L\mathcal{L}L, except that the hinge on Cov⁡kk\sqrt{\operatorname{Cov}_{kk}}Covkk​​ is replaced by the square of 1−Cov⁡kk1-\operatorname{Cov}_{kk}1−Covkk​. No square root is involved.

VICReg matrix. For reals α,γ\alpha,\gammaα,γ and any G∈RN×NG \in \mathbb{R}^{N\times N}G∈RN×N,

Mα,γ(G)=HN−γα (D(G)−G).M_{\alpha,\gamma}(G) = H_N - \frac{\gamma}{\alpha}\,\big(D(G) - G\big).Mα,γ​(G)=HN​−αγ​(D(G)−G).

When α=0\alpha = 0α=0, the coefficient γ/α\gamma/\alphaγ/α is 000, so M0,γ(G)=HNM_{0,\gamma}(G) = H_NM0,γ​(G)=HN​.

Descending eigendecomposition. For M,P∈RN×NM, P \in \mathbb{R}^{N\times N}M,P∈RN×N and λ∈RN\lambda \in \mathbb{R}^Nλ∈RN, the predicate holds when all three of the following are true:

  • P⊤P=INP^\top P = I_NP⊤P=IN​, so PPP is orthogonal;
  • M=P diag⁡(λ) P⊤M = P\,\operatorname{diag}(\lambda)\,P^\topM=Pdiag(λ)P⊤;
  • λ\lambdaλ is non-increasing, meaning λi≥λj\lambda_i \ge \lambda_jλi​≥λj​ whenever i≤ji \le ji≤j.

Ties are allowed. No separate symmetry assumption on MMM is stated.

VICReg optimum. Given P∈RN×NP \in \mathbb{R}^{N\times N}P∈RN×N, λ∈RN\lambda \in \mathbb{R}^Nλ∈RN (no assumptions on either), and K≤NK \le NK≤N, this is the N×KN\times KN×K matrix built from the first KKK columns of PPP, each scaled:

Zik∗=Pik λk N,1≤i≤N, 1≤k≤K.Z^*_{ik} = P_{ik}\,\sqrt{\lambda_k\, N}, \qquad 1\le i\le N,\ 1\le k\le K.Zik∗​=Pik​λk​N​,1≤i≤N, 1≤k≤K.

If λkN<0\lambda_k N < 0λk​N<0, the square root is 000 and the whole kkk-th column is 000.

Laplacian-Eigenmaps solution. For any G∈RN×NG \in \mathbb{R}^{N\times N}G∈RN×N (no assumptions) and Z∈RN×KZ \in \mathbb{R}^{N\times K}Z∈RN×K, the predicate says that ZZZ is feasible and optimal:

  1. Feasibility: Z⊤D(G) Z=IKZ^\top D(G)\, Z = I_KZ⊤D(G)Z=IK​, and every column of ZZZ has unweighted sum zero, ∑iZik=0\sum_{i} Z_{ik} = 0∑i​Zik​=0 for every kkk.
  2. Optimality: for every Z′∈RN×KZ' \in \mathbb{R}^{N\times K}Z′∈RN×K that satisfies the same two constraints,
tr⁡ ⁣(Z⊤(D(G)−G) Z)≤tr⁡ ⁣(Z′⊤(D(G)−G) Z′).\operatorname{tr}\!\big(Z^\top (D(G)-G)\, Z\big) \le \operatorname{tr}\!\big(Z'^\top (D(G)-G)\, Z'\big).tr(Z⊤(D(G)−G)Z)≤tr(Z′⊤(D(G)−G)Z′).

If no matrix satisfies the constraints, no ZZZ satisfies the predicate. Note that the zero-mean constraint is the plain column sum, not a DDD-weighted sum.

Linear-VICReg matrix. For a natural number DDD, reals α,γ\alpha,\gammaα,γ, any G∈RN×NG \in \mathbb{R}^{N\times N}G∈RN×N, and X∈RN×DX \in \mathbb{R}^{N\times D}X∈RN×D,

B=Cov⁡(X)−γαN X⊤(D(G)−G) X∈RD×D.B = \operatorname{Cov}(X) - \frac{\gamma}{\alpha N}\, X^\top (D(G)-G)\, X \in \mathbb{R}^{D\times D}.B=Cov(X)−αNγ​X⊤(D(G)−G)X∈RD×D.

When αN=0\alpha N = 0αN=0, the coefficient is 000 and B=Cov⁡(X)B = \operatorname{Cov}(X)B=Cov(X).

Distance matrix. For an arbitrary function d:RK×RK→Rd:\mathbb{R}^K\times\mathbb{R}^K\to\mathbb{R}d:RK×RK→R (no metric axioms assumed) and Z∈RN×KZ \in \mathbb{R}^{N\times K}Z∈RN×K, the distance matrix Δ∈RN×N\Delta \in \mathbb{R}^{N\times N}Δ∈RN×N has entries

Δij=d(zi,zj).\Delta_{ij} = d(z_i, z_j).Δij​=d(zi​,zj​).

Graph-estimation objective. For any Δ∈RN×N\Delta \in \mathbb{R}^{N\times N}Δ∈RN×N, any function R:RN×N→RR:\mathbb{R}^{N\times N}\to\mathbb{R}R:RN×N→R, and any W∈RN×NW \in \mathbb{R}^{N\times N}W∈RN×N,

ΦΔ,R(W)=∑i,jΔijWij+R(W).\Phi_{\Delta,R}(W) = \sum_{i,j}\Delta_{ij}W_{ij} + R(W).ΦΔ,R​(W)=i,j∑​Δij​Wij​+R(W).

Entropic regulariser. For a real τ\tauτ and any W∈RN×NW \in \mathbb{R}^{N\times N}W∈RN×N,

Rlog⁡τ(W)=∑i≠jτ Wij(log⁡Wij−1).R_{\log}^{\tau}(W) = \sum_{i\ne j} \tau\, W_{ij}\big(\log W_{ij} - 1\big).Rlogτ​(W)=i=j∑​τWij​(logWij​−1).

The diagonal is excluded. Entries with Wij=0W_{ij}=0Wij​=0 contribute 000, because log⁡0=0\log 0 = 0log0=0 by convention. Negative entries are allowed, and for them log⁡Wij\log W_{ij}logWij​ means log⁡∣Wij∣\log|W_{ij}|log∣Wij​∣.

Graph set. GN\mathcal{G}_NGN​ is the set of all W∈RN×NW \in \mathbb{R}^{N\times N}W∈RN×N that satisfy all three of the following:

  • W⊤=WW^\top = WW⊤=W;
  • Wij≥0W_{ij}\ge 0Wij​≥0 for all i,ji,ji,j;
  • Wii=0W_{ii}=0Wii​=0 for all iii.

These are the same three conditions as for a relation matrix.

Right-stochastic graph set. GNrsto={W∈GN:∑jWij=1 for every i}\mathcal{G}^{\mathrm{rsto}}_N = \{W \in \mathcal{G}_N : \sum_j W_{ij} = 1 \text{ for every } i\}GNrsto​={W∈GN​:∑j​Wij​=1 for every i}. These matrices are symmetric, nonnegative, zero-diagonal, and have every row summing to 111. For N=1N=1N=1 the set is empty: the only zero-diagonal matrix is [0][0][0], whose row sum is 000. For N=0N=0N=0 the set contains the empty matrix.

Row-stochastic set. RN\mathcal{R}_NRN​ is the set of all W∈RN×NW \in \mathbb{R}^{N\times N}W∈RN×N that satisfy all three of the following:

  • Wij≥0W_{ij}\ge 0Wij​≥0 for all i,ji,ji,j;
  • Wii=0W_{ii}=0Wii​=0 for all iii;
  • ∑jWij=1\sum_j W_{ij}=1∑j​Wij​=1 for every iii.

Symmetry is not required. For N=1N=1N=1 this set is empty, and for N=0N=0N=0 it contains the empty matrix.

Exponential kernel. For a real τ\tauτ and any Δ∈RN×N\Delta \in \mathbb{R}^{N\times N}Δ∈RN×N,

G^ij={0i=j,exp⁡(−Δij/τ)i≠j.\hat G_{ij} = \begin{cases} 0 & i=j,\\ \exp(-\Delta_{ij}/\tau) & i\ne j.\end{cases}G^ij​={0exp(−Δij​/τ)​i=j,i=j.​

When τ=0\tau = 0τ=0, every off-diagonal entry equals exp⁡(0)=1\exp(0)=1exp(0)=1.

Softmax kernel. For a real τ\tauτ and any Δ∈RN×N\Delta \in \mathbb{R}^{N\times N}Δ∈RN×N,

G^ij={0i=j,exp⁡(−Δij/τ)∑k≠iexp⁡(−Δik/τ)i≠j.\hat G_{ij} = \begin{cases} 0 & i=j,\\[2pt] \dfrac{\exp(-\Delta_{ij}/\tau)}{\sum_{k\ne i}\exp(-\Delta_{ik}/\tau)} & i\ne j.\end{cases}G^ij​=⎩⎨⎧​0∑k=i​exp(−Δik​/τ)exp(−Δij​/τ)​​i=j,i=j.​

For N≥2N\ge 2N≥2 the denominators are positive. When τ=0\tau = 0τ=0, every off-diagonal entry is 1/(N−1)1/(N-1)1/(N−1).

Cosine similarity. For u,v∈RKu,v\in\mathbb{R}^Ku,v∈RK,

CosSim⁡(u,v)=⟨u,v⟩∥u∥2 ∥v∥2.\operatorname{CosSim}(u,v) = \frac{\langle u,v\rangle}{\|u\|_2\,\|v\|_2}.CosSim(u,v)=∥u∥2​∥v∥2​⟨u,v⟩​.

If u=0u=0u=0 or v=0v=0v=0 (in particular whenever K=0K=0K=0), the denominator is 000 and the value is 000.

Cosine distance. For u,v∈RKu,v\in\mathbb{R}^Ku,v∈RK,

CosDist⁡(u,v)=1−CosSim⁡(u,v).\operatorname{CosDist}(u,v) = 1 - \operatorname{CosSim}(u,v).CosDist(u,v)=1−CosSim(u,v).

This equals 111 whenever u=0u=0u=0 or v=0v=0v=0.

SimCLR similarity. For a real τ\tauτ and Z∈RN×KZ\in\mathbb{R}^{N\times K}Z∈RN×K, the N×NN\times NN×N matrix G^(Z)\hat G(Z)G^(Z) has entries

G^(Z)ij={0i=j,exp⁡(CosSim⁡(zi,zj)/τ)∑k≠iexp⁡(CosSim⁡(zi,zk)/τ)i≠j.\hat G(Z)_{ij} = \begin{cases} 0 & i=j,\\[2pt] \dfrac{\exp\big(\operatorname{CosSim}(z_i,z_j)/\tau\big)}{\sum_{k\ne i}\exp\big(\operatorname{CosSim}(z_i,z_k)/\tau\big)} & i\ne j.\end{cases}G^(Z)ij​=⎩⎨⎧​0∑k=i​exp(CosSim(zi​,zk​)/τ)exp(CosSim(zi​,zj​)/τ)​​i=j,i=j.​

The exponent is +CosSim⁡/τ+\operatorname{CosSim}/\tau+CosSim/τ (similarity, not distance). When τ=0\tau=0τ=0, every off-diagonal entry is 1/(N−1)1/(N-1)1/(N−1). Zero rows of ZZZ have cosine similarity 000 with everything.

Squared Frobenius norm. For A∈Rm×nA\in\mathbb{R}^{m\times n}A∈Rm×n,

∥A∥F2=∑i=1m∑j=1nAij2.\|A\|_F^2 = \sum_{i=1}^m\sum_{j=1}^n A_{ij}^2.∥A∥F2​=i=1∑m​j=1∑n​Aij2​.

Linear-probe loss. For a natural number CCC, Y∈RN×CY\in\mathbb{R}^{N\times C}Y∈RN×C, Z∈RN×KZ\in\mathbb{R}^{N\times K}Z∈RN×K, and W∈RK×CW\in\mathbb{R}^{K\times C}W∈RK×C,

L(W)=12 ∥Y−ZW∥F2.\mathcal{L}(W) = \tfrac12\,\|Y - ZW\|_F^2.L(W)=21​∥Y−ZW∥F2​.

Supervised (LDA) relation matrix. For a natural number CCC and a labelling y:{1,…,N}→{1,…,C}y:\{1,\dots,N\}\to\{1,\dots,C\}y:{1,…,N}→{1,…,C}, let Nc=#{k:yk=c}N_c = \#\{k : y_k = c\}Nc​=#{k:yk​=c}. The matrix Gy∈RN×NG^y\in\mathbb{R}^{N\times N}Gy∈RN×N has entries

Gijy={1/Nyiyi=yj,0otherwise.G^y_{ij} = \begin{cases} 1/N_{y_i} & y_i = y_j,\\ 0 & \text{otherwise}.\end{cases}Gijy​={1/Nyi​​0​yi​=yj​,otherwise.​

Since iii itself has label yiy_iyi​, the count Nyi≥1N_{y_i}\ge 1Nyi​​≥1. The diagonal entries are Giiy=1/Nyi>0G^y_{ii} = 1/N_{y_i} > 0Giiy​=1/Nyi​​>0, not 000. So this matrix does not have the zero diagonal required of a relation matrix above.

Within-class scatter. For natural numbers D,CD,CD,C, X∈RN×DX\in\mathbb{R}^{N\times D}X∈RN×D, and labels yyy,

Σw=X⊤(IN−Gy)X∈RD×D.\Sigma_w = X^\top\big(I_N - G^y\big)X \in\mathbb{R}^{D\times D}.Σw​=X⊤(IN​−Gy)X∈RD×D.

No centring and no 1/N1/N1/N normalisation are applied.

Between-class scatter. For natural numbers D,CD,CD,C, X∈RN×DX\in\mathbb{R}^{N\times D}X∈RN×D, and labels yyy,

Σb=X⊤GyX∈RD×D.\Sigma_b = X^\top G^y X \in\mathbb{R}^{D\times D}.Σb​=X⊤GyX∈RD×D.

No centring and no normalisation are applied.

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

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 24, 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