A Fast and Accurate Approach for Covariance Matrix Construction
Felix Reichel
Reichel(2025)将Bariance定义为Bariance(x)=1/n(n-1)∑_i<j(x_i-x_j)^2,它使用标量允许O(n)重新制定。 我们通过显示具有 s=X^⊤1 的 Cov(X)=1/n-1(X^⊤⊤⊤)与 s=X^⊤1_n 的协方差形式在代数上与正数-差分形式相同,但避免了显式中心化。 计算减少到单个 p× p 外矩阵产品和一个减法。 Python 中的 Empirical 基准测试显示,在非 BLAS 调谐的设置中,numpy.cov 的运行时增益明显。 更快的Gram例程,如RXTX(Rybin等)用于 XX^⊤ 进一步降低总成本。
Reichel (2025) defined the Bariance as Bariance(x)=1/n(n-1)∑_i<j(x_i-x_j)^2, which admits an O(n) reformulation using scalar sums. We extend this to the covariance matrix by showing that Cov(X)=1/n-1(X^⊤ X-1/n s s^⊤) with s=X^⊤1_n is algebraically identical to the pairwise-difference form yet avoids explicit centering. Computation reduces to a single p× p outer matrix product and one subtraction. Empirical benchmarks in Python show clear runtime gains over numpy.cov in non-BLAS-tuned settings. F...