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)
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)
def apply(self, population: BasePopulation) -> BasePopulation: return population.mutate(**self.kwargs)
def apply(self, population: BasePopulation) -> BasePopulation: return population.breed(**self.kwargs)
def apply(self, population: BasePopulation) -> BasePopulation: return population.survive(**self.kwargs)
def apply(self, population: BasePopulation) -> BasePopulation: return population.filter(**self.kwargs)
def apply(self, population: BasePopulation) -> BasePopulation: self.count += 1 if self.count >= self.every: self.count = 0 return population.checkpoint(**self.kwargs) return population
def apply(self, population: BasePopulation) -> BasePopulation: return population.normalize(**self.kwargs)