-
Notifications
You must be signed in to change notification settings - Fork 181
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
[BUG] integer_idx not working (trial vectors are still float) #286
Comments
This is intended behavior. The option only signals to the code that the objective function does not "use decimal places". If the objective function requires integer values, it would be simple to (additionally) use a wrapper in the spirit of import numpy as np
class FunWithIntegers:
def __init__(self, fun, integer_indices):
self.fun = fun
self.integer_indices = integer_indices
def __call__(self, x):
x = np.array(x)
for i in self.integer_indices:
x[i] = int(x[i] + 0.5)
return self.fun(x) |
Thanks for the quick answer. So just to confirm, for rmy integer only problem, I can do This seems like a rather odd choice to me. if rounding to nearest integer is done internally, why not pass the those vectors to the objective function as well? In any case it would be nice to explicitly mention this here: |
Yes and no, the variables which are rounded/integer must still be signalled to
that was indeed incorrectly worded, sorry, integer centering indeed assumes rounding, this had slipped my mind.
Integer variables may be rounded sometimes but are not always rounded. The x = np.array(x) is important in that it copies
The first sentence reads "round values of int-variables that are different from the int-mean", which seems to clearly suggest that not all integer variables are rounded. It then reads "This assumes that int-variables change the fitness only if their rounded (genotype) value change", which suggests that the fitness function needs to take care of rounding if necessary. I'll try to make it more clear. |
pycma 4.0.0
python 3.12 on ubuntu
I have a optimization problem involving 14 integer variables. I am calling fmin() in the manner below, where integer_idx is set to 0, ..., 13.
However, when I inspect the vector (of population members) passed to obj_func, they are not integers but floats. Do I need to do something other than setting integer_idx?
Output:
The text was updated successfully, but these errors were encountered: