ConfigSpace icon indicating copy to clipboard operation
ConfigSpace copied to clipboard

Illegal value for the frequent floating precision issue

Open nabenabe0928 opened this issue 1 year ago • 2 comments

Well-known precision issue

Would you be able to use np.isclose or something similar for the comparison? I think the problem came from here.

In [1]: import ConfigSpace as CS

In [2]: config_space = CS.ConfigurationSpace()

In [3]: config_space.add_hyperparameter(CS.UniformFloatHyperparameter("a", 0.0, 1.0))
Out[3]: a, Type: UniformFloat, Range: [0.0, 1.0], Default: 0.5

In [4]: CS.Configuration(config_space, {"a": 1.0 + 1e-12})
---------------------------------------------------------------------------
IllegalValueError                         Traceback (most recent call last)
Cell In[4], line 1
----> 1 CS.Configuration(config_space, {"a": 1.0 + 1e-12})

File ~/anaconda3/envs/config-space/lib/python3.9/site-packages/ConfigSpace/configuration.py:90, in Configuration.__init__(self, configuration_space, values, vector, allow_inactive_with_values, origin, config_id)
     87     continue
     89 if not hp.is_legal(value):
---> 90     raise IllegalValueError(hp, value)
     92 # Truncate the float to be of constant length for a python version
     93 if isinstance(hp, FloatHyperparameter):

IllegalValueError: Value 1.000000000001: (<class 'float'>) is not allowed for hyperparameter a, Type: UniformFloat, Range: [0.0, 1.0], Default: 0.5

nabenabe0928 avatar Jul 07 '23 08:07 nabenabe0928