Passing a first guess to the GA

937 views
Skip to first unread message

Renan Birck Pinheiro

unread,
Oct 25, 2011, 12:32:50 PM10/25/11
to deap-users
Hello,

Is there any way to pass a first guess (specified by the user, in this
case) to the population? I tried this, in my main function:

if use_initialguess:
population.pop() # Drop the first element, which will be replace
by our initial guess.
population.insert(0,paramsinitial_normalized)

where paramsinitial_normalized is the first guess I wish to pass.

However, this fails with this error:


Traceback (most recent call last):
File "../pyco_deap/pyco", line 353, in <module>
main_run()
File "../pyco_deap/pyco", line 317, in main_run
algorithms.eaSimple(toolbox, population, cxpb=args.crossover_rate,
ngen=args.generations
+1,mutpb=args.mutation_rate,halloffame=hof,stats=stats)
File "/opt/python2.7/lib/python2.7/site-packages/deap/
algorithms.py", line 126, in eaSimple
invalid_ind = [ind for ind in population if not ind.fitness.valid]
AttributeError: 'list' object has no attribute 'fitness'

Any suggestions? I'm using deap 0.7.1 with Python 2.7, if that
matters.

Thanks,
Renan

Félix-Antoine Fortin

unread,
Oct 25, 2011, 12:47:27 PM10/25/11
to deap-users
Hi Renan,

Your initial guess needs to be an individual, or at least have fitness
member,
since the eaSimple algorithms presumes that every element in the
population
list has a fitness member.

I guess "paramsinitial_normalized" is a list, to make it an
individual,
just use the creator class for Individual that you have initialized :
guess_ind = creator.Individual(paramsinitial_normalized)

Then you can insert it back in your population :
if use_initialguess:
# Drop the first element,
# which will be replace by our initial guess.
population.pop()
population.insert(0, guess_ind)

If it doesn't solve your problem, could you post your code
on something like github gist : https://gist.github.com/
it will be easier to help you if we get a look at the whole program.

If you have any other questions, don't hesitate.
Félix-Antoine


On Oct 25, 12:32 pm, Renan Birck Pinheiro <renan.ee.u...@gmail.com>
wrote:

Renan Birck Pinheiro

unread,
Oct 25, 2011, 12:53:10 PM10/25/11
to deap-...@googlegroups.com
2011/10/25 Félix-Antoine Fortin <felix.anto...@gmail.com>

I guess "paramsinitial_normalized" is a list, to make it an
individual,
just use the creator class for Individual that you have initialized :
guess_ind = creator.Individual(paramsinitial_normalized)

Then you can insert it back in your population :
if use_initialguess:
   # Drop the first element,
   # which will be replace by our initial guess.
   population.pop()
   population.insert(0, guess_ind)

This did the job. Thank you.

Renan 
--
Renan Birck Pinheiro - Grupo de Microeletrônica - Engenharia Elétrica/UFSM

http://renanbirck.blogspot.com / skype: renan.ee.ufsm
Reply all
Reply to author
Forward
0 new messages