A k-d-tree (k-dimensional tree) is a data structure for storing points in multidimensional space. They can be used to efficiently query for whether a point exists, as well as to do Euclidean nearest-neighbor searches and searches inside of hyperdimensional rectangular regions.
Questions tagged [kdtree]
457 questions
5
votes
0 answers
How to add and remove points from a KDTreeSearcher in matlab
In MATLAB, is there a way to update the data points in a KDTreeSearcher?
I'm starting with a tree with all N data points (a.k.a observations), and iteratively search a point from the tree, after a point is chosen I need to invalidate that point…

xun
- 607
- 2
- 7
- 10
5
votes
3 answers
K-d trees: nearest neighbor search algorithm
This is my understanding of it:
1. Recurse down the tree, taking the left or right subtree according as whether ELEMENT would lie in the left or the right subtree, if it existed.
2. Set CURRENT_BEST as the first leaf node that you reach.
3. As you…

Kaiser Octavius
- 157
- 1
- 2
- 8
5
votes
2 answers
Optimizing Python KD Tree Searches
Scipy (http://www.scipy.org/) offers two KD Tree classes; the KDTree and the cKDTree.
The cKDTree is much faster, but is less customizable and query-able than the KDTree (as far as I can tell from the docs).
Here is my problem:
I have a list of…

Dlinet
- 1,193
- 3
- 15
- 22
4
votes
4 answers
kNN with dynamic insertions in high-dim space
I am looking for a method to do fast nearest neighbour (hopefully O(log n)) for high dimensional points (typically ~11-13 dimensional). I would like it to behave optimally during insertions after having initialized the structure. KD tree came to my…

I J
- 805
- 3
- 9
- 19
4
votes
1 answer
Implementing a k-d tree for 'nearest neighbor' search in MYSQL?
I am designing an automated trading software for the foreign exchange market.
In a MYSQL database I have years of market data at five-minute intervals. I have 4 different metrics for this data alongside the price and time.
[Time|Price|M1|M2|M3|M4]…

Mike Furlender
- 3,869
- 5
- 47
- 75
4
votes
2 answers
Explain this algorithm (Compare points in SURF algorithm)
I need to know if this algorithm is a known one:
void getMatches(IpVec &ipts1, IpVec &ipts2, IpPairVec &matches, float ratio) {
float dist, d1, d2;
Ipoint *match;
matches.clear();
for (unsigned int i = 0; i < ipts1.size(); i++) {
…

Wiliam
- 3,714
- 7
- 36
- 56
4
votes
2 answers
Python's scipy spatial KD-tree is slower than brute force euclidean distances?
I've quickly checked the performance of building a tree and querying it versus just calculating all the euclidean distances. If I query this tree for all other points within a radius, shouldn't it vastly outperform the brute force approach?
Does…

Robin De Schepper
- 4,942
- 4
- 35
- 56
4
votes
1 answer
KDTree with periodic boundary conditions and pair distances in output
I want to run a nearest neighbour search over >10k points that lie within a periodic box and returns me the distances of these points together with their indices.
So far I tried sklearn.neighbors.KDTree(positions).query_radius(positions,…

Christovis
- 91
- 7
4
votes
2 answers
KD-Tree Implementation in SQL
Is anyone aware of a KD-Tree, or similar spatial index, implemented in SQL? I was considering writing my own using Python and Django's ORM, but I'd like to avoid reinventing the wheel.
I have a table containing millions of rows, with each row…

Cerin
- 60,957
- 96
- 316
- 522
4
votes
2 answers
Accord KDTree with custom distance function
I have a graph data structure representing a road network (nodes are points/intersections in the road and edges are roads). The Node object has a latitude and longitude associated with it.
I'm using Accord's KDTree class to find nearby nodes to a…

mchristos
- 1,487
- 1
- 9
- 24
4
votes
1 answer
Predict the required number of preallocated nodes in a kD-Tree
I'm implementing a dynamic kD-Tree in array representation (storing the nodes in std::vector) in breadth-first fashion. Each i-th non-leaf node have a left child at (i<<1)+1 and a right child at (i<<1)+2. It would support incremental insertion of…

plasmacel
- 8,183
- 7
- 53
- 101
4
votes
2 answers
Simple C/C++ library for triangle-intersection acceleration structure
I'm raytracing and would like to speed it up via some acceleration structure (kd-tree, BVH, whatever). I don't want to code it up myself. What I've tried so far:
Yanking the kd-tree out of pbrt. There are so many intra-dependencies that I couldn't…

Meekohi
- 10,390
- 6
- 49
- 58
4
votes
2 answers
Confused about definition of a 'median' when constructing a kd-Tree
Im trying to build a kd-tree for searching through a set of points, but am getting confused about the use of 'median' in the wikipedia article. For ease of use, the wikipedia article states the pseudo-code of kd-tree construction as:
function kdtree…

Stephen
- 6,027
- 4
- 37
- 55
4
votes
1 answer
How to calculate the average time complexity of the nearest neighbor search using kd-tree?
We know the complexity of the nearest neighbor search of kd-tree is O(logn). But how to calculate it? The main problem is the average time complexity of the back tracing. I have tried to read the paper "An Algorithm for Finding Best Matches in…

PyChen
- 63
- 1
- 7
4
votes
1 answer
data structure for movable points in 3d
I have many points (+100,000) in 3 dimensional space. I need to use nearest neighbor and range queries. Firstly I used kdtree (k=3) but each point has a velocity attribute. Their location is not static, they change their location. The problem begins…

Taha Altuntaş
- 93
- 1
- 1
- 4