Questions tagged [nearest-neighbor]

Nearest neighbors are points (or other objects) in close proximity to a given location in some multi-dimensional space, e.g. a plane. Finding such neighbors lies at the core of several algorithms for various applications.

Nearest neighbors are points (or other objects) in close proximity to a given location in some multi-dimensional space, e.g. a plane. Finding such neighbors lies at the core of several algorithms for various applications.

Known applications of nearest-neighbor approaches

  • One of the first algorithms used to determine an approximate solution to the travelling salesman problem works like this: The salesman starts at a random city and repeatedly visits the nearest city until all have been visited.

This tag should be about questions related to

  • How to find nearest neighbors in a given setup
  • How to adjust nearest-neighbor approaches to taiolor them for specific needs
  • Algorithms which make use of nearest neighbors at some point
1155 questions
183
votes
15 answers

Nearest neighbors in high-dimensional data?

I have asked a question a few days back on how to find the nearest neighbors for a given vector. My vector is now 21 dimensions and before I proceed further, because I am not from the domain of Machine Learning nor Math, I am beginning to ask myself…
Legend
  • 113,822
  • 119
  • 272
  • 400
159
votes
6 answers

How to understand Locality Sensitive Hashing?

I noticed that LSH seems a good way to find similar items with high-dimension properties. After reading the paper http://www.slaney.org/malcolm/yahoo/Slaney2008-LSHTutorial.pdf, I'm still confused with those formulas. Does anyone know a blog or…
WoooHaaaa
  • 19,732
  • 32
  • 90
  • 138
71
votes
12 answers

Millions of 3D points: How to find the 10 of them closest to a given point?

A point in 3-d is defined by (x,y,z). Distance d between any two points (X,Y,Z) and (x,y,z) is d= Sqrt[(X-x)^2 + (Y-y)^2 + (Z-z)^2]. Now there are a million entries in a file, each entry is some point in space, in no specific order. Given any point…
Kazoom
  • 5,659
  • 16
  • 56
  • 69
71
votes
5 answers

How to filter numpy array by list of indices?

I have a numpy array, filtered__rows, comprised of LAS data [x, y, z, intensity, classification]. I have created a cKDTree of points and have found nearest neighbors, query_ball_point, which is a list of indices for the point and its neighbors. Is…
Barbarossa
  • 1,045
  • 5
  • 14
  • 24
47
votes
4 answers

What is the meaning of "from distinct vertex chains" in this nearest neighbor algorithm?

The following pseudo-code is from the first chapter of an online preview version of The Algorithm Design Manual (page 7 from this PDF). The example is of a flawed algorithm, but I still really want to understand it: [...] A different idea might be…
ClosureCowboy
  • 20,825
  • 13
  • 57
  • 71
31
votes
2 answers

Nearest Neighbor Search: Python

I have a 2 dimensional array: MyArray = array([6588252.24, 1933573.3, 212.79, 0, 0], [6588253.79, 1933602.89, 212.66, 0, 0], etc...) The first two elements MyArray[0] and MyArray[1] are the X and Y coordinates of…
Dlinet
  • 1,193
  • 3
  • 15
  • 22
23
votes
3 answers

Iterative Closest Point (ICP) implementation on python

I have been searching for an implementation of the ICP algorithm in python lately with no result. According to wikipedia article http://en.wikipedia.org/wiki/Iterative_closest_point, the algorithm steps are: Associate points by the nearest neighbor…
Harry R.
  • 751
  • 1
  • 5
  • 11
21
votes
3 answers

Image interpolation mode in Chrome/Safari?

I need to have an image render with nearest-neighbor resizing and not the bicubic way that is currently used. I currently use the following: ms-interpolation-mode: nearest-neighbor; image-rendering: -moz-crisp-edges; This works in IE and Firefox,…
Deniz Zoeteman
  • 9,691
  • 26
  • 70
  • 97
21
votes
6 answers

How to efficiently find k-nearest neighbours in high-dimensional data?

So I have about 16,000 75-dimensional data points, and for each point I want to find its k nearest neighbours (using euclidean distance, currently k=2 if this makes it easiser) My first thought was to use a kd-tree for this, but as it turns out they…
20
votes
1 answer

Find all nearest neighbors within a specific distance

I have a large list of x and y coordinates, stored in an numpy array. Coordinates = [[ 60037633 289492298] [ 60782468 289401668] [ 60057234 289419794]] ... ... What I want is to find all nearest neighbors within a specific distance (lets say 3…
Kitumijasi
  • 411
  • 1
  • 6
  • 13
20
votes
4 answers

Nearest-neighbor interpolation algorithm in MATLAB

I am trying to write my own function for scaling up an input image by using the Nearest-neighbor interpolation algorithm. The bad part is I am able to see how it works but cannot find the algorithm itself. I will be grateful for any help. Here's…
Hellnar
  • 62,315
  • 79
  • 204
  • 279
19
votes
3 answers

Finding near neighbors

I need to find "near" neighbors among a set of points. There are 10 points in the above image. Red lines are edges from the Delaunay Triangulation, black stars mark the mid-lines of the edges, blue lines are the Voronoi tesselation. Point 1 has…
Jonas
  • 74,690
  • 10
  • 137
  • 177
19
votes
8 answers

Pixel neighbors in 2d array (image) using Python

I have a numpy array like this: x = np.array([[1,2,3],[4,5,6],[7,8,9]]) I need to create a function let's call it "neighbors" with the following input parameter: x: a numpy 2d array (i,j): the index of an element in a 2d array d: neighborhood…
blueSurfer
  • 5,651
  • 13
  • 42
  • 63
18
votes
3 answers

How does the KD-tree nearest neighbor search work?

I am looking at the Wikipedia page for KD trees. As an example, I implemented, in python, the algorithm for building a kd tree listed. The algorithm for doing KNN search with a KD tree, however, switches languages and isn't totally clear. The…
davea
  • 181
  • 1
  • 1
  • 4
18
votes
1 answer

How to allow sklearn K Nearest Neighbors to take custom distance metric?

I have a custom distance metric that I need to use for KNN, K Nearest Neighbors. I tried following this, but I cannot get it to work for some reason. I would assume that the distance metric is supposed to take two vectors/arrays of the same…
makansij
  • 9,303
  • 37
  • 105
  • 183
1
2 3
76 77