evolutionary-algorithmdeap

DEAP evolutionary module, always evaluate entire population


I'm trying to solve a non-deterministic problem with DEAP. the problem is that the module only evaluate new chromosome and uses the score kept in memory for old ones.

How can i set the module, so at each generation the ENTIRE population will be evaluated, and not just the new ones?

Thx


Solution

  • You can modify 2-3 lines in your current chosen algorithm like below to force evaluation on all items. This can be done via copying from the source, to your local script, and then editing the invalid_individual flagged item check pre evaluation. Make sure in main you call local easimple and not algorithms.easimple to make the switch to local code.

    If you are using easimple or eaMuPlusLambda, for example, you can find that function here in this file: https://github.com/DEAP/deap/blob/master/deap/algorithms.py#L85

    The 0th gen case here may not change(but can change anyway, unless your individuals come with a fitness already and you want to skip evaluation):

    #(line 149 in above URL)
    invalid_ind = [ind for ind in population if not ind.fitness.valid]
    

    And then inside the generational process loop:

    #(line 171 in url above):
    invalid_ind = [ind for ind in offspring if not ind.fitness.valid]
    

    Removing the invalid check will result in all items being passed to evaluation:

    invalid_ind = [ind for ind in population] #149
    ...
    invalid_ind = [ind for ind in offspring] #171
    

    But keep the algorithms import! note you also need to change varAnd(case of easimple) to algorithms.varAnd to prevent a break.

    offspring = algorithms.varAnd(offspring, toolbox, cxpb, mutpb)