зеркало из https://github.com/microsoft/MLOS.git
Merged PR 507: add log space support to integer parameters in emukit
add log space support to integer parameters in emukit
This commit is contained in:
Родитель
4da70d96bf
Коммит
a4d84ccfe7
|
@ -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
|
||||
|
|
|
@ -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']
|
||||
exclude_patterns = ['_build', '**.ipynb_checkpoints']
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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)
|
||||
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)))
|
2
setup.py
2
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',
|
||||
|
|
Загрузка…
Ссылка в новой задаче