CartesianDomain#
Module for the Cartesian Domain.
- class CartesianDomain(cartesian_dict)[source]
Bases:
BaseDomainImplementation of the hypercube domain, obtained as the cartesian product of one-dimensional intervals.
- Example:
>>> cartesian_domain = CartesianDomain({'x': [0, 1], 'y': [0, 1]}) >>> cartesian_domain = CartesianDomain({'x': [0, 1], 'y': 1.0})
Initialization of the
CartesianDomainclass.- Parameters:
cartesian_dict (dict) – A dictionary where the keys are the variable names and the values are the domain extrema. The domain extrema can be either a list or tuple with two elements or a single number. If the domain extrema is a single number, the variable is fixed to that value.
- Raises:
TypeError – If the cartesian dictionary is not a dictionary.
ValueError – If the cartesian dictionary contains variables with invalid ranges.
ValueError – If the cartesian dictionary contains values that are neither numbers nor lists/tuples of numbers of length 2.
- is_inside(point, check_border=False)[source]
Check if a point is inside the domain.
- Parameters:
point (LabelTensor) – The point to check.
check_border (bool) – If
True, the boundary is considered inside the domain. Default isFalse.
- Raises:
ValueError – If
pointis not aLabelTensor.ValueError – If the labels of
pointdiffer from the variables of the domain.
- Returns:
Whether the point is inside the domain or not.
- Return type:
- sample(n, mode='random', variables='all')[source]
The sampling routine.
- Parameters:
n (int) – The number of samples to generate. See Note for reference.
mode (str) – The sampling method. Available modes:
randomfor random sampling;latinorlhfor latin hypercube sampling;chebyshevfor chebyshev sampling;gridfor grid sampling. Default israndom.variables (list[str] | str) – The list of variables to sample. If
all, all variables are sampled. Default isall.
- Raises:
AssertionError – If
nis not a positive integer.ValueError – If the sampling mode is invalid.
ValueError – If
variablesis neitherall, a string, nor a list/tuple of strings.ValueError – If any of the specified variables is unknown.
- Returns:
The sampled points.
- Return type:
Note
When multiple variables are involved, the total number of sampled points may differ depending on the chosen
mode. Ifmodeisgridorchebyshev, points are sampled independently for each variable and then combined, resulting in a total number of points equal tonraised to the power of the number of variables. Ifmodeisrandom,lhorlatin, all variables are sampled together, and the total number of points remainsn.Warning
The extrema of CartesianDomain are only sampled when using the
gridmode.- Example:
>>> cartesian_domain = CartesianDomain({'x': [0, 1], 'y': [0, 1]}) >>> cartesian_domain.sample(n=3, mode='random') LabelTensor([[0.0108, 0.7643], [0.4477, 0.8015], [0.8735, 0.6349]]) >>> cartesian_domain.sample(n=3, mode='grid') LabelTensor([[0.0000, 0.0000], [0.5000, 0.0000], [1.0000, 0.0000], [0.0000, 0.5000], [0.5000, 0.5000], [1.0000, 0.5000], [0.0000, 1.0000], [0.5000, 1.0000], [1.0000, 1.0000]])