我在多維空間中有大量的點。我想找到幾個鄰居(在附近)任何給定的點(要求是爲了避免掃描所有點)。查找大集合中的nearset鄰居
我想知道如果我的解決辦法是適當的:
預處理:
- 定義設置的ortogonal軸系
- 使每個點的投影每個軸上
- 每個投影都與從軸(鍵)的起點到點(值)的標識符的距離相關聯。 指數預測 - 把所有的人都到有序set(如樹集)
dist = distance of projection to the start point of axis point_num = number of point sorted_set.put(dist, point_num)
找到任何給定的點的鄰居:
- 查找其投射在每個軸上
- 使用idexes - 在每個exis上查找最近投影數
- 查找實際的鄰居 - 相交所有的導致
dx = radius of neighborhood (some constant) dist_1 = distance of projection of given point to start point of axis_1 list_1 = sorted_set_1.get_sub_set(dist_1 - dx, dist_1 + dx) dist_2 = distance of projection of given point to start point of axis_2 list_2 = sorted_set_2.get_sub_set(dist_2 - dx, dist_2 + dx) return intersection_of(list_1, list_2)
下面是一個簡單的例子:
相交[2, 4, 1]
和[4, 5]
產生回答[4]
請點我,如果我在我的算法來實現任何錯誤
感謝
「2.對每個軸上的每個點進行投影」如何避免掃描所有需要的點? – AndyG 2013-02-15 16:11:06
預處理將只進行一次(在紅黑樹的情況下,複雜度爲O(N * lg(N))作爲索引的基礎結構) - 所以這對我來說不是問題。但是發現鄰居是非常頻繁的操作,所以我不想每次掃描所有點時,找到每個給定點的鄰居。 – stemm 2013-02-15 16:19:47
你看過K-D樹嗎? http://en.wikipedia.org/wiki/K-d_tree – AndyG 2013-02-15 16:21:24