Function for finding a 2D Pareto frontier given two lists of matched length.
1 2 3 4 5 6 7 8 9 10 11 12 13 | def pareto_frontier(Xs, Ys, maxX = True, maxY = True):
myList = sorted([[Xs[i], Ys[i]] for i in range(len(Xs))], reverse=maxX)
p_front = [myList[0]]
for pair in myList[1:]:
if maxY:
if pair[1] >= p_front[-1][1]:
p_front.append(pair)
else:
if pair[1] <= p_front[-1][1]:
p_front.append(pair)
p_frontX = [pair[0] for pair in p_front]
p_frontY = [pair[1] for pair in p_front]
return p_frontX, p_frontY
|
This is a simple method for finding a 2D Pareto frontier. It gives the option to prefer either small or large values for the X and Y parameters.
For more info and discussion see the Pareto frontiers in Python post on the oCo Carbon blog.