Kd树问题

发布于 2024-11-13 07:51:26 字数 1045 浏览 5 评论 0原文

我正在尝试实现并理解 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 of
Calculate the median x-value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

夜空下最亮的亮点 2024-11-20 07:51:26

您的具有xy值。通过排序可以得到x值的中位数通过x,然后取中间元素的x(对于奇数个)或两个中间点的平均值< /code>' x (对于偶数个)。

或者,使用快速选择算法,例如中位数中位数。

Your points have x and y values. The median of x values can be obtained by sorting by x, then taking the middle element's x (for an odd number of points) or the mean of the two middle points' x (for an even number of points).

Alternatively, use a fast selection algorithm such as median-of-medians.

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