[Mono-list] K-Nearest Neighbor algorithm

Jon Harrop jon at ffconsultancy.com
Tue Dec 9 19:50:57 EST 2008


On Wednesday 10 December 2008 00:10:20 Yoav HaCohen wrote:
> Dear all,
>
> Does anybody knows a Mono/.Net library that supplies k-nearest neighbor
> functionality?

This algorithm is described in detail in my book F# for Scientists using 
Microsoft's F# programming language for .NET and in the context of the 
analysis of large-scale molecular dynamics results. The algorithm is 
essentially:

  let rec nth nn (n, i) =
    match n with
    | 0 -> set [i]
    | 1 -> nn i
    | n ->
        let s1, s2 = nth nn (n-1, i), nth nn (n-2, i)
        Seq.fold Set.union Set.empty (Seq.map nn s1) - s2 - s1)

where "nn" is a function that returns the neighbors of the given vertex, "n" 
is the neighbor shell being sought and "i" is the origin vertex.

The web page for the book is here but that code is not yet on-line:

  http://www.ffconsultancy.com/products/fsharp_for_scientists/?mono

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e


More information about the Mono-list mailing list