4

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.

1 Answer 1

2

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)
2
  • Wow! I had not realized this, really that is the right way, thank you! Commented Nov 6, 2018 at 12:10
  • I had the same problem. In EC evaluation function is commonly called the fitness function. I think that DEAP uses the evaluation function to map genotype to quality of measure. Then fitness function for comparing this measure.
    – Talos
    Commented Jan 18, 2022 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.