I'm trying to calculate the following Mahlanobis distance.


Since covariance matrix, $C$ is singular, pinv($C$) means pseudo-inverse of C. However, my $C$ is very large, so it's very time-consuming to calculate pinv($C$). Thus, I'm trying to calculate this without pseudo-inverse computation like this. Since C is symmetric, C has eigen decomposition. $C = USU^T = US^{1/2}(US^{1/2})^T=JJ^T$ (here, $J=US^{1/2}$)

Then, $x^T$pinv($C$)$x$ $=$ $x^T$pinv($JJ^T$)$x$$=$(pinv($J$)$x$)$^T$(pinv($J$)$x$)$=$$y^Ty$ (here, $y$$=$pinv($J$)$x$)

$y$ can be calculated from $Jy = x$ using QR factorization.

This is my idea. Is there any problem in my logic?

  • 2
    $\begingroup$ This should work, but finding $J$ shouldn't really be any faster than $\operatorname{pinv}(C)$: you're doing an eigendecomposition, which is equally expensive as the SVD used in pinv.... It may be more numerically stable, though. $\endgroup$ – Dougal Jul 3 '15 at 7:59

If it's a singular matrix you can't invert it by definition. Mahalonobis distance will have no meaning, it'll be undefined.

  • $\begingroup$ But, in the paper that I'm reading now, Mahalanobis distance is defined with pseudo inverse instead of inverse. $\endgroup$ – regress May 2 '15 at 4:12
  • $\begingroup$ Show us the paper. I bet it's because they're computing the distance between the vectors of different lengths. $\endgroup$ – Aksakal May 2 '15 at 4:14
  • 1
    $\begingroup$ Mahalanobis distance might be defined with inverse, but in many cases the covariance matrix is singular, so many people are trying to handle this problem. In my work the covariance matrix is singular too. If you google on it, you can find many people are using pseudo-inverse to calculate Mahalanobis distance with singular covarince matrix. $\endgroup$ – regress May 2 '15 at 16:38
  • $\begingroup$ Is your covariance matrix singular because you have duplicate variables? $\endgroup$ – Aksakal Mar 16 '17 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.