1

I'm trying to calculate the following Mahlanobis distance.

$x^{T}$pinv($C$)$x$

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?

regress
  • 107
  • 2
    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. – Danica Jul 03 '15 at 07:59

1 Answers1

-1

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

Aksakal
  • 61,310
  • But, in the paper that I'm reading now, Mahalanobis distance is defined with pseudo inverse instead of inverse. – regress May 02 '15 at 04:12
  • Show us the paper. I bet it's because they're computing the distance between the vectors of different lengths. – Aksakal May 02 '15 at 04:14
  • 2
    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. – regress May 02 '15 at 16:38
  • Is your covariance matrix singular because you have duplicate variables? – Aksakal Mar 16 '17 at 20:34