CartesianDomain#
Module for the Cartesian Domain.
- class CartesianDomain(cartesian_dict)[source]
Bases:
DomainInterface
Implementation of the hypercube domain.
Initialization of the
CartesianDomain
class.- 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 with two elements or a single number. If the domain extrema is a single number, the variable is fixed to that value.
- Example:
>>> spatial_domain = CartesianDomain({'x': [0, 1], 'y': [0, 1]})
- property sample_modes
List of available sampling modes.
- property variables
List of variables of the domain.
- update(new_domain)[source]
Add new dimensions to an existing
CartesianDomain
object.- Parameters:
new_domain (CartesianDomain) – New domain to be added to an existing
CartesianDomain
object.- Example:
>>> spatial_domain = CartesianDomain({'x': [0, 1], 'y': [0, 1]}) >>> spatial_domain.variables ['x', 'y'] >>> spatial_domain_2 = CartesianDomain({'z': [3, 4], 'w': [0, 1]}) >>> spatial_domain.update(spatial_domain_2) >>> spatial_domain.variables ['x', 'y', 'z', 'w']
- sample(n, mode='random', variables='all')[source]
Sampling routine.
- Parameters:
n (int) – Number of points to sample, see Note below for reference.
mode (str) – Sampling method. Default is
random
. Available modes: random sampling,random
; latin hypercube sampling,latin
orlh
; chebyshev sampling,chebyshev
; grid samplinggrid
.variables (list[str]) – variables to be sampled. Default is
all
.
- Returns:
Sampled points.
- Return type:
Note
When multiple variables are involved, the total number of sampled points may differ from
n
, depending on the chosenmode
. Ifmode
isgrid
orchebyshev
, points are sampled independently for each variable and then combined, resulting in a total number of points equal ton
raised to the power of the number of variables. If ‘mode’ is ‘random’,lh
orlatin
, all variables are sampled together, and the total number of points remainsn
.Warning
The extrema of CartesianDomain are only sampled when using the
grid
mode.- Example:
>>> spatial_domain = CartesianDomain({'x': [0, 1], 'y': [0, 1]}) >>> spatial_domain.sample(n=4, mode='random') tensor([[0.0108, 0.7643], [0.4477, 0.8015], [0.2063, 0.8087], [0.8735, 0.6349]]) >>> spatial_domain.sample(n=4, mode='grid') tensor([[0.0000, 0.0000], [0.3333, 0.0000], [0.6667, 0.0000], [1.0000, 0.0000], [0.0000, 0.3333], [0.3333, 0.3333], [0.6667, 0.3333], [1.0000, 0.3333], [0.0000, 0.6667], [0.3333, 0.6667], [0.6667, 0.6667], [1.0000, 0.6667], [0.0000, 1.0000], [0.3333, 1.0000], [0.6667, 1.0000], [1.0000, 1.0000]])
- is_inside(point, check_border=False)[source]
Check if a point is inside the hypercube.
- Parameters:
point (LabelTensor) – Point to be checked.
check_border (bool) – If
True
, the border is considered inside the hypercube. Default isFalse
.
- Returns:
True
if the point is inside the domain,False
otherwise.- Return type: