diff --git a/doc/references.bib b/doc/references.bib
new file mode 100644
index 0000000..e69de29
diff --git a/examples/door.ipynb b/examples/door.ipynb
index f4a9463..bfd8ff1 100644
--- a/examples/door.ipynb
+++ b/examples/door.ipynb
@@ -2,16 +2,23 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 1,
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
- "end_time": "2024-03-26T16:33:15.695152Z",
- "start_time": "2024-03-26T16:33:15.610016Z"
+ "end_time": "2024-03-26T16:37:47.504496Z",
+ "start_time": "2024-03-26T16:37:47.308104Z"
}
},
"outputs": [
+ {
+ "data": {
+ "text/html": " \n "
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
{
"data": {
"application/vnd.plotly.v1+json": {
@@ -61,7 +68,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": true,
"x": [
@@ -141,7 +148,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": false,
"x": [
@@ -221,7 +228,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": false,
"x": [
@@ -301,7 +308,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": false,
"x": [
@@ -381,7 +388,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": false,
"x": [
@@ -461,7 +468,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": false,
"x": [
@@ -541,7 +548,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": false,
"x": [
@@ -621,7 +628,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": false,
"x": [
@@ -701,7 +708,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": false,
"x": [
@@ -781,7 +788,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": false,
"x": [
@@ -861,7 +868,7 @@
7,
6
],
- "legendgroup": "140375482657952",
+ "legendgroup": "139628582763248",
"name": "Event",
"showlegend": false,
"x": [
@@ -941,7 +948,7 @@
7,
6
],
- "legendgroup": "140376849258528",
+ "legendgroup": "139628582698864",
"name": "Event",
"showlegend": true,
"x": [
@@ -1021,7 +1028,7 @@
7,
6
],
- "legendgroup": "140376849258528",
+ "legendgroup": "139628582698864",
"name": "Event",
"showlegend": false,
"x": [
@@ -1101,7 +1108,7 @@
7,
6
],
- "legendgroup": "140375508535424",
+ "legendgroup": "139628582698768",
"name": "Event",
"showlegend": true,
"x": [
@@ -1125,14 +1132,14 @@
0
],
"z": [
- 5,
- 5,
- 5,
- 5,
- 9,
- 9,
- 9,
- 9
+ 6,
+ 6,
+ 6,
+ 6,
+ 8,
+ 8,
+ 8,
+ 8
],
"type": "mesh3d"
},
@@ -1181,7 +1188,7 @@
7,
6
],
- "legendgroup": "140375508535424",
+ "legendgroup": "139628582698768",
"name": "Event",
"showlegend": false,
"x": [
@@ -1205,94 +1212,14 @@
0
],
"z": [
- 5,
- 5,
- 5,
- 5,
- 9,
- 9,
- 9,
- 9
- ],
- "type": "mesh3d"
- },
- {
- "color": "#bcbd22",
- "flatshading": true,
- "i": [
- 7,
- 0,
- 0,
- 0,
- 4,
- 4,
6,
6,
- 4,
- 0,
- 3,
- 2
- ],
- "j": [
- 3,
- 4,
- 1,
- 2,
- 5,
- 6,
- 5,
- 2,
- 0,
- 1,
6,
- 3
- ],
- "k": [
- 0,
- 7,
- 2,
- 3,
6,
- 7,
- 1,
- 1,
- 5,
- 5,
- 7,
- 6
- ],
- "legendgroup": "140375508535424",
- "name": "Event",
- "showlegend": false,
- "x": [
- 2,
- 2,
- 2.5,
- 2.5,
- 2,
- 2,
- 2.5,
- 2.5
- ],
- "y": [
- 0,
- 5,
- 5,
- 0,
- 0,
- 5,
- 5,
- 0
- ],
- "z": [
- 5,
- 5,
- 5,
- 5,
- 6,
- 6,
- 6,
- 6
+ 8,
+ 8,
+ 8,
+ 8
],
"type": "mesh3d"
},
@@ -1341,7 +1268,7 @@
7,
6
],
- "legendgroup": "140375508535424",
+ "legendgroup": "139628582698768",
"name": "Event",
"showlegend": false,
"x": [
@@ -1421,87 +1348,7 @@
7,
6
],
- "legendgroup": "140375508535424",
- "name": "Event",
- "showlegend": false,
- "x": [
- 3.5,
- 3.5,
- 4,
- 4,
- 3.5,
- 3.5,
- 4,
- 4
- ],
- "y": [
- 0,
- 5,
- 5,
- 0,
- 0,
- 5,
- 5,
- 0
- ],
- "z": [
- 5,
- 5,
- 5,
- 5,
- 6,
- 6,
- 6,
- 6
- ],
- "type": "mesh3d"
- },
- {
- "color": "#bcbd22",
- "flatshading": true,
- "i": [
- 7,
- 0,
- 0,
- 0,
- 4,
- 4,
- 6,
- 6,
- 4,
- 0,
- 3,
- 2
- ],
- "j": [
- 3,
- 4,
- 1,
- 2,
- 5,
- 6,
- 5,
- 2,
- 0,
- 1,
- 6,
- 3
- ],
- "k": [
- 0,
- 7,
- 2,
- 3,
- 6,
- 7,
- 1,
- 1,
- 5,
- 5,
- 7,
- 6
- ],
- "legendgroup": "140375508535424",
+ "legendgroup": "139628582698768",
"name": "Event",
"showlegend": false,
"x": [
@@ -1581,7 +1428,7 @@
7,
6
],
- "legendgroup": "140375508535424",
+ "legendgroup": "139628582698768",
"name": "Event",
"showlegend": false,
"x": [
@@ -2448,7 +2295,7 @@
"plotlyServerURL": "https://plot.ly"
}
},
- "text/html": "
"
+ "text/html": ""
},
"metadata": {},
"output_type": "display_data"
@@ -2474,8 +2321,14 @@
"keyhole_rod = Event({y: portion.closedopen(0, 5), x: portion.closedopen(2.5, 3.5), z: portion.closedopen(3, 6)})\n",
"keyhole |= keyhole_rod\n",
"\n",
- "keyhole_outer_ring = Event({y: portion.closedopen(0, 5), x: portion.closedopen(1, 5), z: portion.closedopen(5, 9)})\n",
+ "keyhole_outer_ring = (Event({y: portion.closedopen(0, 5), x: portion.closedopen(1, 5), z: portion.closedopen(6, 8)}) | \n",
+ " Event({y: portion.closedopen(0, 5), x: portion.closedopen(2, 4), z: portion.closedopen(8, 9)})) \n",
"keyhole_outer_ring = keyhole_outer_ring.difference(keyhole)\n",
+ "keyhole_teeth = ComplexEvent([])\n",
+ "\n",
+ "for event in keyhole_outer_ring:\n",
+ " ...\n",
+ "\n",
"\n",
"lock = lock.difference(keyhole)\n",
"fig = go.Figure()\n",
diff --git a/examples/product_spaces.ipynb b/examples/product_spaces.ipynb
index 11050ce..a4ef131 100644
--- a/examples/product_spaces.ipynb
+++ b/examples/product_spaces.ipynb
@@ -3,9 +3,9 @@
{
"cell_type": "markdown",
"source": [
- "# Product Spaces\n",
+ "# Product $\\sigma$-Algebra\n",
"\n",
- "This tutorial aids in understanding product spaces and there implementation in the `random_events` package.\n",
+ "This tutorial is part of a bigger series on probabilistic machine learning and aids in understanding product $\\sigma$-algebras.\n",
"As mentioned in the introduction, research has shown that events that are described by independent constraints (rules) are most likely the only events where probability estimation is tractable.\n",
"Spaces that are constructed by independent constraints are called product spaces.\n",
"\n",
@@ -20,13 +20,13 @@
},
{
"cell_type": "code",
- "execution_count": 18,
+ "execution_count": 1,
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:09.997853Z",
- "start_time": "2024-03-21T17:15:09.959748Z"
+ "end_time": "2024-03-27T11:41:11.325527Z",
+ "start_time": "2024-03-27T11:41:11.145238Z"
}
},
"outputs": [
@@ -45,13 +45,27 @@
"import plotly\n",
"plotly.offline.init_notebook_mode()\n",
"import plotly.graph_objects as go\n",
- "import itertools"
+ "from itertools import chain, combinations, product"
]
},
{
"cell_type": "markdown",
"source": [
- "First, let's create some variables and an event."
+ "We begin by reciting the definition of a $\\sigma$-algebra.\n",
+ "\n",
+ "### $\\sigma$-Algebra\n",
+ "\n",
+ "A $\\sigma$ algebra is a set of sets that contains all set-differences that can be constructed by combining arbitrary subsets of said set. Furthermore, it contains all countable unions of sets and all infinite intersection of the set. More formally, according to Kolmogoroff: \n",
+ "\n",
+ "Let $E$ be a space of elementary events. Consider the powerset $2^E$ and le $\\Im \\subset 2^E$ be a set of subsets of $E$. Elements of $\\Im$ are called random events. If $\\Im$ satisfies the following properties,it is called a $\\sigma$-algebra.\n",
+ "\n",
+ "1. $E \\in \\Im$\n",
+ "2. $(A, B) \\in \\Im \\Rightarrow (A - B) \\in \\Im$\n",
+ "3. $(A_1, A_2, ... \\in \\Im) \\Rightarrow \\left( \\bigcup_{i=1}^\\mathbb{N} A_i \\in \\Im \\wedge \\bigcap_{i=1}^\\infty A_i \\in \\Im \\right)$\n",
+ "\n",
+ "The tuple $(E, \\Im)$ is called a measurable space.\n",
+ "\n",
+ "An example of such a set of sets is the following:"
],
"metadata": {
"collapsed": false
@@ -60,101 +74,379 @@
},
{
"cell_type": "code",
- "execution_count": 19,
"outputs": [
{
"data": {
- "text/plain": "{Symbolic(pets): ('cat', 'dog'), Integer(age): (5, 6, 7, 8, 9), Continuous(weight): (5,50)}"
+ "text/plain": "[set(),\n {'c'},\n {'a'},\n {'b'},\n {'a', 'c'},\n {'b', 'c'},\n {'a', 'b'},\n {'a', 'b', 'c'}]"
},
- "execution_count": 19,
+ "execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "pets = Symbolic(\"pets\", [\"cat\", \"dog\", \"fish\", \"mouse\"])\n",
- "age = Integer(\"age\", range(30))\n",
- "weight = Continuous(\"weight\")\n",
+ "def powerset(iterable):\n",
+ " s = list(iterable)\n",
+ " result = list(chain.from_iterable(combinations(s, r) for r in range(len(s) + 1)))\n",
+ " return [set(x) for x in result]\n",
+ "\n",
"\n",
- "event = Event({pets: [\"cat\", \"dog\"], age: range(5, 10), weight: portion.open(5, 50)})\n",
- "event"
+ "E = {\"a\", \"b\", \"c\"}\n",
+ "powerset_of_E = powerset(E)\n",
+ "powerset_of_E"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "efd225f025a25755",
+ "execution_count": 2
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "We can see that this is a correct $\\sigma$-algebra by verifying all axioms. First, check if it contains the space of elementary Events $E$:"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "a5548beba930410e"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": "True"
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "E in powerset_of_E"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "4718cfb47e7aabf5",
+ "execution_count": 3
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Next, check if it contains all set differences:"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "a8e23b88ee558e34"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "for A, B in combinations(powerset_of_E, 2):\n",
+ " if A - B not in powerset_of_E:\n",
+ " print(f\"Set difference {A - B} not in powerset\")"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "dc64275c217072e",
+ "execution_count": 4
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Finally, check if it contains all countable unions and intersections:"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "1b94834332d48104"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "for A, B in combinations(powerset_of_E, 2):\n",
+ " if A.union(B) not in powerset_of_E:\n",
+ " print(f\"Union {A.union(B)} not in powerset\")\n",
+ " if A.intersection(B) not in powerset_of_E:\n",
+ " print(f\"Intersection {A.intersection(B)} not in powerset\")"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:10.039291Z",
- "start_time": "2024-03-21T17:15:10.035907Z"
+ "end_time": "2024-03-27T11:41:11.377945Z",
+ "start_time": "2024-03-27T11:41:11.373670Z"
}
},
- "id": "27ea010bc8892833"
+ "id": "e7dc354bb8a70a12",
+ "execution_count": 5
},
{
"cell_type": "markdown",
"source": [
- "This event describes every element that has the following properties:\n",
- "- `pets` is either a cat or a dog\n",
- "- `age` is between 5 and 10\n",
- "- `weight` is between 5 and 50\n",
- "\n",
- "There are no constraints possible such as `age > weight`, since these constraints are dependent.\n",
- "In general, descriptions for events that only contain discrete information results in sets that are constructed via the cartesian product of every constraint. \n",
+ "We have constructed a $\\sigma$-algebra. This is a very simple example, but it is important to understand the concept of such a system of sets.\n",
+ "As you can probably imagine, it is very inefficient to work with powersets of sets due to their exponential size. That's why I introduce the concept of product $\\sigma$-algebras.\n",
"\n",
- "Let's investigate the product of the discrete information on the pets and age."
+ "Product $\\sigma$-algebras are constructed by taking the cartesian product of sets and then constructing the $\\sigma$-algebra on the resulting set.\n",
+ "In this package, we generate product algebras from a viewpoint of classical machine learning. In machine learning scenarios we typically have a set of variables that we want to reason about. Random Events also start there. Let's start by defining some variables."
],
"metadata": {
"collapsed": false
},
- "id": "209fdcd01619b7dd"
+ "id": "9760a7401df5d50e"
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 6,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
- "('cat', 5)\n",
- "('cat', 6)\n",
- "('cat', 7)\n",
- "('cat', 8)\n",
- "('cat', 9)\n",
- "('dog', 5)\n",
- "('dog', 6)\n",
- "('dog', 7)\n",
- "('dog', 8)\n",
- "('dog', 9)\n"
+ "Symbolic(item, ('bowl', 'cup', 'spoon'))\n",
+ "Symbolic(color, ('blue', 'green', 'red'))\n"
]
}
],
"source": [
- "all_elements = itertools.product(event[pets], event[age])\n",
- "print(*all_elements, sep=\"\\n\")"
+ "item = Symbolic(\"item\", [\"bowl\", \"cup\", \"spoon\"])\n",
+ "color = Symbolic(\"color\", [\"blue\", \"green\", \"red\"])\n",
+ "print(item)\n",
+ "print(color)"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "ExecuteTime": {
+ "end_time": "2024-03-27T11:41:11.383495Z",
+ "start_time": "2024-03-27T11:41:11.378610Z"
+ }
+ },
+ "id": "27ea010bc8892833"
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "The variables we just constructed consisted of a name and a set of possible values, the so-called domain.\n",
+ "While the name is just an identifier, the domain is the set of elementary events, as described in the definition of a $\\sigma$-algebra.\n",
+ "Regarding the formal terms from above, we can write a variable as a measurable space $(\\text{variable.domain}, 2^\\text{variable.domain})$, which means in common words that everything inside the domain is a possible and every combination of the things inside the domain is possible.\n",
+ "\n",
+ "Forming combinations of those two variables introduces the product algebra."
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "4177e337f8508dbb"
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### Product $\\sigma$-Algebra\n",
+ "\n",
+ "Let $(E_1,\\Im_1)$ and $(E_2,\\Im_2)$ be measurable spaces.\n",
+ "The product $\\sigma$-algebra of $\\Im_1$ and $\\Im_2$ is denoted $\\Im_1 \\otimes \\Im_2$, and defined as:\n",
+ "$\\Im_1 \\otimes \\Im_2 := \\sigma(\\{S_1 \\times S_2 : S_1 \\in \\Im_1 \\wedge S_2 \\in \\Im_2\\})$\n",
+ "where $\\sigma$ denotes generated $\\sigma$-algebra and $\\times$ denotes Cartesian product.\n",
+ "This is a $\\sigma$-algebra on the Cartesian product $E_1 \\times E_2$."
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "1e540dd7a73f029"
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "An example of this product algebra is the combination of the item and color variables."
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "f79082602711ff4b"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [
+ {
+ "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": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "product_E = product(item.domain, color.domain)\n",
+ "list(product_E)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:10.044733Z",
- "start_time": "2024-03-21T17:15:10.040231Z"
+ "end_time": "2024-03-27T11:41:11.389386Z",
+ "start_time": "2024-03-27T11:41:11.384286Z"
}
},
- "id": "3654b51ed6b0b7e2"
+ "id": "379cef1a50307c47",
+ "execution_count": 7
},
{
"cell_type": "markdown",
"source": [
- "As we can see, these results in all ten atomic events that are described by the above event."
+ "However, as these are already 9 elementary events the powerset contains $2^9 = 512$ elements. This is not feasible to work with. Hence, a better description of a subset of the powerset is needed.\n",
+ "This is where the concept of events comes into play. Events are subsets of the powerset that are constructed by constraints on the variables. The event they describe is given by the Cartesian product of all elements within the constraints."
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "a2f15178104f46bc"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": "[('bowl', 'blue'), ('cup', 'blue')]"
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "event = Event({item: (\"bowl\", \"cup\"), color: \"blue\"})\n",
+ "list(product(*event.values()))"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "ExecuteTime": {
+ "end_time": "2024-03-27T11:41:11.394755Z",
+ "start_time": "2024-03-27T11:41:11.390099Z"
+ }
+ },
+ "id": "a53e718226f00339",
+ "execution_count": 8
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Unfortunately, a union of such event cannot be accurately described by a single event. Consider the following "
],
"metadata": {
"collapsed": false
},
"id": "c1d0eb7d2d61b478"
},
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "event1 = Event({item: \"bowl\", color: \"blue\"})\n",
+ "event2 = Event({item: \"cup\", color: \"red\"})"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "ExecuteTime": {
+ "end_time": "2024-03-27T11:41:11.399327Z",
+ "start_time": "2024-03-27T11:41:11.395848Z"
+ }
+ },
+ "id": "1bb140fb470e3cf7",
+ "execution_count": 9
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "If the union of these events is constructed for every variable, one would obtain the following event"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "6ac423435581d08e"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": "{Symbolic(item): ('bowl', 'cup'), Symbolic(color): ('blue', 'red')}"
+ },
+ "execution_count": 10,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "union = Event({item: (\"bowl\", \"cup\"), color: (\"blue\", \"red\")})\n",
+ "union"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "ExecuteTime": {
+ "end_time": "2024-03-27T11:41:11.404742Z",
+ "start_time": "2024-03-27T11:41:11.399885Z"
+ }
+ },
+ "id": "b74c89bfbed07d6f",
+ "execution_count": 10
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "However, this is not the union of the two events. This union contains the event (\"blue\", \"cup\"), which was not part of any of the above events. Hence the real union is constructed this way: "
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "f9e5079fb88147e6"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": "\"{color: ('blue',), item: ('bowl',)} u {item: ('cup',), color: ('red',)}\""
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "real_union = event1 | event2\n",
+ "str(real_union)"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "ExecuteTime": {
+ "end_time": "2024-03-27T11:41:11.410421Z",
+ "start_time": "2024-03-27T11:41:11.405470Z"
+ }
+ },
+ "id": "7fd789bf96187ca1",
+ "execution_count": 11
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "The correct union is a complex event. A complex event is a union of disjoint events."
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "bf5b8159724db75"
+ },
{
"cell_type": "markdown",
"source": [
"## Continuous Domains\n",
- "Let's have a more intuitive look at events that are composed of continuous independent constraints."
+ "\n",
+ "Getting a better understanding for such abstract concepts is best done through visualisations. Hence, we will now work with continuous variables.\n",
+ "In continuous variables, the possible values are intervals. This package uses portion to represent intervals. Let's get some hands on by defining continuous variables."
],
"metadata": {
"collapsed": false
@@ -163,7 +455,7 @@
},
{
"cell_type": "code",
- "execution_count": 21,
+ "execution_count": 20,
"outputs": [
{
"data": {
@@ -1036,7 +1328,7 @@
"plotlyServerURL": "https://plot.ly"
}
},
- "text/html": ""
+ "text/html": ""
},
"metadata": {},
"output_type": "display_data"
@@ -1054,8 +1346,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:10.054918Z",
- "start_time": "2024-03-21T17:15:10.045493Z"
+ "end_time": "2024-03-27T14:18:43.878509Z",
+ "start_time": "2024-03-27T14:18:43.872359Z"
}
},
"id": "a86b223360f60725"
@@ -1075,13 +1367,13 @@
},
{
"cell_type": "code",
- "execution_count": 22,
+ "execution_count": 13,
"outputs": [
{
"data": {
"text/plain": "{Continuous(x): [2,3] | [4,5] | [6,7], Continuous(y): [10,15] | [25,27]}"
},
- "execution_count": 22,
+ "execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
@@ -1093,8 +1385,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:10.061292Z",
- "start_time": "2024-03-21T17:15:10.055789Z"
+ "end_time": "2024-03-27T11:41:11.425929Z",
+ "start_time": "2024-03-27T11:41:11.423090Z"
}
},
"id": "86d42ecd896bef10"
@@ -1111,7 +1403,7 @@
},
{
"cell_type": "code",
- "execution_count": 23,
+ "execution_count": 14,
"outputs": [
{
"data": {
@@ -2044,7 +2336,7 @@
"plotlyServerURL": "https://plot.ly"
}
},
- "text/html": ""
+ "text/html": ""
},
"metadata": {},
"output_type": "display_data"
@@ -2058,8 +2350,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:10.072215Z",
- "start_time": "2024-03-21T17:15:10.062573Z"
+ "end_time": "2024-03-27T11:41:11.433972Z",
+ "start_time": "2024-03-27T11:41:11.426820Z"
}
},
"id": "7d81de549d20f02b"
@@ -2076,7 +2368,7 @@
},
{
"cell_type": "code",
- "execution_count": 24,
+ "execution_count": 15,
"outputs": [
{
"data": {
@@ -4302,7 +4594,7 @@
"plotlyServerURL": "https://plot.ly"
}
},
- "text/html": ""
+ "text/html": ""
},
"metadata": {},
"output_type": "display_data"
@@ -4319,8 +4611,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:10.091818Z",
- "start_time": "2024-03-21T17:15:10.073469Z"
+ "end_time": "2024-03-27T11:41:11.515868Z",
+ "start_time": "2024-03-27T11:41:11.499928Z"
}
},
"id": "da2b51a986fa9d05"
@@ -4356,7 +4648,7 @@
"data": [
{
"fill": "toself",
- "legendgroup": "Event",
+ "legendgroup": "140154644927104",
"line": {
"color": "#636EFA"
},
@@ -4395,7 +4687,7 @@
},
{
"fill": "toself",
- "legendgroup": "Event",
+ "legendgroup": "140154644927104",
"line": {
"color": "#636EFA"
},
@@ -5274,7 +5566,7 @@
"plotlyServerURL": "https://plot.ly"
}
},
- "text/html": ""
+ "text/html": ""
},
"metadata": {},
"output_type": "display_data"
@@ -5291,12 +5583,12 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:10.104115Z",
- "start_time": "2024-03-21T17:15:10.093771Z"
+ "end_time": "2024-03-27T11:41:11.530368Z",
+ "start_time": "2024-03-27T11:41:11.522022Z"
}
},
"id": "97f6f80a61c8abaf",
- "execution_count": 25
+ "execution_count": 16
},
{
"cell_type": "markdown",
@@ -5316,6 +5608,7 @@
"application/vnd.plotly.v1+json": {
"data": [
{
+ "color": "#636EFA",
"flatshading": true,
"i": [
7,
@@ -5359,6 +5652,9 @@
7,
6
],
+ "legendgroup": "140154644926624",
+ "name": "Event",
+ "showlegend": true,
"x": [
-1,
-1,
@@ -5392,6 +5688,7 @@
"type": "mesh3d"
},
{
+ "color": "#636EFA",
"flatshading": true,
"i": [
7,
@@ -5435,6 +5732,9 @@
7,
6
],
+ "legendgroup": "140154644926624",
+ "name": "Event",
+ "showlegend": false,
"x": [
1,
1,
@@ -5468,6 +5768,7 @@
"type": "mesh3d"
},
{
+ "color": "#636EFA",
"flatshading": true,
"i": [
7,
@@ -5511,6 +5812,9 @@
7,
6
],
+ "legendgroup": "140154644926624",
+ "name": "Event",
+ "showlegend": false,
"x": [
0,
0,
@@ -5544,6 +5848,7 @@
"type": "mesh3d"
},
{
+ "color": "#636EFA",
"flatshading": true,
"i": [
7,
@@ -5587,6 +5892,9 @@
7,
6
],
+ "legendgroup": "140154644926624",
+ "name": "Event",
+ "showlegend": false,
"x": [
0,
0,
@@ -5620,6 +5928,7 @@
"type": "mesh3d"
},
{
+ "color": "#636EFA",
"flatshading": true,
"i": [
7,
@@ -5663,6 +5972,9 @@
7,
6
],
+ "legendgroup": "140154644926624",
+ "name": "Event",
+ "showlegend": false,
"x": [
0,
0,
@@ -5696,6 +6008,7 @@
"type": "mesh3d"
},
{
+ "color": "#636EFA",
"flatshading": true,
"i": [
7,
@@ -5739,6 +6052,9 @@
7,
6
],
+ "legendgroup": "140154644926624",
+ "name": "Event",
+ "showlegend": false,
"x": [
0,
0,
@@ -6620,7 +6936,7 @@
"plotlyServerURL": "https://plot.ly"
}
},
- "text/html": ""
+ "text/html": ""
},
"metadata": {},
"output_type": "display_data"
@@ -6641,12 +6957,12 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:10.114835Z",
- "start_time": "2024-03-21T17:15:10.105316Z"
+ "end_time": "2024-03-27T11:41:11.620509Z",
+ "start_time": "2024-03-27T11:41:11.606657Z"
}
},
"id": "9e47b2f884e4c9dd",
- "execution_count": 26
+ "execution_count": 17
},
{
"cell_type": "markdown",
@@ -6671,7 +6987,7 @@
"data": [
{
"fill": "toself",
- "legendgroup": "Event",
+ "legendgroup": "140154644601440",
"line": {
"color": "#636EFA"
},
@@ -6698,7 +7014,7 @@
},
{
"fill": "toself",
- "legendgroup": "Event",
+ "legendgroup": "140154644601440",
"line": {
"color": "#636EFA"
},
@@ -6725,7 +7041,7 @@
},
{
"fill": "toself",
- "legendgroup": "Event",
+ "legendgroup": "140154644601440",
"line": {
"color": "#636EFA"
},
@@ -6752,7 +7068,7 @@
},
{
"fill": "toself",
- "legendgroup": "Event",
+ "legendgroup": "140154644601440",
"line": {
"color": "#636EFA"
},
@@ -7619,7 +7935,7 @@
"plotlyServerURL": "https://plot.ly"
}
},
- "text/html": ""
+ "text/html": ""
},
"metadata": {},
"output_type": "display_data"
@@ -7640,12 +7956,12 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:10.126182Z",
- "start_time": "2024-03-21T17:15:10.116159Z"
+ "end_time": "2024-03-27T11:41:11.637373Z",
+ "start_time": "2024-03-27T11:41:11.627497Z"
}
},
"id": "b8916038b2521a38",
- "execution_count": 27
+ "execution_count": 18
},
{
"cell_type": "markdown",
@@ -7666,7 +7982,7 @@
"data": [
{
"fill": "toself",
- "legendgroup": "Event",
+ "legendgroup": "140154644888496",
"line": {
"color": "#636EFA"
},
@@ -7693,7 +8009,7 @@
},
{
"fill": "toself",
- "legendgroup": "Event",
+ "legendgroup": "140154644888496",
"line": {
"color": "#636EFA"
},
@@ -7732,7 +8048,7 @@
},
{
"fill": "toself",
- "legendgroup": "Event",
+ "legendgroup": "140154644888496",
"line": {
"color": "#636EFA"
},
@@ -7759,7 +8075,7 @@
},
{
"fill": "toself",
- "legendgroup": "Event",
+ "legendgroup": "140154644888496",
"line": {
"color": "#636EFA"
},
@@ -8638,7 +8954,7 @@
"plotlyServerURL": "https://plot.ly"
}
},
- "text/html": ""
+ "text/html": ""
},
"metadata": {},
"output_type": "display_data"
@@ -8652,12 +8968,12 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-03-21T17:15:10.139382Z",
- "start_time": "2024-03-21T17:15:10.127017Z"
+ "end_time": "2024-03-27T11:41:11.662740Z",
+ "start_time": "2024-03-27T11:41:11.652118Z"
}
},
"id": "510b80164a41cfc",
- "execution_count": 28
+ "execution_count": 19
},
{
"cell_type": "markdown",
diff --git a/src/random_events/events.py b/src/random_events/events.py
index 67117f6..ebe1eaa 100644
--- a/src/random_events/events.py
+++ b/src/random_events/events.py
@@ -115,6 +115,9 @@ class Event(SupportsSetOperations, EventMapType, SubclassJSONSerializer):
A map of variables to values of their respective domains.
"""
+ def __str__(self):
+ return "{" + ", ".join(f"{variable.name}: {value}" for variable, value in self.items()) + "}"
+
def check_same_type(self, other: Any):
"""
Check that both self and other are of the same type.