Accord.NET (KNN) using F#: Distance Function

Tags: f# accord.net
Question!

I am using Accord.NET in F# for the first time and I am having problems creating the function to calculate the distance for KNN.

Here is my code

static member RunKNN =
    let inputs = MachineLearningEngine.TrainingInputClass
    let outputs = MachineLearningEngine.TrainingOutputClass

    let knn = new KNearestNeighbors<int*int*int*int>(1,inputs,outputs,null)
    let input = 1,1,1,1
    knn.Compute(input)

When I swap out the null for a function like this

let distanceFunction = fun (a:int,b:int,c:int,d:int)
                           (e:int,f:int,g:int,h:int)
                           (i:float) ->
                           0 

I get an exception like this:

*Error 1 This expression was expected to have type System.Func<(int * int * int * int),(int * int * int * int),float> but here has type int * int * int * int -> int * int * int * int -> float -> int*

So far, the only article I found close to my problem is this one. Apparently, there is a problem with how F# and C# handle delegates?

I posted this same question on the Google group for Accord.NET here.

Thanks in advance



Answers

I would guess you should use the tuple form like so

let distanceFunction = fun ((a:int,b:int,c:int,d:int),
                           (e:int,f:int,g:int,h:int),
                           (i:float)) -


This video can help you solving your question :)
By: admin