Guy Barash
Guy Barash

Reputation: 490

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

Upvotes: 1

Views: 439

Answers (2)

DMTishler
DMTishler

Reputation: 509

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)

Upvotes: 1

Thieu Nguyen
Thieu Nguyen

Reputation: 161

I don't think DEAP package can do that. You can simply implement the algorithm on your own or find the new packages.

Anyway, check out my library contains most of the state-of-the-art meta-heuristic algorithms. It also evaluates the entire population in each generation. https://github.com/thieunguyen5991/mealpy

Upvotes: 2

Related Questions