offspring empty randrange error

344 views
Skip to first unread message

Fabian Braennstroem

unread,
Jan 3, 2014, 4:11:00 AM1/3/14
to deap-...@googlegroups.com
Hello,

using the eaSimple algorithmen I get after the first population this error:

gen      evals    std      max      avg      min
0        10       [49.66, 3.982e+04] [175.9, 9.974e+04] [47.52, 2.009e+04] [0.8, 7.5]
Traceback (most recent call last):
  File "deap_ga_onemax.py", line 122, in <module>
    main()
  File "deap_ga_onemax.py", line 115, in main
    newpop = algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2, ngen=NGEN, stats=stats, halloffame=hof, verbose=True)
  File "/data/Software/Python/EDP/Env/User/lib/python2.7/site-packages/deap-0.9.1-py2.7.egg/deap/algorithms.py", line 152, in eaSimple
    offspring = varAnd(offspring, toolbox, cxpb, mutpb)
  File "/data/Software/Python/EDP/Env/User/lib/python2.7/site-packages/deap-0.9.1-py2.7.egg/deap/algorithms.py", line 72, in varAnd
    offspring[i-1], offspring[i] = toolbox.mate(offspring[i-1], offspring[i])
  File "/data/Software/Python/EDP/Env/User/lib/python2.7/site-packages/deap-0.9.1-py2.7.egg/deap/tools.py", line 737, in cxTwoPoints
    cxpoint2 = random.randint(1, size - 1)
  File "/data/Software/Python/EDP/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/random.py", line 241, in randint
    return self.randrange(a, b+1)
  File "/data/Software/Python/EDP/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/random.py", line 217, in randrange
    raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width)
ValueError: empty range for randrange() (1,1, 0)


I attached it togeterh with the python script.
Actually I am (almost) sure, that it worked before (it works with more parementers... just tested it again. Do you have a hint, what I need to adjust to get rid of the optimization?
Thanks in advance!

--
Regards!
Fabian
error.txt
error.py

François-Michel De Rainville

unread,
Jan 3, 2014, 9:51:21 AM1/3/14
to deap-...@googlegroups.com

That looks like one of your individual is of size 2. Is that normal? Do you have a variable length genotype?

--
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/groups/opt_out.

Fabian Braennstroem

unread,
Jan 3, 2014, 3:23:43 PM1/3/14
to deap-...@googlegroups.com
Actually I do not understand your answer...
my original population looks like:

INFO:root:[array('d', [442.84747866880366]), array('d', [489.06571629566554]), array('d', [421.1882908705419]), array('d', [576.0072038028981])]

so the individual is for of size 1.

Thanks for the help!
Fabian

Francois-Michel De Rainville

unread,
Jan 3, 2014, 3:34:23 PM1/3/14
to deap-...@googlegroups.com
Then the error is normal. We cannot perform a two point crossover on an individual of size 1, it would require at least 3 genes to be effective. Maybe you should try a different crossover method like the simulated binary.

Regards,
François-Michel

Fabian Braennstroem

unread,
Jan 5, 2014, 1:41:01 PM1/5/14
to deap-...@googlegroups.com
Thank you for the help!
Changing the line for the individual worked:
toolbox.register("individual", tools.initCycle, creator.Individual, func_seq, n=2)

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