Conditions¶
ConfigSpace can realize equal, not equal, less than, greater than and in conditions. Conditions can be combined by using the conjunctions and and or. To see how to use conditions, please take a look at the user guide.
EqualsCondition¶
- class ConfigSpace.conditions.EqualsCondition¶
Hyperparameter
child
is conditional on theparent
hyperparameter being equal tovalue
.Make b an active hyperparameter if a has the value 1
>>> from ConfigSpace import ConfigurationSpace, EqualsCondition >>> >>> cs = ConfigurationSpace({ ... "a": [1, 2, 3], ... "b": (1.0, 8.0) ... }) >>> cond = EqualsCondition(cs['b'], cs['a'], 1) >>> cs.add_condition(cond) b | a == 1
- Parameters:
child (Hyperparameters) – This hyperparameter will be sampled in the configspace if the equal condition is satisfied
parent (Hyperparameters) – The hyperparameter, which has to satisfy the equal condition
value (str, float, int) – Value, which the parent is compared to
NotEqualsCondition¶
- class ConfigSpace.conditions.NotEqualsCondition¶
Hyperparameter
child
is conditional on theparent
hyperparameter being not equal tovalue
.Make b an active hyperparameter if a has not the value 1
>>> from ConfigSpace import ConfigurationSpace, NotEqualsCondition >>> >>> cs = ConfigurationSpace({ ... "a": [1, 2, 3], ... "b": (1.0, 8.0) ... }) >>> cond = NotEqualsCondition(cs['b'], cs['a'], 1) >>> cs.add_condition(cond) b | a != 1
- Parameters:
child (Hyperparameters) – This hyperparameter will be sampled in the configspace if the not-equals condition is satisfied
parent (Hyperparameters) – The hyperparameter, which has to satisfy the not equal condition
value (str, float, int) – Value, which the parent is compared to
LessThanCondition¶
- class ConfigSpace.conditions.LessThanCondition¶
Hyperparameter
child
is conditional on theparent
hyperparameter being less thanvalue
.Make b an active hyperparameter if a is less than 5
>>> from ConfigSpace import ConfigurationSpace, LessThanCondition >>> >>> cs = ConfigurationSpace({ ... "a": (0, 10), ... "b": (1.0, 8.0) ... }) >>> cond = LessThanCondition(cs['b'], cs['a'], 5) >>> cs.add_condition(cond) b | a < 5
- Parameters:
child (Hyperparameters) – This hyperparameter will be sampled in the configspace, if the LessThanCondition is satisfied
parent (Hyperparameters) – The hyperparameter, which has to satisfy the LessThanCondition
value (str, float, int) – Value, which the parent is compared to
GreaterThanCondition¶
- class ConfigSpace.conditions.GreaterThanCondition¶
Hyperparameter
child
is conditional on theparent
hyperparameter being greater thanvalue
.Make b an active hyperparameter if a is greater than 5
>>> from ConfigSpace import ConfigurationSpace, GreaterThanCondition >>> >>> cs = ConfigurationSpace({ ... "a": (0, 10), ... "b": (1.0, 8.0) ... }) >>> cond = GreaterThanCondition(cs['b'], cs['a'], 5) >>> cs.add_condition(cond) b | a > 5
- Parameters:
child (Hyperparameters) – This hyperparameter will be sampled in the configspace, if the GreaterThanCondition is satisfied
parent (Hyperparameters) – The hyperparameter, which has to satisfy the GreaterThanCondition
value (str, float, int) – Value, which the parent is compared to
InCondition¶
- class ConfigSpace.conditions.InCondition¶
Hyperparameter
child
is conditional on theparent
hyperparameter being in a set ofvalues
.make b an active hyperparameter if a is in the set [1, 2, 3, 4]
>>> from ConfigSpace import ConfigurationSpace, InCondition >>> >>> cs = ConfigurationSpace({ ... "a": (0, 10), ... "b": (1.0, 8.0) ... }) >>> cond = InCondition(cs['b'], cs['a'], [1, 2, 3, 4]) >>> cs.add_condition(cond) b | a in {1, 2, 3, 4}
- Parameters:
child (Hyperparameters) – This hyperparameter will be sampled in the configspace, if the InCondition is satisfied
parent (Hyperparameters) – The hyperparameter, which has to satisfy the InCondition
values (list(str, float, int)) – Collection of values, which the parent is compared to
AndConjunction¶
- class ConfigSpace.conditions.AndConjunction¶
By using the AndConjunction, constraints can easily be connected.
The following example shows how two constraints with an AndConjunction can be combined.
>>> from ConfigSpace import ( ... ConfigurationSpace, ... LessThanCondition, ... GreaterThanCondition, ... AndConjunction ... ) >>> >>> cs = ConfigurationSpace({ ... "a": (5, 15), ... "b": (0, 10), ... "c": (0.0, 1.0) ... }) >>> less_cond = LessThanCondition(cs['c'], cs['a'], 10) >>> greater_cond = GreaterThanCondition(cs['c'], cs['b'], 5) >>> cs.add_condition(AndConjunction(less_cond, greater_cond)) (c | a < 10 && c | b > 5)
- Parameters:
*args (Conditions) – conditions, which will be combined with an AndConjunction
OrConjunction¶
- class ConfigSpace.conditions.OrConjunction¶
Similar to the AndConjunction, constraints can be combined by using the OrConjunction.
>>> from ConfigSpace import ( ... ConfigurationSpace, ... LessThanCondition, ... GreaterThanCondition, ... OrConjunction ... ) >>> >>> cs = ConfigurationSpace({ ... "a": (5, 15), ... "b": (0, 10), ... "c": (0.0, 1.0) ... }) >>> less_cond = LessThanCondition(cs['c'], cs['a'], 10) >>> greater_cond = GreaterThanCondition(cs['c'], cs['b'], 5) >>> cs.add_condition(OrConjunction(less_cond, greater_cond)) (c | a < 10 || c | b > 5)
- Parameters:
*args (Conditions) – conditions, which will be combined with an OrConjunction