Kd树问题
我正在尝试实现并理解 KdTree
,以下是我找到的链接。 http://ldots.org/kdtree/#buildingAkDTree 但我无法理解以下算法
tuple function build_kd_tree(int depth, set points):
if points contains only one point:
return that point as a leaf.
if depth is even:
Calculate the median x-value.
Create a set of points (pointsLeft) that have x-values less than
the median.
Create a set of points (pointsRight) that have x-values greater
than or equal to the median.
else:
Calculate the median y-value.
Create a set of points (pointsLeft) that have y-values less than
the median.
Create a set of points (pointsRight) that have y-values greater
than or equal to the median.
treeLeft = build_kd_tree(depth + 1, pointsLeft)
treeRight = build_kd_tree(depth + 1, pointsRight)
return(median, treeLeft, treeRight)
我不明白是什么意思 计算 x 值中位数。
I am trying to implementation and understand KdTree
, Following is the link I found.
http://ldots.org/kdtree/#buildingAkDTree
But I fail to understand following algorithm
tuple function build_kd_tree(int depth, set points):
if points contains only one point:
return that point as a leaf.
if depth is even:
Calculate the median x-value.
Create a set of points (pointsLeft) that have x-values less than
the median.
Create a set of points (pointsRight) that have x-values greater
than or equal to the median.
else:
Calculate the median y-value.
Create a set of points (pointsLeft) that have y-values less than
the median.
Create a set of points (pointsRight) that have y-values greater
than or equal to the median.
treeLeft = build_kd_tree(depth + 1, pointsLeft)
treeRight = build_kd_tree(depth + 1, pointsRight)
return(median, treeLeft, treeRight)
I do not understand what is the meaning ofCalculate the median x-value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
点
具有x
和y
值。通过排序可以得到x
值的中位数通过x
,然后取中间元素的x
(对于奇数个点
)或两个中间点的平均值< /code>'
x
(对于偶数个点
)。或者,使用快速选择算法,例如中位数中位数。
Your
points
havex
andy
values. The median ofx
values can be obtained by sorting byx
, then taking the middle element'sx
(for an odd number ofpoints
) or the mean of the two middlepoints
'x
(for an even number ofpoints
).Alternatively, use a fast selection algorithm such as median-of-medians.