Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion with (Sq)Mahalanobis Definition #244

Open
btmit opened this issue Sep 15, 2022 · 1 comment
Open

Confusion with (Sq)Mahalanobis Definition #244

btmit opened this issue Sep 15, 2022 · 1 comment

Comments

@btmit
Copy link

btmit commented Sep 15, 2022

In this package the SqMahalanobis distance is implemented and documented as $(x - y)' * Q * (x - y)$. However, the documentation refers to $Q$ as the covariance matrix. Unless I'm mistaken, this is incorrect. In this formulation $Q$ is referred to as either the information matrix, precision matrix, or concentration matrix, which is equivalent to the inverse of the covariance matrix. The traditional square Mahalanobis equation reads $(x - y)' * Q^{-1} * (x - y)$.

I can verify this against the implementation in the Distributions package or a hand-coded version.

using Distributions, Distances
q = rand(3,3)
Q = q'q

x = rand(3)
y = rand(3)

d0 = (x-y)'*inv(Q)*(x-y)  # hand-coded
d1 = sqmahal(MvNormal(x, Q), y)  # Distributions.jl
d2 = sqmahalanobis(x, y, Q)
d3 = sqmahalanobis(x, y, inv(Q))

d0  d2  # false
d0  d1  d3  # true

Am I misunderstanding the intended use or documentation of this function?

@dkarrasch
Copy link
Member

Judging by, e.g., https://en.wikipedia.org/wiki/Mahalanobis_distance, that seems to be correct. Could you perhaps submit a PR which clarifies the terminology?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants