Ejemplo n.º 1
0
    def evaluation_function(self, *recommendations: p.Parameter) -> float:
        """Provides the evaluation crieterion for the experiment.
        In case of mono-objective, it defers to evaluation_function
        Otherwise, it uses the hypervolume.
        This function can be overriden to provide custom behaviors.

        Parameters
        ----------
        *pareto: Parameter
            pareto front provided by the optimizer
        """

        if self.multiobjective_upper_bounds is None:  # singleobjective case
            assert len(recommendations) == 1
            output = self.function(*recommendations[0].args,
                                   **recommendations[0].kwargs)
            assert isinstance(
                output, numbers.Number
            ), f"evaluation_function can only be called on singleobjective experiments (output={output}) function={self.function}."
            return output
        # multiobjective case
        hypervolume = mobj.HypervolumePareto(
            upper_bounds=self.multiobjective_upper_bounds,
            seed=self.parametrization.random_state)
        for candidate in recommendations:
            hypervolume.add(candidate)
        return -hypervolume.best_volume
Ejemplo n.º 2
0
 def evaluation_function(self, *recommendations: p.Parameter) -> float:
     if self._pareto_size is not None and len(recommendations) > self._pareto_size:
         # select a subset
         hypervolume = mobj.HypervolumePareto(upper_bounds=self.multiobjective_upper_bounds)
         hypervolume.extend(recommendations)
         recommendations = tuple(
             hypervolume.pareto_front(
                 size=self._pareto_size,
                 subset=self._pareto_subset,
                 subset_tentatives=self._pareto_subset_tentatives,
             )
         )
     return min(self._evaluation.evaluation_function(recom) for recom in recommendations)