From 747f3c4c41100cd663b79428cb5c6db189597e73 Mon Sep 17 00:00:00 2001 From: Tom Schierenbeck Date: Thu, 28 Mar 2024 12:50:41 +0100 Subject: [PATCH] Fixed bug in simplify method --- examples/door.ipynb | 53 +++++----- examples/example.ipynb | 96 +++++++++--------- examples/logo_generation.ipynb | 106 ++++++++++---------- examples/product_spaces.ipynb | 174 ++++++++++++++++----------------- src/random_events/__init__.py | 2 +- src/random_events/events.py | 64 +++++++----- test/test_events.py | 14 ++- test/test_variables.py | 1 - 8 files changed, 265 insertions(+), 245 deletions(-) diff --git a/examples/door.ipynb b/examples/door.ipynb index bfd8ff1..f988504 100644 --- a/examples/door.ipynb +++ b/examples/door.ipynb @@ -2,23 +2,16 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { - "end_time": "2024-03-26T16:37:47.504496Z", - "start_time": "2024-03-26T16:37:47.308104Z" + "end_time": "2024-03-28T11:49:10.440780Z", + "start_time": "2024-03-28T11:49:10.420290Z" } }, "outputs": [ - { - "data": { - "text/html": " \n " - }, - "metadata": {}, - "output_type": "display_data" - }, { "data": { "application/vnd.plotly.v1+json": { @@ -68,7 +61,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": true, "x": [ @@ -148,7 +141,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": false, "x": [ @@ -228,7 +221,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": false, "x": [ @@ -308,7 +301,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": false, "x": [ @@ -388,7 +381,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": false, "x": [ @@ -468,7 +461,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": false, "x": [ @@ -548,7 +541,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": false, "x": [ @@ -628,7 +621,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": false, "x": [ @@ -708,7 +701,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": false, "x": [ @@ -788,7 +781,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": false, "x": [ @@ -868,7 +861,7 @@ 7, 6 ], - "legendgroup": "139628582763248", + "legendgroup": "140525813576272", "name": "Event", "showlegend": false, "x": [ @@ -948,7 +941,7 @@ 7, 6 ], - "legendgroup": "139628582698864", + "legendgroup": "140526905190288", "name": "Event", "showlegend": true, "x": [ @@ -1028,7 +1021,7 @@ 7, 6 ], - "legendgroup": "139628582698864", + "legendgroup": "140526905190288", "name": "Event", "showlegend": false, "x": [ @@ -1108,7 +1101,7 @@ 7, 6 ], - "legendgroup": "139628582698768", + "legendgroup": "140526501139600", "name": "Event", "showlegend": true, "x": [ @@ -1188,7 +1181,7 @@ 7, 6 ], - "legendgroup": "139628582698768", + "legendgroup": "140526501139600", "name": "Event", "showlegend": false, "x": [ @@ -1268,7 +1261,7 @@ 7, 6 ], - "legendgroup": "139628582698768", + "legendgroup": "140526501139600", "name": "Event", "showlegend": false, "x": [ @@ -1348,7 +1341,7 @@ 7, 6 ], - "legendgroup": "139628582698768", + "legendgroup": "140526501139600", "name": "Event", "showlegend": false, "x": [ @@ -1428,7 +1421,7 @@ 7, 6 ], - "legendgroup": "139628582698768", + "legendgroup": "140526501139600", "name": "Event", "showlegend": false, "x": [ @@ -2295,7 +2288,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -2326,7 +2319,7 @@ "keyhole_outer_ring = keyhole_outer_ring.difference(keyhole)\n", "keyhole_teeth = ComplexEvent([])\n", "\n", - "for event in keyhole_outer_ring:\n", + "for event in keyhole_outer_ring.events:\n", " ...\n", "\n", "\n", diff --git a/examples/example.ipynb b/examples/example.ipynb index e6e7b71..ab06571 100644 --- a/examples/example.ipynb +++ b/examples/example.ipynb @@ -16,13 +16,13 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { - "end_time": "2024-03-26T12:36:19.578198Z", - "start_time": "2024-03-26T12:36:19.539637Z" + "end_time": "2024-03-28T11:49:17.716003Z", + "start_time": "2024-03-28T11:49:17.678852Z" } }, "outputs": [ @@ -55,13 +55,13 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 13, "outputs": [ { "data": { "text/plain": "(Symbolic(symbol), Integer(integer), Continuous(real))" }, - "execution_count": 16, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -73,7 +73,11 @@ "symbol, integer, real" ], "metadata": { - "collapsed": false + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-03-28T11:49:17.720159Z", + "start_time": "2024-03-28T11:49:17.717130Z" + } }, "id": "49b07deb8aecb5d0" }, @@ -89,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 14, "outputs": [ { "name": "stdout", @@ -107,8 +111,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:36:19.624431Z", - "start_time": "2024-03-26T12:36:19.622170Z" + "end_time": "2024-03-28T11:49:17.755498Z", + "start_time": "2024-03-28T11:49:17.753307Z" } }, "id": "a3aed36278dab281" @@ -125,13 +129,13 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 15, "outputs": [ { "data": { "text/plain": "{Symbolic(symbol): ('Rain',), Continuous(real): (-inf,2)}" }, - "execution_count": 18, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -143,8 +147,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:36:19.630312Z", - "start_time": "2024-03-26T12:36:19.625221Z" + "end_time": "2024-03-28T11:49:17.761778Z", + "start_time": "2024-03-28T11:49:17.756709Z" } }, "id": "a81cd22d80129c04" @@ -162,7 +166,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 16, "outputs": [ { "name": "stdout", @@ -180,8 +184,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:36:19.634878Z", - "start_time": "2024-03-26T12:36:19.630986Z" + "end_time": "2024-03-28T11:49:17.768157Z", + "start_time": "2024-03-28T11:49:17.762723Z" } }, "id": "4975045ed9540d52" @@ -198,14 +202,14 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 17, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{Symbolic(symbol): ('Rain',), Continuous(real): (1,2)}\n", - "{Symbolic(symbol): ('Rain',), Continuous(real): (1,2)}\n" + "{real: (1,2), symbol: ('Rain',)}\n", + "{real: (1,2), symbol: ('Rain',)}\n" ] } ], @@ -217,8 +221,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:36:19.640375Z", - "start_time": "2024-03-26T12:36:19.635510Z" + "end_time": "2024-03-28T11:49:17.773573Z", + "start_time": "2024-03-28T11:49:17.768994Z" } }, "id": "b4da0a20e367a1c0" @@ -235,15 +239,15 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{Continuous(real): (-inf,2), Symbolic(symbol): ('Rain',)} u {Continuous(real): (1,4), Symbolic(symbol): ('Apple',)} u {Continuous(real): [2,4), Symbolic(symbol): ('Rain',)}\n", - "{Continuous(real): (1,4), Symbolic(symbol): ('Apple',)} u {Continuous(real): [2,4), Symbolic(symbol): ('Rain',)}\n", - "{Continuous(real): (-inf,+inf), Symbolic(symbol): ('Apple', 'Dog')} u {Continuous(real): [2,+inf), Symbolic(symbol): ('Rain',)}\n" + "{real: (-inf,2), symbol: ('Rain',)} u {real: [2,4), symbol: ('Apple', 'Rain')} u {real: (1,2), symbol: ('Apple',)}\n", + "{real: [2,4), symbol: ('Apple', 'Rain')} u {real: (1,2), symbol: ('Apple',)}\n", + "{real: (-inf,+inf), symbol: ('Apple', 'Dog')} u {real: [2,+inf), symbol: ('Rain',)}\n" ] } ], @@ -255,8 +259,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:36:19.646899Z", - "start_time": "2024-03-26T12:36:19.641439Z" + "end_time": "2024-03-28T11:49:17.779131Z", + "start_time": "2024-03-28T11:49:17.775125Z" } }, "id": "e8bb102d6d36e9a8" @@ -273,14 +277,14 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 19, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{Symbolic(symbol): (2,), Continuous(real): (-inf,2)}\n", - "{Symbolic(symbol): (0, 2), Continuous(real): (1,4)}\n" + "{symbol: (2,), real: (-inf,2)}\n", + "{symbol: (0, 2), real: (1,4)}\n" ] } ], @@ -291,8 +295,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:36:19.652239Z", - "start_time": "2024-03-26T12:36:19.647768Z" + "end_time": "2024-03-28T11:49:17.786224Z", + "start_time": "2024-03-28T11:49:17.780012Z" } }, "id": "1463b40805ebaddd" @@ -1178,7 +1182,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -1194,12 +1198,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:36:19.659964Z", - "start_time": "2024-03-26T12:36:19.652890Z" + "end_time": "2024-03-28T11:49:17.798205Z", + "start_time": "2024-03-28T11:49:17.786860Z" } }, "id": "8c25f3846c860230", - "execution_count": 23 + "execution_count": 20 }, { "cell_type": "markdown", @@ -1220,7 +1224,7 @@ "data": [ { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "140569888183872", "line": { "color": "#636EFA" }, @@ -1259,7 +1263,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "140569888183872", "line": { "color": "#636EFA" }, @@ -2138,7 +2142,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -2154,12 +2158,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:36:19.670541Z", - "start_time": "2024-03-26T12:36:19.660541Z" + "end_time": "2024-03-28T11:49:17.807173Z", + "start_time": "2024-03-28T11:49:17.798871Z" } }, "id": "d22ef1b9c9b7c767", - "execution_count": 24 + "execution_count": 21 }, { "cell_type": "markdown", @@ -2178,7 +2182,7 @@ "data": { "text/plain": "True" }, - "execution_count": 26, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -2191,12 +2195,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:36:29.802735Z", - "start_time": "2024-03-26T12:36:29.799361Z" + "end_time": "2024-03-28T11:49:17.813127Z", + "start_time": "2024-03-28T11:49:17.808962Z" } }, "id": "12b0c378134e8a09", - "execution_count": 26 + "execution_count": 22 } ], "metadata": { diff --git a/examples/logo_generation.ipynb b/examples/logo_generation.ipynb index 4c5d3fe..4a8ed9e 100644 --- a/examples/logo_generation.ipynb +++ b/examples/logo_generation.ipynb @@ -15,13 +15,13 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 6, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { - "end_time": "2024-03-26T12:53:03.558691Z", - "start_time": "2024-03-26T12:53:03.390668Z" + "end_time": "2024-03-28T11:49:24.529348Z", + "start_time": "2024-03-28T11:49:24.491102Z" } }, "outputs": [ @@ -53,14 +53,10 @@ "y = Continuous(\"y\")" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-03-26T12:53:03.562325Z", - "start_time": "2024-03-26T12:53:03.559940Z" - } + "collapsed": false }, "id": "29d0b28a5e6f48ca", - "execution_count": 2 + "execution_count": 7 }, { "cell_type": "markdown", @@ -80,7 +76,7 @@ "text/plain": "", "image/png": "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" }, - "execution_count": 3, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -93,12 +89,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:53:03.620120Z", - "start_time": "2024-03-26T12:53:03.562953Z" + "end_time": "2024-03-28T11:49:24.569031Z", + "start_time": "2024-03-28T11:49:24.565509Z" } }, "id": "6dfb4ca602b7491b", - "execution_count": 3 + "execution_count": 8 }, { "cell_type": "markdown", @@ -119,7 +115,7 @@ "data": [ { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -146,7 +142,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -209,7 +205,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -248,7 +244,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -287,7 +283,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -326,7 +322,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -401,7 +397,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -512,7 +508,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -575,7 +571,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -614,7 +610,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -653,7 +649,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -692,7 +688,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790934077200", "line": { "color": "rgb(0,0,0)" }, @@ -719,7 +715,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930816832", "line": { "color": "rgb(124,176,118)" }, @@ -770,7 +766,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930816832", "line": { "color": "rgb(124,176,118)" }, @@ -821,7 +817,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930816832", "line": { "color": "rgb(124,176,118)" }, @@ -848,7 +844,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930816832", "line": { "color": "rgb(124,176,118)" }, @@ -875,7 +871,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930816832", "line": { "color": "rgb(124,176,118)" }, @@ -902,7 +898,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930904208", "line": { "color": "rgb(236,26,27)" }, @@ -929,7 +925,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930904208", "line": { "color": "rgb(236,26,27)" }, @@ -956,7 +952,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930904208", "line": { "color": "rgb(236,26,27)" }, @@ -983,7 +979,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930904208", "line": { "color": "rgb(236,26,27)" }, @@ -1010,7 +1006,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930904208", "line": { "color": "rgb(236,26,27)" }, @@ -1073,7 +1069,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930904208", "line": { "color": "rgb(236,26,27)" }, @@ -1979,7 +1975,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -2015,12 +2011,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:53:03.707686Z", - "start_time": "2024-03-26T12:53:03.621171Z" + "end_time": "2024-03-28T11:49:24.657999Z", + "start_time": "2024-03-28T11:49:24.588202Z" } }, "id": "767c932bc1a6beb", - "execution_count": 4 + "execution_count": 9 }, { "cell_type": "markdown", @@ -2042,7 +2038,7 @@ "data": [ { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -2069,7 +2065,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -2108,7 +2104,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -2147,7 +2143,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -2174,7 +2170,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -2237,7 +2233,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -2276,7 +2272,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -2315,7 +2311,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -2354,7 +2350,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -2393,7 +2389,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -2420,7 +2416,7 @@ }, { "fill": "toself", - "legendgroup": "Event", + "legendgroup": "139790930873264", "line": { "color": "#636EFA" }, @@ -3290,7 +3286,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -3305,12 +3301,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-26T12:53:03.755929Z", - "start_time": "2024-03-26T12:53:03.708529Z" + "end_time": "2024-03-28T11:49:24.709114Z", + "start_time": "2024-03-28T11:49:24.659193Z" } }, "id": "ce38e8a948d2a0d5", - "execution_count": 5 + "execution_count": 10 }, { "cell_type": "markdown", diff --git a/examples/product_spaces.ipynb b/examples/product_spaces.ipynb index 8e74753..d0f8fff 100644 --- a/examples/product_spaces.ipynb +++ b/examples/product_spaces.ipynb @@ -40,13 +40,13 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 96, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.252002Z", - "start_time": "2024-03-28T09:00:49.216907Z" + "end_time": "2024-03-28T11:47:54.695815Z", + "start_time": "2024-03-28T11:47:54.647783Z" } }, "outputs": [ @@ -99,7 +99,7 @@ "data": { "text/plain": "[set(),\n {'a'},\n {'b'},\n {'c'},\n {'a', 'b'},\n {'a', 'c'},\n {'b', 'c'},\n {'a', 'b', 'c'}]" }, - "execution_count": 59, + "execution_count": 97, "metadata": {}, "output_type": "execute_result" } @@ -118,12 +118,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.298182Z", - "start_time": "2024-03-28T09:00:49.294046Z" + "end_time": "2024-03-28T11:47:54.739063Z", + "start_time": "2024-03-28T11:47:54.735669Z" } }, "id": "efd225f025a25755", - "execution_count": 59 + "execution_count": 97 }, { "cell_type": "markdown", @@ -142,7 +142,7 @@ "data": { "text/plain": "True" }, - "execution_count": 60, + "execution_count": 98, "metadata": {}, "output_type": "execute_result" } @@ -153,12 +153,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.304090Z", - "start_time": "2024-03-28T09:00:49.299383Z" + "end_time": "2024-03-28T11:47:54.747531Z", + "start_time": "2024-03-28T11:47:54.739940Z" } }, "id": "4718cfb47e7aabf5", - "execution_count": 60 + "execution_count": 98 }, { "cell_type": "markdown", @@ -181,12 +181,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.309071Z", - "start_time": "2024-03-28T09:00:49.304784Z" + "end_time": "2024-03-28T11:47:54.753107Z", + "start_time": "2024-03-28T11:47:54.748289Z" } }, "id": "dc64275c217072e", - "execution_count": 61 + "execution_count": 99 }, { "cell_type": "markdown", @@ -211,12 +211,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.316136Z", - "start_time": "2024-03-28T09:00:49.310238Z" + "end_time": "2024-03-28T11:47:54.758169Z", + "start_time": "2024-03-28T11:47:54.753794Z" } }, "id": "e7dc354bb8a70a12", - "execution_count": 62 + "execution_count": 100 }, { "cell_type": "markdown", @@ -234,7 +234,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 101, "outputs": [ { "name": "stdout", @@ -254,8 +254,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.320810Z", - "start_time": "2024-03-28T09:00:49.316944Z" + "end_time": "2024-03-28T11:47:54.765596Z", + "start_time": "2024-03-28T11:47:54.759202Z" } }, "id": "27ea010bc8892833" @@ -307,7 +307,7 @@ "data": { "text/plain": "[('bowl', 'blue'),\n ('bowl', 'green'),\n ('bowl', 'red'),\n ('cup', 'blue'),\n ('cup', 'green'),\n ('cup', 'red'),\n ('spoon', 'blue'),\n ('spoon', 'green'),\n ('spoon', 'red')]" }, - "execution_count": 64, + "execution_count": 102, "metadata": {}, "output_type": "execute_result" } @@ -319,12 +319,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.326522Z", - "start_time": "2024-03-28T09:00:49.321490Z" + "end_time": "2024-03-28T11:47:54.771290Z", + "start_time": "2024-03-28T11:47:54.766273Z" } }, "id": "379cef1a50307c47", - "execution_count": 64 + "execution_count": 102 }, { "cell_type": "markdown", @@ -344,7 +344,7 @@ "data": { "text/plain": "[('bowl', 'blue'), ('cup', 'blue')]" }, - "execution_count": 65, + "execution_count": 103, "metadata": {}, "output_type": "execute_result" } @@ -356,12 +356,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.332076Z", - "start_time": "2024-03-28T09:00:49.327154Z" + "end_time": "2024-03-28T11:47:54.776384Z", + "start_time": "2024-03-28T11:47:54.772103Z" } }, "id": "a53e718226f00339", - "execution_count": 65 + "execution_count": 103 }, { "cell_type": "markdown", @@ -383,12 +383,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.337038Z", - "start_time": "2024-03-28T09:00:49.332889Z" + "end_time": "2024-03-28T11:47:54.781173Z", + "start_time": "2024-03-28T11:47:54.777788Z" } }, "id": "1bb140fb470e3cf7", - "execution_count": 66 + "execution_count": 104 }, { "cell_type": "markdown", @@ -407,7 +407,7 @@ "data": { "text/plain": "{Symbolic(item): ('bowl', 'cup'), Symbolic(color): ('blue', 'red')}" }, - "execution_count": 67, + "execution_count": 105, "metadata": {}, "output_type": "execute_result" } @@ -419,12 +419,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.342190Z", - "start_time": "2024-03-28T09:00:49.338370Z" + "end_time": "2024-03-28T11:47:54.787017Z", + "start_time": "2024-03-28T11:47:54.783981Z" } }, "id": "b74c89bfbed07d6f", - "execution_count": 67 + "execution_count": 105 }, { "cell_type": "markdown", @@ -443,7 +443,7 @@ "data": { "text/plain": "\"{color: ('blue',), item: ('bowl',)} u {item: ('cup',), color: ('red',)}\"" }, - "execution_count": 68, + "execution_count": 106, "metadata": {}, "output_type": "execute_result" } @@ -455,12 +455,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.349675Z", - "start_time": "2024-03-28T09:00:49.342868Z" + "end_time": "2024-03-28T11:47:54.796483Z", + "start_time": "2024-03-28T11:47:54.792970Z" } }, "id": "7fd789bf96187ca1", - "execution_count": 68 + "execution_count": 106 }, { "cell_type": "markdown", @@ -498,7 +498,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 107, "outputs": [ { "data": { @@ -1371,7 +1371,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -1389,8 +1389,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.377357Z", - "start_time": "2024-03-28T09:00:49.371423Z" + "end_time": "2024-03-28T11:47:54.810736Z", + "start_time": "2024-03-28T11:47:54.805069Z" } }, "id": "a86b223360f60725" @@ -1410,13 +1410,13 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 108, "outputs": [ { "data": { "text/plain": "{Continuous(x): [2,3] | [4,5] | [6,7], Continuous(y): [10,15] | [25,27]}" }, - "execution_count": 70, + "execution_count": 108, "metadata": {}, "output_type": "execute_result" } @@ -1428,8 +1428,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.382698Z", - "start_time": "2024-03-28T09:00:49.379835Z" + "end_time": "2024-03-28T11:47:54.907908Z", + "start_time": "2024-03-28T11:47:54.904410Z" } }, "id": "86d42ecd896bef10" @@ -1446,7 +1446,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 109, "outputs": [ { "data": { @@ -2379,7 +2379,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -2393,8 +2393,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.430495Z", - "start_time": "2024-03-28T09:00:49.425129Z" + "end_time": "2024-03-28T11:47:54.951792Z", + "start_time": "2024-03-28T11:47:54.943952Z" } }, "id": "7d81de549d20f02b" @@ -2411,7 +2411,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 110, "outputs": [ { "data": { @@ -4637,7 +4637,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -4654,8 +4654,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.511362Z", - "start_time": "2024-03-28T09:00:49.499268Z" + "end_time": "2024-03-28T11:47:55.040208Z", + "start_time": "2024-03-28T11:47:54.994045Z" } }, "id": "da2b51a986fa9d05" @@ -4691,7 +4691,7 @@ "data": [ { "fill": "toself", - "legendgroup": "140005024932816", + "legendgroup": "140005024656640", "line": { "color": "#636EFA" }, @@ -4730,7 +4730,7 @@ }, { "fill": "toself", - "legendgroup": "140005024932816", + "legendgroup": "140005024656640", "line": { "color": "#636EFA" }, @@ -5609,7 +5609,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -5626,12 +5626,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.521705Z", - "start_time": "2024-03-28T09:00:49.514608Z" + "end_time": "2024-03-28T11:47:55.051862Z", + "start_time": "2024-03-28T11:47:55.041304Z" } }, "id": "97f6f80a61c8abaf", - "execution_count": 73 + "execution_count": 111 }, { "cell_type": "markdown", @@ -5695,7 +5695,7 @@ 7, 6 ], - "legendgroup": "140005024932096", + "legendgroup": "140005025507264", "name": "Event", "showlegend": true, "x": [ @@ -5775,7 +5775,7 @@ 7, 6 ], - "legendgroup": "140005024932096", + "legendgroup": "140005025507264", "name": "Event", "showlegend": false, "x": [ @@ -5855,7 +5855,7 @@ 7, 6 ], - "legendgroup": "140005024932096", + "legendgroup": "140005025507264", "name": "Event", "showlegend": false, "x": [ @@ -5935,7 +5935,7 @@ 7, 6 ], - "legendgroup": "140005024932096", + "legendgroup": "140005025507264", "name": "Event", "showlegend": false, "x": [ @@ -6015,7 +6015,7 @@ 7, 6 ], - "legendgroup": "140005024932096", + "legendgroup": "140005025507264", "name": "Event", "showlegend": false, "x": [ @@ -6095,7 +6095,7 @@ 7, 6 ], - "legendgroup": "140005024932096", + "legendgroup": "140005025507264", "name": "Event", "showlegend": false, "x": [ @@ -6979,7 +6979,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -7000,12 +7000,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.533752Z", - "start_time": "2024-03-28T09:00:49.522521Z" + "end_time": "2024-03-28T11:47:55.064229Z", + "start_time": "2024-03-28T11:47:55.052570Z" } }, "id": "9e47b2f884e4c9dd", - "execution_count": 74 + "execution_count": 112 }, { "cell_type": "markdown", @@ -7030,7 +7030,7 @@ "data": [ { "fill": "toself", - "legendgroup": "140005024696592", + "legendgroup": "140005025311904", "line": { "color": "#636EFA" }, @@ -7057,7 +7057,7 @@ }, { "fill": "toself", - "legendgroup": "140005024696592", + "legendgroup": "140005025311904", "line": { "color": "#636EFA" }, @@ -7084,7 +7084,7 @@ }, { "fill": "toself", - "legendgroup": "140005024696592", + "legendgroup": "140005025311904", "line": { "color": "#636EFA" }, @@ -7111,7 +7111,7 @@ }, { "fill": "toself", - "legendgroup": "140005024696592", + "legendgroup": "140005025311904", "line": { "color": "#636EFA" }, @@ -7978,7 +7978,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -7999,12 +7999,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.544428Z", - "start_time": "2024-03-28T09:00:49.534748Z" + "end_time": "2024-03-28T11:47:55.077692Z", + "start_time": "2024-03-28T11:47:55.065240Z" } }, "id": "b8916038b2521a38", - "execution_count": 75 + "execution_count": 113 }, { "cell_type": "markdown", @@ -8025,7 +8025,7 @@ "data": [ { "fill": "toself", - "legendgroup": "140005023904048", + "legendgroup": "140005024511456", "line": { "color": "#636EFA" }, @@ -8052,7 +8052,7 @@ }, { "fill": "toself", - "legendgroup": "140005023904048", + "legendgroup": "140005024511456", "line": { "color": "#636EFA" }, @@ -8091,7 +8091,7 @@ }, { "fill": "toself", - "legendgroup": "140005023904048", + "legendgroup": "140005024511456", "line": { "color": "#636EFA" }, @@ -8118,7 +8118,7 @@ }, { "fill": "toself", - "legendgroup": "140005023904048", + "legendgroup": "140005024511456", "line": { "color": "#636EFA" }, @@ -8997,7 +8997,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -9011,12 +9011,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T09:00:49.559742Z", - "start_time": "2024-03-28T09:00:49.549873Z" + "end_time": "2024-03-28T11:47:55.089737Z", + "start_time": "2024-03-28T11:47:55.078484Z" } }, "id": "510b80164a41cfc", - "execution_count": 76 + "execution_count": 114 }, { "cell_type": "markdown", diff --git a/src/random_events/__init__.py b/src/random_events/__init__.py index 9d2551a..fca23f6 100644 --- a/src/random_events/__init__.py +++ b/src/random_events/__init__.py @@ -1 +1 @@ -__version__ = '2.0.9' +__version__ = '2.0.10' diff --git a/src/random_events/events.py b/src/random_events/events.py index ebe1eaa..5166319 100644 --- a/src/random_events/events.py +++ b/src/random_events/events.py @@ -456,6 +456,13 @@ def _from_json(cls, data: Dict[str, Any]) -> Self: result[variable] = assignment return result + def get_variables_where_assignment_is_different(self, other: Self) -> List[Variable]: + """ + Get all variables where the assignment is different from the other event's assignment + """ + return [variable for variable in self.keys() if self[variable] != other[variable]] + + class EncodedEvent(Event): """ @@ -605,33 +612,44 @@ def simplify(self) -> Self: """ Simplify the complex event such that sub-unions of events that can be expressed as a single events are merged. + + This is done by seeking events that are equal in all but one dimensions to another event and merging them. """ if len(self.variables) == 1: return self.merge_if_one_dimensional() - # for every pair of events + # for every unique pair of events for index, event in enumerate(self.events): - for other_event in self.events[index + 1:]: - - # for every variable in the event - for variable, value in event.items(): - - # if the events match in this dimension - if other_event[variable] == value: - - # form the simpler union of the two events - unified_event = Event({variable: value}) - for variable_ in event.keys(): - if variable_ != variable: - unified_event[variable_] = variable.union_of_assignments(event[variable_], - other_event[variable_]) - # recurse into the simpler complex event - result = ComplexEvent([]) - result.events.append(unified_event) - result.events.extend([event__ for event__ in self.events if event__ != event - and event__ != other_event]) - return result.simplify() + for other_index, other_event in enumerate(self.events[index + 1:]): + other_index += index + 1 + + # get the different variables + different_variables = event.get_variables_where_assignment_is_different(other_event) + + # if they are the same event + if len(different_variables) == 0: + # recurse into the simpler complex event + result = ComplexEvent([]) + result.events.extend([event_ for index_, event_ in enumerate(self.events) + if index_ != other_index]) + return result.simplify() + + # if they differ in only one dimension + if len(different_variables) == 1: + mismatching_variable = different_variables[0] + + unified_event = event.__copy__() + unified_event[mismatching_variable] = (mismatching_variable. + union_of_assignments(event[mismatching_variable], + other_event[mismatching_variable])) + + # recurse into the simpler complex event + result = ComplexEvent([]) + result.events.append(unified_event) + result.events.extend([event_ for index_, event_ in enumerate(self.events) + if index_ not in [index, other_index]]) + return result.simplify() # if no simplification is possible, return the current complex event return self.__copy__() @@ -640,7 +658,7 @@ def intersection(self, other: EventType) -> Self: if isinstance(other, Event): return self.intersection(ComplexEvent([other])) intersections = [event.intersection(other_event) for other_event in other.events for event in self.events] - return ComplexEvent(intersections) + return ComplexEvent(intersections).simplify() def difference(self, other: EventType) -> Self: if isinstance(other, Event): @@ -652,7 +670,7 @@ def complement(self) -> Self: for event in self.events[1:]: current_complement = event.complement() result = result.intersection(current_complement) - return result.make_events_disjoint() # .simplify() + return result.make_events_disjoint().simplify() def are_events_disjoint(self) -> bool: """ diff --git a/test/test_events.py b/test/test_events.py index 57a93c4..c921ae8 100644 --- a/test/test_events.py +++ b/test/test_events.py @@ -290,9 +290,7 @@ def test_union_of_complex_events(self): complex_event_1 = event_1.union(event_2) event_3 = Event({self.x: portion.closed(0.5, 2), self.y: portion.closed(-0.5, 2)}) complex_event_2 = event_1.union(event_3) - result = complex_event_1.union(complex_event_2) - self.assertIsInstance(result, ComplexEvent) self.assertTrue(result.are_events_disjoint()) @@ -431,6 +429,18 @@ def test_intersection_symbol_and_real(self): self.assertEqual(event_[self.x], portion.closed(0, 1)) self.assertEqual(event_[self.a], (0, )) + def test_no_simplify_high_dimensions(self): + x = Continuous("x") + y = Continuous("y") + z = Continuous("z") + + event_1 = Event({x: portion.closed(0, 1), y: portion.closed(0, 1), z: portion.closed(0, 1)}) + event_2 = Event({x: portion.closed(0, 1), y: portion.closed(0.5, 1.5), z: portion.closed(0.5, 1.5)}) + complex_event = ComplexEvent([event_1, event_2]) + simplified = complex_event.simplify() + self.assertEqual(len(simplified.events), 2) + + class PlottingTestCase(unittest.TestCase): x: Continuous = Continuous("x") diff --git a/test/test_variables.py b/test/test_variables.py index 869d638..e06a50f 100644 --- a/test/test_variables.py +++ b/test/test_variables.py @@ -101,6 +101,5 @@ def test_complement_of_assignment(self): self.assertEqual(self.symbol.complement_of_assignment(("a",)), ("b", "c", )) - if __name__ == '__main__': unittest.main()