import matplotlib.pyplot as plt
def plot_pareto_frontier(Xs, Ys, maxX=True, maxY=True):
'''Pareto frontier selection process'''
sorted_list = sorted([[Xs[i], Ys[i]] for i in range(len(Xs))], reverse=maxY)
pareto_front = [sorted_list[0]]
for pair in sorted_list[1:]:
if maxY:
if pair[1] >= pareto_front[-1][1]:
pareto_front.append(pair)
else:
if pair[1] <= pareto_front[-1][1]:
pareto_front.append(pair)
'''Plotting process'''
plt.scatter(Xs,Ys)
pf_X = [pair[0] for pair in pareto_front]
pf_Y = [pair[1] for pair in pareto_front]
plt.plot(pf_X, pf_Y)
plt.xlabel("Objective 1")
plt.ylabel("Objective 2")
plt.show()
An example Pareto frontier graphic is produced by above python function.
Reference 1. http://code.activestate.com/recipes/578230-pareto-front/
This code has an error in it. The line:
ReplyDeletesorted_list = sorted([[Xs[i], Ys[i]] for i in range(len(Xs))], reverse=maxY)
should read
sorted_list = sorted([[Xs[i], Ys[i]] for i in range(len(Xs))], reverse=maxX)
Note differences with this implementation: http://oco-carbon.com/2012/07/31/find-pareto-frontiers-in-python/