diff --git a/README.md b/README.md index 773e4b228c..ab8d01f3ee 100644 --- a/README.md +++ b/README.md @@ -44,10 +44,10 @@ For both design requires intend to reuse as much OSS libraries as possible. ```sh # this will install it with emukit support: - pip install dist/mlos_core-0.0.2-py3-none-any.whl[emukit] + pip install dist/mlos_core-0.0.3-py3-none-any.whl[emukit] # this will install it with skopt support: - pip install dist/mlos_core-0.0.2-py3-none-any.whl[skopt] + pip install dist/mlos_core-0.0.3-py3-none-any.whl[skopt] ``` ## See Also diff --git a/doc/source/conf.py b/doc/source/conf.py index 9480253311..75180cc264 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -26,7 +26,7 @@ copyright = '2022, GSL' author = 'GSL' # The full version, including alpha/beta/rc tags -release = '0.0.2' +release = '0.0.3' # -- General configuration --------------------------------------------------- @@ -80,4 +80,4 @@ html_static_path = ['_static'] # nbsphinx_execute = 'never' # enable to stop nbsphinx from executing notebooks nbsphinx_kernel_name = 'python3' # Exclude build directory and Jupyter backup files: -exclude_patterns = ['_build', '**.ipynb_checkpoints'] \ No newline at end of file +exclude_patterns = ['_build', '**.ipynb_checkpoints'] diff --git a/doc/source/installation.rst b/doc/source/installation.rst index a3fc27ba0a..c32ad96f60 100644 --- a/doc/source/installation.rst +++ b/doc/source/installation.rst @@ -40,7 +40,7 @@ Distributing .. code-block:: shell # this will install it with emukit support: - pip install dist/mlos_core-0.0.2-py3-none-any.whl[emukit] + pip install dist/mlos_core-0.0.3-py3-none-any.whl[emukit] # this will install it with skopt support: - pip install dist/mlos_core-0.0.2-py3-none-any.whl[skopt] + pip install dist/mlos_core-0.0.3-py3-none-any.whl[skopt] diff --git a/mlos_core/spaces/__init__.py b/mlos_core/spaces/__init__.py index bd8af952d1..bc18da4cc0 100644 --- a/mlos_core/spaces/__init__.py +++ b/mlos_core/spaces/__init__.py @@ -55,12 +55,15 @@ def configspace_to_emukit_space(config_space: ConfigSpace.ConfigurationSpace): import emukit.core # pylint: disable=import-outside-toplevel def _one_parameter_convert(parameter): - if getattr(parameter, 'log', False): + log = getattr(parameter, 'log', False) + if log and not isinstance(parameter, ConfigSpace.UniformIntegerHyperparameter): raise ValueError("Emukit doesn't support log parameters.") if isinstance(parameter, ConfigSpace.UniformFloatHyperparameter): return emukit.core.ContinuousParameter(name=parameter.name, min_value=parameter.lower, max_value=parameter.upper) elif isinstance(parameter, ConfigSpace.UniformIntegerHyperparameter): - return emukit.core.DiscreteParameter(name=parameter.name, domain=np.arange(parameter.lower, parameter.upper+1)) + if log: + return emukit.core.DiscreteParameter(name=parameter.name, domain=np.exp(np.arange(np.ceil(np.log(parameter.lower)), np.floor(np.log(parameter.upper+1))))) + return emukit.core.DiscreteParameter(name=parameter.name, domain=np.arange(parameter.lower, parameter.upper + 1)) elif isinstance(parameter, ConfigSpace.CategoricalHyperparameter): if len(np.unique(parameter.probabilities)) > 1: raise ValueError("Emukit doesn't support categorical parameters with non-uniform probabilities.") diff --git a/mlos_core/spaces/tests/spaces_test.py b/mlos_core/spaces/tests/spaces_test.py index 80432324f3..2e2812877f 100644 --- a/mlos_core/spaces/tests/spaces_test.py +++ b/mlos_core/spaces/tests/spaces_test.py @@ -136,7 +136,21 @@ class TestEmukitConversion(BaseConversion): configspace_to_emukit_space(input_space) def test_log_spaces(self): + # continuous not supported input_space = CS.ConfigurationSpace() input_space.add_hyperparameter(CS.UniformFloatHyperparameter("b", lower=1, upper=5, log=True)) with pytest.raises(ValueError, match="log"): - configspace_to_emukit_space(input_space) \ No newline at end of file + configspace_to_emukit_space(input_space) + # integer is supported + input_space = CS.ConfigurationSpace() + input_space.add_hyperparameter(CS.UniformIntegerHyperparameter("d", lower=1, upper=20, log=True)) + converted_space = configspace_to_skopt_space(input_space) + + random_state = np.random.RandomState(42) + integer_log_uniform = converted_space.rvs(n_samples=1000, random_state=random_state) + + # log integer + integer_log_uniform = np.array(integer_log_uniform).ravel() + integer_log_uniform = integer_log_uniform - integer_log_uniform.min() + # TODO double check the math on this + assert_uniform_counts(np.log(np.bincount(integer_log_uniform))) \ No newline at end of file diff --git a/setup.py b/setup.py index 7fb2f2abf4..8d6acdf297 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from setuptools import setup, find_packages setup( name="mlos-core", - version="0.0.2", + version="0.0.3", packages=find_packages(), install_requires=[ 'scikit-learn>=0.22.1',