Skip to content

discrete

Discrete(feature_name, values)

Bases: Domain, Iterable[tuple[str, float]]

A domain of discrete values.

This domain describes a discrete set of values for a feature.

Initialize the discrete domain.

Parameters:

Name Type Description Default
feature_name str

The name of the feature the domain belongs to.

required
values list[float]

The list of values of the domain.

required
Source code in src/flowcean/core/tool/testing/domain/discrete.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def __init__(
    self,
    feature_name: str,
    values: list[float],
) -> None:
    """Initialize the discrete domain.

    Args:
        feature_name: The name of the feature the domain belongs to.
        values: The list of values of the domain.
    """
    super().__init__(feature_name)
    self.values = values

    self.rng = random.Random()

__len__()

Get the number of discrete values in the domain.

Returns:

Type Description
int

The number of discrete values in the domain.

Source code in src/flowcean/core/tool/testing/domain/discrete.py
31
32
33
34
35
36
37
def __len__(self) -> int:
    """Get the number of discrete values in the domain.

    Returns:
        The number of discrete values in the domain.
    """
    return len(self.values)

get_value()

Get a random value from the domain.

Source code in src/flowcean/core/tool/testing/domain/discrete.py
39
40
41
def get_value(self) -> float:
    """Get a random value from the domain."""
    return self.rng.choice(self.values)

__iter__()

Iterate over the values of the range.

Source code in src/flowcean/core/tool/testing/domain/discrete.py
46
47
48
49
def __iter__(self) -> Iterator[tuple[str, float]]:
    """Iterate over the values of the range."""
    for value in self.values:
        yield (self.feature_name, value)