Group Abstract Group Abstract

Message Boards Message Boards

1
|
9.4K Views
|
6 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Exact Schur Decomposition in special cases (MahalanobisDistanceTransform)

There is something known as a MahalanobisDistance. I can write a Mathematica function to calculate it for two vectors u and v with respect to some data. Here's a function that implements it.

    MahalanobisDistance[data_?MatrixQ,u_,v_]:= Sqrt[u.Inverse[Covariance[data]].v]

Frequently, one is trying to find the distance from some vector u to the mean of data, so one can also write a two argument form:

MahalanobisDistance[data_?MatrixQ,u_]:=MahalanobisDistance[data,u,ArrayReduce[Mean,data,1]]

So far, so good, I think. But it is also correctly reported that the MahalanobisdDistance is the same as the EuclideanDistance when the points are subjected to a special linear transformation. After some poking about, it appears that one can find the transformation through the following process:

MahalanobisTransform[data_]:=Module[{q,t},
{q,t}=SchurDecomposition[N[Inverse[Covariance[data]]];
MatrixPower[t,1/2].Transpose[q]
]

And, this seems to work. But ... SchurDecomposition insists that its argument be numeric. Thus, the N in the code above. But surely, I say, at least where the matrix in question has the properties of an inverse covariance matrix (symmetry and who knows what else) there is some way of computing an exact or symbolic answer. I;ve seem some stuff on the internet suggesting that there are eigenvalues involved, but, I can't seem to get any of it to work. Any suggestions for either a special case of SchurDecomposition that works on integer or symbolic matrices or an alternative way of generating the MahalanobisTransform. I have the sense there is a way to do this.

This is all relevant to inference of causation from observational data and computational efficiency, if anyone wants to know why anyone might care. I'd like to be able to write a MahlanobisDistanceFunction that is something like this. It would be nice if T could be symbolic.

MahalanobisDistanceFunction[data_]:={x,y}|->Evaluate@With[{T=MahalanobisTransform[data]},EuclideanDistance[T.x,T.y]]

Ultimately, I'd like an elegant ResourceFunction to come of this work.

POSTED BY: Seth Chandler
6 Replies

I'm probably missing something, but should it not be:

MahalanobisDistance[data_?MatrixQ,u_,v_]:= Sqrt[(u-v).Inverse[Covariance[data]].(u-v)]

instead of

MahalanobisDistance[data_?MatrixQ,u_,v_]:= Sqrt[u.Inverse[Covariance[data]].v]

?

POSTED BY: Richard Frost

@Richard Frost, It is not at all clear what you mean by claiming the Mahalanobis distance can fail triangle inequality. Bear in mind that it is a Euclidean metric after transforming coordinates by a (symmetric) positive semidefinite matrix.

Related links:

https://courses.engr.illinois.edu/ece417/fa2017/ece417fa2017lecture2.pdf

https://math.stackexchange.com/questions/528318/how-can-one-prove-that-mahalanobis-distance-is-a-metric

POSTED BY: Daniel Lichtblau
POSTED BY: Richard Frost
POSTED BY: Seth Chandler

From what I see at this Wikipedia page, I think you can obtain an equivalent transformation matrix using CholeskyDecomposition.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard