简体   繁体   English

计算到平滑线的距离

[英]Calculate distance to smoothed line

I'm trying to find the distance of a point (in 4 dimensions, only 2 are shown here) (any coloured crosses in the figure) to a supposed Pareto frontier (black line). 我试图找到一个点的距离(在4维中,这里只显示2个)(图中的任何彩色十字)到假定的帕累托边界(黑线)。 This line represents the best Pareto frontier representation during an optimization process. 该线代表优化过程中最佳的Pareto前沿表示。

Pareto = [[0.3875575798354123, -2.4122340425531914], [0.37707675586149786, -2.398936170212766], [0.38176077842761763, -2.4069148936170213], [0.4080534133844003, -2.4914285714285715], [0.35963459448268725, -2.3631532329495126], [0.34395217638838566, -2.3579931972789114], [0.32203302106516224, -2.344858156028369], [0.36742404637441123, -2.3886054421768708], [0.40461156254852226, -2.4141156462585034], [0.36387868122767975, -2.375], [0.3393199109776927, -2.348404255319149]]

Right now, I calculate the distance from any point to the Pareto frontier like this: 现在,我计算从任何一点到帕累托边境的距离,如下所示:

def dominates(row, rowCandidate):
return all(r >= rc for r, rc in zip(row, rowCandidate))

def dist2Pareto(pareto,candidate):
    listDist = []

    dominateN = 0
    dominatePoss = 0
    if len(pareto) >= 2:
        for i in pareto:
            if i != candidate:
                dominatePoss += 1
                dominate = dominates(candidate,i)
                if dominate == True:
                    dominateN += 1
                listDist.append(np.linalg.norm(np.array(i)-np.array(candidate)))

        listDist.sort()

        if dominateN == len(pareto):
            print "beyond"            
            return listDist[0]  
        else:
            return listDist[0]

Where I calculate the distance to each point of the black line, and retrieve the shortest distance (distance to the closest point of the known Frontier). 我计算到黑线每个点的距离,并检索最短距离(到已知前沿的最近点的距离)。

However, I feel I should calculate the distance to the closest line segment instead. 但是,我觉得我应该计算到最近的线段的距离。 How would I go about achieving this? 我将如何实现这一目标?

在此输入图像描述

The formula for the coordinates of the nearest point on the line is given here . 这里给出了线上最近点坐标的公式。 Specifically, you are interested in the one called "line defined by two points". 具体来说,您对“由两点定义的线”感兴趣。 For posterity, the formula is: 对于后代,公式是:

由两点和第三点定义的直线之间的距离公式

Because the frontier is relatively simple, you can loop through each two-point line segment in the frontier, and calculate the closest distance for each, keeping the smallest. 由于边界相对简单,您可以遍历边界中的每个两点线段,并计算每个线段的最近距离,保持最小。 You could introduce other constraints / pre-computations to limit the number of calculations required. 您可以引入其他约束/预计算来限制所需的计算次数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM