SimplexDomain#

Module for the Simplex Domain.

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

Bases: BaseDomain

Implementation of the simplex domain.

Example:
>>> simplex_domain = SimplexDomain(
        [
            LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
            LabelTensor(torch.tensor([[1, 1]]), labels=["x", "y"]),
            LabelTensor(torch.tensor([[0, 1]]), labels=["x", "y"]),
        ]
    )

Initialization of the SimplexDomain class.

Parameters:
  • simplex_matrix (list[LabelTensor] | tuple[LabelTensor]) – The matrix of the simplex vertices.

  • sample_surface (bool) – If True, only the surface of the simplex is considered part of the domain. Default is False.

Raises:
  • ValueError – If any element of simplex_matrix is not a LabelTensor.

  • TypeError – If simplex_matrix is not a list or tuple.

  • ValueError – If sample_surface is not a boolean.

  • ValueError – If the labels of the vertices do not match.

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

is_inside(point, check_border=False)[source]

Check if a point is inside the simplex.

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

update(domain)[source]

Update the current domain by substituting the simplex vertices with those contained in domain. Only domains of the same type can be used for update.

Parameters:

domain (SimplexDomain) – The domain whose vertices are to be set into the current one.

Raises:

TypeError – If the domain is not a SimplexDomain object.

Returns:

A new domain instance with the merged labels.

Return type:

SimplexDomain

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

Sampling routine.

Parameters:
  • n (int) – The number of samples to generate.

  • mode (str) – The sampling method. Available modes: random for random 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

Example:
>>> simplex_domain = SimplexDomain(
        [
            LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
            LabelTensor(torch.tensor([[1, 1]]), labels=["x", "y"]),
            LabelTensor(torch.tensor([[0, 1]]), labels=["x", "y"]),
        ]
    )
>>> simplex_domain.sample(n=5)
    LabelTensor([[0.0125, 0.0439],
                 [0.1346, 0.1950],
                 [0.8811, 0.9939],
                 [0.2722, 0.5535],
                 [0.4750, 0.7433]])
partial()[source]

Return the boundary of the domain as a new domain object.

Returns:

The boundary of the domain.

Return type:

SimplexDomain

property variables

The list of variables of the domain.

Returns:

The list of variables of the domain.

Return type:

list[str]

property domain_dict

The dictionary representing the domain. For the simplex domain, the keys are of the form ‘v0’, ‘v1’, …, ‘vn’, where each key corresponds to a vertex of the simplex.

Returns:

The dictionary representing the domain.

Return type:

dict

property range

Return an empty dictionary since the simplex domain does not have range variables. Implemented to comply with the BaseDomain interface.

Returns:

The range variables of the domain.

Return type:

dict

property fixed

Return an empty dictionary since the simplex domain does not have fixed variables. Implemented to comply with the BaseDomain interface.

Returns:

The fixed variables of the domain.

Return type:

dict

property sample_surface

Whether only the surface of the simplex is considered part of the domain.

Returns:

True if only the surface is considered part of the domain, False otherwise.

Return type:

bool

property vert_matrix

The vertex matrix of the simplex.

Returns:

The vertex matrix.

Return type:

LabelTensor