Forbidden
ConfigSpace.forbidden
#
ForbiddenLike
module-attribute
#
ForbiddenLike = Union[
ForbiddenClause, ForbiddenConjunction, ForbiddenRelation
]
Type alias for forbidden clauses, conjunctions, and relations.
ForbiddenAndConjunction
#
ForbiddenAndConjunction(
*args: ForbiddenClause
| ForbiddenConjunction
| ForbiddenRelation,
)
Bases: ForbiddenConjunction
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)
print(cs)
PARAMETER | DESCRIPTION |
---|---|
*args |
forbidden clauses, which should be combined
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
*args |
forbidden clauses, which should be combined
TYPE:
|
Source code in src/ConfigSpace/forbidden.py
components
instance-attribute
#
components: tuple[
ForbiddenClause
| ForbiddenConjunction
| ForbiddenRelation,
...,
]
Components of the conjunction.
dlcs
instance-attribute
#
dlcs: tuple[ForbiddenClause | ForbiddenRelation, ...]
Descendant literal clauses of the conjunction.
These are the base forbidden clauses/relations that are part of conjunctions.
Note
This will only store a unique set of the descendant clauses, no duplicates.
get_descendant_literal_clauses
#
get_descendant_literal_clauses() -> (
tuple[ForbiddenClause | ForbiddenRelation, ...]
)
Get the descendant literal clauses of the conjunction.
Deprecated
Please use the .dlcs
attribute instead.
Source code in src/ConfigSpace/forbidden.py
set_vector_idx
#
Set vector index of hyperparameters in each element of the conjunction.
ForbiddenClause
#
ForbiddenClause(hyperparameter: Hyperparameter)
Bases: ABC
Base class for forbidden clauses.
PARAMETER | DESCRIPTION |
---|---|
hyperparameter |
Hyperparameter on which a restriction will be made
TYPE:
|
Source code in src/ConfigSpace/forbidden.py
hyperparameter
instance-attribute
#
hyperparameter: Hyperparameter = hyperparameter
Hyperparameter on which a restriction will be made.
vector_id
instance-attribute
#
vector_id: intp | None = None
Index of the hyperparameter in the vector representation.
is_forbidden_value
abstractmethod
#
Check if a value is forbidden.
PARAMETER | DESCRIPTION |
---|---|
values |
A dictionary of hyperparameter names to values |
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the value is forbidden, False otherwise
TYPE:
|
Source code in src/ConfigSpace/forbidden.py
is_forbidden_vector
abstractmethod
#
Check if a vector is forbidden.
Will use .vector_id
to
index the vector.
PARAMETER | DESCRIPTION |
---|---|
vector |
A vector representation of the hyperparameters |
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the vector is forbidden, False otherwise
TYPE:
|
Source code in src/ConfigSpace/forbidden.py
is_forbidden_vector_array
abstractmethod
#
Check if an array of vectors is forbidden.
Will use .vector_id
to
index the array.
PARAMETER | DESCRIPTION |
---|---|
arr |
An array of vector representations of the hyperparameters |
RETURNS | DESCRIPTION |
---|---|
Mask
|
A boolean mask of the forbidden vectors
TYPE:
|
Source code in src/ConfigSpace/forbidden.py
set_vector_idx
#
ForbiddenConjunction
#
ForbiddenConjunction(
*args: ForbiddenClause
| ForbiddenConjunction
| ForbiddenRelation,
)
Bases: ABC
Base class for forbidden conjunctions.
PARAMETER | DESCRIPTION |
---|---|
*args |
forbidden clauses, which should be combined
TYPE:
|
Source code in src/ConfigSpace/forbidden.py
components
instance-attribute
#
components: tuple[
ForbiddenClause
| ForbiddenConjunction
| ForbiddenRelation,
...,
] = args
Components of the conjunction.
dlcs
instance-attribute
#
dlcs: tuple[ForbiddenClause | ForbiddenRelation, ...] = (
tuple(unique_everseen(dlcs, key=lambda x: id(x)))
)
Descendant literal clauses of the conjunction.
These are the base forbidden clauses/relations that are part of conjunctions.
Note
This will only store a unique set of the descendant clauses, no duplicates.
get_descendant_literal_clauses
#
get_descendant_literal_clauses() -> (
tuple[ForbiddenClause | ForbiddenRelation, ...]
)
Get the descendant literal clauses of the conjunction.
Deprecated
Please use the .dlcs
attribute instead.
Source code in src/ConfigSpace/forbidden.py
is_forbidden_value
abstractmethod
#
is_forbidden_vector
abstractmethod
#
is_forbidden_vector_array
abstractmethod
#
set_vector_idx
#
Set vector index of hyperparameters in each element of the conjunction.
ForbiddenEqualsClause
#
ForbiddenEqualsClause(
hyperparameter: Hyperparameter, value: Any
)
Bases: ForbiddenClause
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_a)
print(cs)
PARAMETER | DESCRIPTION |
---|---|
hyperparameter |
Methods on which a restriction will be made
TYPE:
|
value |
forbidden value
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
hyperparameter |
Hyperparameter on which a restriction will be made
TYPE:
|
value |
forbidden value
TYPE:
|
Source code in src/ConfigSpace/forbidden.py
hyperparameter
instance-attribute
#
hyperparameter: Hyperparameter
Hyperparameter on which a restriction will be made.
vector_id
instance-attribute
#
vector_id: intp | None = None
Index of the hyperparameter in the vector representation.
set_vector_idx
#
ForbiddenEqualsRelation
#
ForbiddenEqualsRelation(
left: Hyperparameter, right: Hyperparameter
)
Bases: ForbiddenRelation
A ForbiddenEquals relation between two hyperparameters.
The ForbiddenEquals compares the values of two hyperparameters.
from ConfigSpace import ConfigurationSpace, ForbiddenEqualsRelation
cs = ConfigurationSpace({"a": [1, 2, 3], "b": [2, 5, 6]})
forbidden_clause = ForbiddenEqualsRelation(cs['a'], cs['b'])
cs.add(forbidden_clause)
print(cs)
Note
If the values of the both hyperparameters are not comparible (e.g. comparing int and str), a TypeError is raised. For OrdinalHyperparameters the actual values are used for comparison not their ordinal value.
PARAMETER | DESCRIPTION |
---|---|
left |
left side of the comparison
TYPE:
|
right |
right side of the comparison
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
left |
left side of the comparison
TYPE:
|
right |
right side of the comparison
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If |
Note
If the values of the both hyperparameters are not comparible (e.g. comparing int and str), a TypeError is raised. For OrdinalHyperparameters the actual values are used for comparison not their ordinal value.
Source code in src/ConfigSpace/forbidden.py
ForbiddenGreaterThanRelation
#
ForbiddenGreaterThanRelation(
left: Hyperparameter, right: Hyperparameter
)
Bases: ForbiddenRelation
A ForbiddenGreaterThan relation between two hyperparameters.
The ForbiddenGreaterThan compares the values of two hyperparameters.
from ConfigSpace import ConfigurationSpace, ForbiddenGreaterThanRelation
cs = ConfigurationSpace({"a": [1, 2, 3], "b": [2, 5, 6]})
forbidden_clause = ForbiddenGreaterThanRelation(cs['a'], cs['b'])
cs.add(forbidden_clause)
Note
If the values of the both hyperparameters are not comparible (e.g. comparing int and str), a TypeError is raised. For OrdinalHyperparameters the actual values are used for comparison not their ordinal value.
PARAMETER | DESCRIPTION |
---|---|
left |
left side of the comparison
TYPE:
|
right |
right side of the comparison
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
left |
left side of the comparison
TYPE:
|
right |
right side of the comparison
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If |
Note
If the values of the both hyperparameters are not comparible (e.g. comparing int and str), a TypeError is raised. For OrdinalHyperparameters the actual values are used for comparison not their ordinal value.
Source code in src/ConfigSpace/forbidden.py
ForbiddenInClause
#
ForbiddenInClause(
hyperparameter: Hyperparameter, values: Iterable[Any]
)
Bases: ForbiddenClause
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_a)
print(cs)
Note
The forbidden values have to be a subset of the hyperparameter's values.
PARAMETER | DESCRIPTION |
---|---|
hyperparameter |
Hyperparameter on which a restriction will be made
TYPE:
|
values |
Collection of forbidden values |
Source code in src/ConfigSpace/forbidden.py
hyperparameter
instance-attribute
#
hyperparameter: Hyperparameter
Hyperparameter on which a restriction will be made.
vector_id
instance-attribute
#
vector_id: intp | None = None
Index of the hyperparameter in the vector representation.
set_vector_idx
#
ForbiddenLessThanRelation
#
ForbiddenLessThanRelation(
left: Hyperparameter, right: Hyperparameter
)
Bases: ForbiddenRelation
A ForbiddenLessThan relation between two hyperparameters.
The ForbiddenLessThan compares the values of two hyperparameters.
from ConfigSpace import ConfigurationSpace, ForbiddenLessThanRelation
cs = ConfigurationSpace({"a": [10, 2, 3], "b": [2, 5, 6]})
forbidden_clause = ForbiddenLessThanRelation(cs['a'], cs['b'])
cs.add(forbidden_clause)
print(cs)
Note
If the values of the both hyperparameters are not comparible (e.g. comparing int and str), a TypeError is raised. For OrdinalHyperparameters the actual values are used for comparison not their ordinal value.
PARAMETER | DESCRIPTION |
---|---|
left |
left side of the comparison
TYPE:
|
right |
right side of the comparison
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
left |
left side of the comparison
TYPE:
|
right |
right side of the comparison
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If |
Note
If the values of the both hyperparameters are not comparible (e.g. comparing int and str), a TypeError is raised. For OrdinalHyperparameters the actual values are used for comparison not their ordinal value.
Source code in src/ConfigSpace/forbidden.py
ForbiddenRelation
#
ForbiddenRelation(
left: Hyperparameter, right: Hyperparameter
)
Bases: ABC
Base class for forbidden relations between hyperparameters.
PARAMETER | DESCRIPTION |
---|---|
left |
left side of the comparison
TYPE:
|
right |
right side of the comparison
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If |
Note
If the values of the both hyperparameters are not comparible (e.g. comparing int and str), a TypeError is raised. For OrdinalHyperparameters the actual values are used for comparison not their ordinal value.
Source code in src/ConfigSpace/forbidden.py
vector_ids
instance-attribute
#
Indices of the hyperparameters in the vector representation.
is_forbidden_value
abstractmethod
#
is_forbidden_vector
abstractmethod
#
is_forbidden_vector_array
abstractmethod
#
set_vector_idx
#
Set the vector index of the hyperparameters.
Source code in src/ConfigSpace/forbidden.py
to_dict
#
Convert the forbidden relation to a dictionary representation.