Translation invariance of a categorical covariance matrix
Provedcategorical_covariance_sandwich_shift_invariantLet be real weights on a finite index set with . Let be a real matrix with columns indexed by , and let be a vector indexed by its rows. Define . Subtracting from every column of preserves the matrix :
The row index set can be arbitrary; only the column index set is finite. The shift is arbitrary and need not be the weighted mean. Nonnegative weights give the familiar covariance interpretation. The algebraic identity itself requires only normalization, so signed normalized weights are permitted.
This is a finite-matrix form of the classical translation invariance of covariance. Its motivation is the matrix in Appendix B, equations (12)–(13), of Alswaidan and Varner, Stochastic Attention via Langevin Dynamics on the Modern Hopfield Energy, arXiv:2603.06875v1. The displayed translation identity is an elementary derived corollary of that matrix expression, rather than a separately stated theorem in the paper. It can be applied to finite matrix data without introducing a probability measure. No assertion about the full Hopfield energy, its Hessian derivation, or its convexity is part of this theorem.
import Mathlib.Data.Matrix.Basic import Mathlib.Data.Real.Basic open scoped BigOperators set_option autoImplicit false
theorem categorical_covariance_sandwich_shift_invariant
{m n : Type*} [Fintype n] [DecidableEq n]
(p : n → ℝ) (hp : ∑ j, p j = 1) (X : Matrix m n ℝ) (c : m → ℝ) :
(X - Matrix.vecMulVec c (fun _ : n => (1 : ℝ))) *
(Matrix.diagonal p - Matrix.vecMulVec p p) *
(X - Matrix.vecMulVec c (fun _ : n => (1 : ℝ))).transpose =
X * (Matrix.diagonal p - Matrix.vecMulVec p p) * X.transpose := by sorry