scipy.spatial.KDTree.query中distance_upper_bound参数的度量标准是什么? [英] What is the metric for distance_upper_bound parameter in scipy.spatial.KDTree.query?

查看:510
本文介绍了scipy.spatial.KDTree.query中distance_upper_bound参数的度量标准是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉scipy。我似乎不太清楚在 scipy.spatial.KDTree.query distance_upper_bound 的指标。是公里还是弧度

I am new to using scipy. I can't quite seem to figure out the metric of distance_upper_bound in scipy.spatial.KDTree.query. Is it in Kilometers or Radians?

推荐答案

这就是值根据您决定使用参数 p 的度量标准。

It's exactly the value in terms of the chosen metric on which you decided using parameter p.

如果确实选择了 p = 1 ,又称曼哈顿距离,向量的距离: x = [1,2,3] y = [2,3,4] 3 。如果您使用 distance_upper_bound = 2 并且 y x的下一个邻居您在寻找,不要期望正确的结果。

If you did chose p=1, aka manhattan-distance, the distance of the vectors: x=[1,2,3] and y=[2,3,4] is 3. If you would have used distance_upper_bound=2 and y is the next neighbor to x you are looking for, don't expect a correct result.

备注:您正在谈论的此参数设置为 inf 默认情况。

Remark: this parameter you are talking about is set to inf by default.

您的任务似乎与纬度/经度有关。在这种情况下,我认为您想使用 Haversine-metric (免责声明:我不是这方面的专家)。

Your task seems to be about latitude/longitude points. In this case, i think you want to use the Haversine-metric (disclaimer: i'm no expert in this area).

遗憾的是,根据 p规范,这是scipy的邻居搜索中唯一支持的规范!

Sadly, this metric is imho not available in terms of a p-norm, the only ones supported in scipy's neighbor-searches!

但是:sklearn的 BallTree 可以与Haversine一起使用! (KDTree不会!仍然是p范数!)

But: sklearn's BallTree can work with Haversine! (KDTree does not! Still p-norms!)

大概有一个很好的理由(无论是数学还是实际表现)为何KDTree不支持Haversine,而BallTree却支持。不要试图盲目地滚动自己的Haversine-KDTree!

There is probably a good reason (either math or practical performance) why KDTree is not supporting Haversine, while BallTree does. Don't try to roll your own Haversine-KDTree blindly!

来自

From here:


二叉搜索树无法通过设计处理极坐标表示的环绕。您可能需要将坐标转换为3D笛卡尔空间,然后应用自己喜欢的搜索算法,例如kD-Tree,Octree等。

A binary search tree cannot handle the wraparound of the polar representation by design. You might need to transform the coordinates to a 3D cartesian space and then apply your favorite search algorithm, e.g., kD-Tree, Octree etc.



from sklearn.neighbors import KDTree, BallTree

KDTree.valid_metrics
# ['euclidean', 'l2', 'minkowski', 'p', 'manhattan', 'cityblock', 'l1', 'chebyshev',
#  'infinity']

BallTree.valid_metrics
# ['euclidean', 'l2', 'minkowski', 'p', 'manhattan', 'cityblock', 'l1', 'chebyshev',
#  'infinity', 'seuclidean', 'mahalanobis', 'wminkowski', 'hamming', 'canberra',
#  'braycurtis', 'matching', 'jaccard', 'dice', 'kulsinski', 'rogerstanimoto', 'russellrao',
#  'sokalmichener', 'sokalsneath', 'haversine', 'pyfunc']

这篇关于scipy.spatial.KDTree.query中distance_upper_bound参数的度量标准是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆