multidim.PointCloud.nearest_neighbors_slow

PointCloud.nearest_neighbors_slow(k)[source]

Compute k nearest-neighbors of the PointCloud, by brute-force. Answers are cached in self._nn[k]

Parameters:
k: int

How many nearest neighbors to compute

Returns:
np array with dtype int and shape==(N,k+1). Entry [i,j] is the jth
nearest neighbor of vertex i. Note that entry [i,0] == i, so [i,k]
is the kth nearest neighbor.

Notes

This method is intended for testing, and should only be used on small datasets. On a random example with 1,000 points in \(\mathbb{R}^2:\) seeking k=5 nearest neighbors, this method takes at least twice as long as nearest_neighbors(), and the discrepency is roughly quadratic. On 2,000 points, it is about 4 times slower.

Examples

>>> pc = PointCloud(np.array([[ 0.58814682,  0.45405299],
...                           [ 0.09197879,  0.39721367],
...                           [ 0.29128654,  0.28372039],
...                           [ 0.14593167,  0.7027367 ],
...                           [ 0.77068438,  0.37849037],
...                           [ 0.17281855,  0.70204687],
...                           [ 0.48146217,  0.54619034],
...                           [ 0.27831744,  0.67327757],
...                           [ 0.49074255,  0.70847318],
...                           [ 0.132656,    0.0860524 ]]))
>>> pc.nearest_neighbors_slow(3)
array([[0, 6, 4, 8],
       [1, 2, 3, 9],
       [2, 1, 9, 6],
       [3, 5, 7, 1],
       [4, 0, 6, 8],
       [5, 3, 7, 1],
       [6, 0, 8, 7],
       [7, 5, 3, 8],
       [8, 6, 7, 0],
       [9, 2, 1, 6]])