soft-matter / trackpy

Python particle tracking toolkit
http://soft-matter.github.io/trackpy
Other
441 stars 131 forks source link

Allowing `DistanceMetric` strings with scikit-learn `BTree` #691

Open freemansw1 opened 2 years ago

freemansw1 commented 2 years ago

Hi,

I'm curious if the maintainers would be amenable to a PR that allows for users to input a string that is passed to scikit-learn for dist_func in trackpy.link et al. Allowing a user-passed python dist_func is great, but some of the DistanceMetrics available in scikit-learn (https://scikit-learn.org/stable/modules/generated/sklearn.metrics.DistanceMetric.html?highlight=distancemetric#sklearn.metrics.DistanceMetric) are useful and can be substantially faster than passing along a python function.

I'm happy to put together a PR allowing dist_func to be a string or a python function, and if it is a string, to pull a scikit-learn DistanceMetric object, if the maintainers are interested.

nkeim commented 2 years ago

This sounds awesome! It's always a big win when the call signature doesn't change. That said, it looks like some of the sklearn metrics require arguments, most notably Minkowski. Would it make sense for dist_func to accept any DistanceMetric instance instead? Or, is it worth the extra code (and docstring text) to allow both strings and instances?

freemansw1 commented 2 years ago

Okay, great! I put in a PR (#692) to allow the user to pass any DistanceMetric class. I agree that that is generally better than allowing the user to pass in a string. I think it would also enable the user to extend the DistanceMetric class with their class and/or metrics, which would be great generally!