We place three algorithms for computing the unbiased sample covariance matrix in streaming and distributed settings on a common algebraic, numerical, and statistical foundation. The Gram algorithm, derived from the variance reformulation, maintains the running cross-product matrix $G_t = \sum_{i=1}^t x_i x_i^\top$ and the column-sum vector $s_t = \sum_{i=1}^t x_i$, yielding the unbiased covariance estimator $S_t = (t-1)^{-1}(G_t - t^{-1}s_t s_t^\top)$ in $O(p^2)$ time per update. The Welford algorithm propagates a running mean $m_t$ and outer-product corrections $M_t$, with updates $m_t = m_{t-1} + (x_t - m_{t-1})/t$ and $M_t = M_{t-1} + (x_t - m_{t-1})(x_t - m_t)^\top$, achieving the same asymptotic cost with improved numerical stability under large data shifts. The Chan-Golub-LeVeque algorithm supports block-parallel merging through the exact identity $M = M_A + M_B + \frac{n_A n_B}{n_A+n_B}(m_B - m_A)(m_B - m_A)^\top$, making it the natural choice for distributed and map-reduce architectures. All three algorithms produce the same estimator $S_t = M_t/(t-1)$ in exact arithmetic, although their finite-precision behavior differs markedly. Beyond runtime and numerical comparisons, we introduce a conformal prediction framework for streaming covariance estimation that yields finite-sample, distribution-free confidence sets $C_{t,jk}$ for each entry $S_{t,jk}$ of the covariance matrix at any step $t$ of the data stream. Experiments confirm that the Gram algorithm is fastest for batch computation, Welford is uniquely robust to catastrophic cancellation under large mean shifts, CGL is optimal for distributed settings, and conformal intervals achieve the nominal coverage level across all three algorithms.
翻译:本文在统一的代数、数值与统计基础上,研究了三种适用于流式与分布式环境下的无偏样本协方差矩阵计算方法。基于方差重构推导出的Gram算法通过维护运行交叉积矩阵$G_t = \sum_{i=1}^t x_i x_i^\top$与列和向量$s_t = \sum_{i=1}^t x_i$,以每次更新$O(p^2)$时间复杂度获得无偏协方差估计量$S_t = (t-1)^{-1}(G_t - t^{-1}s_t s_t^\top)$。Welford算法则递推更新运行均值$m_t$及外积修正项$M_t$,其更新式为$m_t = m_{t-1} + (x_t - m_{t-1})/t$与$M_t = M_{t-1} + (x_t - m_{t-1})(x_t - m_t)^\top$,在相同渐近复杂度下对大幅数据偏移具有更优数值稳定性。Chan-Golub-LeVeque算法通过精确恒等式$M = M_A + M_B + \frac{n_A n_B}{n_A+n_B}(m_B - m_A)(m_B - m_A)^\top$支持分块并行合并,成为分布式与Map-Reduce架构的理想选择。在精确算术条件下,三种算法均可产生相同估计量$S_t = M_t/(t-1)$,但其有限精度表现存在显著差异。除运行时间与数值精度对比外,本文针对流式协方差估计引入保形预测框架,该框架可在数据流的任意时刻$t$给出协方差矩阵每个元素$S_{t,jk}$的有限样本、无分布假设的置信集$C_{t,jk}$。实验证实:Gram算法批量计算速度最快,Welford算法对大均值移位导致的灾难性抵消具有独特鲁棒性,CGL算法适用于分布式场景,且保形区间在三种算法下均达到名义覆盖水平。