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
I am getting the following error in cxSimulatedBinaryBounded in crossover.py (note I've added debug print statements in so the line numbers are different from a vanilla crossover.py):
~\anaconda3\envs\tf_gpu\lib\site-packages\deap\tools\crossover.py in cxSimulatedBinaryBounded(ind1, ind2, eta, low, up)
363 print(f'c2={c2}, xl={xl}, xu={xu}')
364 c1 = min(max(c1, xl), xu)
--> 365 c2 = min(max(c2, xl), xu)
366
367 if random.random() <= 0.5:
TypeError: '>' not supported between instances of 'float' and 'complex'
I have added some logging to this function in order to determine why I am getting this error:
def cxSimulatedBinaryBounded(ind1, ind2, eta, low, up):
"""Executes a simulated binary crossover that modify in-place the input
individuals. The simulated binary crossover expects :term:`sequence`
individuals of floating point numbers.
:param ind1: The first individual participating in the crossover.
:param ind2: The second individual participating in the crossover.
:param eta: Crowding degree of the crossover. A high eta will produce
children resembling to their parents, while a small eta will
produce solutions much more different.
:param low: A value or a :term:`python:sequence` of values that is the lower
bound of the search space.
:param up: A value or a :term:`python:sequence` of values that is the upper
bound of the search space.
:returns: A tuple of two individuals.
This function uses the :func:`~random.random` function from the python base
:mod:`random` module.
.. note::
This implementation is similar to the one implemented in the
original NSGA-II C code presented by Deb.
"""
print(f'cxSimulatedBinaryBounded(ind1={ind1}, ind2={ind2}, eta={eta}, low={low}, up={up})')
size = min(len(ind1), len(ind2))
if not isinstance(low, Sequence):
low = repeat(low, size)
elif len(low) < size:
raise IndexError("low must be at least the size of the shorter individual: %d < %d" % (len(low), size))
if not isinstance(up, Sequence):
up = repeat(up, size)
elif len(up) < size:
raise IndexError("up must be at least the size of the shorter individual: %d < %d" % (len(up), size))
for i, xl, xu in zip(range(size), low, up):
print(f'**** cxSimulatedBinaryBounded(): i={i}, xl={xl}, xu={xu}')
if random.random() <= 0.5:
# This epsilon should probably be changed for 0 since
# floating point arithmetic in Python is safer
if abs(ind1[i] - ind2[i]) > 1e-14:
x1 = min(ind1[i], ind2[i])
x2 = max(ind1[i], ind2[i])
rand = random.random()
beta = 1.0 + (2.0 * (x1 - xl) / (x2 - x1))
alpha = 2.0 - beta ** -(eta + 1)
if rand <= 1.0 / alpha:
beta_q = (rand * alpha) ** (1.0 / (eta + 1))
else:
beta_q = (1.0 / (2.0 - rand * alpha)) ** (1.0 / (eta + 1))
print('c1 = 0.5 * (x1 + x2 + beta_q * (x2 - x1))')
print(f'c1=0.5*({x1}+{x2}-{beta_q} * ({x2}-{x1}))')
c1 = 0.5 * (x1 + x2 - beta_q * (x2 - x1))
beta = 1.0 + (2.0 * (xu - x2) / (x2 - x1))
print(f'beta: {beta} = 1.0 + (2.0 * ({xu} - {x2}) / ({x2} - {x1}))')
alpha = 2.0 - beta ** -(eta + 1)
print(f'alpha: {alpha} = 2.0 - {beta} ** -({eta} + 1)')
if rand <= 1.0 / alpha:
print(f'rand: {rand} <= 1.0 / {alpha}')
beta_q = (rand * alpha) ** (1.0 / (eta + 1))
print(f'beta_q: {beta_q} = ({rand} * {alpha}) ** (1.0 / ({eta} + 1))')
else:
print(f'rand: {rand} > 1.0 / {alpha}')
beta_q = (1.0 / (2.0 - rand * alpha)) ** (1.0 / (eta + 1))
print(f'beta_q: {beta_q} = (1.0 / (2.0 - {rand} * {alpha})) ** (1.0 / ({eta} + 1))')
print('c2 = 0.5 * (x1 + x2 + beta_q * (x2 - x1))')
print(f'c2=0.5*({x1}+{x2}+{beta_q} * ({x2}-{x1}))')
c2 = 0.5 * (x1 + x2 + beta_q * (x2 - x1))
print(f'c1={c1}, xl={xl}, xu={xu}')
print(f'c2={c2}, xl={xl}, xu={xu}')
c1 = min(max(c1, xl), xu)
c2 = min(max(c2, xl), xu)
if random.random() <= 0.5:
ind1[i] = c2
ind2[i] = c1
else:
ind1[i] = c1
ind2[i] = c2
return ind1, ind2
This is the output I get leading up to this failure:
I am getting the following error in cxSimulatedBinaryBounded in crossover.py (note I've added debug print statements in so the line numbers are different from a vanilla crossover.py):
I have added some logging to this function in order to determine why I am getting this error:
This is the output I get leading up to this failure:
What I can see is this calculation returns a complex number:
However, if I calculate this manually I don't get the complex number:
Why is this?
The text was updated successfully, but these errors were encountered: