mapado / haversine

Calculate the distance between 2 points on Earth
MIT License
330 stars 62 forks source link

Add haversine cdist #30

Open MuellerSeb opened 4 years ago

MuellerSeb commented 4 years ago

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 commented 4 years ago

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

jdeniau commented 4 years ago

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 ?

MuellerSeb commented 4 years ago

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.

jdeniau commented 4 years ago

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 ?

MuellerSeb commented 4 years ago

Almost. This is the pdist functionality.

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

Noezor commented 2 years ago

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?

jdeniau commented 2 years ago

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