Covariance, eigenvectors and SVD
Center the data, A = X − μ. Then:
- Covariance:
C = AᵀA / (n − 1), shape(p, p)— one einsum contracting the sample axis. - Eigendecomposition:
C vⱼ = λⱼ vⱼ, largest first. - SVD:
A = UΣVᵀ; keepVₖ. ScoresS = AVₖ = UₖΣₖ, reconstructionX̂ = SVₖᵀ + μ, andλⱼ = σⱼ² / (n − 1).
The training residual at rank k equals the sum of the discarded squared singular values — and you must add the mean back to reconstruct raw sensor values.
Direct SVD is preferred because forming AᵀA squares the condition ratio.