我在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