简体   繁体   中英

Python DEAP - Custom fitness function

My question is about the possibility to implement a custom fitness function in DEAP/Python in my Genetic Programming implementation.

After search and reading DEAP official documentation, i don't find anything about it, so, if one of you could help me, i appreciate it.

Thanks.

Are you sure you need a custom fitness function?

It's a bit confusing, but you might be referring to a custom evaluation function. This should return a number that then the fitness function tries to maximize or minimize.

A great example is https://deap.readthedocs.io/en/master/examples/ga_onemax.html

In this tutorial, the standard maximizing fitness function is set up:

creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", list, fitness=creator.FitnessMax)

followed by the "custom" evaluation function:

def evalOneMax(individual):
    return sum(individual),

which is then registered to the toolbox:

toolbox.register("evaluate", evalOneMax)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM