是否有可能找到位于 KD 树 *IN* 中的节点的 KNN?

发布于 2024-08-26 07:53:14 字数 222 浏览 8 评论 0原文

尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦屿孤独相伴 2024-09-02 07:53:14

如果您想要树中的 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).

清醇 2024-09-02 07:53:14

这并不是一个真正的答案,但我无法将我想要粘贴到评论中的内容放入其中。无论如何,这是来自维基百科的相关文本:

该算法可以扩展为
通过简单修改的​​几种方法。
它可以提供k-最近邻
通过维持 k 电流达到某一点
最好的而不是只有一个。分支机构
只有当他们不能时才会被淘汰
有比 k 中任何一个更接近的点
目前最好的。

它也可以转换为
近似算法运行得更快。
例如,近似最近的
邻居搜索可以通过以下方式实现
只需设置一个上限
树中要检查的点数,
或通过中断搜索过程
基于实时时钟(
可能更适合硬件
实施)。最近邻居
对于树中的点
已经可以通过不实现
更新节点的细化
给出零距离作为结果,这
缺点是会丢弃分数
这些并不是唯一的,但是
与原始搜索位于同一位置
点。

近似最近邻很有用
在实时应用程序中,例如
机器人技术由于速度显着
不寻找所获得的增加
详尽地阐述了最好的观点。之一
它的实现是 Best Bin First。

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:

The algorithm can be extended in
several ways by simple modifications.
It can provide the k-Nearest Neighbors
to a point by maintaining k current
bests instead of just one. Branches
are only eliminated when they can't
have points closer than any of the k
current bests.

It can also be converted to an
approximation algorithm to run faster.
For example, approximate nearest
neighbour searching can be achieved by
simply setting an upper bound on the
number points to examine in the tree,
or by interrupting the search process
based upon a real time clock (which
may be more appropriate in hardware
implementations). Nearest neighbour
for points that are in the tree
already can be achieved by not
updating the refinement for nodes that
give zero distance as the result, this
has the downside of discarding points
that are not unique, but are
co-located with the original search
point.

Approximate nearest neighbor is useful
in real time applications such as
robotics due to the significant speed
increase gained by not searching for
the best point exhaustively. One of
its implementations is Best Bin First.

┊风居住的梦幻卍 2024-09-02 07:53:14

我建议您查看 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文