Mahalanobis distance (source code)

= Mahalanobis distance
{c}
{title2=$d_M(x,y)=\sqrt{(x-y)^T\Sigma^{-1}(x-y)}$}

For a <positive-definite> <covariance matrix>, this is <Euclidean distance> after whitening. It accounts for both scales and correlations and is invariant under consistent nonsingular linear changes of coordinates. Estimating the covariance can be unstable with small samples, and a singular covariance requires restricting to a nonsingular subspace rather than claiming an ordinary <metric> on the full space.