deephyper.problem.HpProblem

deephyper.problem.HpProblem

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

Bases: object

Class to define an hyperparameter problem.

>>> from deephyper.problem 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 a list of condition to the HpProblem.

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.

add_starting_point

Add starting points to the HpProblem.

check_configuration

meta private

Attributes

hyperparameter_names

space

The wrapped ConfigSpace object.

starting_point

Starting point(s) of the search space.

starting_point_asdict

Starting point(s) of the search space.

add_condition(condition)[source]

Add a condition to the HpProblem.

>>> from deephyper.problem 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))
Parameters

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.problem 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: Optional[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

add_starting_point(**parameters)[source]

Add starting points to the HpProblem. It is useful when a good-baseline is known to help initialize the search at a given location of the search space.

>>> from deephyper.problem import HpProblem
>>> problem = HpProblem()
>>> x = problem.add_hyperparameter((0.0, 10.0), "x")
>>> problem.add_starting_point(x=1.0)
property space

The wrapped ConfigSpace object.

property starting_point

Starting point(s) of the search space.

Returns

list of starting points where each point is a list of values. Values are indexed in the same order as the order of creation of space’s dimensions.

Return type

list

property starting_point_asdict

Starting point(s) of the search space.

Returns

list of starting points where each point is a dict of values. Each key are correspnding to dimensions of the space.

Return type

list(dict)