Difference#
Module for Difference class.
- class Difference(geometries)[source]#
Bases:
OperationInterface
PINA implementation of Difference of Domains. Given two sets \(A\) and \(B\) then the domain difference is defined as:
\[A - B = \{x \mid x \in A \land x \not\in B\},\]with \(x\) a point in \(\mathbb{R}^N\) and \(N\) the dimension of the geometry space.
- Parameters:
geometries (list) – A list of geometries from
pina.geometry
such asEllipsoidDomain
orCartesianDomain
. The first geometry in the list is the geometry from which points are sampled. The rest of the geometries are the geometries that are excluded from the first geometry to find the difference.- Example:
>>> # Create two ellipsoid domains >>> ellipsoid1 = EllipsoidDomain({'x': [-1, 1], 'y': [-1, 1]}) >>> ellipsoid2 = EllipsoidDomain({'x': [0, 2], 'y': [0, 2]}) >>> # Create a Difference of the ellipsoid domains >>> difference = Difference([ellipsoid1, ellipsoid2])
- is_inside(point, check_border=False)[source]#
Check if a point is inside the
Difference
domain.- Parameters:
point (torch.Tensor) – Point to be checked.
check_border (bool) – If
True
, the border is considered inside.
- Returns:
True
if the point is inside the Exclusion domain,False
otherwise.- Return type:
- sample(n, mode='random', variables='all')[source]#
Sample routine for
Difference
domain.- Parameters:
- Returns:
Returns
LabelTensor
of n sampled points.- Return type:
- Example:
>>> # Create two Cartesian domains >>> cartesian1 = CartesianDomain({'x': [0, 2], 'y': [0, 2]}) >>> cartesian2 = CartesianDomain({'x': [1, 3], 'y': [1, 3]}) >>> # Create a Difference of the ellipsoid domains >>> difference = Difference([cartesian1, cartesian2]) >>> # Sampling >>> difference.sample(n=5) LabelTensor([[0.8400, 0.9179], [0.9154, 0.5769], [1.7403, 0.4835], [0.9545, 1.2851], [1.3726, 0.9831]]) >>> len(difference.sample(n=5) 5