Fast calculation of Pareto front in Python

后端 未结 5 2159
鱼传尺愫
鱼传尺愫 2020-12-13 03:13

I have a set of points in a 3D space, from which I need to find the Pareto frontier. Speed of execution is very important here, and time increases very fast as I add points

5条回答
  •  遥遥无期
    2020-12-13 03:37

    Peter, nice response.

    I just wanted to generalise for those who want to choose between maximisation to your default of minimisation. It's a trivial fix, but nice to document here:

    def is_pareto(costs, maximise=False):
        """
        :param costs: An (n_points, n_costs) array
        :maximise: boolean. True for maximising, False for minimising
        :return: A (n_points, ) boolean array, indicating whether each point is Pareto efficient
        """
        is_efficient = np.ones(costs.shape[0], dtype = bool)
        for i, c in enumerate(costs):
            if is_efficient[i]:
                if maximise:
                    is_efficient[is_efficient] = np.any(costs[is_efficient]>=c, axis=1)  # Remove dominated points
                else:
                    is_efficient[is_efficient] = np.any(costs[is_efficient]<=c, axis=1)  # Remove dominated points
        return is_efficient
    

提交回复
热议问题