python – KD-tree最近鄰搜尋如何工作?
中實現了用於構建列出的kd樹的演算法.
然而,使用KD樹進行KNN搜尋的演算法切換語言,並不完全清楚.英語解釋開始有意義,但其中的一部分(例如“放鬆遞迴”來檢查其他葉節點)的區域對我來說並不真實.
這是如何工作的,如何用python中的KD樹進行KNN搜尋?這不是一個“發給我的程式碼!”型別的問題,我不期望.只是一個簡短的解釋請:)
,第3頁:
Given a set of n points in a d-dimensional space, the kd-tree is constructedrecursively as follows. First, one finds a median of the values of the ithcoordinates of the points (initially, i = 1). That is, a value M is computed,so that at least 50% of the points have their ith coordinate greater-or-equalto M, while at least 50% of the points have their ith coordinate smallerthan or equal to M. The value of x is stored, and the set P is partitionedinto PL and PR , where PL contains only the points with their ith coordinatesmaller than or equal to M, and |PR | = |PL |±1. The process is then repeatedrecursively on both PL and PR , with i replaced by i + 1 (or 1, if i = d).When the set of points at a node has size 1, the recursion stops.
以下段落討論了它在解決最近鄰居方面的用途.
或者,這裡是original 1975 paper by Jon Bentley .
編輯:我應該補充說,SciPy有一個kdtree實現:
程式碼日誌版權宣告:
翻譯自:http://stackoverflow.com/questions/4418450/how-does-the-kd-tree-nearest-neighbor-search-work