diff --git a/src/random_events/__init__.py b/src/random_events/__init__.py index 7f5601d..726691b 100644 --- a/src/random_events/__init__.py +++ b/src/random_events/__init__.py @@ -1 +1 @@ -__version__ = '3.1.0' +__version__ = '3.1.1' diff --git a/src/random_events/product_algebra.py b/src/random_events/product_algebra.py index 497781e..df441e1 100644 --- a/src/random_events/product_algebra.py +++ b/src/random_events/product_algebra.py @@ -429,6 +429,23 @@ def marginal(self, variables: VariableSet) -> Event: result.add_simple_set(simple_set.marginal(variables)) return result.make_disjoint() + def bounding_box(self) -> SimpleEvent: + """ + Compute the bounding box of the event. + The bounding box is the smallest simple event that contains this event. It is computed by taking the union + of all simple events variable wise. + + :return: The bounding box as a simple event + """ + result = SimpleEvent() + for variable in self.all_variables: + for simple_set in self.simple_sets: + if variable not in result: + result[variable] = simple_set[variable] + else: + result[variable] = result[variable].union_with(simple_set[variable]) + return result + def plot(self, color="#636EFA") -> Union[List[go.Scatter], List[go.Mesh3d]]: """ Plot the complex event. diff --git a/test/test_product_algebra.py b/test/test_product_algebra.py index 4a0e97a..bf66efb 100644 --- a/test/test_product_algebra.py +++ b/test/test_product_algebra.py @@ -115,6 +115,15 @@ def test_to_json_multiple_events(self): event_ = AbstractSimpleSet.from_json(event.to_json()) self.assertEqual(event_, event) + def test_bounding_box(self): + event_1 = SimpleEvent({self.x: closed(0, 1), self.y: SimpleInterval(0, 1)}).as_composite_set() + event_2 = SimpleEvent({self.x: closed(1, 2), self.y: Interval(SimpleInterval(3, 4))}).as_composite_set() + event = event_1 | event_2 + bounding_box = event.bounding_box() + result = SimpleEvent({self.x: closed(0, 2), + self.y: SimpleInterval(0, 1).as_composite_set() | SimpleInterval(3, 4).as_composite_set()}) + self.assertEqual(bounding_box, result) + class NoneTypeObjectInDifferenceTestCase(unittest.TestCase): x: Continuous = Continuous("x")