deephyper.hpo.HpProblem#

class deephyper.hpo.HpProblem(config_space=None)[source]#

Bases: object

Class to define an hyperparameter problem.

>>> from deephyper.hpo import HpProblem
>>> problem = HpProblem()
Parameters:

config_space (ConfigurationSpace, optional) – In case the HpProblem is defined from a ConfigurationSpace.

Methods

add_condition

Add a condition to the HpProblem.

add_conditions

add_forbidden_clause

Add a forbidden clause to the HpProblem.

add_hyperparameter

Add an hyperparameter to the HpProblem.

add_hyperparameters

Add a list of hyperparameters.

check_configuration

Check if a configuration is valid.

to_json

Returns a dict version of the space which can be saved as JSON.

Attributes

default_configuration

The default configuration as a dictionnary.

hyperparameter_names

The list of hyperparameters names.

space

The wrapped ConfigSpace object.

add_condition(condition)[source]#

Add a condition to the HpProblem.

>>> from deephyper.hpo import HpProblem
>>> import ConfigSpace as cs
>>> problem = HpProblem()
>>> x = problem.add_hyperparameter((0.0, 10.0), "x")
>>> y = problem.add_hyperparameter((1e-4, 1.0), "y")
>>> problem.add_condition(cs.LessThanCondition(y, x, 1.0))
s
Args:

condition: A ConfigSpace condition.

add_conditions(conditions: list) None[source]#

Add a list of condition to the HpProblem.

Parameters:

conditions (list) – A list of ConfigSpace conditions.

add_forbidden_clause(clause)[source]#

Add a forbidden clause to the HpProblem.

For example if we want to optimize \(\frac{1}{x}\) where \(x\) cannot be equal to 0:

>>> from deephyper.hpo import HpProblem
>>> import ConfigSpace as cs
>>> problem = HpProblem()
>>> x = problem.add_hyperparameter((0.0, 10.0), "x")
>>> problem.add_forbidden_clause(cs.ForbiddenEqualsClause(x, 0.0))
Parameters:

clause – a ConfigSpace forbidden clause.

add_hyperparameter(value, name: str = None, default_value=None) ConfigSpace.hyperparameters.Hyperparameter[source]#

Add an hyperparameter to the HpProblem.

Hyperparameters can be added to a HpProblem with a short syntax:

>>> problem.add_hyperparameter((0, 10), "discrete", default_value=5)
>>> problem.add_hyperparameter((0.0, 10.0), "real", default_value=5.0)
>>> problem.add_hyperparameter([0, 10], "categorical", default_value=0)

Sampling distributions can be provided:

>>> problem.add_hyperparameter((0.0, 10.0, "log-uniform"), "real", default_value=5.0)

It is also possible to use ConfigSpace Hyperparameters:

>>> import ConfigSpace.hyperparameters as csh
>>> csh_hp = csh.UniformIntegerHyperparameter(
...     name='uni_int', lower=10, upper=100, log=False)
>>> problem.add_hyperparameter(csh_hp)
Parameters:
  • value (tuple or list or ConfigSpace.Hyperparameter) – a valid hyperparametr description.

  • name (str) – The name of the hyperparameter to add.

  • default_value (float or int or str) – A default value for the corresponding hyperparameter.

Returns:

a ConfigSpace Hyperparameter object corresponding to the (value, name, default_value).

Return type:

ConfigSpace.Hyperparameter

add_hyperparameters(hp_list)[source]#

Add a list of hyperparameters. It can be useful when a list of ConfigSpace.Hyperparameter are defined and we need to add them to the HpProblem.

Parameters:

hp_list (ConfigSpace.Hyperparameter) – a list of ConfigSpace hyperparameters.

Returns:

The list of added hyperparameters.

Return type:

list

check_configuration(parameters: dict)[source]#

Check if a configuration is valid. Raise an error if not.

property default_configuration#

The default configuration as a dictionnary.

property hyperparameter_names#

The list of hyperparameters names.

property space#

The wrapped ConfigSpace object.

to_json()[source]#

Returns a dict version of the space which can be saved as JSON.