def sigma_scaled(population: List[Genome], **kwargs) -> Iterator[PAIR_T]:
try:
assert len(population) > 1
except AssertionError:
raise TooFewIndividuals
fitnesses = tuple(x.fitness for x in population)
try:
assert any(f > 0.0 for f in fitnesses)
except AssertionError:
return random_choice(population)
sigma = stdev(fitnesses)
average_fitness = mean(fitnesses)
expected_value_func = lambda x: 1 if sigma == 0 else 1 + ((x - average_fitness) / (2 * sigma))
sigma_sum = sum(expected_value_func(x) for x in fitnesses)
scaling_func = lambda x: expected_value_func(x) / sigma_sum
return roulette(population=population, scaling_func=scaling_func, **kwargs)
评论列表
文章目录