luinardi / hypermapper

Black-box Optimizer based on Bayesian Optimization
MIT License
152 stars 26 forks source link

Predicted integer parameter out of bounds #86

Open ThrivikramanV opened 1 year ago

ThrivikramanV commented 1 year ago

Observation

For an integer parameter with a min value of 1 and a max value of 15, HyperMapper predicts a value of 16 in some iterations.

Hypothesis

I believe it is due to an issue in line 448 of hypermapper/space.py

samples = np.round(X_copy * self.get_size() - 0.5 + self.get_min()).astype(int)

Suppose an element in X_copy has the value 1. Assuming an integer parameter with a min value of 1 and a max value of 15. The predicted value here would be np.round([1] * 15 - 0.5 + 1).astype(int) = np.round([15.5]).astype(int) = [16]

np.round rounds 15.5 to 16, since 16 is the nearest even integer (another example would be np.round([14.5]) = [14.]). Official documentation - https://numpy.org/doc/1.13/reference/generated/numpy.around.html#numpy.around

Potential solution

If line 448 is modified to the following, would it resolve the issue?

samples = np.round(X_copy * (self.get_size() - 1) + self.get_min()).astype(int)

For the example in hand, this translates to np.round(X_copy * 14 + 1).astype(int). The minimum value that this evaluates to is 1, and the maximum value is 15.