SimplexDomain#

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

Bases: Location

PINA implementation of a Simplex.

Parameters:
  • simplex_matrix (list[LabelTensor]) – A matrix of LabelTensor objects representing a vertex of the simplex (a tensor), and the coordinates of the point (a list of labels).

  • sample_surface (bool) – A variable for choosing sample strategies. If sample_surface=True only samples on the Simplex surface frontier are taken. If sample_surface=False, no such criteria is followed.

Warning

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

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
    )
is_inside(point, check_border=False)[source]

Check if a point is inside the simplex. Uses the algorithm described involving barycentric coordinates: https://en.wikipedia.org/wiki/Barycentric_coordinate_system.

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

  • check_border (bool) – Check if the point is also on the frontier of the simplex, default False.

Returns:

Returning True if the point is inside, False otherwise.

Return type:

bool

Note

When sample_surface in the __init()__ is set to True, then the method only checks points on the surface, and not inside the domain.

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

Sample n points from Simplex domain.

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

  • mode (str) – Mode for sampling, defaults to random. Available modes include: random.

  • variables (str | list[str]) – Variables to be sampled, defaults to all.

Returns:

Returns LabelTensor of n sampled points.

Return type:

LabelTensor

Warning

When sample_surface = True in the initialization, all the variables are sampled, despite passing different once in variables.