Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between scipy.spatial.KDTree and scipy.spatial.cKDTree

What is the difference between these two algorithms?

like image 694
Benjamin Avatar asked Aug 03 '11 18:08

Benjamin


People also ask

What is scipy KDTree?

kd-tree for quick nearest-neighbor lookup. This class provides an index into a set of k-dimensional points which can be used to rapidly look up the nearest neighbors of any point.

How do you use Scipy KDTree?

Let's understand with an example by following the below steps: Import the required libraries using the below python code. Generate data points using the random generator as shown in the below code. Pass the points to kdtree and find all point pairings within a r distance in a kd-tree using the below code.

What Scipy spatial?

scipy. spatial can compute triangulations, Voronoi diagrams, and convex hulls of a set of points, by leveraging the Qhull library. Moreover, it contains KDTree implementations for nearest-neighbor point queries, and utilities for distance computations in various metrics.


1 Answers

cKDTree is a subset of KDTree, implemented in C++ wrapped in Cython, so therefore faster.

Each of them is

a binary trie, each of whose nodes represents an axis-aligned hyperrectangle. Each node specifies an axis and splits the set of points based on whether their coordinate along that axis is greater than or less than a particular value.

but KDTree

also supports all-neighbors queries, both with arrays of points and with other kd-trees. These do use a reasonably efficient algorithm, but the kd-tree is not necessarily the best data structure for this sort of calculation.

like image 168
agf Avatar answered Sep 22 '22 05:09

agf