selection.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:CA-NEAT 作者: mathiasose 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号