NSGA-II example: initial population and objective functions evaluation

1,333 views
Skip to first unread message

José Ignacio Díaz González

unread,
Feb 17, 2016, 1:23:44 AM2/17/16
to deap-users
Hello,

I'm new in EC and Python and I have to work with several algorithms for my thesis project. I'm using DEAP and your nsga2.py example as a guide but I have some doubts about the code. For instance, in line 77 the population (pop) is created and then in lines 80 to 83 different operations are executed to check and/or create the fitness values for each individual.

1) Is verification in line 80 necessary considering that the population was just created and it is known that individuals do not have fitnesses yet and therefore the evaluation must be applied to the entire population)?
2) Can lines 81 to 83 be replaced only for one line with "toolbox.map(toolbox.evaluate, pop)" and to modify the evaluation function to return the individual with the fitness values already inside it?

I thought in something like this:

def evaluation(chromosome):
     fitness_1 = # Calculations for objective function 1
     fitness_2 = # Calculation for objective function 2
     fitness_n = # Calculations for objective function n
     chromosome.fitness.values = (fitness_1, fitness_2, fitness_n)
     return chromosome

I think the output should be the same as your example code (nsga2.py), but I'm not sure because of my ignorance about Python/NSGA-II) and maybe the example code must be in that way.

Thanks in advance.
 

François-Michel De Rainville

unread,
Feb 17, 2016, 1:31:10 AM2/17/16
to deap-users
Hi,

I hope you enjoy using DEAP!
  
For instance, in line 77 the population (pop) is created and then in lines 80 to 83 different operations are executed to check and/or create the fitness values for each individual.
1) Is verification in line 80 necessary considering that the population was just created and it is known that individuals do not have fitnesses yet and therefore the evaluation must be applied to the entire population)?

The example is built to allow reload of a population instead of building a fresh one. The loaded population could have not evaluated individuals. 
 
2) Can lines 81 to 83 be replaced only for one line with "toolbox.map(toolbox.evaluate, pop)" and to modify the evaluation function to return the individual with the fitness values already inside it?

Yes they can. The goal of DEAP is that you copy/paste only the lines that you need!
 
I thought in something like this:

def evaluation(chromosome):
     fitness_1 = # Calculations for objective function 1
     fitness_2 = # Calculation for objective function 2
     fitness_n = # Calculations for objective function n
     chromosome.fitness.values = (fitness_1, fitness_2, fitness_n)
     return chromosome

The evaluation function has to return a tuple of values, the algorithm will assign the values to the chromosomes itself.

return (fitness_1, fitness_2, fitness_n)

is the correct way to do it.

If you have any other question don't hesitate.

José Ignacio Díaz González

unread,
Feb 21, 2016, 10:11:19 PM2/21/16
to deap-users
Thanks for your reply, it is clear now : )

Fabian Braennstroem

unread,
Feb 23, 2016, 8:39:58 PM2/23/16
to deap-...@googlegroups.com
Hello Francois-Michel,

I have an additional question to nsga2 based on deap.
When looking at the convergence of our  multi-objective optimization (33 Parameter and 5 objective functions) it seems that we have always better optimization of the first objective function (2nd best by the second objective function and so on...).
Do you have an idea how this could happen and how to avoid this?

Thanks in advance!
Best Regards
Fabian
--
You received this message because you are subscribed to the Google Groups "deap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Fabian Braennstroem

unread,
Feb 24, 2016, 4:40:50 PM2/24/16
to deap-...@googlegroups.com
Hello,

it seems, that the problem lies in the way we calculate each objective function.
Sorry for the trouble!

Best Regards
Fabian
--
Regards!
Fabian
Reply all
Reply to author
Forward
0 new messages