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.

Returns:

List of available sampling modes.

Return type:

list[str]

property variables

List of variables of the domain.

Returns:

List of variables of the domain.

Return type:

list[str]

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 or lh; chebyshev sampling, chebyshev; grid sampling grid.

  • variables (list[str]) – variables to be sampled. Default is all.

Returns:

Sampled points.

Return type:

LabelTensor

Note

When multiple variables are involved, the total number of sampled points may differ from n, depending on the chosen mode. If mode is grid or chebyshev, points are sampled independently for each variable and then combined, resulting in a total number of points equal to n raised to the power of the number of variables. If ‘mode’ is ‘random’, lh or latin, all variables are sampled together, and the total number of points remains n.

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 is False.

Returns:

True if the point is inside the domain, False otherwise.

Return type:

bool