我在3D空间中有一组点,我需要从中找到帕累托边界。执行速度在这里非常重要,并且时间增加非常快,因为我添加了测试点。快速计算Python中的Pareto前沿
的点的集合是这样的:
[[0.3296170319979843, 0.0, 0.44472108843537406], [0.3296170319979843,0.0, 0.44472108843537406], [0.32920760896951373, 0.0, 0.4440408163265306], [0.32920760896951373, 0.0, 0.4440408163265306], [0.33815192743764166, 0.0, 0.44356462585034007]]
现在,我使用这个算法:
def dominates(row, candidateRow):
return sum([row[x] >= candidateRow[x] for x in range(len(row))]) == len(row)
def simple_cull(inputPoints, dominates):
paretoPoints = set()
candidateRowNr = 0
dominatedPoints = set()
while True:
candidateRow = inputPoints[candidateRowNr]
inputPoints.remove(candidateRow)
rowNr = 0
nonDominated = True
while len(inputPoints) != 0 and rowNr < len(inputPoints):
row = inputPoints[rowNr]
if dominates(candidateRow, row):
# If it is worse on all features remove the row from the array
inputPoints.remove(row)
dominatedPoints.add(tuple(row))
elif dominates(row, candidateRow):
nonDominated = False
dominatedPoints.add(tuple(candidateRow))
rowNr += 1
else:
rowNr += 1
if nonDominated:
# add the non-dominated point to the Pareto frontier
paretoPoints.add(tuple(candidateRow))
if len(inputPoints) == 0:
break
return paretoPoints, dominatedPoints
这里找到:http://code.activestate.com/recipes/578287-multidimensional-pareto-front/
什么是找到的最快方法一组解决方案中的非主导解决方案?或者,简而言之,Python可以比这个算法做得更好吗?
哇,我错过了,谢谢彼得!我不确定我是否能够获得成本阵列,你能举一个简单的例子吗?再一次感谢,这看起来太棒了。 – Rodolphe
成本数组只是一个二维数组,其中cost [i,j]是第j个我认为它和你的inputPoints数组是一样的,你可以看到[tests here](https://github.com/QUVA-Lab/artemis/blob/master/artemis/general/) test_pareto_efficiency.py),它演示了它的用法。 – Peter