SimplexDomain#

Module for the Simplex Domain.

class SimplexDomain(simplex_matrix, sample_surface=False)[source]

Bases: DomainInterface

Implementation of the simplex domain.

Initialization of the SimplexDomain class.

Parameters:
  • simplex_matrix (list[LabelTensor]) – A matrix representing the vertices of the simplex.

  • sample_surface (bool) – A flag to choose the sampling strategy. If True, samples are taken only from the surface of the simplex. If False, samples are taken from the interior of the simplex. Default is False.

Raises:
  • ValueError – If the labels of the vertices don’t match.

  • ValueError – If the number of vertices is not equal to the dimension of the simplex plus one.

Warning

Sampling for dimensions greater or equal to 10 could result in a shrinkage of the simplex, which degrades the quality of the samples. For dimensions higher than 10, use other sampling algorithms.

Example:
>>> spatial_domain = SimplexDomain(
        [
            LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
            LabelTensor(torch.tensor([[1, 1]]), labels=["x", "y"]),
            LabelTensor(torch.tensor([[0, 2]]), labels=["x", "y"]),
        ], sample_surface = True
    )
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]

is_inside(point, check_border=False)[source]

Check if a point is inside the simplex. It uses an algorithm involving barycentric coordinates.

Parameters:
  • point (LabelTensor) – Point to be checked.

  • check_border – If True, the border is considered inside the simplex. Default is False.

Raises:

ValueError – If the labels of the point are different from those passed in the __init__ method.

Returns:

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

Return type:

bool

sample(n, mode='random', variables='all')[source]

Sampling routine.

Parameters:
  • n (int) – Number of points to sample.

  • mode (str) – Sampling method. Default is random. Available modes: random sampling, random.

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

Raises:

NotImplementedError – If the sampling method is not implemented.

Returns:

Sampled points.

Return type:

LabelTensor

Warning

When sample_surface=True, all variables are sampled, ignoring the variables parameter.