电子围栏的局部最优

发布于 2024-08-21 13:07:56 字数 1096 浏览 9 评论 0原文

我正在为 Usaco 问题“电围栏”编写一个解决方案。 在该问题中,您必须在大量线段中找到点的最佳位置,因此点线段距离之和尽可能最小。

我有一个想法,也许可以进行爬山,并且它适用于所有测试用例。给定的分析使用了类似的方法,但没有解释为什么这种方法有效。

因此,我仍然无法证明或反驳给定任务中局部最优的存在。我有一个想法,可以使用归纳法来完成,但我一直无法使其发挥作用。你能帮助我吗?

更新定义

给定一组 (x1,y1,x2,y2) 线段,找到 (x,y) 点 P,从而最小化函数:

def Val(x,y):
    d = 0
    for x1,y1,x2,y2 in LineSegments:
        if triangle (x1,y1,x2,y2,x,y) is not obtuse in (x1,y1) or (x2,y2):
            d += DistPointToLine(x,y,x1,y1,x2,y2)
        else:
            d += min(DistPointToPoint(x,y,x1,y1), DistPointToPoint(x,y,x2,y2))
    return d

由于某种原因,问题仅包含一个局部最优值,并且因此可以使用以下过程来解决它:

precision = ((-0.1,0), (0.1,0), (0,-0.1), (0,0.1))
def Solve(precision=0.1):
    x = 0; y = 0
    best = Val(x,y)
    while True:
        for dx,dy in precision:
            if Val(x+dx, y+dy) > best:
                x += dx; y += dy
                best = Val(x,y)
                break
        else:
            break
    return (x,y)

问题是:为什么这不会在实现全局最优的过程中陷入困境?为什么没有本地山顶来将这个简单的过程带到它的膝盖?

I'm writing a solution for the Usaco problem "Electric Fences".
In the problem you have to find the optimal location for a point among a large amount of linesegments, so the sum of point-linesegment distances is smallest possible.

I had an idea, that it might be possible to do a hillclimb, and it worked for all testcases. The given analysis used a similar method, but it did not explain why this would work.

Thus I'm still unable to either prove or disprove the existence of local optimums in the given tasks. I had an idea that it could be done using induction, but I haven't been able to make it work. Can you help me?

Updated definition

Given a set of (x1,y1,x2,y2) linesegments find the (x,y) point P, that minimizes the function:

def Val(x,y):
    d = 0
    for x1,y1,x2,y2 in LineSegments:
        if triangle (x1,y1,x2,y2,x,y) is not obtuse in (x1,y1) or (x2,y2):
            d += DistPointToLine(x,y,x1,y1,x2,y2)
        else:
            d += min(DistPointToPoint(x,y,x1,y1), DistPointToPoint(x,y,x2,y2))
    return d

By some reason the problem contains only one local optima, and thus the following procedure can be used to solve it:

precision = ((-0.1,0), (0.1,0), (0,-0.1), (0,0.1))
def Solve(precision=0.1):
    x = 0; y = 0
    best = Val(x,y)
    while True:
        for dx,dy in precision:
            if Val(x+dx, y+dy) > best:
                x += dx; y += dy
                best = Val(x,y)
                break
        else:
            break
    return (x,y)

The questions is: Why does this not get stuck somewhere on the way to the global optimum? Why is there no local hilltops to bring this naive procedure to its knees?

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

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

发布评论

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

评论(1

捎一片雪花 2024-08-28 13:07:56

如果我们注意到单线段的距离函数是一个凸函数,那么很容易证明算法的正确性。在这种情况下,凸意味着如果我们将距离函数视为表面 z=f(x,y),那么如果我们填充表面上方的体积,我们就会得到一个凸实体。在距单条线段的距离的情况下,实体看起来像具有圆锥形末端的三角形楔子。

由于凸函数之和也是凸的,那么多条线的距离之和线段也将是凸函数。因此,由于函数是凸函数,您找到的任何局部最小值也必须是全局最小值。

It is easy to prove the algorithm's correctness if we notice that the distance function for a single line segment is a convex function. Convex in this case means that if we think of the distance function as a surface z=f(x,y), then if we filled in the volume above the surface, we'd have a convex solid. In the case of the distance from a single line segment, the solid would look like a triangular wedge with conical ends.

Since the sum of convex functions is also convex, then the sum of distances from multiple line segments will also be a convex function. Therefore, any local minimum you find must also be a global minimum by virtue of the function being convex.

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