I have been trying to get Accord's KDTree working but am running into probloems. The help file for that page looks like C???.
I have the following code. pointArray is an array where each value is an array of doubles:
pointArray(0) = new array (1) {2,5]
pointArray(1) = new array (1) {7,2]
pointArray(2) = new array (1) {100,5]
Dim tree As KDTree(Of Array) = KDTree.FromData(Of Array)(pointArray)
I keep getting an error:
Unable to cast object of type 'System.Array[]' to type 'System.Double[][]'.
I have tried as many combinations of array and doubles as I can but to no avail. Can anybody help me use this in VB.net?
' This is the same example found in Wikipedia page on
' k-d trees: http://en.wikipedia.org/wiki/K-d_tree
' Suppose we have the following set of points:
Dim points =
{
New Double() {2, 3},
New Double() {5, 4},
New Double() {9, 6},
New Double() {4, 7},
New Double() {8, 1},
New Double() {7, 2}
}
' To create a tree from a set of points, we use
Dim tree = KDTree.FromData(Of Integer)(points)
' Now we can manually navigate the tree
Dim node = tree.Root.Left.Right
' Or traverse it automatically
For Each n As KDTreeNode(Of Integer) In tree
Dim location = n.Position
Console.WriteLine(location.Length)
Next
' Given a query point, we can also query for other
' points which are near this point within a radius
Dim query = New Double() {5, 3}
' Locate all nearby points within an Euclidean distance of 1.5
' (answer should be a single point located at position (5,4))
Dim result = tree.Nearest(query, radius:=1.5)
' We can also use alternate distance functions
tree.Distance = Function(a, b) Accord.Math.Distance.Manhattan(a, b)
' And also query for a fixed number of neighbor points
' (answer should be the points at (5,4), (7,2), (2,3))
Dim neighbors = tree.Nearest(query, neighbors:=3)
By the way, if you are going to use the kd-trees, I would suggest to stick with the radius method for the time being. There is currently a small issue with the nearest neighbors method in the current version. The fix will be available in the next release, which should be available soon.