Forbidden Clauses

ConfigSpace contains forbidden equal and forbidden in clauses. The ForbiddenEqualsClause and the ForbiddenInClause can forbid values to be sampled from a configuration space if a certain condition is met. The ForbiddenAndConjunction can be used to combine ForbiddenEqualsClauses and the ForbiddenInClauses.

For a further example, please take a look in the user guide.

ForbiddenEqualsClause

class ConfigSpace.ForbiddenEqualsClause(hyperparameter, value)

A ForbiddenEqualsClause

It forbids a value from the value range of a hyperparameter to be equal to value.

Forbids the value 2 for the hyperparameter a

>>> from ConfigSpace import ConfigurationSpace, ForbiddenEqualsClause
>>>
>>> cs = ConfigurationSpace({"a": [1, 2, 3]})
>>> forbidden_clause_a = ForbiddenEqualsClause(cs["a"], 2)
>>> cs.add_forbidden_clause(forbidden_clause_a)
Forbidden: a == 2
Parameters:
  • hyperparameter (Hyperparameters) – Methods on which a restriction will be made

  • value (Any) – forbidden value

ForbiddenInClause

class ConfigSpace.ForbiddenInClause(hyperparameter, values)

A ForbiddenInClause.

It forbids a value from the value range of a hyperparameter to be in a collection of values.

Forbids the values 2, 3 for the hyperparameter a

>>> from ConfigSpace import ConfigurationSpace, ForbiddenInClause
>>>
>>> cs = ConfigurationSpace({"a": [1, 2, 3]})
>>> forbidden_clause_a = ForbiddenInClause(cs['a'], [2, 3])
>>> cs.add_forbidden_clause(forbidden_clause_a)
Forbidden: a in {2, 3}

Note

The forbidden values have to be a subset of the hyperparameter’s values.

Parameters:
  • hyperparameter ((Hyperparameters, dict)) – Hyperparameter on which a restriction will be made

  • values (Any) – Collection of forbidden values

ForbiddenAndConjunction

class ConfigSpace.ForbiddenAndConjunction(*args)

A ForbiddenAndConjunction.

The ForbiddenAndConjunction combines forbidden-clauses, which allows to build powerful constraints.

>>> from ConfigSpace import (
...     ConfigurationSpace,
...     ForbiddenEqualsClause,
...     ForbiddenInClause,
...     ForbiddenAndConjunction
... )
>>>
>>> cs = ConfigurationSpace({"a": [1, 2, 3], "b": [2, 5, 6]})
>>>
>>> forbidden_clause_a = ForbiddenEqualsClause(cs["a"], 2)
>>> forbidden_clause_b = ForbiddenInClause(cs["b"], [2])
>>>
>>> forbidden_clause = ForbiddenAndConjunction(forbidden_clause_a, forbidden_clause_b)
>>>
>>> cs.add_forbidden_clause(forbidden_clause)
(Forbidden: a == 2 && Forbidden: b in {2})
Parameters:

*args (list(Forbidden Clauses)) – forbidden clauses, which should be combined