Non-native functions with k nearest neighbours?

User 2001 | 10/13/2015, 10:59:45 AM

I'm trying to create a k-nn model using a composite distance function which includes my own custom distance function:

euc_dist = [('features',), 'euclidean', 1]
my_dist = [('my_label',), my_function, 1]
comp_dist = [euc_dist, my_dist]
nn_model = graphlab.nearest_neighbors.create(images, distance=comp_dist)

However I receive the following error:

TypeError: Only native functions, or simple lambdas of native functions (with constant capture values) can be passed to an extension function.

Is there any work-around to do what I'm trying to do? Either way, are the use of non-native functions in k-nn something you would consider for a future release? I'm sure many people would find this useful.

Comments

User 940 | 10/13/2015, 5:15:16 PM

Hi @Joeetaku ,

How is my_function defined? It will be easier to figure out a workaround if we know what distance function you are trying to compute.

Cheers! -Piotr


User 2001 | 10/14/2015, 2:37:20 PM

Hi both,

Thank you for your response. Unfortunately I'm not really at liberty to reveal how my_function works at present, but I've found a work-around that will do for now anyway.

Really my main question was about the inclusion of completely custom functions, which you've now answered. I look forward to this feature in the future :)

Thanks and regards,

Joe