SimplexDomain#
Module for the Simplex Domain.
- class SimplexDomain(simplex_matrix, sample_surface=False)[source]
Bases:
BaseDomainImplementation 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
SimplexDomainclass.- 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 isFalse.
- Raises:
ValueError – If any element of
simplex_matrixis not aLabelTensor.TypeError – If
simplex_matrixis not a list or tuple.ValueError – If
sample_surfaceis 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 isFalse.
- Raises:
ValueError – If
pointis not aLabelTensor.ValueError – If the labels of
pointdiffer from the variables of the domain.
- Returns:
Whether the point is inside the domain or not.
- Return type:
- 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
SimplexDomainobject.- Returns:
A new domain instance with the merged labels.
- Return type:
SimplexDomain
- sample(n, mode='random', variables='all')[source]
Sampling routine.
- Parameters:
- Raises:
AssertionError – If
nis not a positive integer.ValueError – If the sampling mode is invalid.
ValueError – If
variablesis neitherall, a string, nor a list/tuple of strings.ValueError – If any of the specified variables is unknown.
- Returns:
The sampled points.
- Return type:
- 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.
- 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:
- property range
Return an empty dictionary since the simplex domain does not have range variables. Implemented to comply with the
BaseDomaininterface.- Returns:
The range variables of the domain.
- Return type:
- property fixed
Return an empty dictionary since the simplex domain does not have fixed variables. Implemented to comply with the
BaseDomaininterface.- Returns:
The fixed variables of the domain.
- Return type:
- property sample_surface
Whether only the surface of the simplex is considered part of the domain.
- Returns:
Trueif only the surface is considered part of the domain,Falseotherwise.- Return type:
- property vert_matrix
The vertex matrix of the simplex.
- Returns:
The vertex matrix.
- Return type: