简而言之:
只有自己进行时间测量才能确定。
您应该确保 NN 库是否比蛮力更快,您的数据可能就是这种情况。
正如评论中提到的安德拉斯,搜索半径也起着重要作用。如果很多点落入搜索半径内,搜索会变得非常缓慢。
完整答案:
3 个维度并不多。由于您拥有的点数而出现问题。
ANN 代表近似最近邻搜索。在涉及 NNS(最近邻搜索)时,接受准确度和速度之间的权衡是很常见的。
这意味着您执行搜索的速度更快,但您可能找不到确切的 NN,而是找到一个接近的(例如,不是最近的点,而是第二近的点,依此类推)。更快的速度意味着更低的准确性,反之亦然。
CGAL还有一个参数epsilon,代表精度(ε=0表示完全精度)。 CGAL 是为了达到 3 个维度,所以你可以试一试。
我可以测试自己并发布答案。但是,这不是 100% 安全的,因为您所拥有的点可能有一些关系。如果要利用点(可能)彼此之间的关系,这对库的性能非常重要。
另一个需要考虑的因素,安装的容易程度。
CGAL 很难安装。当我这样做时,我遵循these 的步骤。
ANN 易于安装。
我还建议你看看 BOOST Geometry,它可能会派上用场。
FLANN 也是该领域的佼佼者,但我不建议这样做,因为它旨在处理更大尺寸的数据集(例如 128)。
....
好吧,我承认,我现在对自己很好奇,我要进行一些测试!
....
ANN
(我没有发布代码,因此答案不会变得太大。文档中有示例,您当然可以询问是否需要!)。
输出:
// 克莱因瓶
samaras@samaras-A15:~/Inria/nn_libs/ANN/ann_1.1.2/code$ g++ main.cpp -O3 -I ../include/ -L../lib -lANN -std=c++0x -o myExe
samaras@samaras-A15:~/Inria/nn_libs/ANN/ann_1.1.2/code$ ./myExe
N = 1000000
D = 3
ε = 0 // full accuracy
Misses: 0
creation of the tree took 1.06638 seconds.
Brute force for min: 0.009985598 seconds.
NN for 0.0 0.000078551 seconds.
Speedup of ANN for NN = 8.721533780
对于ε = 0.1,我得到了:
Misses: 1000
creation of the tree took 0.727613 seconds.
Brute force for min: 0.006351318 seconds.
NN for 0.0 0.000004260 seconds.
Speedup of ANN for NN = 8.678169573
//对于一个shpere
ε = 0
Misses: 0
creation of the tree took 1.28098 seconds.
Brute force for min: 0.006382912 seconds.
NN for 0.0 0.000022341 seconds.
Speedup of ANN for NN = 4.897436311
ε = 0.1
Misses: 1000
creation of the tree took 1.25572 seconds.
Brute force for min: 0.006482465 seconds.
NN for 0.0 0.000004379 seconds.
Speedup of ANN for NN = 5.144413371
注意加速的差异!这与数据集的性质有关,如上所述(点之间的关系)。
CGAL:
// 克莱因瓶
samaras@samaras-A15:~/code/NN$ ./myExe
ε = 0
SplitingRule = Sliding_midpoint, N = 1000000, D = 3
creation of the tree took 0.02478 seconds.
Tree statistics:
Number of items stored: 1000000
Number of nodes: 471492
Tree depth: 34
0x80591e4
Brute force for min: 0.007979495 seconds.
NN for 0.0 0.008085704 seconds.
Speedup of cgal for NN = 0.983849423
ε = 0.1
SplitingRule = Sliding_midpoint, N = 1000000, D = 3
creation of the tree took 0.02628 seconds.
Tree statistics:
Number of items stored: 1000000
Number of nodes: 471492
Tree depth: 34
0x80591e4
Brute force for min: 0.007852951 seconds.
NN for 0.0 0.007856228 seconds.
Speedup of cgal for NN = 0.996250305
// 球体
samaras@samaras-A15:~/code/NN$ ./myExe
ε = 0
SplitingRule = Sliding_midpoint, N = 1000000, D = 3
creation of the tree took 0.025502 seconds.
Tree statistics:
Number of items stored: 1000000
Number of nodes: 465002
Tree depth: 32
0x80591e4
Brute force for min: 0.007946504 seconds.
NN for 0.0 0.007981456 seconds.
Speedup of cgal for NN = 0.992449817
samaras@samaras-A15:~/code/NN$ ./myExe
ε = 0.1
SplitingRule = Sliding_midpoint, N = 1000000, D = 3
creation of the tree took 0.025106 seconds.
Tree statistics:
Number of items stored: 1000000
Number of nodes: 465002
Tree depth: 32
0x80591e4
Brute force for min: 0.008115519 seconds.
NN for 0.0 0.008117261 seconds.
Speedup of cgal for NN = 0.996702679
在我的测试中,ANN 比 CGAL 更清晰,可能你的也一样!
附注:
您实际上要求每个点的 NN。但是,图书馆不知道这一点,也没有考虑到之前为每个点所做的工作,这是一个遗憾。但是,我不知道有任何图书馆这样做。