如何生成空间数据帧的k近邻矩阵?
我有一个大约有 3000 个点的空间数据框。我想生成一个矩阵,为每个点提供 k 个(在本例中为 30 个)最近邻点。
我可以使用循环来做到这一点,但我觉得对于我不知道的空间点数据帧类应该有一种优雅且最佳的方法。
I have a spatial dataframe with about 3000 points. I want to generate a matrix that provides the k (in this case 30) nearest neighbors for each point.
I can do it using a loop but i feel that there should be an elegant and optimal way for spatial points dataframe class that i do not know of.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最快的可能是使用
RANN
包 - 假设您有x
和y
:为您提供最近邻的 3000 x 30 矩阵。它比简单的二次搜索快几个数量级。
编辑:为了完整起见,您选择哪个 ANN 前端并不重要,使用
FNN
(由 Spacedman 建议)这将是Probably the fastest is to use
RANN
package - assuming you havex
andy
:gives you a 3000 x 30 matrix of closest neighbors. It is several orders of magnitude faster than a naive quadratic search.
Edit: Just for completeness, it doesn't matter which ANN frontend you pick, with
FNN
(suggested by Spacedman) this would be