Skip to content

Forbidden

ConfigSpace.forbidden #

ForbiddenLike module-attribute #

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)
Configuration space object:
  Hyperparameters:
    a, Type: Categorical, Choices: {1, 2, 3}, Default: 1
    b, Type: Categorical, Choices: {2, 5, 6}, Default: 2
  Forbidden Clauses:
    (Forbidden: a == 2 && Forbidden: b in {2})
PARAMETER DESCRIPTION
*args

forbidden clauses, which should be combined

TYPE: ForbiddenClause | ForbiddenConjunction | ForbiddenRelation DEFAULT: ()

PARAMETER DESCRIPTION
*args

forbidden clauses, which should be combined

TYPE: ForbiddenClause | ForbiddenConjunction | ForbiddenRelation DEFAULT: ()

Source code in src/ConfigSpace/forbidden.py
def __init__(
    self,
    *args: ForbiddenClause | ForbiddenConjunction | ForbiddenRelation,
) -> None:
    """Initialize a ForbiddenConjunction.

    Args:
        *args: forbidden clauses, which should be combined
    """
    # Test the classes
    acceptable = (ForbiddenClause, ForbiddenConjunction, ForbiddenRelation)
    for idx, component in enumerate(args):
        if not isinstance(component, acceptable):
            raise TypeError(
                "Argument #%d is not an instance of %s, "
                "but %s" % (idx, acceptable, type(component)),
            )

    self.components = args
    dlcs: list[ForbiddenClause | ForbiddenRelation] = []
    for component in self.components:
        if isinstance(component, ForbiddenConjunction):
            dlcs.extend(component.dlcs)
        else:
            dlcs.append(component)

    self.dlcs: tuple[ForbiddenClause | ForbiddenRelation, ...] = tuple(
        unique_everseen(dlcs, key=lambda x: id(x)),
    )

components instance-attribute #

Components of the conjunction.

dlcs instance-attribute #

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
@deprecated("Use `.dlcs` instead")
def get_descendant_literal_clauses(
    self,
) -> tuple[ForbiddenClause | ForbiddenRelation, ...]:
    """Get the descendant literal clauses of the conjunction.

    !!! note "Deprecated"

        Please use the `.dlcs` attribute instead.
    """
    return self.dlcs

set_vector_idx #

set_vector_idx(
    hyperparameter_to_idx: Mapping[str, int]
) -> None

Set vector index of hyperparameters in each element of the conjunction.

Source code in src/ConfigSpace/forbidden.py
def set_vector_idx(self, hyperparameter_to_idx: Mapping[str, int]) -> None:
    """Set vector index of hyperparameters in each element of the conjunction."""
    for component in self.components:
        component.set_vector_idx(hyperparameter_to_idx)

ForbiddenClause #

ForbiddenClause(hyperparameter: Hyperparameter)

Bases: ABC

Base class for forbidden clauses.

PARAMETER DESCRIPTION
hyperparameter

Hyperparameter on which a restriction will be made

TYPE: Hyperparameter

Source code in src/ConfigSpace/forbidden.py
def __init__(self, hyperparameter: Hyperparameter) -> None:
    """Initialize a ForbiddenClause.

    Args:
        hyperparameter: Hyperparameter on which a restriction will be made
    """
    self.hyperparameter = hyperparameter
    self.vector_id: np.intp | None = None

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 #

is_forbidden_value(values: dict[str, Any]) -> bool

Check if a value is forbidden.

PARAMETER DESCRIPTION
values

A dictionary of hyperparameter names to values

TYPE: dict[str, Any]

RETURNS DESCRIPTION
bool

True if the value is forbidden, False otherwise

TYPE: bool

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def is_forbidden_value(self, values: dict[str, Any]) -> bool:
    """Check if a value is forbidden.

    Args:
        values: A dictionary of hyperparameter names to values

    Returns:
        bool: True if the value is forbidden, False otherwise
    """

is_forbidden_vector abstractmethod #

is_forbidden_vector(vector: Array[f64]) -> bool

Check if a vector is forbidden.

Will use .vector_id to index the vector.

PARAMETER DESCRIPTION
vector

A vector representation of the hyperparameters

TYPE: Array[f64]

RETURNS DESCRIPTION
bool

True if the vector is forbidden, False otherwise

TYPE: bool

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def is_forbidden_vector(self, vector: Array[f64]) -> bool:
    """Check if a vector is forbidden.

    Will use [`.vector_id`][ConfigSpace.forbidden.ForbiddenClause.vector_id] to
    index the vector.

    Args:
        vector: A vector representation of the hyperparameters

    Returns:
        bool: True if the vector is forbidden, False otherwise
    """

is_forbidden_vector_array abstractmethod #

is_forbidden_vector_array(arr: Array[f64]) -> Mask

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

TYPE: Array[f64]

RETURNS DESCRIPTION
Mask

A boolean mask of the forbidden vectors

TYPE: Mask

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def is_forbidden_vector_array(self, arr: Array[f64]) -> Mask:
    """Check if an array of vectors is forbidden.

    Will use [`.vector_id`][ConfigSpace.forbidden.ForbiddenClause.vector_id] to
    index the array.

    Args:
        arr: An array of vector representations of the hyperparameters

    Returns:
        Mask: A boolean mask of the forbidden vectors
    """

set_vector_idx #

set_vector_idx(
    hyperparameter_to_idx: Mapping[str, Any]
) -> None

Set the vector index of the hyperparameter.

Source code in src/ConfigSpace/forbidden.py
def set_vector_idx(self, hyperparameter_to_idx: Mapping[str, Any]) -> None:
    """Set the vector index of the hyperparameter."""
    self.vector_id = np.intp(hyperparameter_to_idx[self.hyperparameter.name])

to_dict abstractmethod #

to_dict() -> dict[str, Any]

Convert the forbidden clause to a dictionary representation.

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def to_dict(self) -> dict[str, Any]:
    """Convert the forbidden clause to a dictionary representation."""

ForbiddenConjunction #

ForbiddenConjunction(
    *args: ForbiddenClause
    | ForbiddenConjunction
    | ForbiddenRelation,
)

Bases: ABC

Base class for forbidden conjunctions.

PARAMETER DESCRIPTION
*args

forbidden clauses, which should be combined

TYPE: ForbiddenClause | ForbiddenConjunction | ForbiddenRelation DEFAULT: ()

Source code in src/ConfigSpace/forbidden.py
def __init__(
    self,
    *args: ForbiddenClause | ForbiddenConjunction | ForbiddenRelation,
) -> None:
    """Initialize a ForbiddenConjunction.

    Args:
        *args: forbidden clauses, which should be combined
    """
    # Test the classes
    acceptable = (ForbiddenClause, ForbiddenConjunction, ForbiddenRelation)
    for idx, component in enumerate(args):
        if not isinstance(component, acceptable):
            raise TypeError(
                "Argument #%d is not an instance of %s, "
                "but %s" % (idx, acceptable, type(component)),
            )

    self.components = args
    dlcs: list[ForbiddenClause | ForbiddenRelation] = []
    for component in self.components:
        if isinstance(component, ForbiddenConjunction):
            dlcs.extend(component.dlcs)
        else:
            dlcs.append(component)

    self.dlcs: tuple[ForbiddenClause | ForbiddenRelation, ...] = tuple(
        unique_everseen(dlcs, key=lambda x: id(x)),
    )

components instance-attribute #

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
@deprecated("Use `.dlcs` instead")
def get_descendant_literal_clauses(
    self,
) -> tuple[ForbiddenClause | ForbiddenRelation, ...]:
    """Get the descendant literal clauses of the conjunction.

    !!! note "Deprecated"

        Please use the `.dlcs` attribute instead.
    """
    return self.dlcs

is_forbidden_value abstractmethod #

is_forbidden_value(values: dict[str, Any]) -> bool

Check if a value is forbidden.

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def is_forbidden_value(self, values: dict[str, Any]) -> bool:
    """Check if a value is forbidden."""

is_forbidden_vector abstractmethod #

is_forbidden_vector(vector: Array[f64]) -> bool

Check if a vector is forbidden.

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def is_forbidden_vector(self, vector: Array[f64]) -> bool:
    """Check if a vector is forbidden."""

is_forbidden_vector_array abstractmethod #

is_forbidden_vector_array(arr: Array[f64]) -> Mask

Check if an array of vectors is forbidden.

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def is_forbidden_vector_array(self, arr: Array[f64]) -> Mask:
    """Check if an array of vectors is forbidden."""

set_vector_idx #

set_vector_idx(
    hyperparameter_to_idx: Mapping[str, int]
) -> None

Set vector index of hyperparameters in each element of the conjunction.

Source code in src/ConfigSpace/forbidden.py
def set_vector_idx(self, hyperparameter_to_idx: Mapping[str, int]) -> None:
    """Set vector index of hyperparameters in each element of the conjunction."""
    for component in self.components:
        component.set_vector_idx(hyperparameter_to_idx)

to_dict abstractmethod #

to_dict() -> dict[str, Any]

Convert the forbidden conjunction to a dictionary representation.

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def to_dict(self) -> dict[str, Any]:
    """Convert the forbidden conjunction to a dictionary representation."""

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)
Configuration space object:
  Hyperparameters:
    a, Type: Categorical, Choices: {1, 2, 3}, Default: 1
  Forbidden Clauses:
    Forbidden: a == 2
PARAMETER DESCRIPTION
hyperparameter

Methods on which a restriction will be made

TYPE: Hyperparameter

value

forbidden value

TYPE: Any

PARAMETER DESCRIPTION
hyperparameter

Hyperparameter on which a restriction will be made

TYPE: Hyperparameter

value

forbidden value

TYPE: Any

Source code in src/ConfigSpace/forbidden.py
def __init__(self, hyperparameter: Hyperparameter, value: Any) -> None:
    """Initialize a ForbiddenEqualsClause.

    Args:
        hyperparameter: Hyperparameter on which a restriction will be made
        value: forbidden value
    """
    if not hyperparameter.legal_value(value):
        raise ValueError(
            "Forbidden clause must be instantiated with a "
            f"legal hyperparameter value for '{hyperparameter}', but got "
            f"'{value!s}'",
        )
    super().__init__(hyperparameter)
    self.value = value

    # OPTIM: Since forbiddens are used in sampling which converts everything to
    # f64, we pre-convert the value here to make the comparison check faster
    self.vector_value = f64(self.hyperparameter.to_vector(self.value))

hyperparameter instance-attribute #

hyperparameter: Hyperparameter

Hyperparameter on which a restriction will be made.

value instance-attribute #

value: Any = value

Forbidden value.

vector_id instance-attribute #

vector_id: intp | None = None

Index of the hyperparameter in the vector representation.

set_vector_idx #

set_vector_idx(
    hyperparameter_to_idx: Mapping[str, Any]
) -> None

Set the vector index of the hyperparameter.

Source code in src/ConfigSpace/forbidden.py
def set_vector_idx(self, hyperparameter_to_idx: Mapping[str, Any]) -> None:
    """Set the vector index of the hyperparameter."""
    self.vector_id = np.intp(hyperparameter_to_idx[self.hyperparameter.name])

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)
Configuration space object:
  Hyperparameters:
    a, Type: Categorical, Choices: {1, 2, 3}, Default: 1
    b, Type: Categorical, Choices: {2, 5, 6}, Default: 2
  Forbidden Clauses:
    Forbidden: a == b

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: Hyperparameter

right

right side of the comparison

TYPE: Hyperparameter

PARAMETER DESCRIPTION
left

left side of the comparison

TYPE: Hyperparameter

right

right side of the comparison

TYPE: Hyperparameter

RAISES DESCRIPTION
TypeError

If left or right are not instances of Hyperparameter

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
def __init__(self, left: Hyperparameter, right: Hyperparameter):
    """Initialize a ForbiddenRelation.

    Args:
        left: left side of the comparison
        right: right side of the comparison

    Raises:
        TypeError: If `left` or `right` are not instances of `Hyperparameter`

    !!! 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.
    """
    if not isinstance(left, Hyperparameter):
        raise TypeError(f"Argument 'left' is not of type {Hyperparameter}.")
    if not isinstance(right, Hyperparameter):
        raise TypeError(f"Argument 'right' is not of type {Hyperparameter}.")

    self.left = left
    self.right = right
    self.vector_ids: tuple[None, None] | tuple[np.intp, np.intp] = (None, None)

left instance-attribute #

Left side of the comparison.

right instance-attribute #

Right side of the comparison.

vector_ids instance-attribute #

vector_ids: tuple[None, None] | tuple[intp, intp]

Indices of the hyperparameters in the vector representation.

set_vector_idx #

set_vector_idx(
    hyperparameter_to_idx: Mapping[str, int]
) -> None

Set the vector index of the hyperparameters.

Source code in src/ConfigSpace/forbidden.py
def set_vector_idx(self, hyperparameter_to_idx: Mapping[str, int]) -> None:
    """Set the vector index of the hyperparameters."""
    self.vector_ids = (
        np.intp(hyperparameter_to_idx[self.left.name]),
        np.intp(hyperparameter_to_idx[self.right.name]),
    )

to_dict #

to_dict() -> dict[str, Any]

Convert the forbidden relation to a dictionary representation.

Source code in src/ConfigSpace/forbidden.py
def to_dict(self) -> dict[str, Any]:
    """Convert the forbidden relation to a dictionary representation."""
    return {
        "left": self.left.name,
        "right": self.right.name,
        "type": "RELATION",
        "lambda": self._RELATION_STR,
    }

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: Hyperparameter

right

right side of the comparison

TYPE: Hyperparameter

PARAMETER DESCRIPTION
left

left side of the comparison

TYPE: Hyperparameter

right

right side of the comparison

TYPE: Hyperparameter

RAISES DESCRIPTION
TypeError

If left or right are not instances of Hyperparameter

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
def __init__(self, left: Hyperparameter, right: Hyperparameter):
    """Initialize a ForbiddenRelation.

    Args:
        left: left side of the comparison
        right: right side of the comparison

    Raises:
        TypeError: If `left` or `right` are not instances of `Hyperparameter`

    !!! 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.
    """
    if not isinstance(left, Hyperparameter):
        raise TypeError(f"Argument 'left' is not of type {Hyperparameter}.")
    if not isinstance(right, Hyperparameter):
        raise TypeError(f"Argument 'right' is not of type {Hyperparameter}.")

    self.left = left
    self.right = right
    self.vector_ids: tuple[None, None] | tuple[np.intp, np.intp] = (None, None)

left instance-attribute #

Left side of the comparison.

right instance-attribute #

Right side of the comparison.

vector_ids instance-attribute #

vector_ids: tuple[None, None] | tuple[intp, intp]

Indices of the hyperparameters in the vector representation.

set_vector_idx #

set_vector_idx(
    hyperparameter_to_idx: Mapping[str, int]
) -> None

Set the vector index of the hyperparameters.

Source code in src/ConfigSpace/forbidden.py
def set_vector_idx(self, hyperparameter_to_idx: Mapping[str, int]) -> None:
    """Set the vector index of the hyperparameters."""
    self.vector_ids = (
        np.intp(hyperparameter_to_idx[self.left.name]),
        np.intp(hyperparameter_to_idx[self.right.name]),
    )

to_dict #

to_dict() -> dict[str, Any]

Convert the forbidden relation to a dictionary representation.

Source code in src/ConfigSpace/forbidden.py
def to_dict(self) -> dict[str, Any]:
    """Convert the forbidden relation to a dictionary representation."""
    return {
        "left": self.left.name,
        "right": self.right.name,
        "type": "RELATION",
        "lambda": self._RELATION_STR,
    }

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)
Configuration space object:
  Hyperparameters:
    a, Type: Categorical, Choices: {1, 2, 3}, Default: 1
  Forbidden Clauses:
    Forbidden: a in {2, 3}

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: Hyperparameter

values

Collection of forbidden values

TYPE: Iterable[Any]

Source code in src/ConfigSpace/forbidden.py
def __init__(self, hyperparameter: Hyperparameter, values: Iterable[Any]) -> None:
    """Initialize a ForbiddenInClause.

    Args:
        hyperparameter: Hyperparameter on which a restriction will be made
        values: Collection of forbidden values
    """
    values = tuple(values)
    for v in values:
        if not hyperparameter.legal_value(v):
            raise ValueError(
                "Forbidden clause must be instantiated with a "
                f"legal hyperparameter value for '{hyperparameter}', but got "
                f"'{v!s}'",
            )
    super().__init__(hyperparameter)
    self.values = values
    self.vector_values = tuple(hyperparameter.to_vector(v) for v in values)

hyperparameter instance-attribute #

hyperparameter: Hyperparameter

Hyperparameter on which a restriction will be made.

values instance-attribute #

values: tuple[Any, ...] = values

Collection of forbidden values.

vector_id instance-attribute #

vector_id: intp | None = None

Index of the hyperparameter in the vector representation.

set_vector_idx #

set_vector_idx(
    hyperparameter_to_idx: Mapping[str, Any]
) -> None

Set the vector index of the hyperparameter.

Source code in src/ConfigSpace/forbidden.py
def set_vector_idx(self, hyperparameter_to_idx: Mapping[str, Any]) -> None:
    """Set the vector index of the hyperparameter."""
    self.vector_id = np.intp(hyperparameter_to_idx[self.hyperparameter.name])

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)
Configuration space object:
  Hyperparameters:
    a, Type: Categorical, Choices: {10, 2, 3}, Default: 10
    b, Type: Categorical, Choices: {2, 5, 6}, Default: 2
  Forbidden Clauses:
    Forbidden: a < b

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: Hyperparameter

right

right side of the comparison

TYPE: Hyperparameter

PARAMETER DESCRIPTION
left

left side of the comparison

TYPE: Hyperparameter

right

right side of the comparison

TYPE: Hyperparameter

RAISES DESCRIPTION
TypeError

If left or right are not instances of Hyperparameter

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
def __init__(self, left: Hyperparameter, right: Hyperparameter):
    """Initialize a ForbiddenRelation.

    Args:
        left: left side of the comparison
        right: right side of the comparison

    Raises:
        TypeError: If `left` or `right` are not instances of `Hyperparameter`

    !!! 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.
    """
    if not isinstance(left, Hyperparameter):
        raise TypeError(f"Argument 'left' is not of type {Hyperparameter}.")
    if not isinstance(right, Hyperparameter):
        raise TypeError(f"Argument 'right' is not of type {Hyperparameter}.")

    self.left = left
    self.right = right
    self.vector_ids: tuple[None, None] | tuple[np.intp, np.intp] = (None, None)

left instance-attribute #

Left side of the comparison.

right instance-attribute #

Right side of the comparison.

vector_ids instance-attribute #

vector_ids: tuple[None, None] | tuple[intp, intp]

Indices of the hyperparameters in the vector representation.

set_vector_idx #

set_vector_idx(
    hyperparameter_to_idx: Mapping[str, int]
) -> None

Set the vector index of the hyperparameters.

Source code in src/ConfigSpace/forbidden.py
def set_vector_idx(self, hyperparameter_to_idx: Mapping[str, int]) -> None:
    """Set the vector index of the hyperparameters."""
    self.vector_ids = (
        np.intp(hyperparameter_to_idx[self.left.name]),
        np.intp(hyperparameter_to_idx[self.right.name]),
    )

to_dict #

to_dict() -> dict[str, Any]

Convert the forbidden relation to a dictionary representation.

Source code in src/ConfigSpace/forbidden.py
def to_dict(self) -> dict[str, Any]:
    """Convert the forbidden relation to a dictionary representation."""
    return {
        "left": self.left.name,
        "right": self.right.name,
        "type": "RELATION",
        "lambda": self._RELATION_STR,
    }

ForbiddenRelation #

ForbiddenRelation(
    left: Hyperparameter, right: Hyperparameter
)

Bases: ABC

Base class for forbidden relations between hyperparameters.

PARAMETER DESCRIPTION
left

left side of the comparison

TYPE: Hyperparameter

right

right side of the comparison

TYPE: Hyperparameter

RAISES DESCRIPTION
TypeError

If left or right are not instances of Hyperparameter

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
def __init__(self, left: Hyperparameter, right: Hyperparameter):
    """Initialize a ForbiddenRelation.

    Args:
        left: left side of the comparison
        right: right side of the comparison

    Raises:
        TypeError: If `left` or `right` are not instances of `Hyperparameter`

    !!! 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.
    """
    if not isinstance(left, Hyperparameter):
        raise TypeError(f"Argument 'left' is not of type {Hyperparameter}.")
    if not isinstance(right, Hyperparameter):
        raise TypeError(f"Argument 'right' is not of type {Hyperparameter}.")

    self.left = left
    self.right = right
    self.vector_ids: tuple[None, None] | tuple[np.intp, np.intp] = (None, None)

left instance-attribute #

Left side of the comparison.

right instance-attribute #

Right side of the comparison.

vector_ids instance-attribute #

vector_ids: tuple[None, None] | tuple[intp, intp] = (
    None,
    None,
)

Indices of the hyperparameters in the vector representation.

is_forbidden_value abstractmethod #

is_forbidden_value(values: dict[str, Any]) -> bool

Check if a value is forbidden.

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def is_forbidden_value(self, values: dict[str, Any]) -> bool:
    """Check if a value is forbidden."""

is_forbidden_vector abstractmethod #

is_forbidden_vector(vector: Array[f64]) -> bool

Check if a vector is forbidden.

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def is_forbidden_vector(self, vector: Array[f64]) -> bool:
    """Check if a vector is forbidden."""

is_forbidden_vector_array abstractmethod #

is_forbidden_vector_array(arr: Array[f64]) -> Mask

Check if an array of vectors is forbidden.

Source code in src/ConfigSpace/forbidden.py
@abstractmethod
def is_forbidden_vector_array(self, arr: Array[f64]) -> Mask:
    """Check if an array of vectors is forbidden."""

set_vector_idx #

set_vector_idx(
    hyperparameter_to_idx: Mapping[str, int]
) -> None

Set the vector index of the hyperparameters.

Source code in src/ConfigSpace/forbidden.py
def set_vector_idx(self, hyperparameter_to_idx: Mapping[str, int]) -> None:
    """Set the vector index of the hyperparameters."""
    self.vector_ids = (
        np.intp(hyperparameter_to_idx[self.left.name]),
        np.intp(hyperparameter_to_idx[self.right.name]),
    )

to_dict #

to_dict() -> dict[str, Any]

Convert the forbidden relation to a dictionary representation.

Source code in src/ConfigSpace/forbidden.py
def to_dict(self) -> dict[str, Any]:
    """Convert the forbidden relation to a dictionary representation."""
    return {
        "left": self.left.name,
        "right": self.right.name,
        "type": "RELATION",
        "lambda": self._RELATION_STR,
    }