1

The Euclidean distance can be formulated like: $I_{xy}=\sqrt{||x||^2+||y||^2-2||x||||y||c_{xy}}$ where $c_{xy}=\left<x|y\right>$ is the inner product.

Now, I'd like to formulate the Mahalanobis distance with the $c_{xy}$ inner product.

I know that the Mahalanobis distance is $\sqrt{(x-\mu)^T\Sigma^{-1}(x-\mu)}$ but here the inner product does not appear.

What is the right formulation? Thank you.

user12910
  • 123
  • 3

1 Answers1

1

$$ \begin{align} (x-\mu)^T\Sigma^{-1}(x-\mu) &= x^T\Sigma^{-1}x + \mu^T\Sigma^{-1}\mu - \mu^T\Sigma^{-1}x - x^T\Sigma^{-1}\mu \\ &= x^T\Sigma^{-1}x + \mu^T\Sigma^{-1}\mu - 2 x^T\Sigma^{-1}\mu \\ &=x\Sigma^{-1/2}\Sigma^{-1/2}x + \mu\Sigma^{-1/2}\Sigma^{-1/2}\mu - 2 \left<x\Sigma^{-1/2}|\Sigma^{-1/2}\mu\right> \\ &=:||a||^2+||b||^2-2\left<a|b\right>\text{, where } a=\Sigma^{-1/2}x, b=\Sigma^{-1/2}\mu \end{align}$$

In the second step we used the fact that $\mu^T\Sigma^{-1}x$ is a real number, so it is equal to its transpose, and the fact that $\Sigma$ has to be symmetric.

In a sense, the result is of the form "two squared terms minus twice an inner product", similar to the Euclidean distance form.

Also I think your Euclidean distance formula has a mistake (or at least we're using different notations). It should be $I_{xy}=\sqrt{||x||^2+||y||^2-2\left<x|y\right>}$.

  • Thank you it's exactly what I'm looking for.

    I noticed the mistake in the Euclidean distance formula also, but it comes from a paper, and I thought it was a misunderstanding from myself.

    – user12910 Oct 10 '22 at 08:47
  • I have a (probably naive) question concerning your answer. I have a Σ matrix which contains negative values, so when I compute the square root of Σ to get a or b coefficients, my soft raises an error, so actually in my soft I compute a=Σx, but it is not rigorous. Thanx. – user12910 Dec 01 '22 at 15:14
  • It's the matrix square root, not the element wise square root. A covariance matrix is always positive semidefinite so this is always well defined. Look up https://en.m.wikipedia.org/wiki/Square_root_of_a_matrix#Positive_semidefinite_matrices – Benjamin Wang Dec 01 '22 at 18:01