CartesianDomain#

Module for the Cartesian Domain.

class CartesianDomain(cartesian_dict)[source]

Bases: BaseDomain

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

Raises:
  • ValueError – If point is not a LabelTensor.

  • ValueError – If the labels of point differ from the variables of the domain.

Returns:

Whether the point is inside the domain or not.

Return type:

bool

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: random for random sampling; latin or lh for latin hypercube sampling; chebyshev for chebyshev sampling; grid for grid sampling. Default is random.

  • variables (list[str] | str) – The list of variables to sample. If all, all variables are sampled. Default is all.

Raises:
  • AssertionError – If n is not a positive integer.

  • ValueError – If the sampling mode is invalid.

  • ValueError – If variables is neither all, a string, nor a list/tuple of strings.

  • ValueError – If any of the specified variables is unknown.

Returns:

The sampled points.

Return type:

LabelTensor

Note

When multiple variables are involved, the total number of sampled points may differ 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:
>>> 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]])
partial()[source]

Return the boundary of the domain as a Union object.

Returns:

The boundary of the domain.

Return type:

Union