Multidimensional Pareto front,,import numpy


import numpy as npdef pareto_frontier_multi(myArray):    # Sort on first dimension    myArray = myArray[myArray[:,0].argsort()]    # Add first row to pareto_frontier    pareto_frontier = myArray[0:1,:]    # Test next row against the last row in pareto_frontier    for row in myArray[1:,:]:        if sum([row[x] >= pareto_frontier[-1][x]                for x in range(len(row))]) == len(row):            # If it is better on all features add the row to pareto_frontier            pareto_frontier = np.concatenate((pareto_frontier, [row]))    return pareto_frontierdef test()    myArray = np.array([[1,1,1],[2,2,2],[4,4,4],[3,3,3]])    print pareto_frontier_multi(myArray)test()

评论关闭