在 DEAP 中实施清算程序

Implementing a clearing procedure in DEAP

清除程序 (Petrowski 96) 是一种解决多模态问题的利基方法。有没有办法使用 DEAP 的清算程序?

对于共享等其他小生境方法,只需要修改适应度函数即可。因此,这些方法很容易部署在 DEAP 框架中。然而,清除需要算法中的额外循环来更新每个个体的适应度。是否有 DEAP 函数可以执行此操作?

仅仅改变适应度函数是不够的,因为你需要对所有个体进行额外的传递,以根据附近主导个体的存在来更新它们的适应度。但是,您可以为此制定自己的算法。

根据 Petrowski 96

中描述的程序,一旦您定义了程序以遍历种群中的所有个体来设置他们的适应度
def update_fitness(population):
    ... # set fitness of non-dominant individuals to 0
    return population

然后您可以重新定义标准算法,例如eaMuPlusLambda

def eaMuPlusLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen):
    invalid_ind = [ind for ind in population if not ind.fitness.valid]
    fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
    for ind, fit in zip(invalid_ind, fitnesses):
        ind.fitness.values = fit

    population = update_fitness(population)

    # Begin the generational process
    for gen in range(1, ngen + 1):
        # Vary the population
        offspring = varOr(population, toolbox, lambda_, cxpb, mutpb)

        # Evaluate the individuals with an invalid fitness
        invalid_ind = [ind for ind in offspring if not ind.fitness.valid]
        fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
        for ind, fit in zip(invalid_ind, fitnesses):
            ind.fitness.values = fit

        # Select the next generation population
        population[:] = toolbox.select(population + offspring, mu)

    return population