Example #1
0
class DefaultTermination(ToleranceBasedTermination):
    def __init__(self,
                 x_tol,
                 cv_tol,
                 f_tol,
                 nth_gen=5,
                 n_last=20,
                 n_max_gen=1000,
                 n_max_evals=100000,
                 **kwargs) -> None:
        """

        Parameters
        ----------
        cv_tol
        x_tol
        f_tol

        n_max_gen : int
            A limit on maximum number of generations to avoid it never terminates
            (set to `None` or infinity to disable)

        n_max_evals : int
            A limit on maximum number of function evaluations to avoid it never terminates
            (set to `None` or infinity to disable)

        nth_gen
        n_last
        kwargs
        """

        super().__init__(n_last=n_last, nth_gen=nth_gen, **kwargs)

        self.n_max_gen = MaximumGenerationTermination(n_max_gen)
        self.n_max_evals = MaximumFunctionCallTermination(n_max_evals)

        self.x_tol = DesignSpaceToleranceTermination(tol=x_tol,
                                                     n_last=n_last,
                                                     nth_gen=nth_gen)

        self.cv = ConstraintViolationToleranceTermination(tol=cv_tol,
                                                          n_last=n_last,
                                                          nth_gen=nth_gen)
        self.f_tol = f_tol

    def _store(self, algorithm):
        return {
            "n_max_gen": self.n_max_gen.do_continue(algorithm),
            "n_max_evals": self.n_max_evals.do_continue(algorithm),
            "x_tol": self.x_tol.do_continue(algorithm),
            "cv": self.cv.do_continue(algorithm),
            "f_tol": self.f_tol.do_continue(algorithm)
        }

    def _decide(self):
        metric = self.history[-1]
        return metric["n_max_gen"] and metric["n_max_evals"] and metric[
            "x_tol"] and (metric["cv"] or metric["f_tol"])
Example #2
0
    def __init__(self,
                 x_tol,
                 cv_tol,
                 f_tol,
                 nth_gen=5,
                 n_last=20,
                 n_max_gen=1000,
                 n_max_evals=100000,
                 **kwargs) -> None:
        """

        Parameters
        ----------
        cv_tol
        x_tol
        f_tol

        n_max_gen : int
            A limit on maximum number of generations to avoid it never terminates
            (set to `None` or infinity to disable)

        n_max_evals : int
            A limit on maximum number of function evaluations to avoid it never terminates
            (set to `None` or infinity to disable)

        nth_gen
        n_last
        kwargs
        """

        super().__init__(n_last=n_last, nth_gen=nth_gen, **kwargs)

        self.n_max_gen = MaximumGenerationTermination(n_max_gen)
        self.n_max_evals = MaximumFunctionCallTermination(n_max_evals)

        self.x_tol = DesignSpaceToleranceTermination(tol=x_tol,
                                                     n_last=n_last,
                                                     nth_gen=nth_gen)

        self.cv = ConstraintViolationToleranceTermination(tol=cv_tol,
                                                          n_last=n_last,
                                                          nth_gen=nth_gen)
        self.f_tol = f_tol
Example #3
0
    def setup(self, problem, **kwargs):
        super().setup(problem, **kwargs)

        # if maximum functions termination convert it to generations
        if isinstance(self.termination, MaximumFunctionCallTermination):
            n_gen = np.ceil((self.termination.n_max_evals - self.pop_size) / self.n_offsprings)
            self.termination = MaximumGenerationTermination(n_gen)

        # check whether the n_gen termination is used - otherwise this algorithm can be not run
        if not isinstance(self.termination, MaximumGenerationTermination):
            raise Exception("Please use the n_gen or n_eval as a termination criterion to execute RVEA!")

        return self
Example #4
0
    def _setup(self, problem, **kwargs):

        self.norm = ObjectiveSpaceNormalization()

        # if maximum functions termination convert it to generations
        if isinstance(self.termination, MaximumFunctionCallTermination):
            n_gen = np.ceil((self.termination.n_max_evals - self.pop_size) /
                            self.n_offsprings)
            self.termination = MaximumGenerationTermination(n_gen)

        # check whether the n_gen termination is used - otherwise this algorithm can be not run
        if not isinstance(self.termination, MaximumGenerationTermination):
            raise Exception(
                "Please use the n_gen or n_eval as a termination criterion to run ICMA!"
            )
Example #5
0
    def __init__(self,
                 metric_window_size=None,
                 data_window_size=None,
                 min_data_for_metric=1,
                 nth_gen=1,
                 n_max_gen=None,
                 n_max_evals=None,
                 truncate_metrics=True,
                 truncate_data=True,
                 ) -> None:
        """

        Parameters
        ----------

        metric_window_size : int
            The last generations that should be considering during the calculations

        data_window_size : int
            How much of the history should be kept in memory based on a sliding window.

        nth_gen : int
            Each n-th generation the termination should be checked for

        """

        super().__init__(MaximumGenerationTermination(n_max_gen=n_max_gen),
                         MaximumFunctionCallTermination(n_max_evals=n_max_evals))

        # the window sizes stored in objects
        self.data_window_size = data_window_size
        self.metric_window_size = metric_window_size

        # the obtained data at each iteration
        self.data = SlidingWindow(data_window_size) if truncate_data else []

        # the metrics calculated also in a sliding window
        self.metrics = SlidingWindow(metric_window_size) if truncate_metrics else []

        # each n-th generation the termination decides whether to terminate or not
        self.nth_gen = nth_gen

        # number of entries of data need to be stored to calculate the metric at all
        self.min_data_for_metric = min_data_for_metric
Example #6
0
 def from_args(cls, args: Namespace, index=None) -> Termination:
     n = cls._parsed_argument('n', args, index=index)
     return MaximumGenerationTermination(n)