K-d tree: Difference between revisions

Content added Content deleted
Line 1,313: Line 1,313:
const kdtree = KDTree(Float64.(data))
const kdtree = KDTree(Float64.(data))
const indexpoint = [9,2]
const indexpoint = [9,2]
idxs, dists = knn(kdtree, indexpoint, 1)
idx, dist = knn(kdtree, indexpoint, 1)
println("Wikipedia example: The nearest neighbor to $indexpoint is ",
println("Wikipedia example: The nearest neighbor to $indexpoint is ",
"$(data[1:2, idxs[1]]) at distance $(dists).")
"$(data[1:2, idx[1]]) at distance $(dist).")
NearestNeighbors.print_stats()
NearestNeighbors.print_stats()


Line 1,322: Line 1,322:
const kdcubetree = KDTree(cubedis)
const kdcubetree = KDTree(cubedis)
const rand3point = rand(3, 1)
const rand3point = rand(3, 1)
idxs, dists = knn(kdcubetree, rand3point, 1)
idx, dist = knn(kdcubetree, rand3point, 1)


println("\n\nThe point $rand3point is closest to the point $(cubedis[1:3, idxs[1]])",
println("\n\n1000 cube points: The point $rand3point is closest to the point $(cubedis[1:3, idx[1]])",
" at distance $(dists[1]).")
" at distance $(dist[1]).")
NearestNeighbors.print_stats()
NearestNeighbors.print_stats()


Line 1,331: Line 1,331:
NearestNeighbors.reset_stats()
NearestNeighbors.reset_stats()
const cubedis2 = rand(3, 500000)
const cubedis2 = rand(3, 500000)
const kdcubetree2 = KDTree(cubedis)
const kdcubetree2 = KDTree(cubedis2)
const rand3point2 = rand(3, 1)
const rand3point2 = rand(3, 1)
idxs, dists = knn(kdcubetree2, rand3point2, 1)
idx, dist = knn(kdcubetree2, rand3point2, 1)


println("\n\nThe point $rand3point2 is closest to the point $(cubedis2[1:3, idxs[1]]) out of $(size(cubedis2)[2]) points, ",
println("\n\nExtra: The point $rand3point2 is closest to the point $(cubedis2[1:3, idx[1]]) out of $(size(cubedis2)[2]) points,",
" at distance $(dists[1]).")
" at distance $(dist[1]).")
NearestNeighbors.print_stats()
NearestNeighbors.print_stats()
</lang>
</lang>
Line 1,346: Line 1,346:




The point [0.857886; 0.503096; 0.0873481] is closest to the point [0.885883; 0.475486; 0.0320433] at distance [0.0678589].
1000 cube points: The point [0.386894; 0.465532; 0.710547] is closest to the point [0.389152; 0.459995; 0.639123] at distance [0.0716743].
Nodes visited: 14
Nodes visited: 13
Points visited: 30, out of these: 0 unchecked.
Points visited: 30, out of these: 0 unchecked.




The point [0.535338; 0.546231; 0.984988] is closest to the point [0.430079; 0.848971; 0.689986] out of 500000 points, at distance [0.0608899].
Extra: The point [0.373496; 0.740711; 0.417431] is closest to the point [0.377841; 0.744084; 0.420237] out of 500000 points, at distance [0.00617466].
Nodes visited: 21
Nodes visited: 28
Points visited: 50, out of these: 0 unchecked.
Points visited: 40, out of these: 0 unchecked.
</pre>
</pre>