Welcome, guest | Sign In | My Account | Store | Cart
import numpy as np

def 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_frontier

def test()
    myArray = np.array([[1,1,1],[2,2,2],[4,4,4],[3,3,3]])
    print pareto_frontier_multi(myArray)

test()

Diff to Previous Revision

--- revision 1 2012-10-13 23:25:12
+++ revision 2 2012-10-13 23:26:12
@@ -6,7 +6,7 @@
     # 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:
+    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

History