8 commitsLast commit ≈ 15 months ago0 stars0 forks
KD-Tree-Python
KD-Tree Implementation in Python
1
contributor
Cite this software
Description
KD-Tree Implementation in Python
This repository contains Python implementation of the kd-tree data structure and performing k-nearest neighbour search.
Its Matlab implementation is located here: KD-Tree-Matlab
About
The kd-tree is a space-partitioning data structure for organizing points in a k-dimensional space.
Scripts
-
build_kdtree.pyBuilds a kd-tree from a set of points.
-
nearest_neighbour_search.pyPerforms nearest neighbour search using the built kd-tree.
-
hypercube_points.pyGenerates n-Dimensional Points Uniformly in an n-Dimensional Hypercube.
Example Usage
from kdtree.build_kdtree import build_kdtree
from kdtree.nearest_neighbor_search import nearest_neighbor_search
from examples.hypercube_points import hypercube_points
num_points = 5000
cube_size = 10
num_dimensions = 10
points = hypercube_points(num_points, cube_size, num_dimensions)
hypercube_kdtree = build_kdtree(points.tolist())
query_point = np.random.rand(num_dimensions).tolist()
nearest_point, nearest_dist, nodes_visited = nearest_neighbor_search(hypercube_kdtree, query_point)
print(f"Query point: {query_point}")
print(f"Nearest point: {nearest_point}")
print(f"Distance: {nearest_dist:.4f}")
print(f"Nodes visited: {nodes_visited}")
Contributors
RA
Author
Karlsruhe Institute of Technology - The Research University in the Helmholtz Association