Exemplo n.º 1
0
 def _apply_grouped(self, population: BasePopulation) -> BasePopulation:
     groups = population.group(grouping_function=self.grouping_function,
                               **self.kwargs)
     if population.pool:
         results = population.pool.map(
             lambda group: group.evolve(evolution=self.evolution, n=self.n),
             groups)
     else:
         results = [
             group.evolve(evolution=self.evolution, n=self.n)
             for group in groups
         ]
     return population.combine(*results,
                               intended_size=population.intended_size,
                               pool=population.pool)
Exemplo n.º 2
0
 def apply(self, population: BasePopulation) -> BasePopulation:
     if self.grouping_function is None:
         if len(self.kwargs) > 0:
             raise ValueError(
                 f'Unexpected argument(s) for non-grouped repeat step: {self.kwargs}'
             )
         return population.evolve(evolution=self.evolution, n=self.n)
     else:
         return self._apply_grouped(population=population)
Exemplo n.º 3
0
 def apply(self, population: BasePopulation) -> BasePopulation:
     return population.mutate(**self.kwargs)
Exemplo n.º 4
0
 def apply(self, population: BasePopulation) -> BasePopulation:
     return population.breed(**self.kwargs)
Exemplo n.º 5
0
 def apply(self, population: BasePopulation) -> BasePopulation:
     return population.survive(**self.kwargs)
Exemplo n.º 6
0
 def apply(self, population: BasePopulation) -> BasePopulation:
     return population.filter(**self.kwargs)
Exemplo n.º 7
0
 def apply(self, population: BasePopulation) -> BasePopulation:
     self.count += 1
     if self.count >= self.every:
         self.count = 0
         return population.checkpoint(**self.kwargs)
     return population
Exemplo n.º 8
0
 def apply(self, population: BasePopulation) -> BasePopulation:
     return population.normalize(**self.kwargs)