计算到平滑线的距离

时间:2015-11-11 20:42:29

标签: python numpy interpolation

我试图找到一个点的距离(4维,这里只显示2个)(图中的任何彩色十字)到假定的帕累托边界(黑线)。该线代表优化过程中最佳的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]]

现在,我计算从任何一点到帕累托边境的距离,如下所示:

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]

我计算到黑线每个点的距离,并检索最短距离(到已知边界的最近点的距离)。

但是,我觉得我应该计算到最近的线段的距离。我将如何实现这一目标?

enter image description here

1 个答案:

答案 0 :(得分:1)

线上最近点坐标的公式为here。具体来说,您感兴趣的是由两个点"定义的名为"的行。对于后代,公式是:

Formula for distance between a line defined by two points, and a third point

由于边界相对简单,您可以遍历边界中的每个两点线段,并计算每个线段的最近距离,保持最小。您可以引入其他约束/预计算来限制所需的计算次数。