Cross-entropy and symmetric losses on the sphere, simplex ETFs, and the relaxed energy
DefinitionNeuralCollapseCE_BasicObjects of Section 1 of Lu and Steinerberger, Neural collapse with cross-entropy loss (arXiv:2012.08465).
- Configurations. Points with the Euclidean norm and inner product . A configuration is admissible if for every . The unit sphere of is written , as in the paper.
- Symmetric loss (eq. 1). For ,
- Cross-entropy loss (eq. 2).
- Global minimisers. is a global minimiser of if it is admissible and for every admissible . is a global minimiser of if and are admissible and for all admissible .
- Simplex equiangular tight frame. Unit vectors with for all .
- Uniform measure and empirical measures. is the surface measure of normalised to total mass . For points , .
- Relaxed energy (eq. 3). For a measure on ,
Formalization Note is EuclideanSpace ℝ (Fin d) and is its unit sphere Metric.sphere 0 1, so here is the sphere of dimension (the paper's own notation). The uniform measure is Mathlib's Measure.toSphere of Lebesgue measure divided by its total mass. The simplex ETF is defined by unit norms and the pairwise inner products , which is the characterisation the paper's proofs use; the formula is meant for , and every statement using it assumes .
import Mathlib
/-!
Lu and Steinerberger, *Neural collapse with cross-entropy loss*, arXiv:2012.08465v2 (2021):
the unit-sphere configurations, the symmetric loss `L_α` (eq. (1)), the cross-entropy loss `L`
(eq. (2)), their constrained global minimisers (Theorems 1 and 2), the simplex equiangular tight
frame, the uniform probability measure on the sphere, the empirical measure of a configuration
(Theorem 3) and the relaxed energy `L_α(μ)` on probability measures (eq. (3), Proposition 4),
all from Section 1.
-/
open MeasureTheory
noncomputable section
namespace NeuralCollapseCE
/-- Section 1.1, p. 1: the feature space `ℝ^d` with the Euclidean norm `‖·‖` and inner
product `⟨·,·⟩`. -/
abbrev Vec (d : ℕ) : Type := EuclideanSpace ℝ (Fin d)
/-- Section 1.3, Theorem 3, p. 3: the unit sphere `S^d = {x ∈ ℝ^d : ‖x‖ = 1}` (the paper writes
`S^d` for the unit sphere of `ℝ^d`, on which the points `u_i ∈ ℝ^d`, `‖u_i‖ = 1` lie). -/
abbrev Sph (d : ℕ) : Type := Metric.sphere (0 : Vec d) 1
/-- Section 1.1, eqs. (1)-(2), p. 1, and Theorems 1-3: the constraint `‖u_i‖ = 1` for
`i = 1, …, n`. -/
def IsUnitConfig {n d : ℕ} (u : Fin n → Vec d) : Prop :=
∀ i, ‖u i‖ = 1
/-- Eq. (1), p. 1: the symmetric loss
`L_α(u) = ∑_{i=1}^n log (1 + ∑_{j ≠ i} exp (α (⟨u_j, u_i⟩ - 1)))`. -/
def symLoss {n d : ℕ} (α : ℝ) (u : Fin n → Vec d) : ℝ :=
∑ i, Real.log (1 + ∑ j ∈ Finset.univ.erase i, Real.exp (α * (inner ℝ (u j) (u i) - 1)))
/-- Eq. (2), p. 1: the cross-entropy loss
`L(u, v) = ∑_{i=1}^n log ((∑_{j=1}^n exp ⟨v_j, u_i⟩) / exp ⟨v_i, u_i⟩)`. -/
def ceLoss {n d : ℕ} (u v : Fin n → Vec d) : ℝ :=
∑ i, Real.log ((∑ j, Real.exp (inner ℝ (v j) (u i))) / Real.exp (inner ℝ (v i) (u i)))
/-- Theorem 2, p. 2 (and Theorem 3, p. 3): `u` is a global minimiser of `L_α(u)` subject to
`u_i ∈ ℝ^d`, `‖u_i‖ = 1`, `i = 1, …, n`. -/
def IsSymMinimizer {n d : ℕ} (α : ℝ) (u : Fin n → Vec d) : Prop :=
IsUnitConfig u ∧ ∀ w : Fin n → Vec d, IsUnitConfig w → symLoss α u ≤ symLoss α w
/-- Theorem 1, p. 2: `(u, v)` is a global minimiser of `L(u, v)` subject to `u_i, v_i ∈ ℝ^d`,
`‖u_i‖ = ‖v_i‖ = 1`, `i = 1, …, n`. -/
def IsCEMinimizer {n d : ℕ} (u v : Fin n → Vec d) : Prop :=
IsUnitConfig u ∧ IsUnitConfig v ∧
∀ u' v' : Fin n → Vec d, IsUnitConfig u' → IsUnitConfig v' → ceLoss u v ≤ ceLoss u' v'
/-- Theorems 1 and 2, p. 2: `{u_i}_{i=1}^n` form a simplex equiangular tight frame, i.e. unit
vectors with `⟨u_i, u_j⟩ = -1/(n-1)` for `i ≠ j` (the characterisation used at the end of the
proofs of Theorem 2, p. 6, and Theorem 1, p. 8; meaningful for `n ≥ 2`). -/
def IsSimplexETF {n d : ℕ} (u : Fin n → Vec d) : Prop :=
(∀ i, ‖u i‖ = 1) ∧ ∀ i j, i ≠ j → inner ℝ (u i) (u j) = -1 / ((n : ℝ) - 1)
/-- Theorem 3 and Proposition 4, p. 3: the uniform probability measure on `S^d`, i.e. the surface
measure (Mathlib's `Measure.toSphere` of Lebesgue measure) normalised to total mass one. -/
def uniformSphere (d : ℕ) : Measure (Sph d) :=
((volume : Measure (Vec d)).toSphere Set.univ)⁻¹ • (volume : Measure (Vec d)).toSphere
/-- Theorem 3, p. 3: the probability measure `μ_n = (1/n) ∑_{i=1}^n δ_{u_i}` generated by a
configuration of `n` points of `S^d`. -/
def empiricalMeasure {n d : ℕ} (u : Fin n → Sph d) : Measure (Sph d) :=
((n : ENNReal)⁻¹) • ∑ i, Measure.dirac (u i)
/-- Eq. (3), p. 3: the relaxed energy of a measure `μ` on `S^d`,
`L_α(μ) = ∫ log (∫ exp (α (⟨x, y⟩ - 1)) μ(dy)) μ(dx)`. -/
def measureEnergy {d : ℕ} (α : ℝ) (μ : Measure (Sph d)) : ℝ :=
∫ x, Real.log (∫ y, Real.exp (α * (inner ℝ (x : Vec d) (y : Vec d) - 1)) ∂μ) ∂μ
end NeuralCollapseCE
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Feature space . For a natural number , denotes -dimensional real Euclidean space: vectors with the standard inner product and norm
The case is allowed. Then is the one-point space.
Unit sphere . For a natural number , is the set of vectors of norm exactly :
with its subspace (Borel) structure. Conventionally this is the -dimensional sphere sitting in . Degenerate cases:
- : is empty.
- : .
Unit configuration. A family of vectors in (indexed by indices, ) is a unit configuration if for every index . Edge cases:
- : the condition holds vacuously for the empty family.
- and : no unit configuration exists.
Symmetric loss . For any real number (positive, zero or negative) and any family of vectors in , not required to have unit norm,
where is the natural logarithm. Each logarithm's argument is at least , so no junk values of arise. When , . When , the inner sum is empty and .
Cross-entropy loss . For two families and of vectors in , not required to have unit norm,
There is no temperature, scaling or bias parameter. Each argument of is positive and at least . When , .
Global minimiser of . For a real , a family in is a minimiser of if both of the following hold:
- is a unit configuration;
- for every unit configuration in with the same and .
This is a global (not local) minimality condition, with non-strict inequality, so ties are allowed and minimisers need not be unique. Edge cases:
- and : no minimiser exists, since there are no unit configurations.
- : the empty family is a minimiser.
Global minimiser of . A pair of families , in is a minimiser of the cross-entropy loss if all of the following hold:
- is a unit configuration;
- is a unit configuration;
- for every pair of unit configurations in of the same length .
The minimisation is joint over both families, with non-strict inequality, so ties are allowed. Edge cases:
- and : no minimiser exists.
- : the pair of empty families is a minimiser.
Simplex equiangular tight frame. A family in is called a simplex ETF if both of the following hold:
- for every ;
- for every pair of distinct indices ,
where is computed as a real number.
No further condition (spanning, tightness, or a relation to ) is imposed beyond these Gram-matrix entries. Edge cases:
- : every family qualifies vacuously.
- : there are no distinct pairs, so the only requirement is . The would-be division by zero never occurs.
- and : no such family exists, because the prescribed Gram matrix has rank .
Uniform measure on the sphere . Let be Lebesgue measure on . Let be the induced surface measure on , defined for measurable by
The measure is then normalised by its total mass:
with the inverse taken in .
- : the total mass is finite and positive, so is a rotation-invariant probability measure on . For it gives mass to each of .
- : is empty, the total mass is , and the convention makes the zero measure, not a probability measure.
Empirical measure . For a family of points of the unit sphere ,
where is the Dirac point mass at . Repeated points are counted with multiplicity. The factor is computed in .
- : is a probability measure on .
- : multiplies the empty sum , giving the zero measure.
Relaxed energy . For a real and an arbitrary measure on (not required to be a probability measure, or even finite),
Integrals here follow these conventions:
- An integral whose integrand is not integrable is assigned the value .
- The logarithm satisfies and for ; the inner integral is never negative, so only can actually come into play.
Consequences:
- If is the zero measure, .
- If is not finite, the inner integral may be non-integrable and is then replaced by .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.