Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithms for finding closest vector

I have a set of vectors. For a vector in that set I like to find the sub set that is closeest to this vector. What algorithm can do this.

like image 966
joel Avatar asked Apr 14 '10 08:04

joel


People also ask

How do you find the nearest vector?

It is the minimization of the sum of squares of the components of →b−A→x, so that ||→b−A→x∗||≤||→b−A→x||,∀→x∈R4. This is precisely the vector "closest" to →b.

How do you find the shortest vector in lattice?

This can be done by using a quite simple algorithm, called the Lagrange-Gauss algorithm. This algorithm iteratively improves the shortness of the two vectors of our basis, until one of the basis vector becomes a shortest element of the lattice.


3 Answers

This class of algorithms is called Nearest Neighbor or K Nearest Neighbor.

The cosine similarity as excepeiont says will work if direction of vector is important. If the vector represents a position in a space, then any metric for representing a distance in the space will work.

For example the Euclidean distance: take the square root of the sum of squares difference in each dimension. This will give you a distance for each vector, then sort your set of vectors ascending on this distance.

This process will be O(N) in time. If this is too slow for you, you might want to look at some common K Nearest Neighbour algorithms.

like image 91
Nick Fortescue Avatar answered Sep 24 '22 02:09

Nick Fortescue


use the cosinus similarity (http://en.wikipedia.org/wiki/Cosine_similarity) among the vectors and then sort them.

like image 22
excepeiont32 Avatar answered Sep 26 '22 02:09

excepeiont32


If your problem relates to large amount of data:

I published a related algorithm on ddj.com, that finds the nearest line to a given point:

Accelerated Search For the Nearest Line

You would have to modify this algorithm by i.e. by converting the given vector to a number of points. This will reduce the number of possible matches drastically. The exact match has then to be checked for each possible match by

  • Find the cutting point of both vectors or
  • Get distance from vector start and end point to the possible match, as described in the article
like image 33
RED SOFT ADAIR Avatar answered Sep 24 '22 02:09

RED SOFT ADAIR