RuntimeWarning: overflow encountered in double_scalars

616 views
Skip to first unread message

Nicola Menga

unread,
Jun 6, 2019, 1:33:31 PM6/6/19
to deap-users
Hi I'm new on deap, I'm getting this error during the evolution of a genetic program script: "RuntimeWarning: overflow encountered in double_scalars       return left * right"
Can you help please? Thanks in advance!!
I defined a function for multiplication in this way:

def protectedMul(left, right):
try:
return left * right
except OverflowError or ZeroDivisionError or FloatingPointError:
print(left, right)
return 1

Marc-André Gardner

unread,
Jun 6, 2019, 3:27:38 PM6/6/19
to deap-...@googlegroups.com

Hi Nicola,

Well I cannot tell why you get these overflow errors, but the reason why you're not able to catch them is because your syntax is wrong. You should not use "except A or B or C", but "except (A, B, C)", as outlined in the Python doc : https://docs.python.org/3/tutorial/errors.html#handling-exceptions

Also, to get overflow on doubles, you need to have huge numbers, it would be important to check where they are coming from, assuming it is not a single, isolated case.

Marc-Andre

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/deap-users/5633509a-8777-460a-a44e-492f999bc12d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicola Menga

unread,
Jun 7, 2019, 1:02:05 PM6/7/19
to deap-users
Ooh thank you so much, now it works well!!! I've lost 5 hours of my life that no one will give me back but I learned an important thing: to read carefully the Python doc!!!
Thank you again! Have a nice day


On Thursday, 6 June 2019 20:27:38 UTC+1, Marc-André Gardner wrote:

Hi Nicola,

Well I cannot tell why you get these overflow errors, but the reason why you're not able to catch them is because your syntax is wrong. You should not use "except A or B or C", but "except (A, B, C)", as outlined in the Python doc : https://docs.python.org/3/tutorial/errors.html#handling-exceptions

Also, to get overflow on doubles, you need to have huge numbers, it would be important to check where they are coming from, assuming it is not a single, isolated case.

Marc-Andre

On 2019-06-06 13:33, Nicola Menga wrote:
Hi I'm new on deap, I'm getting this error during the evolution of a genetic program script: "RuntimeWarning: overflow encountered in double_scalars       return left * right"
Can you help please? Thanks in advance!!
I defined a function for multiplication in this way:

def protectedMul(left, right):
    try:
        return left * right
    except OverflowError or ZeroDivisionError or FloatingPointError:
        print(left, right)
        return 1
--
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-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages