How to find the closest 2 points in a 100 dimensional space with 500,000 points?

前端 未结 5 1980
无人及你
无人及你 2021-01-31 11:26

I have a database with 500,000 points in a 100 dimensional space, and I want to find the closest 2 points. How do I do it?

Update: Space is Euclidean, Sorry. And thanks

相关标签:
5条回答
  • 2021-01-31 11:55

    There's a chapter in Introduction to Algorithms devoted to finding two closest points in two-dimensional space in O(n*logn) time. You can check it out on google books. In fact, I suggest it for everyone as the way they apply divide-and-conquer technique to this problem is very simple, elegant and impressive.

    Although it can't be extended directly to your problem (as constant 7 would be replaced with 2^101 - 1), it should be just fine for most datasets. So, if you have reasonably random input, it will give you O(n*logn*m) complexity where n is the number of points and m is the number of dimensions.

    edit
    That's all assuming you have Euclidian space. I.e., length of vector v is sqrt(v0^2 + v1^2 + v2^2 + ...). If you can choose metric, however, there could be other options to optimize the algorithm.

    0 讨论(0)
  • 2021-01-31 11:57

    Run PCA on your data to convert vectors from 100 dimensions to say 20 dimensions. Then create a K-Nearest Neighbor tree (KD-Tree) and get the closest 2 neighbors based on euclidean distance.

    Generally if no. of dimensions are very large then you have to either do a brute force approach (parallel + distributed/map reduce) or a clustering based approach.

    0 讨论(0)
  • 2021-01-31 12:00

    Use the data structure known as a KD-TREE. You'll need to allocate a lot of memory, but you may discover an optimization or two along the way based on your data.

    http://en.wikipedia.org/wiki/Kd-tree.

    My friend was working on his Phd Thesis years ago when he encountered a similar problem. His work was on the order of 1M points across 10 dimensions. We built a kd-tree library to solve it. We may be able to dig-up the code if you want to contact us offline.

    Here's his published paper: http://www.elec.qmul.ac.uk/people/josh/documents/ReissSelbieSandler-WIAMIS2003.pdf

    0 讨论(0)
  • 2021-01-31 12:06

    Use a kd tree. You're looking at a nearest neighbor problem and there are highly optimized data structures for handling this exact class of problems.

    http://en.wikipedia.org/wiki/Kd-tree

    P.S. Fun problem!

    0 讨论(0)
  • 2021-01-31 12:11

    You could try the ANN library, but that only gives reliable results up to 20 dimensions.

    0 讨论(0)
提交回复
热议问题