Interval Pattern#
- class paspailleur.bip.IntervalPattern(value: PatternValueType)#
A class representing an interval as a pattern.
This class allows for the creation and manipulation of patterns that represent intervals, including operations such as intersection, union, and difference.
Attributes#
- PatternValueType:
The type of the pattern’s value, which is a tuple of bounds.
- BoundsUniverse: list[float]
A list representing the universe of bounds for the interval.
Properties#
- lower_bound
Return the lower bound of the interval.
- is_lower_bound_closed
Check if the lower bound is closed.
- upper_bound
Return the upper bound of the interval.
- is_upper_bound_closed
Check if the upper bound is closed.
- atomic_patterns
Return the set of all less precise patterns that cannot be obtained by intersection of other patterns.
- min_pattern
Return the minimal possible pattern for the interval pattern.
- max_pattern
Return the maximal possible pattern for the interval pattern.
- maximal_atoms
Return the maximal atomic patterns for the interval pattern.
Notes
The IntervalPattern can be defined by a string representation of the interval, or by an pair of two numbers, or by just one number.
Examples
>>> p1 = IntervalPattern( ((5, True), (10, False)) ) # The explicit way to define half-open interval [5, 10) >>> p2 = IntervalPattern( "[5, 10)" ) # A more readable way to define interval [5, 10) >>> print(p1 == p2) True
>>> p3 = IntervalPattern( ((1, True), (1, True)) ) # The explicit way to define closed interval [1, 1] >>> p4 = IntervalPattern( "[1, 1]" ) >>> p5 = IntervalPattern( [1, 1] ) >>> p6 = IntervalPattern( 1 ) >>> print(p3 == p4, p3 == p5, p3 == p6) True, True, True
>>> p7 = IntervalPattern( "[1, ∞]" ) >>> p8 = IntervalPattern( ">=1" ) >>> print(p7 == p8) True
- PatternValueType#
alias of
tuple
[tuple
[float
,bool
],tuple
[float
,bool
]]
- property lower_bound: float#
Return the lower bound of the interval.
- Returns:
bound – The lower bound of the interval.
- Return type:
float
Examples
>>> IntervalPattern( "[1, 5)" ).lower_bound 1.0
- property is_lower_bound_closed: bool#
Check if the lower bound is closed.
- Returns:
closed – True if the lower bound is closed, False otherwise.
- Return type:
bool
Examples
>>> IntervalPattern( "[1, 5)" ).is_lower_bound_closed True
- property upper_bound: float#
Return the upper bound of the interval.
- Returns:
bound – The upper bound of the interval.
- Return type:
float
Examples
>>> IIntervalPattern( "[1, 5)" ).upper_bound 5.0
- property is_upper_bound_closed: bool#
Check if the upper bound is closed.
- Returns:
closed – True if the upper bound is closed, False otherwise.
- Return type:
bool
Examples
>>> IntervalPattern( "[1, 5)" ).is_upper_bound_closed False
- classmethod parse_string_description(value: str) tuple[tuple[float, bool], tuple[float, bool]] #
Parse a string description into an interval pattern value.
- Parameters:
value (str) – The string description of the interval pattern.
- Returns:
parsed – The parsed interval pattern value.
- Return type:
PatternValueType
Examples
>>> IntervalPattern.parse_string_description('[1, 5)') ((1.0, True), (5.0, False))
- classmethod preprocess_value(value) tuple[tuple[float, bool], tuple[float, bool]] #
Preprocess the value before storing it in the interval pattern.
- Parameters:
value – The value to preprocess.
- Returns:
value – The preprocessed value as a tuple of bounds.
- Return type:
PatternValueType
Examples
>>> IntervalPattern.preprocess_value((1, 5)) ((1.0, True), (5.0, True))
- atomise(atoms_configuration: Literal['min', 'max'] = 'min') set[Self] #
Split the pattern into atomic patterns, i.e. the set of one-sided intervals
- Parameters:
atoms_configuration (Literal['min', 'max']) – If equals to ‘min’, return up to 2 atomic patterns each representing a bound of the original interval. If equals to ‘max’, return _all_ less precise one-sided intervals, where the bounds are defined by BoundUniverse class attribute.
- Returns:
atomic_patterns – The set of atomic patterns, i.e. the set of unsplittable patterns whose join equals to the pattern.
- Return type:
set[Self]
Notes
Speaking in terms of Ordered Set Theory: We say that every pattern can be represented as the join of a subset of atomic patterns, that are join-irreducible elements of the lattice of all patterns.
Considering the set of atomic patterns as a partially ordered set (where the order follows the order on patterns), every pattern can be represented by an _antichain_ of atomic patterns (when atoms_configuration = ‘min’), and by an order ideal of atomic patterns (when atoms_configuration = ‘max’).
- property atomic_patterns: set[Self]#
Return the set of all less precise patterns that cannot be obtained by intersection of other patterns.
For an IntervalPattern an atomic pattern is a half-bounded interval.
- Returns:
atoms – A set of atomic patterns derived from the interval.
- Return type:
set[Self]
Examples
>>> IntervalPattern( "[1, 5]" )atomic_patterns {IntervalPattern("[-∞, ∞]"), IntervalPattern(">=1"), IntervalPattern("<=5") }
- property atomisable: bool#
Check if the pattern can be atomized. IntervalPattern can only be atomised when BoundsUniverse is defined
- Returns:
flag – True if the pattern can be atomized, False otherwise.
- Return type:
bool
Examples
>>> p = Pattern("example") >>> p.atomisable True
- classmethod get_min_pattern() Self #
Return the minimal possible pattern for the interval pattern, i.e. interval [-inf, +inf]
- Returns:
min – The minimal interval pattern, which is defined as [-inf, inf].
- Return type:
Self
Examples
>>> IntervalPattern.get_min_pattern() IntervalPattern('[-inf, +inf]')
- classmethod get_max_pattern() Self #
Return the maximal possible pattern for the interval pattern, i.e. the empty interval.
Empty interval is the maximal pattern, because it does not cover any other interval. So it describes no objects.
- Returns:
max – The maximal interval pattern, which is represented as ‘ø’.
- Return type:
Self
Examples
>>> IntervalPattern.get_max_pattern() IntervalPattern('ø')
- property maximal_atoms: set[Self] | None#
Return the maximal atomic patterns for the interval pattern.
- Returns:
max_atoms – A set of maximal atomic patterns or None if undefined.
- Return type:
Optional[set[Self]]
Examples
>>> IntervalPattern().maximal_atoms {...}