DEAP / deap

Distributed Evolutionary Algorithms in Python
http://deap.readthedocs.org/
GNU Lesser General Public License v3.0
5.75k stars 1.12k forks source link

SBX operator generates complex numbers and raises exception #54

Closed apleonhardt closed 9 years ago

apleonhardt commented 9 years ago

I've been using DEAP for a simple genetic algorithm using NSGA-II. For large populations and many applications of the cxSimulatedBinaryBounded operator, I eventually end up with a TypeError:

TypeError: unorderable types: complex() < float()

The culprit is the following line:

c1 = min(max(c1, xl), xu)

I assume that for certain values, c1 ends up complex (using Python 3.4.1). User error? Bug? Should there be some safeguard that prevents this? It's unfortunate because it (stochastically) kills large jobs.

fmder commented 9 years ago

Can you track which variable becomes complex first?

Do any of you individuals contain values smaller than low or larger than up? There is no check done in the operator.

fmder commented 9 years ago

I'll flag this as invalid as I cannot reproduce the error. Do not hesitate to reopen it if you can provide a minimal example that reproduces it.

apleonhardt commented 9 years ago

Apologies for the delay. It was indeed the problem you mentioned -- the population initialisation was buggy, so individuals outside [low, high] would show up. User error!

However, it might be nice to offer a more informative error: that is, some form of bounds checking as opposed to what happens now.