是否有可能找到位于 KD 树 *IN* 中的节点的 KNN?
尝试使用 KD 树创建 KNN 搜索。我可以很好地形成 KD 树(或者至少,我相信我可以!)。我的问题是我正在寻找距离点列表中每个点最近的 2 个邻居。
那么,有没有一种方法可以使用 KD 树找到某个点的 K 个最近邻,即使该点实际上在树中,还是我需要为每个点构建一个单独的 KD 树,而忽略我希望的点寻找?
我的实现语言是 C++,但我更寻找算法或一般帮助,谢谢!
谢谢, 斯蒂芬
Trying to create a KNN search using a KD-tree. I can form the KD-tree fine (or at least, I believe I can!). My problem is that I am searching to find the closest 2 neighbours to every point in a list of points.
So, is there a method to find the K nearest neighbours to a point using a KD tree even if the point is actually IN the tree, or do I need to construct a seperate KD tree for each point, leaving out the point that I wish to search for?
My implementation language is C++, but I am more looking for either an algorithm or general help, thanks!
Thanks,
Stephen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想要树中的 K 精确 个最近邻居,只需在树中查询 K+1 个邻居(显然是从第一个最近邻居开始)将是您的查询)。
If you want the K exact nearest-neighbors within your tree, just query the tree for K+1 neighbors (obviously since the first nearest neighbor will be your query).
这并不是一个真正的答案,但我无法将我想要粘贴到评论中的内容放入其中。无论如何,这是来自维基百科的相关文本:
This isn't really much of an answer, but I can't fit what I want to paste into a comment. Anyhow, here's the relevant text from Wikipedia:
我建议您查看 ANN 以了解实施细节 http://www.cs。 umd.edu/~mount/ANN/
它专为近似最近邻搜索而设计,但也可以进行精确最近邻搜索。它也是我发现的最清晰、编写得最好的代码之一,即使您想要自己的实现,也应该为您提供一些见解。
I'd recommend taking a look at ANN for implementation details http://www.cs.umd.edu/~mount/ANN/
It's designed for approximate nearest neighbor searches, but can also do exact nearest neighbor searches. It's also some of the clearest and best written code I've ever found, and should give you some insight even if you want your own implementation.