haversine icon indicating copy to clipboard operation
haversine copied to clipboard

Add haversine cdist

Open MuellerSeb opened this issue 4 years ago • 7 comments

Hey there,

nice package! I was wondering, if you could implement a routine to compute a pairwise distance matrix like scipy.spatial.distance.cdist does.

Cheers, Sebastian

MuellerSeb avatar Apr 21 '20 18:04 MuellerSeb

Related implementation: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.haversine_distances.html

MuellerSeb avatar Apr 21 '20 18:04 MuellerSeb

Hi,

Thanks !

If your issue is with performance, #26 added the haversine_vector function to optimize performance.

You can see how to use it in the documentation

If that's not performance-related, can you explain why you need this ?

jdeniau avatar Apr 21 '20 20:04 jdeniau

cdist is constructing a n times m matrix for two input arrays with n and m points respectively. The vector version does not do this.

MuellerSeb avatar Apr 21 '20 20:04 MuellerSeb

OK so let me rephrase to make sure I understand your needs :

You have a list of geopoints, and you need to calculate the distance between every points :

pseudo-code :

LYON = (45.7597, 4.8422)
PARIS = (48.8567, 2.3508)
NEW_YORK = (40.7033962, -74.2351462)

calculate_each_distances([LYON, PARIS, NEW_YORK])

and the output should be something like that :

[
  [    0,  392, 6163],
  [  392,    0, 5853],
  [ 6163, 5853,    0],
]

Is that it ?

jdeniau avatar Apr 22 '20 07:04 jdeniau

Almost. This is the pdist functionality.

One step further is, to provide two lists of points for rows and cols in the resulting matrix.

MuellerSeb avatar Apr 22 '20 16:04 MuellerSeb

This already exists, see https://github.com/mapado/haversine/blob/0b47ac417d82c4ae15ba49c7856453bf81afa1b9/tests/test_haversine_vector.py#L21-L30

However, I believe the comb parameter is not clear from the docstring (one needs to read the implementation). @jdeniau do you mind if I rework the docstring a bit?

Noezor avatar Feb 20 '22 17:02 Noezor

@Noezor help yourself! Every improvement in the documentation is helpful 👍

jdeniau avatar Feb 27 '22 17:02 jdeniau