简体   繁体   English

具有周期性边界条件的最近邻搜索

[英]Nearest neighbor search with periodic boundary conditions

In a cubic box I have a large collection points in R^3. 在立方体盒子里,我在R ^ 3中有一个大的收集点。 I'd like to find the k nearest neighbors for each point. 我想为每个点找到k个最近邻居。 Normally I'd think to use something like a kd tree, but in this case I have periodic boundary conditions. 通常我认为使用类似kd树的东西,但在这种情况下我有周期性的边界条件。 As I understand it, a kd tree works by partitioning the space by cutting it into hyper planes of one less dimension, ie in 3D we would split the space by drawing 2D planes. 据我了解,kd树的工作原理是通过将空间切割成一个较小维度的超平面来划分空间,即在3D中我们将通过绘制2D平面来分割空间。 For any given point, it is either on the plane, above it, or below it. 对于任何给定的点,它可以在平面上,在它上面,也可以在它下面。 However, when you split the space with periodic boundary conditions a point could be considered to be on either side! 但是,当您使用周期性边界条件分割空间时,可以认为点在两侧!

What's the most efficient method of finding and maintaining a list of nearest neighbors with periodic boundary conditions in R^3? 在R ^ 3中找到并维护具有周期性边界条件的最近邻居列表的最有效方法是什么?

Approximations are not sufficient, and the points will only be moved one at a time (think Monte Carlo not N-body simulation). 近似是不够的,这些点只能一次移动一个(想想蒙特卡罗不是N体模拟)。

Even in the Euclidean case, a point and its nearest neighbor may be on opposite sides of a hyperplane. 即使在欧几里德的情况下,一个点及其最近的邻居可能位于超平面的相对侧。 The core of nearest-neighbor search in a kd tree is a primitive that determines the distance between a point and a box; kd树中最近邻搜索的核心是确定点和盒之间距离的基元; the only modification necessary for your case is to take the possibility of wraparound into account. 您的案例所需的唯一修改是考虑环绕的可能性。

Alternatively, you could implement cover trees, which work on any metric. 或者,您可以实现覆盖树,它适用于任何指标。

(I'm posting this answer even though I'm not fully sure it works. Intuitively it seems right, but there might be an edge case I haven't considered) (我发布这个答案,即使我不完全确定它是否有效。直观地看来它是正确的,但可能有一个我没有考虑的边缘情况)

If you're working with periodic boundary conditions, then you can think of space as being cut into a series of blocks of some fixed size that are all then superimposed on top of one another. 如果您正在处理周期性边界条件,那么您可以将空间视为切割成一系列固定大小的块,然后将它们叠加在一起。 Suppose that we're in R 2 . 假设我们在R 2 Then one option would be to replicate that block nine times and arrange them into a 3x3 grid of duplicates of the block. 然后一个选项是复制该块九次并将它们排列成块的3x3网格重复。 Given this, if we find the nearest neighbor of any single node in the central square, then either 鉴于此,如果我们找到中心正方形中任何单个节点的最近邻居,那么

  1. The nearest neighbor is inside the central square, in which case the neighbor is a nearest neighbor, or 最近的邻居在中心广场内,在这种情况下,邻居是最近的邻居,或
  2. The nearest neighbor is in a square other than the central square. 最近的邻居在中心广场以外的广场上。 In that case, if we find the point in the central square that the neighbor corresponds to, that point should be the nearest neighbor of the original test point under the periodic boundary condition. 在这种情况下,如果我们在中心方块中找到邻居所对应的点,则该点应该是在周期性边界条件下的原始测试点的最近邻居。

In other words, we just replicate the elements enough times so that the Euclidean distance between points lets us find the corresponding distance in the modulo space. 换句话说,我们只需复制元素足够多次,以便点之间的欧几里德距离让我们在模数空间中找到相应的距离。

In n dimensions, you would need to make 3 n copies of all the points, which sounds like a lot, but for R 3 is only a 27x increase over the original data size. 在n维中,您需要为所有点制作3 n个副本,这听起来很多,但对于R 3而言 ,仅比原始数据大小增加了27倍。 This is certainly a huge increase, but if it's within acceptable limits you should be able to use this trick to harness a standard kd-tree (or other spacial tree). 这肯定是一个巨大的增长,但如果它在可接受的范围内,你应该能够使用这个技巧来利用标准的kd树(或其他空间树)。

Hope this helps! 希望这可以帮助! (And hope this is correct!) (希望这是正确的!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM