Difference#

Module for the Difference Operation.

class Difference(geometries)[source]#

Bases: OperationInterface

Implementation of the difference operation between of a list of domains.

Given two sets \(A\) and \(B\), define the difference of the two sets as:

\[A - B = \{x \mid x \in A \land x \not\in B\},\]

where \(x\) is a point in \(\mathbb{R}^N\).

Initialization of the Difference class.

Parameters:

geometries (list[DomainInterface]) – A list of instances of the DomainInterface class on which the difference operation is performed. The first domain in the list serves as the base from which points are sampled, while the remaining domains define the regions to be excluded from the base domain to compute the difference.

Example:
>>> # Create two ellipsoid domains
>>> ellipsoid1 = EllipsoidDomain({'x': [-1, 1], 'y': [-1, 1]})
>>> ellipsoid2 = EllipsoidDomain({'x': [0, 2], 'y': [0, 2]})
>>> # Define the difference between the domains
>>> difference = Difference([ellipsoid1, ellipsoid2])
is_inside(point, check_border=False)[source]#

Check if a point is inside the resulting domain.

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

  • check_border (bool) – If True, the border is considered inside the domain. Default is False.

Returns:

True if the point is inside the domain, False otherwise.

Return type:

bool

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

Sampling routine.

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

  • mode (str) – Sampling method. Default is random. Available modes: random sampling, random;

  • variables (list[str]) – variables to be sampled. Default is all.

Raises:

NotImplementedError – If the sampling method is not implemented.

Returns:

Sampled points.

Return type:

LabelTensor

Example:
>>> # Create two Cartesian domains
>>> cartesian1 = CartesianDomain({'x': [0, 2], 'y': [0, 2]})
>>> cartesian2 = CartesianDomain({'x': [1, 3], 'y': [1, 3]})
>>> # Define the difference between the 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