-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError in PolynomialMutation and SBXCrossover #147
Comments
Note: I just noticed the line numbers are off by a few lines in the original post. |
Hi. Antonio |
Hi, for example let's look at the following code-snipet: betaq = pow(rand*alpha, (1.0/(self.distribution_index + 1.0))) For any distribution_index -2 > x > 0 there is no problem, since the exponent will not be a fraction value between -1 and 1. But anything else will result in a value between -1 and 1. And any value to the power of such a value, will be interpreted as root. And the root of a negative number is a complex number. |
I have used distribution index values within the range (5.0, 400.0). |
I've applied those operators in many studies in the last 15 years and I have never had an error related to complex numbers in pow(), so this issue is intrigues me. |
I see your point. But mathematically it makes sense (in my opinion) to add abs(). I don't always get a negative base, but sometimes. |
The issue is to decide that, if you get a negative base, that should be considered as an error or as a valid value. If it is the former, using abs() would hide the error, which could be very difficult to find later if an algorithms yields unexpected results. |
Sorry for the late answer, I totally get your concern. But since my input variables are not strange at all in my opinion, they somehow still trigger that behavior. I use 9 variables, with lower boundaries [-5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] and upper boundaries [0.0, 50.0, 50.0, 500.0, 1000.0, 2.5, 200.0, 2.5, 50.0]. I don't see how those variables can produce complex numbers. |
I came across a small bug in the implementation of PolynomialMutation and SBXCrossover.
Both use
pow(...)
multiple times. Sometimes the exponent is between 0 and 1 by default. Therefore, complex numbers are introduced if the base is negative and a TypeError occurs.My solution proposal is to add
abs(...)
around the base of thedeltaq
computation inPolynomialMutation
(line 74 and 78) and around the base of thebetaq
computation inSBXCrossover
(line 173, 175, 182 and 184).The text was updated successfully, but these errors were encountered: