lmcinnes / pynndescent

A Python nearest neighbor descent for approximate nearest neighbors
BSD 2-Clause "Simplified" License
897 stars 105 forks source link

Can't pass parameters to weighted_minkowski distance metric #193

Open Stevod opened 2 years ago

Stevod commented 2 years ago

When I run this code, index = NNdescent(data = data, metric = 'weighted_minkowski', metric_kwds={'p':1} ) I get an error of no match with getitem. How can I pass this?

Also, I need to pass an array of weights to weight the metric. How can I pass those? By convetring to a dict?

Thanks, David

lmcinnes commented 2 years ago

That should work; I'll see if I can look into it.

Stevod commented 2 years ago

Many thanks, as the ability to use different/custom metrics is why I selected the pynndescent package in the first place.

Also, I cannot pass the additional 'w' metric into a custom metric using metric_kwds={'w' : w.to_dict()} as I expected. Could you provide an example of how to do that as well for a custom function.

Much appreciated. David

lmcinnes commented 2 years ago

Due to how things have to get handled by numba, in practice you need to pass all the required arguments in the correct order to the distance function. That means for weighted minkowski you'll have to pass w and p (if you just want to use p you cna always use minkowski instead). To pass w you'll need to pass a vector of length giving the weight for each coordinate.