CoverTree
CoverTree copied to clipboard
incorrect computation of nearest neighbor
Hello, I am finding that the nearestNeighbour
queries are not giving the correct result.
In the attached test case, i have three 2D points in the cover-tree, and for two test points, I do get the correct kNearestneighbours
(k=3
) with correct distances. But the nearest neighbor is incorrect.
I will try to look into the code in detail to figure out the cause. But if you have any ideas as to why this could be happening, I would appreciate the fix for this.
The attached program produces the following output.
Number of OpenMP threads: 1
adding 3 points to cover tree!
Entered case 1: 3.31402 1 0
Requesting global lock!
testing for nearest neighbors!
query point 0 : (-0.944485 0.116473)
doing 3-nearest neighbors using direct computation!
nearest 0 : 1, 1.438655
nearest 1 : 2, 1.651407
nearest 2 : 0, 2.003489
doing 3-nearest neighbors using cover_tree!
cover_tree 0 : 2, 1.438655
cover_tree 1 : 0, 1.651407
cover_tree 2 : 0, 2.003489
nearest :: direct = (1, 1.438655) cover_tree = (0, 1.651407)
---------------------------------------------------------------------> mismatch
query point 1 : (-0.931471 0.781848)
doing 3-nearest neighbors using direct computation!
nearest 0 : 1, 1.537557
nearest 1 : 2, 2.114969
nearest 2 : 0, 2.256513
doing 3-nearest neighbors using cover_tree!
cover_tree 0 : 2, 1.537557
cover_tree 1 : 0, 2.114969
cover_tree 2 : 0, 2.256513
nearest :: direct = (1, 1.537557) cover_tree = (0, 2.114969)
---------------------------------------------------------------------> mismatch