def __call__(self, rated_pop: Sequence[Tuple[Number, np.ndarray]]) -> Tuple[np.ndarray, ...]: couples = ga.roulette_wheel_cost_selection(rated_pop) offspring = (ga.single_point_crossover(*couple) for couple in couples) children = tuple(child for pair in offspring for child in pair) for i, j in it.product(range(len(children)), range(len(children[0]))): if self._rand.random() < self._mutation_prob: children[i][j] = 1 - children[i][j] return children
def next_transformation_gen(transforms: Tuple[Tuple[int, np.ndarray], ...])\ -> Tuple[np.ndarray, ...]: # couples = ga.roulette_wheel_rank_selection(transforms) couples = ga.roulette_wheel_cost_selection(transforms) # couples = ga.tournament_selection(transforms, 2) # couples = ga.uniform_random_pairing_selection(transforms) offspring = (ga.single_point_crossover(*couple) for couple in couples) children = tuple(child for pair in offspring for child in pair) mutate(children, .1) return children
def __call__( self, rated_pop: Sequence[Tuple[Number, np.ndarray]]) -> Tuple[np.ndarray, ...]: couples = ga.roulette_wheel_cost_selection(rated_pop) offspring = (ga.single_point_crossover(*couple) for couple in couples) children = tuple(it.chain(*offspring)) for i, j in it.product(range(len(children)), range(len(children[0]))): if self._rand.random() < .01: children[i][j] = self._rand.choice(self._labels) return children