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

Question about covariance matrix used when using Mahalanobis distance #215

Open
rchan26 opened this issue Apr 12, 2023 · 0 comments
Open

Comments

@rchan26
Copy link

rchan26 commented Apr 12, 2023

Hi, I was just wondering what is the default covariance matrix that is used when metric="mahalanobis". I see in the documentation that you could pass in any metric keywords via metric_kwds (I assume I would pass in the inverse by setting metric_kwds={"vinv": cov_inv}), but I can't seem to find in the documentation what is the default that is used if none is passed?

I see in pynndescent/distances.py, that the function to compute the malahonbis has default identity matrix, but I assume that isn't actually what is used if you don't specify vinv in pynndescent.NNDescent.

For a bit of context, for some points $y_{1}, y_{2}, ...$ I would like to approximate the minimum distances between them and some data $X_{1}, X_{2}, ...$ (i.e. for each $i$, compute the distance between $y_{i}$ and each point $X_{1}, X_{2}, ...$ and find the minimum). I want to use the malahonbis distance where I use the covariance matrix for the data $X$, and I have been doing this with:

nnd = pynndescent.NNDescent(X, metric="mahalanobis")
_, nn_d = nnd.query(inlier_signatures)
minimum_distances = inlier_nn_d[:,0]

I was just wondering if I should really be passing in the inverse covariance matrix I want to use like:

nnd = pynndescent.NNDescent(X, metric="mahalanobis", metric_kwds={"vinv": cov_inv})

Any clarification on what the default vinv that is used would be greatly appreciated :)

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

1 participant