You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@fmder you're right that it's not operator precedence- The parenthesization
is already correct there. I dug into this a bit more and think the actual
root cause is one step earlier, in the alpha computation:
beta goes negative when x1 (or x2, in the symmetric second calculation)
falls even slightly outside [xl, xu] which can legitimately happen after
a prior mutation step, before this crossover runs. With a non-integer eta
(a perfectly normal value, e.g. 15.5), beta ** -(eta + 1) is then a
negative base raised to a fractional exponent, which Python evaluates as
complex. That complex alpha is what breaks the <= comparison downstream which is the same failure mode reported again more recently in #740.
Since the function already clamps the output back into [xl, xu]
(c1 = min(max(c1, xl), xu)), the more consistent fix is probably to clamp
the inputs (x1, x2) into [xl, xu] before computing beta, rather than
patching the beta_q line this PR touches and that would stop beta from ever
going negative in the first place, for any eta. Happy to help however's
useful, but wanted to flag the diagnosis in case it changes the direction
of the fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In certain situations, beta_q is creating a complex number (see https://stackoverflow.com/questions/66903214/why-is-python-creating-a-complex-number-here/66903343). This is because the unary - in a negative result for
(1.0 / (2.0 - rand * alpha))takes precedence over** (1.0 / (eta + 1)).This fix identifies the sign (-/+) and uses the absolute values in the calculation for beta_q, then retrospectively applies the correct sign again.