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. IfFalse
, samples are taken from the interior of the simplex. Default isFalse
.
- 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.
- property variables
List of variables of the domain.
- 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 isFalse
.
- 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:
- sample(n, mode='random', variables='all')[source]
Sampling routine.
- Parameters:
- Raises:
NotImplementedError – If the sampling method is not implemented.
- Returns:
Sampled points.
- Return type:
Warning
When
sample_surface=True
, all variables are sampled, ignoring thevariables
parameter.