diff --git a/.gitignore b/.gitignore index 330a467..f7bc340 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ -doc/build -doc/static .idea .pytest_cache build dist src/random_events.egg-info */__pycache__/ +doc/_build +doc/_autosummary \ No newline at end of file diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 8d11a6b..dfc7d21 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -12,15 +12,18 @@ build: python: "3.9" apt_packages: - graphviz + jobs: + pre_build: + # Generate the Sphinx configuration for this Jupyter Book so it builds. + - "jupyter-book config sphinx docs/" -# Build documentation in the "docs/" directory with Sphinx -sphinx: - configuration: doc/conf.py - - -# Optional but recommended, declare the Python requirements required -# to build your documentation -# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html python: install: - - requirements: doc/requirements.txt + - method: pip + path: . + extra_requirements: + - sphinx + +sphinx: + builder: html + diff --git a/doc/Makefile b/doc/Makefile deleted file mode 100644 index 2143bef..0000000 --- a/doc/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -SOURCEDIR = . -BUILDDIR = build - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/doc/logo/Tomato.png b/doc/Tomato.png similarity index 100% rename from doc/logo/Tomato.png rename to doc/Tomato.png diff --git a/doc/_config.yml b/doc/_config.yml new file mode 100644 index 0000000..6e69dcf --- /dev/null +++ b/doc/_config.yml @@ -0,0 +1,55 @@ +####################################################################################### +# A default configuration that will be loaded for all jupyter books +# See the documentation for help and more options: +# https://jupyterbook.org/customize/config.html + +####################################################################################### +# Book settings +title : Random Events # The title of the doc. Will be placed in the left navbar. +author : Tom Schierenbeck # The author of the doc +copyright : "2024" # Copyright year to be placed in the footer +logo : Tomato.png # A path to the doc logo + +# Force re-execution of notebooks on each build. +# See https://jupyterbook.org/content/execute.html +execute: + execute_notebooks: force + +# Define the name of the latex output file for PDF builds +latex: + latex_documents: + targetname: doc.tex + +# Add a bibtex file so that we can create citations +bibtex_bibfiles: + - references.bib + +# Information about where the doc exists on the web +repository: + url: https://github.com/tomsch420/random_events/ # Online location of your doc + path_to_book: doc # Optional path to your doc, relative to the repository root + branch: master # Which branch of the repository should be used when creating links (optional) + +# Add GitHub buttons to your doc +# See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository +html: + use_issues_button: true + use_repository_button: true + +sphinx: + extra_extensions: + - sphinx_proof + - 'sphinx.ext.autodoc' + - 'sphinx.ext.autosummary' + - 'autoapi.extension' + config: + suppress_warnings: ["mystnb.unknown_mime_type"] + autosummary_generate: True + html_js_files: + - https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js + autoapi_dirs: ['../src'] + autoapi_add_toctree_entry: True + +parse: + myst_enable_extensions: + - amsmath \ No newline at end of file diff --git a/doc/_toc.yml b/doc/_toc.yml new file mode 100644 index 0000000..e318bc2 --- /dev/null +++ b/doc/_toc.yml @@ -0,0 +1,11 @@ +# Table of contents +# Learn more at https://jupyterbook.org/customize/toc.html + +format: jb-book +root: intro +chapters: +- file: quickstart +- file: conceptual_guide +- file: technical_guide +- file: advanced_use +- file: autoapi/index \ No newline at end of file diff --git a/doc/advanced_use.md b/doc/advanced_use.md new file mode 100644 index 0000000..f8915f8 --- /dev/null +++ b/doc/advanced_use.md @@ -0,0 +1,92 @@ +--- +jupytext: + cell_metadata_filter: -all + formats: md:myst + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.11.5 +kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + + +# Advanced Use-case + +In this tutorial, we will look at a humorous application of random events. +This examples shows that elements from the product algebra can take almost any shape, such as a tomato. +First, we import the necessary packages and define two variables. + +```{code-cell} ipython3 +:tags: [] + +import os.path +from random_events.product_algebra import Event, SimpleEvent +from random_events.variable import Continuous +from random_events.interval import * +from PIL import Image +import numpy as np +import plotly.graph_objects as go + +x = Continuous("x") +y = Continuous("y") +``` + +Next, let's load the logo of this package. + +```{code-cell} ipython3 +:tags: [] +path = os.path.join("Tomato.png") +image = im=Image.open(path) +image +``` + +We can express this image as an event that can be reasoned about. + +```{code-cell} ipython3 +:tags: [] +image = np.array(image.resize((18, 17), Image.NEAREST)) +colors = np.unique(image.reshape((image.shape[0] * image.shape[1], image.shape[2])), axis=0)[1:] +def indices_to_complex_event(indices: np.array) -> Event: + result = Event() + for index in indices: + event = SimpleEvent({y: closed_open(-index[0] - 1, -index[0]), + x: closed_open(index[1], index[1] + 1)}) + result.simple_sets.add(event) + return result.simplify() + +fig = go.Figure() + +complex_events = [] + +for color in colors: + pixel_indices = np.transpose(np.nonzero(np.all(image == color, axis=-1))) + complex_event = indices_to_complex_event(pixel_indices) + complex_events.append(complex_event) + traces = complex_event.plot(f"rgb({color[0]},{color[1]},{color[2]})") + fig.update_layout(complex_event.plotly_layout()) + fig.add_traces(traces) + +fig.update_layout(title="Random Events Tomato") +fig.show() +``` + +While the shape of a tomato as an event that can be used for probabilistic reasoning serves no particular interest, +it showcases that random events can take approximately any shape and not "just" rectangles. +The entire tomate as measurable space is obtained by union of all the events. + +```{code-cell} ipython3 +:tags: [] + +entire_event = complex_events[0] | complex_events[1] | complex_events[2] +fig = go.Figure(entire_event.plot(), entire_event.plotly_layout()) +fig.update_layout(title="Random Events Tomato as one Event") +fig.show() +``` + +I hope this bizarre examples aids you in understanding of the product algebra capabilities. +Using this event, you can calculate things like the probability of a tomato or the conditional distribution given a tomato. + diff --git a/doc/conceptual_guide.md b/doc/conceptual_guide.md new file mode 100644 index 0000000..1620b0a --- /dev/null +++ b/doc/conceptual_guide.md @@ -0,0 +1,387 @@ +--- +jupytext: + cell_metadata_filter: -all + formats: md:myst + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.11.5 +kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +# Conceptual Guide + +In probability theory, sigma algebras play a fundamental role by formalizing the notion of events within a sample space. +This chapter delves into the development and application of a specific sigma-algebra, the *product sigma algebra* +tailored for the specific needs of tractable probabilistic inference. + +This book walks through the motivation, definition and construction of an algebra that is suitable for tractable +probabilistic reasoning. + +## Motivation + +While foundational concepts like sigma-algebras may appear abstract at first, a thorough understanding of their +properties and, specifically, product sigma-algebras, is crucial for rigorous probability theory and its applications +across various scientific disciplines, like robotics. Key motivating arguments are + +- *Foundations of probability theory*: sigma algebras are the building blocks for defining probability in a rigorous +way. By understanding them, a deeper understanding of how probabilities are assigned to events is gained. +- *Working with complex events:* In real-world scenarios, events can be intricate. Sigma algebras describe not just +simple events but also unions, intersections, and complements of these events, and hence are a powerful tool to analyze +probabilities of more complex situations. +- *Connection to advanced math:* Sigma algebras bridge the gap between set theory and advanced mathematical concepts +like measure theory and integration. Studying them opens doors to these powerful tools used in various scientific +fields. + +Especially in robotics they are important, since +- *Reasoning with uncertainty:* Robots often operate in environments with uncertainty. + Sigma algebras provide a mathematical foundation to represent uncertain events and reason about the probability of +different events happening (like sensor readings or obstacles appearing). +- *Decision-making under probability:* Many robotic tasks involve making decisions based on probabilities. By +understanding sigma algebras, algorithms can be build that consider the chance of different outcomes and choose the +action with the highest probability of success. +- *Planning and control under uncertainty:* Planning robot actions often requires considering various possibilities. +Sigma algebras allow for the creation of probabilistic models of the environment, enabling robots to plan and control +their movements while accounting for uncertainties. + +Research has shown that events that are described by independent constraints (rules) are most likely the only events +where probability estimation is tractable. {cite}`choi2020probabilistic` +Spaces that are constructed by independent constraints are called product spaces. Understanding the shape of such +events is a key competence to building (new) tractable probabilistic models. + +## Sigma Algebra + +A sigma algebra ($sigma$-algebra) is a set of sets that contains all set differences that can be constructed by +combining arbitrary subsets of the said set. Furthermore, it contains all countable unions of sets and all infinite +intersections of the set. + +````{prf:definition} Sigma Algebra +:label: def-sigma-algebra + +Let {math}`E` be a space of elementary events. Consider the powerset {math}`2^E` and let {math}`\Im \subset 2^E` be a +set of subsets of {math}`E`. Elements of {math}`\Im` are called random events. +If {math}`\Im` satisfies the following properties, it is called a sigma-algebra ({math}`\sigma`-algebra). + +```{math} +:label: eq-sigma-algebra +1. & \hspace{.5em} E \in \Im \\ +2. & \hspace{.5em} (A, B) \in \Im \Rightarrow (A - B) \in \Im \\ +3. & \hspace{.5em} (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) +``` + +The tuple {math}`(E, \Im)` is called a **measurable space**. +```` + +An example of such a set of sets is the following: + +```{code-cell} ipython3 +:tags: [] +from itertools import chain, combinations + + +def powerset(iterable): + s = list(iterable) + result = list(chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))) + return [set(x) for x in result] + + +E = {"a", "b", "c"} +powerset_of_E = powerset(E) +powerset_of_E +``` + +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$: + +```{code-cell} ipython3 +:tags: [] + +E in powerset_of_E +``` + +Next, check if it contains all set differences: + +```{code-cell} ipython3 +:tags: [] + +for A, B in combinations(powerset_of_E, 2): + if A - B not in powerset_of_E: + print(f"Set difference {A - B} not in powerset") +``` + +Finally, check if it contains all countable unions and intersections: + +```{code-cell} ipython3 +:tags: [] + +for A, B in combinations(powerset_of_E, 2): + if A.union(B) not in powerset_of_E: + print(f"Union {A.union(B)} not in powerset") + if A.intersection(B) not in powerset_of_E: + print(f"Intersection {A.intersection(B)} not in powerset") +``` + +We have constructed a $\sigma$-algebra. This is a basic example, but it is important to understand the concept +of such a system of sets. + +The set operations union and difference can be constructed from complement and intersection. + +## Intervals +A more advanced example is the set of intervals. Intervals are a common example of a sigma-algebra that is not trivial +but yet easy to construct. + +First, I introduce the concept of simple intervals and composite intervals in {prf:ref}`def-interval`. + +````{prf:definition} Interval +:label: def-interval + +A simple interval is a subset of {math}`\mathbb{R}` denoted by + +```{math} +:label: eq-interval +(a,b) &= \{x\in \mathbb{R} \mid a1. Trivial Sigma Algebra2. Element of F (2 Words)3. Countable _ are included4. Infinite _ are included5. Combination tool for multiple algebras (2 Words)6. Logical Representation of an Element of the Product Algebra (Abbreviation)7. Element of Borel Algebra on the reals8. Property of Constrains in the Product Algebra9. The opposite of an event10. Dimension in Machine Learning11. Other word for Symbolic12. Not Discrete▸6▸81▸93▾3▾44▾2▸76▸12▾10▾5▸115▾12123456Created with XWords – the free online crossword puzzle generatorhttps://www.xwords-generator.de/en \ No newline at end of file diff --git a/doc/index.rst b/doc/index.rst deleted file mode 100644 index a7fbdd1..0000000 --- a/doc/index.rst +++ /dev/null @@ -1,114 +0,0 @@ -.. Random Events documentation master file, created by - sphinx-quickstart on Mon Oct 23 15:23:00 2023. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -Welcome to Random Events' documentation! -========================================= - -Probabilistic Machine Learning frequently requires descriptions of random variables and events -that are shared among many packages. -This package provides a common interface for describing random variables and events, using -usable and easily extensible classes. - -Install the package via - -.. code-block:: bash - - pip install random-events - -The formalism behind this package is the -`Product Measure `_. - -Introduction -============ -The package contains two modules. - -Variables ---------- - -The first one is Variables :mod:`random_events.variables` which contains the taxonomy and definitions -of random variables. Random Variables are described by their name and by their domain. -They are structured as follows - -.. autoapi-inheritance-diagram:: random_events.variables - - -Variables are order-able and comparable by their name. - -Variables split in two categories, :class:`random_events.variables.Discrete` and -:class:`random_events.variables.Continuous`. -Discrete variables are described by a (finite) set of possible values while continuous variables -are defined on the real line. - -Continuous Variables are described using `portion `_ intervals. -This allows to describe intervals with infinite bounds and to perform operations on them, such as -union, intersection, difference, etc. - -Discrete Variables further split into integer variables and symbolic variables. -While integer variables are described by finite sets of order-able elements, symbolic -variables are described by a set of not order-able symbols. - -The domains of discrete variables are stored as tuples and should not be modified after creation. - - -Events ------- - -While the literature describes events as arbitrary sets of outcomes, research has shown that there -is a limited number of events that are tractable to calculate on. These are the sets that -can be described by independent restrictions. -For example, the event that :math:`0 < x < 1` and :math:`y > 2` can be calculated by some models, -since the bounds for :math:`x` and :math:`y` are defined independently of each other. -Unfortunately, it turned out that calculations on dependent integrals, such as :math:`0 < x < y`, are -intractable for most (all) models. Further information on the reasons behind such limitations are -found in literature on `Probabilistic Circuits `_. - -The package contains the module :mod:`random_events.events` for the taxonomy and definitions of -random events. -Random events are structured as follows - -.. autoapi-inheritance-diagram:: random_events.events - :top-classes: collections.UserDict - - -Random events extend dictionary like functionality for easy access and modification. -The most basic class is the :class:`random_events.events.VariableMap` class, which is a dictionary -that assigns variables to arbitrary values. This can be used for storing distributions, for example. -The :class:`random_events.events.Event` class extends the :class:`random_events.events.VariableMap` -class by only allowing the assignment of variables to values that are in the domain of the variable. -These values are automatically converted to the correct type, if possible. -An event is interpreted as a restriction on the full set of the variables involved. -If, for example, :math:`\{ Dog, Cat \}` is assigned to a variable about animals, it describes -the event that the animal is either a dog or a cat. - -Furthermore, intersections of events are possible. The intersection is done variable wise. - -The next class is the :class:`random_events.events.EncodedEvent` class, which converts events to -representations that are usable for indexing. For discrete variables, the values are converted to -indices, while for continuous variables, the values are not changed. - -The last class is the :class:`random_events.events.ComplexEvent` class. This class holds a list of disjoint -events. It can be seen as the result of operations where the result is not a single event, but a set of events. -Formally, it is the product outer measure. - -Examples -======== - -.. nbgallery:: - examples/example - examples/product_spaces - examples/logo_generation - examples/self_assessment - -.. toctree:: - :maxdepth: 2 - :caption: Contents: - - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` diff --git a/doc/intro.md b/doc/intro.md new file mode 100644 index 0000000..6fdbdaa --- /dev/null +++ b/doc/intro.md @@ -0,0 +1,8 @@ +# Welcome to the Random-Events Documentation + +This documentation is intended to provide a comprehensive guide to the Random-Events +package. The package is designed to provide a simple and flexible way to generate +events that are suitable for probabilistic reasoning in a python. + +```{tableofcontents} +``` \ No newline at end of file diff --git a/doc/quickstart.md b/doc/quickstart.md new file mode 100644 index 0000000..beb05c4 --- /dev/null +++ b/doc/quickstart.md @@ -0,0 +1,195 @@ +--- +jupytext: + cell_metadata_filter: -all + formats: md:myst + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.11.5 +kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +# Quickstart +This is a quickstart guide to get you up and running with the `random_events` library. + +## Installation + +To install the library, run the following command + +```bash +pip install random-events +``` + +Next, import the necessary functionality: + +```{code-cell} ipython3 +:tags: [] + + +from random_events.variable import Symbolic, Continuous, Integer +from random_events.product_algebra import SimpleEvent, Event +from random_events.interval import SimpleInterval, Interval, closed, closed_open, open_closed, open +from random_events.set import SetElement, Set +import plotly +import plotly.graph_objects as go +``` + +## Preface + +The `random_events` library is a Python library for working with sigma algebras. +For every algebra, there are two kinds of sets, the simple sets and the composite sets. +Simple sets are sets that can be represented as single objects. +Composite sets are sets that are composed of multiple, sorted simple sets. + + +## Intervals + +Intervals are a fundamental concept in the `random_events` library. +They are used to represent the range of possible values that a numeric variable can take. +There are two classes to interact with intervals: `SimpleInterval` and `Interval`. +However, it is **strongly recommended** to use the `Interval` class, +as it provides an API implementing all set operations. +First, create two simple intervals: + + +```{code-cell} ipython3 +:tags: [] + +si1 = SimpleInterval(0, 1) +si2 = SimpleInterval(0.5, 1.5) +si1, si2 +``` + +Simple sets of any kind can be converted to composite sets using the `.as_composite_set()` method. + +```{code-cell} ipython3 +:tags: [] + +i1 = si1.as_composite_set() +i2 = si2.as_composite_set() +i1, i2 +``` + +All set operations are supported for composite sets. +All set operations automatically return simple and disjoint representations of the resulting set. + +```{code-cell} ipython3 +:tags: [] + +print(i1.intersection_with(i2)) +print(i1.union_with(i2)) +print(i1.difference_with(i2)) +print(i1.complement()) +``` + +Set operations can also be invoked by calling the built-in methods. + +```{code-cell} ipython3 +:tags: [] + +print(i1 & i2) +print(i1 | i2) +print(i1 - i2) +print(~i1) +``` + +Intervals can also be created using shortcuts for the most common types of intervals. + +```{code-cell} ipython3 +:tags: [] + +print(closed(0, 1)) +print(closed_open(0, 1)) +print(open_closed(0, 1)) +print(open(0, 1)) +``` + +## Sets + +Since a sigma algebra requires more information than it is stored in regular python sets, the `SetElement` and `Set` +classes are used. +A set element is a simple set, and a set is a composite set. +Whenever you want to create a set element, you have to create an enum first that specifies all possible set elements. +The empty set should be represented by the value `-1`. + +```{code-cell} ipython3 +:tags: [] + +class Symbol(SetElement): + EMPTY_SET = -1 + APPLE = 0 + DOG = 1 + RAIN = 2 +``` + +Now you can interact with sets and set elements. + +```{code-cell} ipython3 +:tags: [] + +s1 = Set(Symbol.APPLE) +s2 = Set(Symbol.DOG) +print(s1) +print(~s1) +print(s1 & s2) +print(s1 | s2) +``` + +## Variables + +Describing multidimensional algebras requires variables that describe the type of dimension. +Variables are either `Symbolic`, `Integer` or `Continuous`. +Symbolic variables need a class that inherits from `SetElement` to describe the possible values. +Integer and Continuous variables need no specification of their domain. + +```{code-cell} ipython3 +:tags: [] + +a = Symbolic("a", Symbol) +x = Continuous("x") +y = Continuous("y") +z = Integer("z") +a, x, y, z +``` + +## Events + +Describing events requires the use of the `SimpleEvent` and `Event` classes. +Events are elements of the product algebra. +Simple events are dictionary like objects that describe the values of the variables. + +```{code-cell} ipython3 +:tags: [] + +e1 = SimpleEvent({a: Symbol.APPLE, x: closed(0, 1), y: closed(2, 3), z: closed(0, 10)}).as_composite_set() +e2 = SimpleEvent({a: Set(Symbol.APPLE, Symbol.DOG), x: closed(0, 4), y: closed(0, 5), z: closed(0, 20)}).as_composite_set() +print(e1) +print(e1 & e2) +print(e1 | e2) +print(e2 - e1) +``` + +Events can also be plotted. + +```{code-cell} ipython3 +:tags: [] + +e3 = SimpleEvent({x: closed(0, 1) | closed(2, 2.5), y: closed(2, 3) | closed(4, 5)}).as_composite_set() +fig = go.Figure(e3.plot(), e3.plotly_layout()) +fig.show() +``` + +JSON serialization is also supported for every object. + +```{code-cell} ipython3 +:tags: [] + +e4 = e2 - e1 +print(e4.to_json()) +e5 = Event.from_json(e4.to_json()) +e5 == e4 +``` diff --git a/doc/references.bib b/doc/references.bib index e69de29..a05318d 100644 --- a/doc/references.bib +++ b/doc/references.bib @@ -0,0 +1,25 @@ +--- +--- + + +@article{choi2020probabilistic, + title={Probabilistic circuits: A unifying framework for tractable probabilistic models}, + author={Choi, Y and Vergari, Antonio and Van den Broeck, Guy}, + journal={UCLA. URL: http://starai. cs. ucla. edu/papers/ProbCirc20. pdf}, + pages={6}, + year={2020} +} + +@article{kolmogorov1933grundbegriffe, + title={Grundbegriffe der Wahrscheinlichkeitrechnung (Ergebnisse Der Mathematik). Translated by Morrison, N}, + author={Kolmogorov, A}, + journal={Foundations of probability}, + year={1933} +} + +@book{hunter2011data, + title={Data Mining Compressed, Incomplete and Inaccurate High Dimensional Data}, + author={Hunter, Blake}, + year={2011}, + publisher={University of California, Davis} +} \ No newline at end of file diff --git a/doc/requirements.txt b/doc/requirements.txt index 38e1392..376ee87 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,8 +1,6 @@ - -r ../requirements-dev.txt -sphinx_rtd_theme +jupyter-book +matplotlib +numpy +ghp-import +sphinx-proof sphinx-autoapi -sphinxcontrib-bibtex -nbsphinx -myst-nb -sphinx-gallery -random-events \ No newline at end of file diff --git a/doc/technical_guide.md b/doc/technical_guide.md new file mode 100644 index 0000000..e3592e0 --- /dev/null +++ b/doc/technical_guide.md @@ -0,0 +1,21 @@ +# Technical Guide + +This document guides through the structure of the `random_events` package and explains how to expand it. + +## New Algebras + +Algebraic structures are the main concern of this package. +When you want to add a new algebra, you need to create a new class that inherits from +`AbstractSimpleSet` and `AbstractCompositeSet`. + +`SimpleInterval` and `Interval` provide an easy to grasp example of such an implementation. + +## New Variables + +Describing a multidimensional algebra needs variables that describe the type of dimensions. +In more applied scenarios, it may happen that more information is needed to describe a variable. +Achieving this requires the creation of a new class that inherits from the respective variable. + +## Serialization +The `SubClassJSONSerializer` is a class that automatically serializes and deserializes subclasses of a said class. +I strongly recommended getting familiar with this class when adding new classes to the package. \ No newline at end of file diff --git a/examples/door.ipynb b/examples/door.ipynb deleted file mode 100644 index ebc36d2..0000000 --- a/examples/door.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "id": "initial_id", - "metadata": { - "collapsed": true, - "ExecuteTime": { - "end_time": "2024-05-31T15:17:37.003610Z", - "start_time": "2024-05-31T15:17:36.947152Z" - } - }, - "source": [ - "from random_events.product_algebra import Event, SimpleEvent\n", - "from random_events.variable import Continuous\n", - "from random_events.interval import *\n", - "import plotly\n", - "import plotly.graph_objects as go\n", - "plotly.offline.init_notebook_mode()\n", - "\n", - "grey = \"#7f7f7f\"\n", - "gold = \"#bcbd22\"\n", - "\n", - "x = Continuous(\"x\")\n", - "y = Continuous(\"y\")\n", - "z = Continuous(\"z\")\n", - "\n", - "lock = Event({x: closed_open(0, 6), y: closed_open(0, 10), z: closed_open(0, 10)})\n", - "\n", - "keyhole = Event({y: closed_open(0, 5), x: closed_open(2, 4), z: closed_open(6, 8)})\n", - "keyhole_rod = Event({y: closed_open(0, 5), x: closed_open(2.5, 3.5), z: closed_open(3, 6)})\n", - "keyhole |= keyhole_rod\n", - "\n", - "keyhole_teeth = Event([SimpleEvent({y: closed_open(4, 5), z: closed_open(6, 7), x: closed_open(1, 2)})])\n", - "keyhole_teeth |= Event([SimpleEvent({y: closed_open(3, 4), z: closed_open(7, 8), x: closed_open(4, 5)})])\n", - "keyhole_teeth |= Event([SimpleEvent({y: closed_open(2, 3), z: closed_open(8, 9), x: closed_open(2, 4)})])\n", - "keyhole |= keyhole_teeth\n", - "\n", - "lock = lock.difference(keyhole)\n", - "print(lock)\n", - "fig = go.Figure()\n", - "fig.add_traces(lock.plot(color=\"grey\"))\n", - "fig.add_traces(keyhole.plot(gold))\n", - "fig.show()" - ], - "outputs": [ - { - "data": { - "text/html": [ - " \n", - " " - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "ename": "AttributeError", - "evalue": "'Continuous' object has no attribute 'variables'", - "output_type": "error", - "traceback": [ - "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", - "\u001B[0;31mAttributeError\u001B[0m Traceback (most recent call last)", - "Cell \u001B[0;32mIn[8], line 15\u001B[0m\n\u001B[1;32m 12\u001B[0m y \u001B[38;5;241m=\u001B[39m Continuous(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124my\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 13\u001B[0m z \u001B[38;5;241m=\u001B[39m Continuous(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mz\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m---> 15\u001B[0m lock \u001B[38;5;241m=\u001B[39m \u001B[43mEvent\u001B[49m\u001B[43m(\u001B[49m\u001B[43m{\u001B[49m\u001B[43mx\u001B[49m\u001B[43m:\u001B[49m\u001B[43m \u001B[49m\u001B[43mclosed_open\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m6\u001B[39;49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43my\u001B[49m\u001B[43m:\u001B[49m\u001B[43m \u001B[49m\u001B[43mclosed_open\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m10\u001B[39;49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mz\u001B[49m\u001B[43m:\u001B[49m\u001B[43m \u001B[49m\u001B[43mclosed_open\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m10\u001B[39;49m\u001B[43m)\u001B[49m\u001B[43m}\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 17\u001B[0m keyhole \u001B[38;5;241m=\u001B[39m Event({y: closed_open(\u001B[38;5;241m0\u001B[39m, \u001B[38;5;241m5\u001B[39m), x: closed_open(\u001B[38;5;241m2\u001B[39m, \u001B[38;5;241m4\u001B[39m), z: closed_open(\u001B[38;5;241m6\u001B[39m, \u001B[38;5;241m8\u001B[39m)})\n\u001B[1;32m 18\u001B[0m keyhole_rod \u001B[38;5;241m=\u001B[39m Event({y: closed_open(\u001B[38;5;241m0\u001B[39m, \u001B[38;5;241m5\u001B[39m), x: closed_open(\u001B[38;5;241m2.5\u001B[39m, \u001B[38;5;241m3.5\u001B[39m), z: closed_open(\u001B[38;5;241m3\u001B[39m, \u001B[38;5;241m6\u001B[39m)})\n", - "File \u001B[0;32m~/random-events/src/random_events/product_algebra.py:267\u001B[0m, in \u001B[0;36mEvent.__init__\u001B[0;34m(self, simple_sets)\u001B[0m\n\u001B[1;32m 265\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21m__init__\u001B[39m(\u001B[38;5;28mself\u001B[39m, simple_sets: Iterable[SimpleEvent]):\n\u001B[1;32m 266\u001B[0m \u001B[38;5;28msuper\u001B[39m()\u001B[38;5;241m.\u001B[39m\u001B[38;5;21m__init__\u001B[39m(simple_sets)\n\u001B[0;32m--> 267\u001B[0m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mfill_missing_variables\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n", - "File \u001B[0;32m~/random-events/src/random_events/product_algebra.py:278\u001B[0m, in \u001B[0;36mEvent.fill_missing_variables\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 274\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mfill_missing_variables\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n\u001B[1;32m 275\u001B[0m \u001B[38;5;250m \u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 276\u001B[0m \u001B[38;5;124;03m Fill all simple sets with the missing variables.\u001B[39;00m\n\u001B[1;32m 277\u001B[0m \u001B[38;5;124;03m \"\"\"\u001B[39;00m\n\u001B[0;32m--> 278\u001B[0m all_variables \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mall_variables\u001B[49m\n\u001B[1;32m 279\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m simple_set \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39msimple_sets:\n\u001B[1;32m 280\u001B[0m simple_set\u001B[38;5;241m.\u001B[39mfill_missing_variables(all_variables)\n", - "File \u001B[0;32m~/random-events/src/random_events/product_algebra.py:272\u001B[0m, in \u001B[0;36mEvent.all_variables\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 269\u001B[0m \u001B[38;5;129m@property\u001B[39m\n\u001B[1;32m 270\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mall_variables\u001B[39m(\u001B[38;5;28mself\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m SortedSet[Variable]:\n\u001B[1;32m 271\u001B[0m result \u001B[38;5;241m=\u001B[39m SortedSet()\n\u001B[0;32m--> 272\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m result\u001B[38;5;241m.\u001B[39munion(\u001B[38;5;241m*\u001B[39m[SortedSet(simple_set\u001B[38;5;241m.\u001B[39mvariables) \u001B[38;5;28;01mfor\u001B[39;00m simple_set \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39msimple_sets])\n", - "File \u001B[0;32m~/random-events/src/random_events/product_algebra.py:272\u001B[0m, in \u001B[0;36m\u001B[0;34m(.0)\u001B[0m\n\u001B[1;32m 269\u001B[0m \u001B[38;5;129m@property\u001B[39m\n\u001B[1;32m 270\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mall_variables\u001B[39m(\u001B[38;5;28mself\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m SortedSet[Variable]:\n\u001B[1;32m 271\u001B[0m result \u001B[38;5;241m=\u001B[39m SortedSet()\n\u001B[0;32m--> 272\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m result\u001B[38;5;241m.\u001B[39munion(\u001B[38;5;241m*\u001B[39m[SortedSet(\u001B[43msimple_set\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mvariables\u001B[49m) \u001B[38;5;28;01mfor\u001B[39;00m simple_set \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39msimple_sets])\n", - "\u001B[0;31mAttributeError\u001B[0m: 'Continuous' object has no attribute 'variables'" - ] - } - ], - "execution_count": 8 - }, - { - "metadata": {}, - "cell_type": "markdown", - "source": [ - "# Task\n", - "\n", - "Open the door to more powerful tools by crafting the key to this lock." - ], - "id": "3b7bba368ae82ab6" - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/examples/example.ipynb b/examples/example.ipynb deleted file mode 100644 index e14ff7f..0000000 --- a/examples/example.ipynb +++ /dev/null @@ -1,2275 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "source": [ - "# Quickstart\n", - "\n", - "The tutorial walks through the most common used functions of this package.\n", - "\n", - "First, import the necessary functionality." - ], - "metadata": { - "collapsed": false - }, - "id": "fcedd1911254a80c" - }, - { - "cell_type": "code", - "id": "initial_id", - "metadata": { - "collapsed": true, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:35.971666Z", - "start_time": "2024-06-03T12:18:35.939299Z" - } - }, - "source": [ - "from random_events.variable import Symbolic, Integer, Continuous\n", - "from random_events.product_algebra import SimpleEvent, Event\n", - "from random_events.interval import *\n", - "from random_events.set import *\n", - "import plotly\n", - "import plotly.graph_objects as go\n", - "plotly.offline.init_notebook_mode()" - ], - "outputs": [ - { - "data": { - "text/html": [ - " \n", - " " - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 31 - }, - { - "cell_type": "markdown", - "source": [ - "Next, create a variable of each type and inspect those objects." - ], - "metadata": { - "collapsed": false - }, - "id": "38c6e9a87d07bf4c" - }, - { - "cell_type": "code", - "source": [ - "class SymbolElement(SetElement):\n", - " EMPTY_SET = 0\n", - " APPLE = 1\n", - " DOG = 2\n", - " RAIN = 3\n", - "\n", - "symbol = Symbolic(\"symbol\", SymbolElement)\n", - "integer = Integer(\"integer\")\n", - "real = Continuous(\"real\")\n", - "symbol, integer, real" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:35.975620Z", - "start_time": "2024-06-03T12:18:35.972774Z" - } - }, - "id": "49b07deb8aecb5d0", - "outputs": [ - { - "data": { - "text/plain": [ - "(Symbolic(symbol), Integer(integer), Continuous(real))" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 32 - }, - { - "cell_type": "markdown", - "source": [ - "The variables can be easily serialized by converting objects to json and creating them from a json dict." - ], - "metadata": { - "collapsed": false - }, - "id": "1f9c1dc6a4cf5c6d" - }, - { - "cell_type": "code", - "source": [ - "print(symbol.to_json())\n", - "print(Symbolic.from_json(symbol.to_json()))" - ], - "metadata": { - "collapsed": false - }, - "id": "a3aed36278dab281", - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'random_events.variable.Symbolic', 'name': 'symbol', 'domain': {'type': 'random_events.set.Set', 'simple_sets': [{'type': '__main__.SymbolElement', 'value': 1}, {'type': '__main__.SymbolElement', 'value': 2}, {'type': '__main__.SymbolElement', 'value': 3}]}}\n", - "Symbolic(symbol, {APPLE u DOG u RAIN})\n" - ] - } - ], - "execution_count": 33 - }, - { - "cell_type": "markdown", - "source": [ - "Events can be composed from assignments to variables using a dictionary interface." - ], - "metadata": { - "collapsed": false - }, - "id": "ffb5c36e4b0cdc61" - }, - { - "cell_type": "code", - "source": [ - "event = SimpleEvent({symbol: SymbolElement.RAIN, real: open(-float(\"inf\"), 2)}).as_composite_set()\n", - "event" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:36.004386Z", - "start_time": "2024-06-03T12:18:36.000923Z" - } - }, - "id": "a81cd22d80129c04", - "outputs": [ - { - "data": { - "text/plain": [ - "{{real = {(-inf, 2)}, symbol = {RAIN}}}" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 34 - }, - { - "cell_type": "markdown", - "source": [ - "The created event describes a world where symbol has the value rain and real is lesser than 2. \n", - "Events and generally VariableMaps can be accessed via the variable itself or its name." - ], - "metadata": { - "collapsed": false - }, - "id": "ad6b1850e128d4e1" - }, - { - "cell_type": "code", - "source": [ - "print(event.simple_sets[0][\"real\"])\n", - "print(event.simple_sets[0][real])" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:36.007318Z", - "start_time": "2024-06-03T12:18:36.005380Z" - } - }, - "id": "4975045ed9540d52", - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{(-inf, 2)}\n", - "{(-inf, 2)}\n" - ] - } - ], - "execution_count": 35 - }, - { - "cell_type": "markdown", - "source": "Events can also be intersected with another event using the `intersection_with` method or `&` operator.", - "metadata": { - "collapsed": false - }, - "id": "6c1f81ed4da86454" - }, - { - "cell_type": "code", - "source": [ - "second_event = SimpleEvent({symbol: Set(SymbolElement.RAIN, SymbolElement.APPLE), real: open(1, 4)}).as_composite_set()\n", - "print(event.intersection_with(second_event))\n", - "print(event & second_event)" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:36.009901Z", - "start_time": "2024-06-03T12:18:36.007928Z" - } - }, - "id": "b4da0a20e367a1c0", - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{{real = {(1, 2)}, symbol = {RAIN}}}\n", - "{{real = {(1, 2)}, symbol = {RAIN}}}\n" - ] - } - ], - "execution_count": 36 - }, - { - "cell_type": "markdown", - "source": [ - "For unions, differences and complements, the events generate complex events, since the result is a product outer space." - ], - "metadata": { - "collapsed": false - }, - "id": "154cff93a65fa0a4" - }, - { - "cell_type": "code", - "source": [ - "print(event | second_event) # or event.union_with(second_event)\n", - "print(second_event - event) # or second_event.difference_with(event)\n", - "print(~event) # or event.complement()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:36.015256Z", - "start_time": "2024-06-03T12:18:36.010334Z" - } - }, - "id": "e8bb102d6d36e9a8", - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{{real = {(-inf, 2)}, symbol = {RAIN}} u {real = {(1, 2)}, symbol = {APPLE}} u {real = {[2, 4)}, symbol = {APPLE u RAIN}}}\n", - "{{real = {(1, 2)}, symbol = {APPLE}} u {real = {[2, 4)}, symbol = {APPLE u RAIN}}}\n", - "{{real = {(-inf, 2)}, symbol = {APPLE u DOG}} u {real = {[2, inf)}, symbol = {APPLE u DOG u RAIN}}}\n" - ] - } - ], - "execution_count": 37 - }, - { - "cell_type": "markdown", - "source": [ - "Events can also be plotted." - ], - "metadata": { - "collapsed": false - }, - "id": "d923870f7d4400a4" - }, - { - "cell_type": "code", - "source": [ - "x = Continuous(\"x\")\n", - "y = Continuous(\"y\")\n", - "event = SimpleEvent({x: open(0, 1), y: open(0, 1)}).as_composite_set()\n", - "fig = go.Figure(event.plot(), event.plotly_layout())\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:36.019997Z", - "start_time": "2024-06-03T12:18:36.015938Z" - } - }, - "id": "8c25f3846c860230", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "fill": "toself", - "legendgroup": "139858348227984", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": true, - "x": [ - 0, - 0, - 1, - 1, - 0, - null - ], - "y": [ - 0, - 1, - 1, - 0, - 0, - null - ], - "type": "scatter" - } - ], - "layout": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "marker": { - "line": { - "color": "#283442" - } - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#f2f5fa" - }, - "error_y": { - "color": "#f2f5fa" - }, - "marker": { - "line": { - "color": "rgb(17,17,17)", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "marker": { - "line": { - "color": "#283442" - } - }, - "type": "scattergl" - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#A2B1C6", - "gridcolor": "#506784", - "linecolor": "#506784", - "minorgridcolor": "#506784", - "startlinecolor": "#A2B1C6" - }, - "baxis": { - "endlinecolor": "#A2B1C6", - "gridcolor": "#506784", - "linecolor": "#506784", - "minorgridcolor": "#506784", - "startlinecolor": "#A2B1C6" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#506784" - }, - "line": { - "color": "rgb(17,17,17)" - } - }, - "header": { - "fill": { - "color": "#2a3f5f" - }, - "line": { - "color": "rgb(17,17,17)" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "rgb(17,17,17)", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#f2f5fa" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "rgb(17,17,17)", - "plot_bgcolor": "rgb(17,17,17)", - "polar": { - "bgcolor": "rgb(17,17,17)", - "angularaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "rgb(17,17,17)", - "aaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "baxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "caxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "#283442", - "linecolor": "#506784", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "#283442", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "#283442", - "linecolor": "#506784", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "#283442", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#f2f5fa" - } - }, - "annotationdefaults": { - "arrowcolor": "#f2f5fa", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "rgb(17,17,17)", - "landcolor": "rgb(17,17,17)", - "subunitcolor": "#506784", - "showland": true, - "showlakes": true, - "lakecolor": "rgb(17,17,17)" - }, - "title": { - "x": 0.05 - }, - "updatemenudefaults": { - "bgcolor": "#506784", - "borderwidth": 0 - }, - "sliderdefaults": { - "bgcolor": "#C8D4E3", - "borderwidth": 1, - "bordercolor": "rgb(17,17,17)", - "tickwidth": 0 - }, - "mapbox": { - "style": "dark" - } - } - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 38 - }, - { - "cell_type": "markdown", - "source": "More complex events can also be plotted.", - "metadata": { - "collapsed": false - }, - "id": "4e3a3a43ce75687f" - }, - { - "cell_type": "code", - "source": [ - "complement = event.complement()\n", - "limiting_event = SimpleEvent({x: closed(-1, 2), y: closed(-1, 2)}).as_composite_set()\n", - "result = complement & limiting_event\n", - "fig = go.Figure(result.plot(), result.plotly_layout())\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:36.025615Z", - "start_time": "2024-06-03T12:18:36.020406Z" - } - }, - "id": "d22ef1b9c9b7c767", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "fill": "toself", - "legendgroup": "139858348468880", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": true, - "x": [ - -1, - -1, - 0, - 0, - -1, - null, - 1, - 1, - 2, - 2, - 1, - null - ], - "y": [ - -1, - 2, - 2, - -1, - -1, - null, - -1, - 2, - 2, - -1, - -1, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "139858348468880", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 0, - 0, - 1, - 1, - 0, - null, - 0, - 0, - 1, - 1, - 0, - null - ], - "y": [ - -1, - 0, - 0, - -1, - -1, - null, - 1, - 2, - 2, - 1, - 1, - null - ], - "type": "scatter" - } - ], - "layout": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "marker": { - "line": { - "color": "#283442" - } - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#f2f5fa" - }, - "error_y": { - "color": "#f2f5fa" - }, - "marker": { - "line": { - "color": "rgb(17,17,17)", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "marker": { - "line": { - "color": "#283442" - } - }, - "type": "scattergl" - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#A2B1C6", - "gridcolor": "#506784", - "linecolor": "#506784", - "minorgridcolor": "#506784", - "startlinecolor": "#A2B1C6" - }, - "baxis": { - "endlinecolor": "#A2B1C6", - "gridcolor": "#506784", - "linecolor": "#506784", - "minorgridcolor": "#506784", - "startlinecolor": "#A2B1C6" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#506784" - }, - "line": { - "color": "rgb(17,17,17)" - } - }, - "header": { - "fill": { - "color": "#2a3f5f" - }, - "line": { - "color": "rgb(17,17,17)" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "rgb(17,17,17)", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#f2f5fa" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "rgb(17,17,17)", - "plot_bgcolor": "rgb(17,17,17)", - "polar": { - "bgcolor": "rgb(17,17,17)", - "angularaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "rgb(17,17,17)", - "aaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "baxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "caxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "#283442", - "linecolor": "#506784", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "#283442", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "#283442", - "linecolor": "#506784", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "#283442", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#f2f5fa" - } - }, - "annotationdefaults": { - "arrowcolor": "#f2f5fa", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "rgb(17,17,17)", - "landcolor": "rgb(17,17,17)", - "subunitcolor": "#506784", - "showland": true, - "showlakes": true, - "lakecolor": "rgb(17,17,17)" - }, - "title": { - "x": 0.05 - }, - "updatemenudefaults": { - "bgcolor": "#506784", - "borderwidth": 0 - }, - "sliderdefaults": { - "bgcolor": "#C8D4E3", - "borderwidth": 1, - "bordercolor": "rgb(17,17,17)", - "tickwidth": 0 - }, - "mapbox": { - "style": "dark" - } - } - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 39 - }, - { - "cell_type": "markdown", - "source": [ - "Serialization from and to json is also possible." - ], - "metadata": { - "collapsed": false - }, - "id": "45dd9ba23b5c9d74" - }, - { - "cell_type": "code", - "source": [ - "complement_json = complement.to_json()\n", - "complement_from_json = Event.from_json(complement_json)\n", - "complement_from_json == complement" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:36.028257Z", - "start_time": "2024-06-03T12:18:36.026074Z" - } - }, - "id": "12b0c378134e8a09", - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 40, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 40 - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/examples/logo_generation.ipynb b/examples/logo_generation.ipynb deleted file mode 100644 index 38b8373..0000000 --- a/examples/logo_generation.ipynb +++ /dev/null @@ -1,4414 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "source": [ - "# Advanced Use of Random Events\n", - "\n", - "In this tutorial we will look at a humorous application of random events. This examples shows, that elements from the product algebra, can take almost any shape, such as a tomato. \n", - "First, we import the necessary packages and define two variables." - ], - "metadata": { - "collapsed": false - }, - "id": "398a700bb678f08f" - }, - { - "cell_type": "code", - "id": "initial_id", - "metadata": { - "collapsed": true, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:57.124014Z", - "start_time": "2024-06-03T12:18:57.094109Z" - } - }, - "source": [ - "import os.path\n", - "from random_events.product_algebra import Event, SimpleEvent\n", - "from random_events.variable import Continuous\n", - "from random_events.interval import *\n", - "from PIL import Image\n", - "import numpy as np\n", - "import plotly\n", - "plotly.offline.init_notebook_mode()\n", - "import plotly.graph_objects as go" - ], - "outputs": [ - { - "data": { - "text/html": [ - " \n", - " " - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 6 - }, - { - "cell_type": "code", - "source": [ - "x = Continuous(\"x\")\n", - "y = Continuous(\"y\")" - ], - "metadata": { - "collapsed": false - }, - "id": "29d0b28a5e6f48ca", - "outputs": [], - "execution_count": 7 - }, - { - "cell_type": "markdown", - "source": [ - "Next, let's load the logo of this package." - ], - "metadata": { - "collapsed": false - }, - "id": "754e1b2e8e1fb9f5" - }, - { - "cell_type": "code", - "source": [ - "path = os.path.join(\"..\", \"doc\", \"logo\", \"Tomato.png\")\n", - "image = im=Image.open(path)\n", - "image" - ], - "metadata": { - "collapsed": false - }, - "id": "6dfb4ca602b7491b", - "outputs": [ - { - "data": { - "text/plain": [ - "" - ], - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMYAAAC7CAYAAAA+J+FCAAAGNklEQVR4Ae3dMZIUVxBFUUahJWDBpliNLJmyWI02NVjsAaEQEbj/datyyHoHCyN/Z+Z9daOM/jH98s6/Rwh8e+TQwZmXgxolAwR+G+ihBQLrCBBjXWQGniBAjAnKeqwjQIx1kRl4ggAxJijrsY4AMdZFZuAJAsSYoKzHOgLEWBeZgScIEGOCsh7rCBBjXWQGniDgCsJPysfXPP78+4+fp/7H//316XPyabJLaIW13hghMOUdBIjRkbMtQwLECIEp7yBAjI6cbRkSIEYITHkHAWJ05GzLkAAxQmDKOwgQoyNnW4YEiBECU95BgBgdOdsyJOBaQQjsR7nrI49xW3PKG2NNVAadJECMSdp6rSFAjDVRGXSSADEmaeu1hgAx1kRl0EkCxJikrdcaAsRYE5VBJwkQY5K2XmsIEGNNVAadJECMSdp6rSHw+5pJHxv0+OrGYx+/5tRVHG57pcgbY82zbdBJAsSYpK3XGgLEWBOVQScJEGOStl5rCBBjTVQGnSRAjEnaeq0hQIw1URl0kgAxJmnrtYYAMdZEZdBJAsSYpK3XGgK/ylf6l1xZuOoHXtake/Gg4Q/dJNO8+XPpjZHEpbaGADFqorZoQoAYCS21NQSIURO1RRMCxEhoqa0hQIyaqC2aECBGQkttDQFi1ERt0YQAMRJaamsIEKMmaosmBK786n3VNY/kesO2qya/wm7JDMkD/L32kmfYGyNMQXkHAWJ05GzLkAAxQmDKOwgQoyNnW4YEiBECU95BgBgdOdsyJECMEJjyDgLE6MjZliEBYoTAlHcQIEZHzrYMCaQ/HHN8zePrh4/Ho7z/8npcmxQm1xCieT99Ph7jqusjd94tyuLL6/Ez+T204+sj3hjHj7jCJgLEaErbrscEiHGMSmETAWI0pW3XYwLEOEalsIkAMZrStusxAWIco1LYRIAYTWnb9ZgAMY5RKWwiQIymtO16TOD4K/Ifn3j89Xv4tf7xwElhMkPyuUntVddd7PZfCiHf4+fdGyN5ytXWECBGTdQWTQgQI6GltoYAMWqitmhCgBgJLbU1BIhRE7VFEwLESGiprSFAjJqoLZoQIEZCS20NAWLURG3RhMC/X5Ffcs0jGUItAhMEkusj3hgTieixjgAx1kVm4AkCxJigrMc6AsRYF5mBJwgQY4KyHusIEGNdZAaeIECMCcp6rCNAjHWRGXiCADEmKOuxjgAx1kVm4AkCxJigrMc6AsRYF5mBJwgQY4KyHusIEGNdZAaeIECMCcp6rCNAjHWRGXiCADEmKOuxjgAx1kVm4AkCxJigrMc6AsRYF5mBJwgQY4KyHusIEGNdZAaeIECMCcp6rCNAjHWRGXiCADEmKOuxjgAx1kVm4AkCxJigrMc6AsRYF5mBJwgQY4KyHusIEGNdZAaeIECMCcp6rCNAjHWRGXiCADEmKOuxjgAx1kVm4AkCxJigrMc6AsRYF5mBJwgQY4KyHusIEGNdZAaeIECMCcp6rCNAjHWRGXiCADEmKOuxjgAx1kVm4AkCxJigrMc6Ai/hxN9O679++Hhaqg6Bhwm8//KanD1+3r0xEqxqawgQoyZqiyYEiJHQUltDgBg1UVs0IUCMhJbaGgLEqInaogkBYiS01NYQIEZN1BZNCBAjoaW2hgAxaqK2aEKAGAkttTUEiFETtUUTAsRIaKmtIUCMmqgtmhAgRkJLbQ0BYtREbdGEADESWmprCBCjJmqLJgSIkdBSW0OAGDVRWzQhQIyEltoaAsd/NeEBIv6iyAPQHHn37qq//JGw9cZIaKmtIUCMmqgtmhAgRkJLbQ0BYtREbdGEADESWmprCBCjJmqLJgSIkdBSW0OAGDVRWzQhQIyEltoaAsSoidqiCYErr4QkcxxfH0k+1I/XJLTy2vDqRtLgzZ9Lb4wkLrU1BIhRE7VFEwLESGiprSFAjJqoLZoQIEZCS20NAWLURG3RhAAxElpqawgQoyZqiyYEiJHQUltDgBg1UVs0IfDmX70nwz5Qe8lVkwfmuOuR2z4/3hh3fWTt9RQBYjyFz+G7EiDGXZO111MEiPEUPofvSoAYd03WXk8RIMZT+By+KwFi3DVZez1FgBhP4XP4rgSIcddk7fUUAWI8hc/huxL4B6D7SoucxoO8AAAAAElFTkSuQmCC" - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 8 - }, - { - "cell_type": "markdown", - "source": [ - "We can express this image as an event that can be reasoned about." - ], - "metadata": { - "collapsed": false - }, - "id": "89195166d6606571" - }, - { - "cell_type": "code", - "source": [ - "image = np.array(image.resize((18, 17), Image.NEAREST))\n", - "colors = np.unique(image.reshape((image.shape[0] * image.shape[1], image.shape[2])), axis=0)[1:]\n", - "def indices_to_complex_event(indices: np.array) -> Event:\n", - " result = Event()\n", - " for index in indices:\n", - " event = SimpleEvent({y: closed_open(-index[0] - 1, -index[0]),\n", - " x: closed_open(index[1], index[1] + 1)})\n", - " result.simple_sets.add(event)\n", - " return result.simplify()\n", - "\n", - "fig = go.Figure()\n", - "\n", - "complex_events = []\n", - "\n", - "for color in colors:\n", - " pixel_indices = np.transpose(np.nonzero(np.all(image == color, axis=-1)))\n", - " complex_event = indices_to_complex_event(pixel_indices)\n", - " complex_events.append(complex_event)\n", - " traces = complex_event.plot(f\"rgb({color[0]},{color[1]},{color[2]})\")\n", - " fig.update_layout(complex_event.plotly_layout())\n", - " fig.add_traces(traces)\n", - "\n", - "fig.update_layout(title=\"Random Events Tomato\")\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:57.717717Z", - "start_time": "2024-06-03T12:18:57.129794Z" - } - }, - "id": "767c932bc1a6beb", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": true, - "x": [ - 0, - 0, - 1, - 1, - 0, - null, - 17, - 17, - 18, - 18, - 17, - null - ], - "y": [ - -12, - -8, - -8, - -12, - -12, - null, - -12, - -8, - -8, - -12, - -12, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 1, - 1, - 2, - 2, - 1, - null, - 1, - 1, - 2, - 2, - 1, - null, - 16, - 16, - 17, - 17, - 16, - null, - 16, - 16, - 17, - 17, - 16, - null - ], - "y": [ - -14, - -12, - -12, - -14, - -14, - null, - -8, - -6, - -6, - -8, - -8, - null, - -14, - -12, - -12, - -14, - -14, - null, - -8, - -6, - -6, - -8, - -8, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 2, - 2, - 3, - 3, - 2, - null, - 2, - 2, - 3, - 3, - 2, - null, - 15, - 15, - 16, - 16, - 15, - null, - 15, - 15, - 16, - 16, - 15, - null - ], - "y": [ - -15, - -14, - -14, - -15, - -15, - null, - -6, - -5, - -5, - -6, - -6, - null, - -15, - -14, - -14, - -15, - -15, - null, - -6, - -5, - -5, - -6, - -6, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 3, - 3, - 4, - 4, - 3, - null, - 3, - 3, - 4, - 4, - 3, - null, - 14, - 14, - 15, - 15, - 14, - null, - 14, - 14, - 15, - 15, - 14, - null - ], - "y": [ - -16, - -15, - -15, - -16, - -16, - null, - -8, - -4, - -4, - -8, - -8, - null, - -16, - -15, - -15, - -16, - -16, - null, - -8, - -4, - -4, - -8, - -8, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 4, - 4, - 5, - 5, - 4, - null, - 4, - 4, - 5, - 5, - 4, - null, - 4, - 4, - 5, - 5, - 4, - null, - 13, - 13, - 14, - 14, - 13, - null, - 13, - 13, - 14, - 14, - 13, - null, - 13, - 13, - 14, - 14, - 13, - null - ], - "y": [ - -16, - -15, - -15, - -16, - -16, - null, - -8, - -7, - -7, - -8, - -8, - null, - -5, - -4, - -4, - -5, - -5, - null, - -16, - -15, - -15, - -16, - -16, - null, - -8, - -7, - -7, - -8, - -8, - null, - -5, - -4, - -4, - -5, - -5, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 5, - 5, - 6, - 6, - 5, - null, - 5, - 5, - 6, - 6, - 5, - null, - 5, - 5, - 6, - 6, - 5, - null, - 7, - 7, - 8, - 8, - 7, - null, - 7, - 7, - 8, - 8, - 7, - null, - 7, - 7, - 8, - 8, - 7, - null, - 10, - 10, - 11, - 11, - 10, - null, - 10, - 10, - 11, - 11, - 10, - null, - 10, - 10, - 11, - 11, - 10, - null, - 12, - 12, - 13, - 13, - 12, - null, - 12, - 12, - 13, - 13, - 12, - null, - 12, - 12, - 13, - 13, - 12, - null - ], - "y": [ - -17, - -16, - -16, - -17, - -17, - null, - -7, - -6, - -6, - -7, - -7, - null, - -4, - -3, - -3, - -4, - -4, - null, - -17, - -16, - -16, - -17, - -17, - null, - -7, - -6, - -6, - -7, - -7, - null, - -4, - -3, - -3, - -4, - -4, - null, - -17, - -16, - -16, - -17, - -17, - null, - -7, - -6, - -6, - -7, - -7, - null, - -4, - -3, - -3, - -4, - -4, - null, - -17, - -16, - -16, - -17, - -17, - null, - -7, - -6, - -6, - -7, - -7, - null, - -4, - -3, - -3, - -4, - -4, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 6, - 6, - 7, - 7, - 6, - null, - 6, - 6, - 7, - 7, - 6, - null, - 6, - 6, - 7, - 7, - 6, - null, - 6, - 6, - 7, - 7, - 6, - null - ], - "y": [ - -17, - -16, - -16, - -17, - -17, - null, - -6, - -5, - -5, - -6, - -6, - null, - -4, - -3, - -3, - -4, - -4, - null, - -2, - -1, - -1, - -2, - -2, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 7, - 7, - 8, - 8, - 7, - null, - 7, - 7, - 8, - 8, - 7, - null - ], - "y": [ - -3, - -2, - -2, - -3, - -3, - null, - -1, - 0, - 0, - -1, - -1, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 8, - 8, - 9, - 9, - 8, - null, - 8, - 8, - 9, - 9, - 8, - null, - 8, - 8, - 9, - 9, - 8, - null - ], - "y": [ - -17, - -16, - -16, - -17, - -17, - null, - -8, - -7, - -7, - -8, - -8, - null, - -1, - 0, - 0, - -1, - -1, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 9, - 9, - 10, - 10, - 9, - null, - 9, - 9, - 10, - 10, - 9, - null, - 9, - 9, - 10, - 10, - 9, - null - ], - "y": [ - -17, - -16, - -16, - -17, - -17, - null, - -8, - -7, - -7, - -8, - -8, - null, - -2, - -1, - -1, - -2, - -2, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 10, - 10, - 11, - 11, - 10, - null - ], - "y": [ - -3, - -2, - -2, - -3, - -3, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112733040", - "line": { - "color": "rgb(0,0,0)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 11, - 11, - 12, - 12, - 11, - null, - 11, - 11, - 12, - 12, - 11, - null, - 11, - 11, - 12, - 12, - 11, - null - ], - "y": [ - -17, - -16, - -16, - -17, - -17, - null, - -6, - -5, - -5, - -6, - -6, - null, - -4, - -3, - -3, - -4, - -4, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112918272", - "line": { - "color": "rgb(124,176,118)" - }, - "mode": "lines", - "name": "Event", - "showlegend": true, - "x": [ - 4, - 4, - 5, - 5, - 4, - null, - 8, - 8, - 10, - 10, - 8, - null - ], - "y": [ - -7, - -5, - -5, - -7, - -7, - null, - -7, - -5, - -5, - -7, - -7, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112918272", - "line": { - "color": "rgb(124,176,118)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 5, - 5, - 6, - 6, - 5, - null - ], - "y": [ - -6, - -4, - -4, - -6, - -6, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112918272", - "line": { - "color": "rgb(124,176,118)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 6, - 6, - 13, - 13, - 6, - null - ], - "y": [ - -5, - -4, - -4, - -5, - -5, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112918272", - "line": { - "color": "rgb(124,176,118)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 7, - 7, - 8, - 8, - 7, - null, - 7, - 7, - 8, - 8, - 7, - null - ], - "y": [ - -6, - -5, - -5, - -6, - -6, - null, - -2, - -1, - -1, - -2, - -2, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112918272", - "line": { - "color": "rgb(124,176,118)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 8, - 8, - 9, - 9, - 8, - null - ], - "y": [ - -4, - -1, - -1, - -4, - -4, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112918272", - "line": { - "color": "rgb(124,176,118)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 9, - 9, - 10, - 10, - 9, - null - ], - "y": [ - -4, - -2, - -2, - -4, - -4, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112918272", - "line": { - "color": "rgb(124,176,118)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 10, - 10, - 11, - 11, - 10, - null, - 12, - 12, - 14, - 14, - 12, - null - ], - "y": [ - -6, - -5, - -5, - -6, - -6, - null, - -6, - -5, - -5, - -6, - -6, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112918272", - "line": { - "color": "rgb(124,176,118)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 13, - 13, - 14, - 14, - 13, - null - ], - "y": [ - -7, - -6, - -6, - -7, - -7, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112417408", - "line": { - "color": "rgb(236,26,27)" - }, - "mode": "lines", - "name": "Event", - "showlegend": true, - "x": [ - 1, - 1, - 2, - 2, - 1, - null, - 16, - 16, - 17, - 17, - 16, - null - ], - "y": [ - -12, - -8, - -8, - -12, - -12, - null, - -12, - -8, - -8, - -12, - -12, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112417408", - "line": { - "color": "rgb(236,26,27)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 2, - 2, - 3, - 3, - 2, - null - ], - "y": [ - -14, - -6, - -6, - -14, - -14, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112417408", - "line": { - "color": "rgb(236,26,27)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 3, - 3, - 5, - 5, - 3, - null, - 13, - 13, - 15, - 15, - 13, - null - ], - "y": [ - -15, - -8, - -8, - -15, - -15, - null, - -15, - -8, - -8, - -15, - -15, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112417408", - "line": { - "color": "rgb(236,26,27)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 5, - 5, - 8, - 8, - 5, - null - ], - "y": [ - -16, - -7, - -7, - -16, - -16, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112417408", - "line": { - "color": "rgb(236,26,27)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 6, - 6, - 7, - 7, - 6, - null, - 11, - 11, - 12, - 12, - 11, - null, - 15, - 15, - 16, - 16, - 15, - null - ], - "y": [ - -7, - -6, - -6, - -7, - -7, - null, - -7, - -6, - -6, - -7, - -7, - null, - -7, - -6, - -6, - -7, - -7, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112417408", - "line": { - "color": "rgb(236,26,27)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 8, - 8, - 13, - 13, - 8, - null - ], - "y": [ - -16, - -8, - -8, - -16, - -16, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112417408", - "line": { - "color": "rgb(236,26,27)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 10, - 10, - 13, - 13, - 10, - null, - 15, - 15, - 16, - 16, - 15, - null - ], - "y": [ - -8, - -7, - -7, - -8, - -8, - null, - -8, - -7, - -7, - -8, - -8, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004112417408", - "line": { - "color": "rgb(236,26,27)" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 15, - 15, - 16, - 16, - 15, - null - ], - "y": [ - -14, - -8, - -8, - -14, - -14, - null - ], - "type": "scatter" - } - ], - "layout": { - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "marker": { - "line": { - "color": "#283442" - } - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#f2f5fa" - }, - "error_y": { - "color": "#f2f5fa" - }, - "marker": { - "line": { - "color": "rgb(17,17,17)", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "marker": { - "line": { - "color": "#283442" - } - }, - "type": "scattergl" - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#A2B1C6", - "gridcolor": "#506784", - "linecolor": "#506784", - "minorgridcolor": "#506784", - "startlinecolor": "#A2B1C6" - }, - "baxis": { - "endlinecolor": "#A2B1C6", - "gridcolor": "#506784", - "linecolor": "#506784", - "minorgridcolor": "#506784", - "startlinecolor": "#A2B1C6" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#506784" - }, - "line": { - "color": "rgb(17,17,17)" - } - }, - "header": { - "fill": { - "color": "#2a3f5f" - }, - "line": { - "color": "rgb(17,17,17)" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "rgb(17,17,17)", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#f2f5fa" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "rgb(17,17,17)", - "plot_bgcolor": "rgb(17,17,17)", - "polar": { - "bgcolor": "rgb(17,17,17)", - "angularaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "rgb(17,17,17)", - "aaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "baxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "caxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "#283442", - "linecolor": "#506784", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "#283442", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "#283442", - "linecolor": "#506784", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "#283442", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#f2f5fa" - } - }, - "annotationdefaults": { - "arrowcolor": "#f2f5fa", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "rgb(17,17,17)", - "landcolor": "rgb(17,17,17)", - "subunitcolor": "#506784", - "showland": true, - "showlakes": true, - "lakecolor": "rgb(17,17,17)" - }, - "title": { - "x": 0.05 - }, - "updatemenudefaults": { - "bgcolor": "#506784", - "borderwidth": 0 - }, - "sliderdefaults": { - "bgcolor": "#C8D4E3", - "borderwidth": 1, - "bordercolor": "rgb(17,17,17)", - "tickwidth": 0 - }, - "mapbox": { - "style": "dark" - } - } - }, - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "title": { - "text": "Random Events Tomato" - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 9 - }, - { - "cell_type": "markdown", - "source": [ - "While the shape of a tomato as an event that can be used for probabilistic reasoning serves no particular research, it showcases that random events can take approximately any shape and not \"just\" rectangles.\n", - "Unions of complex events of any shape can also performed to get the tomato as an entire event and not a union of three different events." - ], - "metadata": { - "collapsed": false - }, - "id": "5bdcd00ab2fac7cf" - }, - { - "cell_type": "code", - "source": [ - "entire_event = complex_events[0] | complex_events[1] | complex_events[2]\n", - "fig = go.Figure(entire_event.plot(), entire_event.plotly_layout())\n", - "fig.update_layout(title=\"Random Events Tomato as one Event\")\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:18:57.880334Z", - "start_time": "2024-06-03T12:18:57.718292Z" - } - }, - "id": "ce38e8a948d2a0d5", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": true, - "x": [ - 0, - 0, - 2, - 2, - 0, - null, - 16, - 16, - 18, - 18, - 16, - null - ], - "y": [ - -12, - -8, - -8, - -12, - -12, - null, - -12, - -8, - -8, - -12, - -12, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 1, - 1, - 2, - 2, - 1, - null, - 1, - 1, - 2, - 2, - 1, - null, - 16, - 16, - 17, - 17, - 16, - null, - 16, - 16, - 17, - 17, - 16, - null - ], - "y": [ - -14, - -12, - -12, - -14, - -14, - null, - -8, - -6, - -6, - -8, - -8, - null, - -14, - -12, - -12, - -14, - -14, - null, - -8, - -6, - -6, - -8, - -8, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 2, - 2, - 3, - 3, - 2, - null - ], - "y": [ - -14, - -6, - -6, - -14, - -14, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 2, - 2, - 3, - 3, - 2, - null, - 2, - 2, - 3, - 3, - 2, - null, - 15, - 15, - 16, - 16, - 15, - null, - 15, - 15, - 16, - 16, - 15, - null - ], - "y": [ - -15, - -14, - -14, - -15, - -15, - null, - -6, - -5, - -5, - -6, - -6, - null, - -15, - -14, - -14, - -15, - -15, - null, - -6, - -5, - -5, - -6, - -6, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 3, - 3, - 4, - 4, - 3, - null, - 3, - 3, - 4, - 4, - 3, - null, - 14, - 14, - 15, - 15, - 14, - null, - 14, - 14, - 15, - 15, - 14, - null - ], - "y": [ - -16, - -15, - -15, - -16, - -16, - null, - -8, - -4, - -4, - -8, - -8, - null, - -16, - -15, - -15, - -16, - -16, - null, - -8, - -4, - -4, - -8, - -8, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 3, - 3, - 5, - 5, - 3, - null, - 13, - 13, - 15, - 15, - 13, - null - ], - "y": [ - -15, - -8, - -8, - -15, - -15, - null, - -15, - -8, - -8, - -15, - -15, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 4, - 4, - 5, - 5, - 4, - null, - 8, - 8, - 10, - 10, - 8, - null - ], - "y": [ - -7, - -5, - -5, - -7, - -7, - null, - -7, - -5, - -5, - -7, - -7, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 4, - 4, - 5, - 5, - 4, - null, - 4, - 4, - 5, - 5, - 4, - null, - 4, - 4, - 5, - 5, - 4, - null, - 13, - 13, - 14, - 14, - 13, - null, - 13, - 13, - 14, - 14, - 13, - null, - 13, - 13, - 14, - 14, - 13, - null - ], - "y": [ - -16, - -15, - -15, - -16, - -16, - null, - -8, - -7, - -7, - -8, - -8, - null, - -5, - -4, - -4, - -5, - -5, - null, - -16, - -15, - -15, - -16, - -16, - null, - -8, - -7, - -7, - -8, - -8, - null, - -5, - -4, - -4, - -5, - -5, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 5, - 5, - 6, - 6, - 5, - null - ], - "y": [ - -6, - -4, - -4, - -6, - -6, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 5, - 5, - 6, - 6, - 5, - null, - 5, - 5, - 6, - 6, - 5, - null, - 5, - 5, - 6, - 6, - 5, - null, - 7, - 7, - 8, - 8, - 7, - null, - 7, - 7, - 8, - 8, - 7, - null, - 7, - 7, - 8, - 8, - 7, - null, - 10, - 10, - 11, - 11, - 10, - null, - 10, - 10, - 11, - 11, - 10, - null, - 10, - 10, - 11, - 11, - 10, - null, - 12, - 12, - 13, - 13, - 12, - null, - 12, - 12, - 13, - 13, - 12, - null, - 12, - 12, - 13, - 13, - 12, - null - ], - "y": [ - -17, - -16, - -16, - -17, - -17, - null, - -7, - -6, - -6, - -7, - -7, - null, - -4, - -3, - -3, - -4, - -4, - null, - -17, - -16, - -16, - -17, - -17, - null, - -7, - -6, - -6, - -7, - -7, - null, - -4, - -3, - -3, - -4, - -4, - null, - -17, - -16, - -16, - -17, - -17, - null, - -7, - -6, - -6, - -7, - -7, - null, - -4, - -3, - -3, - -4, - -4, - null, - -17, - -16, - -16, - -17, - -17, - null, - -7, - -6, - -6, - -7, - -7, - null, - -4, - -3, - -3, - -4, - -4, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 5, - 5, - 8, - 8, - 5, - null - ], - "y": [ - -16, - -7, - -7, - -16, - -16, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 6, - 6, - 7, - 7, - 6, - null, - 6, - 6, - 7, - 7, - 6, - null, - 6, - 6, - 7, - 7, - 6, - null, - 6, - 6, - 7, - 7, - 6, - null - ], - "y": [ - -17, - -16, - -16, - -17, - -17, - null, - -6, - -5, - -5, - -6, - -6, - null, - -4, - -3, - -3, - -4, - -4, - null, - -2, - -1, - -1, - -2, - -2, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 6, - 6, - 7, - 7, - 6, - null, - 11, - 11, - 12, - 12, - 11, - null, - 13, - 13, - 14, - 14, - 13, - null, - 15, - 15, - 16, - 16, - 15, - null - ], - "y": [ - -7, - -6, - -6, - -7, - -7, - null, - -7, - -6, - -6, - -7, - -7, - null, - -7, - -6, - -6, - -7, - -7, - null, - -7, - -6, - -6, - -7, - -7, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 6, - 6, - 13, - 13, - 6, - null - ], - "y": [ - -5, - -4, - -4, - -5, - -5, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 7, - 7, - 8, - 8, - 7, - null, - 7, - 7, - 8, - 8, - 7, - null - ], - "y": [ - -6, - -5, - -5, - -6, - -6, - null, - -3, - 0, - 0, - -3, - -3, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 8, - 8, - 9, - 9, - 8, - null, - 8, - 8, - 9, - 9, - 8, - null, - 8, - 8, - 9, - 9, - 8, - null - ], - "y": [ - -17, - -16, - -16, - -17, - -17, - null, - -8, - -7, - -7, - -8, - -8, - null, - -4, - 0, - 0, - -4, - -4, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 8, - 8, - 13, - 13, - 8, - null - ], - "y": [ - -16, - -8, - -8, - -16, - -16, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 9, - 9, - 10, - 10, - 9, - null, - 9, - 9, - 10, - 10, - 9, - null, - 9, - 9, - 10, - 10, - 9, - null - ], - "y": [ - -17, - -16, - -16, - -17, - -17, - null, - -8, - -7, - -7, - -8, - -8, - null, - -4, - -1, - -1, - -4, - -4, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 10, - 10, - 11, - 11, - 10, - null - ], - "y": [ - -3, - -2, - -2, - -3, - -3, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 10, - 10, - 11, - 11, - 10, - null, - 12, - 12, - 14, - 14, - 12, - null - ], - "y": [ - -6, - -5, - -5, - -6, - -6, - null, - -6, - -5, - -5, - -6, - -6, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 10, - 10, - 13, - 13, - 10, - null, - 15, - 15, - 16, - 16, - 15, - null - ], - "y": [ - -8, - -7, - -7, - -8, - -8, - null, - -8, - -7, - -7, - -8, - -8, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 11, - 11, - 12, - 12, - 11, - null, - 11, - 11, - 12, - 12, - 11, - null, - 11, - 11, - 12, - 12, - 11, - null - ], - "y": [ - -17, - -16, - -16, - -17, - -17, - null, - -6, - -5, - -5, - -6, - -6, - null, - -4, - -3, - -3, - -4, - -4, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140004147536320", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 15, - 15, - 16, - 16, - 15, - null - ], - "y": [ - -14, - -8, - -8, - -14, - -14, - null - ], - "type": "scatter" - } - ], - "layout": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "marker": { - "line": { - "color": "#283442" - } - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#f2f5fa" - }, - "error_y": { - "color": "#f2f5fa" - }, - "marker": { - "line": { - "color": "rgb(17,17,17)", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "marker": { - "line": { - "color": "#283442" - } - }, - "type": "scattergl" - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#A2B1C6", - "gridcolor": "#506784", - "linecolor": "#506784", - "minorgridcolor": "#506784", - "startlinecolor": "#A2B1C6" - }, - "baxis": { - "endlinecolor": "#A2B1C6", - "gridcolor": "#506784", - "linecolor": "#506784", - "minorgridcolor": "#506784", - "startlinecolor": "#A2B1C6" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#506784" - }, - "line": { - "color": "rgb(17,17,17)" - } - }, - "header": { - "fill": { - "color": "#2a3f5f" - }, - "line": { - "color": "rgb(17,17,17)" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "rgb(17,17,17)", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#f2f5fa" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "rgb(17,17,17)", - "plot_bgcolor": "rgb(17,17,17)", - "polar": { - "bgcolor": "rgb(17,17,17)", - "angularaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "rgb(17,17,17)", - "aaxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "baxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - }, - "caxis": { - "gridcolor": "#506784", - "linecolor": "#506784", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "#283442", - "linecolor": "#506784", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "#283442", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "#283442", - "linecolor": "#506784", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "#283442", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "rgb(17,17,17)", - "gridcolor": "#506784", - "linecolor": "#506784", - "showbackground": true, - "ticks": "", - "zerolinecolor": "#C8D4E3", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#f2f5fa" - } - }, - "annotationdefaults": { - "arrowcolor": "#f2f5fa", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "rgb(17,17,17)", - "landcolor": "rgb(17,17,17)", - "subunitcolor": "#506784", - "showland": true, - "showlakes": true, - "lakecolor": "rgb(17,17,17)" - }, - "title": { - "x": 0.05 - }, - "updatemenudefaults": { - "bgcolor": "#506784", - "borderwidth": 0 - }, - "sliderdefaults": { - "bgcolor": "#C8D4E3", - "borderwidth": 1, - "bordercolor": "rgb(17,17,17)", - "tickwidth": 0 - }, - "mapbox": { - "style": "dark" - } - } - }, - "title": { - "text": "Random Events Tomato as one Event" - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 10 - }, - { - "cell_type": "markdown", - "source": [ - "I hope this bizarre examples aids you in understanding of the product algebra capabilities. \n", - "Using this event, you can calculate things like the probability of a tomato or the conditional distribution given a tomato. " - ], - "metadata": { - "collapsed": false - }, - "id": "576ab8ad7c53f09e" - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/examples/product_spaces.ipynb b/examples/product_spaces.ipynb deleted file mode 100644 index 38a0519..0000000 --- a/examples/product_spaces.ipynb +++ /dev/null @@ -1,10612 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "source": [ - "# Product $\\sigma$-Algebra\n", - "\n", - "This tutorial is part of a bigger series on probabilistic machine learning and aids in understanding product $\\sigma$-algebras.\n", - "At the end of this notebook, you will understand...\n", - "\n", - "- The Definition of the $\\sigma$-Algebra\n", - "- Why these concepts matter, especially for robotics\n", - "- How to apply them using the package \n", - "\n", - "\n", - "## Motivation\n", - "\n", - "Since studying concepts like the $\\sigma$-Algebra is dry, I want to motivate you on why this matters and you should take the time to think about the $\\sigma$-Algebra and specially the Product $\\sigma$-Algebra:\n", - "\n", - "- **Foundations of probability theory**: $\\sigma$-algebras are the building blocks for defining probability in a rigorous way. By understanding them, you gain a deeper understanding of how probabilities are assigned to events.\n", - "- **Working with complex events**: In real-world scenarios, events can be intricate. Sigma algebras allow you to describe not just simple events but also unions, intersections, and complements of these events, giving you a powerful tool to analyze probabilities of more complex situations.\n", - "- **Connection to advanced math**: Sigma algebras bridge the gap between set theory and advanced mathematical concepts like measure theory and integration. Studying them opens doors to these powerful tools used in various scientific fields.\n", - "\n", - "\n", - "If you are interested in robotics, it is also important since:\n", - "\n", - "- **Reasoning with uncertainty**: Robots often operate in environments with uncertainty. $\\sigma$ algebras provide a mathematical foundation to represent uncertain events and reason about the probability of different events happening (like sensor readings or obstacles appearing).\n", - "- **Decision making under probability**: Many robotic tasks involve making decisions based on probabilities. By understanding $\\sigma$-algebras, you can build algorithms that consider the chance of different outcomes and choose the action with the highest probability of success.\n", - "- **Planning and control under uncertainty**: Planning robot actions often requires considering various possibilities. $\\sigma$-algebras allow you to create probabilistic models of the environment, enabling robots to plan and control their movements while accounting for uncertainties.\n", - "\n", - "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", - "Understanding the shape of such events is a key competence to building (new) tractable probabilistic models.\n", - "In this tutorial, we will work with some visualizations of said events, to get a better understanding of their shape, behavior and math." - ], - "metadata": { - "collapsed": false - }, - "id": "29699f791234335" - }, - { - "cell_type": "markdown", - "source": [ - "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 let $\\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 - }, - "id": "e241ab4a9df8dd28" - }, - { - "cell_type": "code", - "source": [ - "from itertools import chain, combinations\n", - " \n", - "\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", - "E = {\"a\", \"b\", \"c\"}\n", - "powerset_of_E = powerset(E)\n", - "powerset_of_E" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:22.799813Z", - "start_time": "2024-06-03T12:28:22.794999Z" - } - }, - "id": "efd225f025a25755", - "outputs": [ - { - "data": { - "text/plain": [ - "[set(),\n", - " {'c'},\n", - " {'b'},\n", - " {'a'},\n", - " {'b', 'c'},\n", - " {'a', 'c'},\n", - " {'a', 'b'},\n", - " {'a', 'b', 'c'}]" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 1 - }, - { - "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", - "source": [ - "E in powerset_of_E" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:22.829140Z", - "start_time": "2024-06-03T12:28:22.827249Z" - } - }, - "id": "4718cfb47e7aabf5", - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 2 - }, - { - "cell_type": "markdown", - "source": [ - "Next, check if it contains all set differences:" - ], - "metadata": { - "collapsed": false - }, - "id": "a8e23b88ee558e34" - }, - { - "cell_type": "code", - "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, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:22.832129Z", - "start_time": "2024-06-03T12:28:22.830663Z" - } - }, - "id": "dc64275c217072e", - "outputs": [], - "execution_count": 3 - }, - { - "cell_type": "markdown", - "source": [ - "Finally, check if it contains all countable unions and intersections:" - ], - "metadata": { - "collapsed": false - }, - "id": "1b94834332d48104" - }, - { - "cell_type": "code", - "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-06-03T12:28:22.834137Z", - "start_time": "2024-06-03T12:28:22.832633Z" - } - }, - "id": "e7dc354bb8a70a12", - "outputs": [], - "execution_count": 4 - }, - { - "cell_type": "markdown", - "source": [ - "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", - "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": "9760a7401df5d50e" - }, - { - "cell_type": "code", - "source": [ - "from random_events.set import *\n", - "from random_events.variable import *\n", - "\n", - "class Item(SetElement):\n", - " EMPTY_SET = 0\n", - " BOWL = 1\n", - " CUP = 2\n", - " SPOON = 3\n", - " \n", - "class Color(SetElement):\n", - " EMPTY_SET = 0\n", - " BLUE = 1\n", - " GREEN = 2\n", - " RED = 3\n", - "\n", - "\n", - "item = Symbolic(\"item\", Item)\n", - "color = Symbolic(\"color\", Color)\n", - "print(item)\n", - "print(color)" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:22.838731Z", - "start_time": "2024-06-03T12:28:22.834639Z" - } - }, - "id": "27ea010bc8892833", - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Symbolic(item, {BOWL u CUP u SPOON})\n", - "Symbolic(color, {BLUE u GREEN u RED})\n" - ] - } - ], - "execution_count": 5 - }, - { - "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", - "source": [ - "from itertools import product\n", - "product_E = product(item.domain, color.domain)\n", - "list(product_E)" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:22.841282Z", - "start_time": "2024-06-03T12:28:22.839316Z" - } - }, - "id": "379cef1a50307c47", - "outputs": [ - { - "data": { - "text/plain": [ - "[(, ),\n", - " (, ),\n", - " (, ),\n", - " (, ),\n", - " (, ),\n", - " (, ),\n", - " (, ),\n", - " (, ),\n", - " (, )]" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 6 - }, - { - "cell_type": "markdown", - "source": [ - "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", - "source": [ - "from random_events.product_algebra import *\n", - "event = SimpleEvent({item: Set(Item.BOWL, Item.CUP), color: Color.BLUE})\n", - "list(product(*event.values()))" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:22.908178Z", - "start_time": "2024-06-03T12:28:22.841673Z" - } - }, - "id": "a53e718226f00339", - "outputs": [ - { - "data": { - "text/plain": [ - "[(, ), (, )]" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 7 - }, - { - "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", - "source": [ - "event1 = SimpleEvent({item: Item.BOWL, color: Color.BLUE}).as_composite_set()\n", - "event2 = SimpleEvent({item: Item.CUP, color: Color.RED}).as_composite_set()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:22.913515Z", - "start_time": "2024-06-03T12:28:22.909406Z" - } - }, - "id": "1bb140fb470e3cf7", - "outputs": [], - "execution_count": 8 - }, - { - "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", - "source": [ - "event_union = SimpleEvent({item: Set(Item.BOWL, Item.CUP), color: Set(Color.BLUE, Color.RED)}).as_composite_set()\n", - "event_union" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:22.919109Z", - "start_time": "2024-06-03T12:28:22.914307Z" - } - }, - "id": "b74c89bfbed07d6f", - "outputs": [ - { - "data": { - "text/plain": [ - "{{color = {BLUE u RED}, item = {BOWL u CUP}}}" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 9 - }, - { - "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", - "source": [ - "real_event_union = event1 | event2\n", - "str(real_event_union)" - ], - "metadata": { - "collapsed": false - }, - "id": "7fd789bf96187ca1", - "outputs": [ - { - "data": { - "text/plain": [ - "'{{color = {BLUE}, item = {BOWL}} u {color = {RED}, item = {CUP}}}'" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 10 - }, - { - "cell_type": "markdown", - "source": [ - "The correct union is a complex event. A complex event is a union of disjoint events.\n", - "\n", - "## Connections to Logic\n", - "\n", - "Algebraic concepts are hard to grasp. Since you, the reader, are very likely a Computer Scientists I will re-explain a random event from the perspective of logic.\n", - "We can rewrite the assignment of a variable to a set as a boolean variable. For example,\n", - "$Item_{\\{\\text{bowl}, \\text{cup}\\}} = item \\in \\{\\text{bowl}, \\text{cup}\\}$\n", - "is a boolean variable that is true if the item is a bowl or a cup.\n", - "We can rewrite the statement of the union as logical statement.\n", - "$$ \\left( Item_{\\{\\text{bowl}\\}} \\land Color_{\\{\\text{blue}\\}} \\right) \\lor \\left( Item_{\\{\\text{cup}\\}} \\land Color_{\\{\\text{red}\\}} \\right) $$\n", - "This logical statement describes either a blue bowl or a red cup.\n", - "The complex random events can always be thought of as a disjunction of conjunctions, hence a logical statement in the [disjunctive normal form](https://en.wikipedia.org/wiki/Disjunctive_normal_form)." - ], - "metadata": { - "collapsed": false - }, - "id": "bf5b8159724db75" - }, - { - "cell_type": "markdown", - "source": [ - "## Continuous Domains\n", - "\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 - }, - "id": "65bf0f9ece0f4bd" - }, - { - "cell_type": "code", - "source": [ - "from random_events.interval import *\n", - "x = Continuous(\"x\")\n", - "y = Continuous(\"y\")\n", - "\n", - "rectangle_event = SimpleEvent({x: closed(2, 3), y: closed(10, 15)}).as_composite_set()\n", - "fig = go.Figure(rectangle_event.plot(), rectangle_event.plotly_layout())\n", - "fig.update_layout(title= \"Rectangle event in 2D\")\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:23.063693Z", - "start_time": "2024-06-03T12:28:22.926073Z" - } - }, - "id": "a86b223360f60725", - "outputs": [ - { - "data": { - "text/html": [ - " \n", - " " - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "fill": "toself", - "legendgroup": "140546924939152", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": true, - "x": [ - 2, - 2, - 3, - 3, - 2, - null - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - null - ], - "type": "scatter" - } - ], - "layout": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "type": "scattergl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "bgcolor": "#E5ECF6", - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "#E5ECF6", - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "white", - "landcolor": "#E5ECF6", - "subunitcolor": "white", - "showland": true, - "showlakes": true, - "lakecolor": "white" - }, - "title": { - "x": 0.05 - }, - "mapbox": { - "style": "light" - } - } - }, - "title": { - "text": "Rectangle event in 2D" - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 11 - }, - { - "cell_type": "markdown", - "source": [ - "We can see that the described event is a rectangle in the x-y-plane. In fact, for higher dimensions, the described event will always be a hyper-rectangle.\n", - "Shapes like triangles, circles, etc. are not possible since they are made from dependent constraints. A circle with radius r, for example, can be described by the constraint `x^2 + y^2 <= r^2`, which is not independent.\n", - "\n", - "The only upper class of more complicated shapes can be constructed by defining more complex, independent constraints." - ], - "metadata": { - "collapsed": false - }, - "id": "f3f413c239110fc0" - }, - { - "cell_type": "code", - "source": [ - "complex_event = SimpleEvent({x: closed(2, 3) | closed(4, 5) | closed(6,7), y: closed(10, 15) | closed(25, 27)})\n", - "complex_event" - ], - "metadata": { - "collapsed": false - }, - "id": "86d42ecd896bef10", - "outputs": [ - { - "data": { - "text/plain": [ - "SimpleEvent({Continuous(x): {[2, 3] u [4, 5] u [6, 7]}, Continuous(y): {[10, 15] u [25, 27]}})" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "execution_count": 12 - }, - { - "cell_type": "markdown", - "source": [ - "Let's have a graphical look at it." - ], - "metadata": { - "collapsed": false - }, - "id": "90cfd9916c8fdcc0" - }, - { - "cell_type": "code", - "source": [ - "fig = go.Figure(complex_event.plot(), complex_event.plotly_layout())\n", - "fig.update_layout(title= \"Complex event in 2D\")\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:23.109159Z", - "start_time": "2024-06-03T12:28:23.068137Z" - } - }, - "id": "7d81de549d20f02b", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "fill": "toself", - "mode": "lines", - "name": "Event", - "x": [ - 2, - 2, - 3, - 3, - 2, - null, - 2, - 2, - 3, - 3, - 2, - null, - 4, - 4, - 5, - 5, - 4, - null, - 4, - 4, - 5, - 5, - 4, - null, - 6, - 6, - 7, - 7, - 6, - null, - 6, - 6, - 7, - 7, - 6, - null - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - null, - 25, - 27, - 27, - 25, - 25, - null, - 10, - 15, - 15, - 10, - 10, - null, - 25, - 27, - 27, - 25, - 25, - null, - 10, - 15, - 15, - 10, - 10, - null, - 25, - 27, - 27, - 25, - 25, - null - ], - "type": "scatter" - } - ], - "layout": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "type": "scattergl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "bgcolor": "#E5ECF6", - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "#E5ECF6", - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "white", - "landcolor": "#E5ECF6", - "subunitcolor": "white", - "showland": true, - "showlakes": true, - "lakecolor": "white" - }, - "title": { - "x": 0.05 - }, - "mapbox": { - "style": "light" - } - } - }, - "title": { - "text": "Complex event in 2D" - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 13 - }, - { - "cell_type": "markdown", - "source": [ - "The generalization of such events in higher dimensions results in hyper-rectangles. Let's visualize the transition from 2D to 3D to get a feel for how these shapes behave." - ], - "metadata": { - "collapsed": false - }, - "id": "4241651b2b1ed30a" - }, - { - "cell_type": "code", - "source": [ - "# extend previous event by 3rd dimension\n", - "z = Continuous(\"z\")\n", - "complex_event_3d = complex_event.copy()\n", - "complex_event_3d[z] = closed(1, 3) | closed(4, 4.5) | closed(10,11.5)\n", - "fig = go.Figure(complex_event_3d.plot(), complex_event_3d.plotly_layout())\n", - "fig.update_layout(title= \"Complex event in 3D\")\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:23.122789Z", - "start_time": "2024-06-03T12:28:23.109669Z" - } - }, - "id": "da2b51a986fa9d05", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "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 - ], - "x": [ - 2, - 2, - 3, - 3, - 2, - 2, - 3, - 3 - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - 15, - 15, - 10 - ], - "z": [ - 1, - 1, - 1, - 1, - 3, - 3, - 3, - 3 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 2, - 2, - 3, - 3, - 2, - 2, - 3, - 3 - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - 15, - 15, - 10 - ], - "z": [ - 4, - 4, - 4, - 4, - 4.5, - 4.5, - 4.5, - 4.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 2, - 2, - 3, - 3, - 2, - 2, - 3, - 3 - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - 15, - 15, - 10 - ], - "z": [ - 10, - 10, - 10, - 10, - 11.5, - 11.5, - 11.5, - 11.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 2, - 2, - 3, - 3, - 2, - 2, - 3, - 3 - ], - "y": [ - 25, - 27, - 27, - 25, - 25, - 27, - 27, - 25 - ], - "z": [ - 1, - 1, - 1, - 1, - 3, - 3, - 3, - 3 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 2, - 2, - 3, - 3, - 2, - 2, - 3, - 3 - ], - "y": [ - 25, - 27, - 27, - 25, - 25, - 27, - 27, - 25 - ], - "z": [ - 4, - 4, - 4, - 4, - 4.5, - 4.5, - 4.5, - 4.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 2, - 2, - 3, - 3, - 2, - 2, - 3, - 3 - ], - "y": [ - 25, - 27, - 27, - 25, - 25, - 27, - 27, - 25 - ], - "z": [ - 10, - 10, - 10, - 10, - 11.5, - 11.5, - 11.5, - 11.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 4, - 4, - 5, - 5, - 4, - 4, - 5, - 5 - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - 15, - 15, - 10 - ], - "z": [ - 1, - 1, - 1, - 1, - 3, - 3, - 3, - 3 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 4, - 4, - 5, - 5, - 4, - 4, - 5, - 5 - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - 15, - 15, - 10 - ], - "z": [ - 4, - 4, - 4, - 4, - 4.5, - 4.5, - 4.5, - 4.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 4, - 4, - 5, - 5, - 4, - 4, - 5, - 5 - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - 15, - 15, - 10 - ], - "z": [ - 10, - 10, - 10, - 10, - 11.5, - 11.5, - 11.5, - 11.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 4, - 4, - 5, - 5, - 4, - 4, - 5, - 5 - ], - "y": [ - 25, - 27, - 27, - 25, - 25, - 27, - 27, - 25 - ], - "z": [ - 1, - 1, - 1, - 1, - 3, - 3, - 3, - 3 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 4, - 4, - 5, - 5, - 4, - 4, - 5, - 5 - ], - "y": [ - 25, - 27, - 27, - 25, - 25, - 27, - 27, - 25 - ], - "z": [ - 4, - 4, - 4, - 4, - 4.5, - 4.5, - 4.5, - 4.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 4, - 4, - 5, - 5, - 4, - 4, - 5, - 5 - ], - "y": [ - 25, - 27, - 27, - 25, - 25, - 27, - 27, - 25 - ], - "z": [ - 10, - 10, - 10, - 10, - 11.5, - 11.5, - 11.5, - 11.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 6, - 6, - 7, - 7, - 6, - 6, - 7, - 7 - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - 15, - 15, - 10 - ], - "z": [ - 1, - 1, - 1, - 1, - 3, - 3, - 3, - 3 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 6, - 6, - 7, - 7, - 6, - 6, - 7, - 7 - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - 15, - 15, - 10 - ], - "z": [ - 4, - 4, - 4, - 4, - 4.5, - 4.5, - 4.5, - 4.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 6, - 6, - 7, - 7, - 6, - 6, - 7, - 7 - ], - "y": [ - 10, - 15, - 15, - 10, - 10, - 15, - 15, - 10 - ], - "z": [ - 10, - 10, - 10, - 10, - 11.5, - 11.5, - 11.5, - 11.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 6, - 6, - 7, - 7, - 6, - 6, - 7, - 7 - ], - "y": [ - 25, - 27, - 27, - 25, - 25, - 27, - 27, - 25 - ], - "z": [ - 1, - 1, - 1, - 1, - 3, - 3, - 3, - 3 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 6, - 6, - 7, - 7, - 6, - 6, - 7, - 7 - ], - "y": [ - 25, - 27, - 27, - 25, - 25, - 27, - 27, - 25 - ], - "z": [ - 4, - 4, - 4, - 4, - 4.5, - 4.5, - 4.5, - 4.5 - ], - "type": "mesh3d" - }, - { - "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 - ], - "x": [ - 6, - 6, - 7, - 7, - 6, - 6, - 7, - 7 - ], - "y": [ - 25, - 27, - 27, - 25, - 25, - 27, - 27, - 25 - ], - "z": [ - 10, - 10, - 10, - 10, - 11.5, - 11.5, - 11.5, - 11.5 - ], - "type": "mesh3d" - } - ], - "layout": { - "scene": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "zaxis": { - "title": { - "text": "z" - } - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "type": "scattergl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "bgcolor": "#E5ECF6", - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "#E5ECF6", - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "white", - "landcolor": "#E5ECF6", - "subunitcolor": "white", - "showland": true, - "showlakes": true, - "lakecolor": "white" - }, - "title": { - "x": 0.05 - }, - "mapbox": { - "style": "light" - } - } - }, - "title": { - "text": "Complex event in 3D" - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 14 - }, - { - "cell_type": "markdown", - "source": [ - "Unfortunately, the visualization of more than three dimensions is infeasible. The behavior of such events in higher dimensions yet remains the same. New constraints just add another dimension to the\n", - "rectangle. The patterns that can be created by having multiple intervals also generalize the same way as it did from 2D to 3D." - ], - "metadata": { - "collapsed": false - }, - "id": "9300c1fdc0ac9ac2" - }, - { - "cell_type": "markdown", - "source": [ - "The final component to look at, is the outer space. When the complement of a rectangular event is created, the result is a set of rectangles that are not part of the original event.\n", - "This may look like this." - ], - "metadata": { - "collapsed": false - }, - "id": "2dd3f6212d340b49" - }, - { - "cell_type": "code", - "source": [ - "event = SimpleEvent({x: open(0, 1), y: open(0, 1)}).as_composite_set()\n", - "complement = event.complement()\n", - "limiting_event = SimpleEvent({x: closed(-1, 2), y: closed(-1, 2)}).as_composite_set()\n", - "result = complement.intersection_with(limiting_event)\n", - "fig = go.Figure(result.plot(), result.plotly_layout())\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:23.129873Z", - "start_time": "2024-06-03T12:28:23.123375Z" - } - }, - "id": "97f6f80a61c8abaf", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "fill": "toself", - "legendgroup": "140546909567056", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": true, - "x": [ - -1, - -1, - 0, - 0, - -1, - null, - 1, - 1, - 2, - 2, - 1, - null - ], - "y": [ - -1, - 2, - 2, - -1, - -1, - null, - -1, - 2, - 2, - -1, - -1, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140546909567056", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 0, - 0, - 1, - 1, - 0, - null, - 0, - 0, - 1, - 1, - 0, - null - ], - "y": [ - -1, - 0, - 0, - -1, - -1, - null, - 1, - 2, - 2, - 1, - 1, - null - ], - "type": "scatter" - } - ], - "layout": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "type": "scattergl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "bgcolor": "#E5ECF6", - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "#E5ECF6", - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "white", - "landcolor": "#E5ECF6", - "subunitcolor": "white", - "showland": true, - "showlakes": true, - "lakecolor": "white" - }, - "title": { - "x": 0.05 - }, - "mapbox": { - "style": "light" - } - } - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 15 - }, - { - "cell_type": "markdown", - "source": [], - "metadata": { - "collapsed": false - }, - "id": "4cc21c60f92af0c9" - }, - { - "cell_type": "markdown", - "source": [ - "In 3D, the outer event looks weird, but it is just the complement of the original event. You can use the interactive zoom functionality to see the missing inner event." - ], - "metadata": { - "collapsed": false - }, - "id": "bc351a7373a9ec7c" - }, - { - "cell_type": "code", - "source": [ - "event = SimpleEvent({x: closed(0, 1),\n", - " y: closed(0, 1),\n", - " z: closed(0, 1)}).as_composite_set()\n", - "complement = event.complement()\n", - "limiting_event = SimpleEvent({x: closed(-1, 2),\n", - " y: closed(-1, 2),\n", - " z: closed(-1, 2)}).as_composite_set()\n", - "result = complement.intersection_with(limiting_event)\n", - "fig = go.Figure(result.plot(), result.plotly_layout())\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:23.139531Z", - "start_time": "2024-06-03T12:28:23.130400Z" - } - }, - "id": "9e47b2f884e4c9dd", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "color": "#636EFA", - "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": "140546909236816", - "name": "Event", - "showlegend": true, - "x": [ - -1, - -1, - 0, - 0, - -1, - -1, - 0, - 0 - ], - "y": [ - -1, - 2, - 2, - -1, - -1, - 2, - 2, - -1 - ], - "z": [ - -1, - -1, - -1, - -1, - 2, - 2, - 2, - 2 - ], - "type": "mesh3d" - }, - { - "color": "#636EFA", - "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": "140546909236816", - "name": "Event", - "showlegend": false, - "x": [ - 1, - 1, - 2, - 2, - 1, - 1, - 2, - 2 - ], - "y": [ - -1, - 2, - 2, - -1, - -1, - 2, - 2, - -1 - ], - "z": [ - -1, - -1, - -1, - -1, - 2, - 2, - 2, - 2 - ], - "type": "mesh3d" - }, - { - "color": "#636EFA", - "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": "140546909236816", - "name": "Event", - "showlegend": false, - "x": [ - 0, - 0, - 1, - 1, - 0, - 0, - 1, - 1 - ], - "y": [ - -1, - 0, - 0, - -1, - -1, - 0, - 0, - -1 - ], - "z": [ - -1, - -1, - -1, - -1, - 2, - 2, - 2, - 2 - ], - "type": "mesh3d" - }, - { - "color": "#636EFA", - "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": "140546909236816", - "name": "Event", - "showlegend": false, - "x": [ - 0, - 0, - 1, - 1, - 0, - 0, - 1, - 1 - ], - "y": [ - 1, - 2, - 2, - 1, - 1, - 2, - 2, - 1 - ], - "z": [ - -1, - -1, - -1, - -1, - 2, - 2, - 2, - 2 - ], - "type": "mesh3d" - }, - { - "color": "#636EFA", - "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": "140546909236816", - "name": "Event", - "showlegend": false, - "x": [ - 0, - 0, - 1, - 1, - 0, - 0, - 1, - 1 - ], - "y": [ - 0, - 1, - 1, - 0, - 0, - 1, - 1, - 0 - ], - "z": [ - -1, - -1, - -1, - -1, - 0, - 0, - 0, - 0 - ], - "type": "mesh3d" - }, - { - "color": "#636EFA", - "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": "140546909236816", - "name": "Event", - "showlegend": false, - "x": [ - 0, - 0, - 1, - 1, - 0, - 0, - 1, - 1 - ], - "y": [ - 0, - 1, - 1, - 0, - 0, - 1, - 1, - 0 - ], - "z": [ - 1, - 1, - 1, - 1, - 2, - 2, - 2, - 2 - ], - "type": "mesh3d" - } - ], - "layout": { - "scene": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "zaxis": { - "title": { - "text": "z" - } - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "type": "scattergl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "bgcolor": "#E5ECF6", - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "#E5ECF6", - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "white", - "landcolor": "#E5ECF6", - "subunitcolor": "white", - "showland": true, - "showlakes": true, - "lakecolor": "white" - }, - "title": { - "x": 0.05 - }, - "mapbox": { - "style": "light" - } - } - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 16 - }, - { - "cell_type": "markdown", - "source": [ - "In case you didn't find the inner, missing event, here is the outer event cut open. " - ], - "metadata": { - "collapsed": false - }, - "id": "3888a2df23a1c3fe" - }, - { - "cell_type": "code", - "source": [ - "cut_result = result.intersection_with(SimpleEvent({y: closed(-1, 1)}).as_composite_set())\n", - "fig = go.Figure(cut_result.plot(), cut_result.plotly_layout())\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:23.145674Z", - "start_time": "2024-06-03T12:28:23.140032Z" - } - }, - "id": "a4ef759878e21dd5", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "color": "#636EFA", - "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": "140546883149104", - "name": "Event", - "showlegend": true, - "x": [ - -1, - -1, - 0, - 0, - -1, - -1, - 0, - 0 - ], - "y": [ - -1, - 1, - 1, - -1, - -1, - 1, - 1, - -1 - ], - "z": [ - -1, - -1, - -1, - -1, - 2, - 2, - 2, - 2 - ], - "type": "mesh3d" - }, - { - "color": "#636EFA", - "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": "140546883149104", - "name": "Event", - "showlegend": false, - "x": [ - 1, - 1, - 2, - 2, - 1, - 1, - 2, - 2 - ], - "y": [ - -1, - 1, - 1, - -1, - -1, - 1, - 1, - -1 - ], - "z": [ - -1, - -1, - -1, - -1, - 2, - 2, - 2, - 2 - ], - "type": "mesh3d" - }, - { - "color": "#636EFA", - "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": "140546883149104", - "name": "Event", - "showlegend": false, - "x": [ - 0, - 0, - 1, - 1, - 0, - 0, - 1, - 1 - ], - "y": [ - -1, - 0, - 0, - -1, - -1, - 0, - 0, - -1 - ], - "z": [ - -1, - -1, - -1, - -1, - 2, - 2, - 2, - 2 - ], - "type": "mesh3d" - }, - { - "color": "#636EFA", - "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": "140546883149104", - "name": "Event", - "showlegend": false, - "x": [ - 0, - 0, - 1, - 1, - 0, - 0, - 1, - 1 - ], - "y": [ - 0, - 1, - 1, - 0, - 0, - 1, - 1, - 0 - ], - "z": [ - -1, - -1, - -1, - -1, - 0, - 0, - 0, - 0 - ], - "type": "mesh3d" - }, - { - "color": "#636EFA", - "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": "140546883149104", - "name": "Event", - "showlegend": false, - "x": [ - 0, - 0, - 1, - 1, - 0, - 0, - 1, - 1 - ], - "y": [ - 0, - 1, - 1, - 0, - 0, - 1, - 1, - 0 - ], - "z": [ - 1, - 1, - 1, - 1, - 2, - 2, - 2, - 2 - ], - "type": "mesh3d" - } - ], - "layout": { - "scene": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "zaxis": { - "title": { - "text": "z" - } - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "type": "scattergl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "bgcolor": "#E5ECF6", - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "#E5ECF6", - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "white", - "landcolor": "#E5ECF6", - "subunitcolor": "white", - "showland": true, - "showlakes": true, - "lakecolor": "white" - }, - "title": { - "x": 0.05 - }, - "mapbox": { - "style": "light" - } - } - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 17 - }, - { - "metadata": {}, - "cell_type": "markdown", - "source": [ - "## Complement of the Product Algebra\n", - "\n", - "[This](https://www.math.ucdavis.edu/~hunter/m206/ch4_measure_notes.pdf) mentions that the complement of an element of the product measure is constructed by\n", - "$$\n", - " (A \\times B)^c = (A^c \\times B) \\cup (A \\times B^c) \\cup (A^c \\times B^c).\n", - "$$\n", - "It is easy to see that this construction would produce exponential many elements with respect to the number of variables. This is unfortunate.\n", - "However, the correct complement can be formed with linear many terms, which is way more efficient. The following equations describe a proof by induction on how that can be done.\n", - "\n", - "Let\n", - "\\begin{align*}\n", - " \\mathbb{A} &= A \\cup A^c \\, , \\\\\n", - " \\mathbb{B} &= B \\cup B^c \\text{ and }\\\\\n", - " \\mathbb{C} &= C \\cup C^c.\n", - "\\end{align*}\n", - "\n", - "### Induction Assumption\n", - "\n", - "\\begin{align*}\n", - " (A \\times B)^c = (A^c \\times \\mathbb{B}) \\cup (A \\times B^C)\n", - "\\end{align*}\n", - "Proof:\n", - "\\begin{align*}\n", - " (A \\times B)^c &= (A^c \\times B) \\cup (A \\times B^c) \\cup (A^c \\times B^c) \\\\\n", - " &= (A^c \\times B) \\cup (A^c \\times B^c) \\cup (A \\times B^c) \\\\\n", - " &= ( A^c \\times (B \\cup B^c) ) \\cup (A \\times B^c) \\\\\n", - " &= (A^c \\times \\mathbb{B}) \\cup (A \\times B^C) \\square\n", - "\\end{align*}\n", - "\n", - "### Induction Step\n", - "\n", - "\\begin{align*}\n", - " (A \\times B \\times C)^c = (A^c \\times \\mathbb{B} \\times \\mathbb{C}) \\cup (A \\times B^C \\times \\mathbb{C} ) \\cup (A \\times B \\times C^c)\n", - "\\end{align*}\n", - "Proof:\n", - "\\begin{align*}\n", - " (A \\times B \\times C)^c &= (A^c \\times B \\times C) \\cup (A \\times B^c \\times C) \\cup (A \\times B \\times C^c) \\cup \n", - " (A^c \\times B^c \\times C) \\cup (A^c \\times B \\times C^c) \\cup (A \\times B^c \\times C^c) \\cup \n", - " (A^c \\times B^c \\times C^c) \\\\\n", - " &= (C \\times \\underbrace{(A^c \\times B) \\cup (A \\times B^c) \\cup (A^c \\times B^c))}_{\\text{Induction Assumption}} \\cup\n", - " (C^c \\times \\underbrace{(A^c \\times B) \\cup (A \\times B^c) \\cup (A^c \\times B^c))}_{\\text{Induction Assumption}} \\cup (A \\times B \\times C^c) \\\\\n", - " &= (C \\times (A^c \\times \\mathbb{B}) \\cup (A \\times B^C)) \\cup \n", - " (C^c \\times (A^c \\times \\mathbb{B}) \\cup (A \\times B^C)) \\cup (A \\times B \\times C^c)\\\\\n", - " &= \n", - "\\end{align*}\n" - ], - "id": "511cdcad45f76bab" - }, - { - "cell_type": "markdown", - "source": [ - "## Application of the Product Algebra\n", - "\n", - "You may ask yourself where the product algebra matters in real applications.\n", - "Consider your kitchen. You most likely have some regions where you are able to stand, and some regions where you can't.\n", - "If you look at floor plan of your kitchen, you could perhaps describe it as the following event. " - ], - "metadata": { - "collapsed": false - }, - "id": "a077c140431ca667" - }, - { - "cell_type": "code", - "source": [ - "kitchen = SimpleEvent({x: closed(0, 6.6), y: closed(0, 7)}).as_composite_set()\n", - "refrigerator = SimpleEvent({x: closed(5, 6), y: closed(6.3, 7)}).as_composite_set()\n", - "top_kitchen_island = SimpleEvent({x: closed(0, 5), y: closed(6.5, 7)}).as_composite_set()\n", - "left_cabinets = SimpleEvent({x: closed(0, 0.5), y: closed(0, 6.5)}).as_composite_set()\n", - "\n", - "center_island = SimpleEvent({x: closed(2, 4), y: closed(3, 5)}).as_composite_set()\n", - "\n", - "occupied_spaces = refrigerator | top_kitchen_island | left_cabinets | center_island\n", - "fig = go.Figure(occupied_spaces.plot(), occupied_spaces.plotly_layout())\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:23.161753Z", - "start_time": "2024-06-03T12:28:23.146154Z" - } - }, - "id": "b8916038b2521a38", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "fill": "toself", - "legendgroup": "140546883351792", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": true, - "x": [ - 0.0, - 0.0, - 0.5, - 0.5, - 0.0, - null - ], - "y": [ - 0.0, - 7.0, - 7.0, - 0.0, - 0.0, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140546883351792", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 0.5, - 0.5, - 5.0, - 5.0, - 0.5, - null - ], - "y": [ - 6.5, - 7.0, - 7.0, - 6.5, - 6.5, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140546883351792", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 2, - 2, - 4, - 4, - 2, - null - ], - "y": [ - 3, - 5, - 5, - 3, - 3, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140546883351792", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 5.0, - 5.0, - 5.0, - 5.0, - 5.0, - null - ], - "y": [ - 6.3, - 6.5, - 6.5, - 6.3, - 6.3, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140546883351792", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 5.0, - 5.0, - 6.0, - 6.0, - 5.0, - null - ], - "y": [ - 6.3, - 7.0, - 7.0, - 6.3, - 6.3, - null - ], - "type": "scatter" - } - ], - "layout": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "type": "scattergl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "bgcolor": "#E5ECF6", - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "#E5ECF6", - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "white", - "landcolor": "#E5ECF6", - "subunitcolor": "white", - "showland": true, - "showlakes": true, - "lakecolor": "white" - }, - "title": { - "x": 0.05 - }, - "mapbox": { - "style": "light" - } - } - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 18 - }, - { - "cell_type": "markdown", - "source": [ - "Now posing the question on where you can stand in your kitchen, you can simply calculate the complement of the occupied space with the kitchen." - ], - "metadata": { - "collapsed": false - }, - "id": "96d63611dffff0f5" - }, - { - "cell_type": "code", - "source": [ - "free_space = kitchen.difference_with(occupied_spaces)\n", - "fig = go.Figure(free_space.plot(), free_space.plotly_layout())\n", - "fig.show()" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-06-03T12:28:23.175180Z", - "start_time": "2024-06-03T12:28:23.162199Z" - } - }, - "id": "510b80164a41cfc", - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "data": [ - { - "fill": "toself", - "legendgroup": "140546909261200", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": true, - "x": [ - 0.5, - 0.5, - 2.0, - 2.0, - 0.5, - null, - 4.0, - 4.0, - 5.0, - 5.0, - 4.0, - null - ], - "y": [ - 0.0, - 6.5, - 6.5, - 0.0, - 0.0, - null, - 0.0, - 6.5, - 6.5, - 0.0, - 0.0, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140546909261200", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 2, - 2, - 4, - 4, - 2, - null, - 2.0, - 2.0, - 4.0, - 4.0, - 2.0, - null - ], - "y": [ - 0, - 3, - 3, - 0, - 0, - null, - 5.0, - 6.5, - 6.5, - 5.0, - 5.0, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140546909261200", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 5.0, - 5.0, - 6.0, - 6.0, - 5.0, - null - ], - "y": [ - 0.0, - 6.3, - 6.3, - 0.0, - 0.0, - null - ], - "type": "scatter" - }, - { - "fill": "toself", - "legendgroup": "140546909261200", - "line": { - "color": "#636EFA" - }, - "mode": "lines", - "name": "Event", - "showlegend": false, - "x": [ - 6.0, - 6.0, - 6.6, - 6.6, - 6.0, - null - ], - "y": [ - 0.0, - 7.0, - 7.0, - 0.0, - 0.0, - null - ], - "type": "scatter" - } - ], - "layout": { - "xaxis": { - "title": { - "text": "x" - } - }, - "yaxis": { - "title": { - "text": "y" - } - }, - "template": { - "data": { - "histogram2dcontour": [ - { - "type": "histogram2dcontour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "choropleth": [ - { - "type": "choropleth", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "histogram2d": [ - { - "type": "histogram2d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmap": [ - { - "type": "heatmap", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "heatmapgl": [ - { - "type": "heatmapgl", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "contourcarpet": [ - { - "type": "contourcarpet", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "contour": [ - { - "type": "contour", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "surface": [ - { - "type": "surface", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ] - } - ], - "mesh3d": [ - { - "type": "mesh3d", - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "parcoords": [ - { - "type": "parcoords", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolargl": [ - { - "type": "scatterpolargl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "scattergeo": [ - { - "type": "scattergeo", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterpolar": [ - { - "type": "scatterpolar", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "scattergl": [ - { - "type": "scattergl", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatter3d": [ - { - "type": "scatter3d", - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattermapbox": [ - { - "type": "scattermapbox", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scatterternary": [ - { - "type": "scatterternary", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "scattercarpet": [ - { - "type": "scattercarpet", - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - } - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ] - }, - "layout": { - "autotypenumbers": "strict", - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "hovermode": "closest", - "hoverlabel": { - "align": "left" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "bgcolor": "#E5ECF6", - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "ternary": { - "bgcolor": "#E5ECF6", - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "sequential": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0.0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1.0, - "#f0f921" - ] - ], - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ] - }, - "xaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "yaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "automargin": true, - "zerolinewidth": 2 - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white", - "gridwidth": 2 - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "geo": { - "bgcolor": "white", - "landcolor": "#E5ECF6", - "subunitcolor": "white", - "showland": true, - "showlakes": true, - "lakecolor": "white" - }, - "title": { - "x": 0.05 - }, - "mapbox": { - "style": "light" - } - } - } - }, - "config": { - "plotlyServerURL": "https://plot.ly" - } - }, - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 19 - }, - { - "cell_type": "markdown", - "source": [ - "Now this already sounds somewhat useful. However, just the events are of limited use. The real power of the product algebra comes when you start to calculate probabilities of events.\n", - "For this, you can check out this tutorial on [probability theory](https://probabilistic-model.readthedocs.io/en/latest/examples/probability_theory.html)." - ], - "metadata": { - "collapsed": false - }, - "id": "86e43578f1c0808d" - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/examples/self_assessment.ipynb b/examples/self_assessment.ipynb deleted file mode 100644 index 6b1e8d0..0000000 --- a/examples/self_assessment.ipynb +++ /dev/null @@ -1,306 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "511a12a53c44b9d2", - "metadata": { - "collapsed": false - }, - "source": [ - "# Self Assessment Test\n", - "\n", - "In this notebook, you can check how well you understand the concepts of the sigma algebra and the implementation in this package." - ] - }, - { - "cell_type": "code", - "id": "initial_id", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [ - "remove-input" - ], - "ExecuteTime": { - "end_time": "2024-06-03T12:41:33.338823Z", - "start_time": "2024-06-03T12:41:33.332949Z" - } - }, - "source": [ - "from jupyterquiz import display_quiz\n", - "\n", - "q1 = {\n", - " \"question\": \"Which shapes can be represented using the product sigma algebra?\",\n", - " \"type\": \"many_choice\",\n", - " \"answers\": [{\"answer\": \"Triangles\", \"correct\": False},\n", - " {\"answer\": \"Squares\", \"correct\": True},\n", - " {\"answer\": \"Circles\", \"correct\": False},\n", - " {\"answer\": \"Rectangles\", \"correct\": True},\n", - " {\"answer\": \"Cubes\", \"correct\": True},\n", - " {\"answer\": \"Lines\", \"correct\": True},\n", - " {\"answer\": \"Trapezoids\", \"correct\": False},\n", - " {\"answer\": \"Parallelograms\", \"correct\": False},\n", - " {\"answer\": \"Pyramids\", \"correct\": False},\n", - " {\"answer\": \"Hyper-Rectangles\", \"correct\": True},\n", - " ]\n", - "}\n", - "display_quiz([q1])" - ], - "outputs": [ - { - "data": { - "text/plain": [ - "" - ], - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ], - "application/javascript": "var questionsTDDPZXphBhqN=[{\"question\": \"Which shapes can be represented using the product sigma algebra?\", \"type\": \"many_choice\", \"answers\": [{\"answer\": \"Triangles\", \"correct\": false}, {\"answer\": \"Squares\", \"correct\": true}, {\"answer\": \"Circles\", \"correct\": false}, {\"answer\": \"Rectangles\", \"correct\": true}, {\"answer\": \"Cubes\", \"correct\": true}, {\"answer\": \"Lines\", \"correct\": true}, {\"answer\": \"Trapezoids\", \"correct\": false}, {\"answer\": \"Parallelograms\", \"correct\": false}, {\"answer\": \"Pyramids\", \"correct\": false}, {\"answer\": \"Hyper-Rectangles\", \"correct\": true}]}];\n // Make a random ID\nfunction makeid(length) {\n var result = [];\n var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n var charactersLength = characters.length;\n for (var i = 0; i < length; i++) {\n result.push(characters.charAt(Math.floor(Math.random() * charactersLength)));\n }\n return result.join('');\n}\n\n// Choose a random subset of an array. Can also be used to shuffle the array\nfunction getRandomSubarray(arr, size) {\n var shuffled = arr.slice(0), i = arr.length, temp, index;\n while (i--) {\n index = Math.floor((i + 1) * Math.random());\n temp = shuffled[index];\n shuffled[index] = shuffled[i];\n shuffled[i] = temp;\n }\n return shuffled.slice(0, size);\n}\n\nfunction printResponses(responsesContainer) {\n var responses=JSON.parse(responsesContainer.dataset.responses);\n var stringResponses='IMPORTANT!To preserve this answer sequence for submission, when you have finalized your answers:
  1. Copy the text in this cell below \"Answer String\"
  2. Double click on the cell directly below the Answer String, labeled \"Replace Me\"
  3. Select the whole \"Replace Me\" text
  4. Paste in your answer string and press shift-Enter.
  5. Save the notebook using the save icon or File->Save Notebook menu item



  6. Answer String:
    ';\n console.log(responses);\n responses.forEach((response, index) => {\n if (response) {\n console.log(index + ': ' + response);\n stringResponses+= index + ': ' + response +\"
    \";\n }\n });\n responsesContainer.innerHTML=stringResponses;\n}\nfunction check_mc() {\n var id = this.id.split('-')[0];\n //var response = this.id.split('-')[1];\n //console.log(response);\n //console.log(\"In check_mc(), id=\"+id);\n //console.log(event.srcElement.id) \n //console.log(event.srcElement.dataset.correct) \n //console.log(event.srcElement.dataset.feedback)\n\n var label = event.srcElement;\n //console.log(label, label.nodeName);\n var depth = 0;\n while ((label.nodeName != \"LABEL\") && (depth < 20)) {\n label = label.parentElement;\n console.log(depth, label);\n depth++;\n }\n\n\n\n var answers = label.parentElement.children;\n\n //console.log(answers);\n\n\n // Split behavior based on multiple choice vs many choice:\n var fb = document.getElementById(\"fb\" + id);\n\n\n\n\n if (fb.dataset.numcorrect == 1) {\n // What follows is for the saved responses stuff\n var outerContainer = fb.parentElement.parentElement;\n var responsesContainer = document.getElementById(\"responses\" + outerContainer.id);\n if (responsesContainer) {\n //console.log(responsesContainer);\n var response = label.firstChild.innerText;\n if (label.querySelector(\".QuizCode\")){\n response+= label.querySelector(\".QuizCode\").firstChild.innerText;\n }\n console.log(response);\n //console.log(document.getElementById(\"quizWrap\"+id));\n var qnum = document.getElementById(\"quizWrap\"+id).dataset.qnum;\n console.log(\"Question \" + qnum);\n //console.log(id, \", got numcorrect=\",fb.dataset.numcorrect);\n var responses=JSON.parse(responsesContainer.dataset.responses);\n console.log(responses);\n responses[qnum]= response;\n responsesContainer.setAttribute('data-responses', JSON.stringify(responses));\n printResponses(responsesContainer);\n }\n // End code to preserve responses\n \n for (var i = 0; i < answers.length; i++) {\n var child = answers[i];\n //console.log(child);\n child.className = \"MCButton\";\n }\n\n\n\n if (label.dataset.correct == \"true\") {\n // console.log(\"Correct action\");\n if (\"feedback\" in label.dataset) {\n fb.textContent = jaxify(label.dataset.feedback);\n } else {\n fb.textContent = \"Correct!\";\n }\n label.classList.add(\"correctButton\");\n\n fb.className = \"Feedback\";\n fb.classList.add(\"correct\");\n\n } else {\n if (\"feedback\" in label.dataset) {\n fb.textContent = jaxify(label.dataset.feedback);\n } else {\n fb.textContent = \"Incorrect -- try again.\";\n }\n //console.log(\"Error action\");\n label.classList.add(\"incorrectButton\");\n fb.className = \"Feedback\";\n fb.classList.add(\"incorrect\");\n }\n }\n else {\n var reset = false;\n var feedback;\n if (label.dataset.correct == \"true\") {\n if (\"feedback\" in label.dataset) {\n feedback = jaxify(label.dataset.feedback);\n } else {\n feedback = \"Correct!\";\n }\n if (label.dataset.answered <= 0) {\n if (fb.dataset.answeredcorrect < 0) {\n fb.dataset.answeredcorrect = 1;\n reset = true;\n } else {\n fb.dataset.answeredcorrect++;\n }\n if (reset) {\n for (var i = 0; i < answers.length; i++) {\n var child = answers[i];\n child.className = \"MCButton\";\n child.dataset.answered = 0;\n }\n }\n label.classList.add(\"correctButton\");\n label.dataset.answered = 1;\n fb.className = \"Feedback\";\n fb.classList.add(\"correct\");\n\n }\n } else {\n if (\"feedback\" in label.dataset) {\n feedback = jaxify(label.dataset.feedback);\n } else {\n feedback = \"Incorrect -- try again.\";\n }\n if (fb.dataset.answeredcorrect > 0) {\n fb.dataset.answeredcorrect = -1;\n reset = true;\n } else {\n fb.dataset.answeredcorrect--;\n }\n\n if (reset) {\n for (var i = 0; i < answers.length; i++) {\n var child = answers[i];\n child.className = \"MCButton\";\n child.dataset.answered = 0;\n }\n }\n label.classList.add(\"incorrectButton\");\n fb.className = \"Feedback\";\n fb.classList.add(\"incorrect\");\n }\n // What follows is for the saved responses stuff\n var outerContainer = fb.parentElement.parentElement;\n var responsesContainer = document.getElementById(\"responses\" + outerContainer.id);\n if (responsesContainer) {\n //console.log(responsesContainer);\n var response = label.firstChild.innerText;\n if (label.querySelector(\".QuizCode\")){\n response+= label.querySelector(\".QuizCode\").firstChild.innerText;\n }\n console.log(response);\n //console.log(document.getElementById(\"quizWrap\"+id));\n var qnum = document.getElementById(\"quizWrap\"+id).dataset.qnum;\n console.log(\"Question \" + qnum);\n //console.log(id, \", got numcorrect=\",fb.dataset.numcorrect);\n var responses=JSON.parse(responsesContainer.dataset.responses);\n if (label.dataset.correct == \"true\") {\n if (typeof(responses[qnum]) == \"object\"){\n if (!responses[qnum].includes(response))\n responses[qnum].push(response);\n } else{\n responses[qnum]= [ response ];\n }\n } else {\n responses[qnum]= response;\n }\n console.log(responses);\n responsesContainer.setAttribute('data-responses', JSON.stringify(responses));\n printResponses(responsesContainer);\n }\n // End save responses stuff\n\n\n\n var numcorrect = fb.dataset.numcorrect;\n var answeredcorrect = fb.dataset.answeredcorrect;\n if (answeredcorrect >= 0) {\n fb.textContent = feedback + \" [\" + answeredcorrect + \"/\" + numcorrect + \"]\";\n } else {\n fb.textContent = feedback + \" [\" + 0 + \"/\" + numcorrect + \"]\";\n }\n\n\n }\n\n if (typeof MathJax != 'undefined') {\n var version = MathJax.version;\n console.log('MathJax version', version);\n if (version[0] == \"2\") {\n MathJax.Hub.Queue([\"Typeset\", MathJax.Hub]);\n } else if (version[0] == \"3\") {\n MathJax.typeset([fb]);\n }\n } else {\n console.log('MathJax not detected');\n }\n\n}\n\nfunction make_mc(qa, shuffle_answers, outerqDiv, qDiv, aDiv, id) {\n var shuffled;\n if (shuffle_answers == \"True\") {\n //console.log(shuffle_answers+\" read as true\");\n shuffled = getRandomSubarray(qa.answers, qa.answers.length);\n } else {\n //console.log(shuffle_answers+\" read as false\");\n shuffled = qa.answers;\n }\n\n\n var num_correct = 0;\n\n\n\n shuffled.forEach((item, index, ans_array) => {\n //console.log(answer);\n\n // Make input element\n var inp = document.createElement(\"input\");\n inp.type = \"radio\";\n inp.id = \"quizo\" + id + index;\n inp.style = \"display:none;\";\n aDiv.append(inp);\n\n //Make label for input element\n var lab = document.createElement(\"label\");\n lab.className = \"MCButton\";\n lab.id = id + '-' + index;\n lab.onclick = check_mc;\n var aSpan = document.createElement('span');\n aSpan.classsName = \"\";\n //qDiv.id=\"quizQn\"+id+index;\n if (\"answer\" in item) {\n aSpan.innerHTML = jaxify(item.answer);\n //aSpan.innerHTML=item.answer;\n }\n lab.append(aSpan);\n\n // Create div for code inside question\n var codeSpan;\n if (\"code\" in item) {\n codeSpan = document.createElement('span');\n codeSpan.id = \"code\" + id + index;\n codeSpan.className = \"QuizCode\";\n var codePre = document.createElement('pre');\n codeSpan.append(codePre);\n var codeCode = document.createElement('code');\n codePre.append(codeCode);\n codeCode.innerHTML = item.code;\n lab.append(codeSpan);\n //console.log(codeSpan);\n }\n\n //lab.textContent=item.answer;\n\n // Set the data attributes for the answer\n lab.setAttribute('data-correct', item.correct);\n if (item.correct) {\n num_correct++;\n }\n if (\"feedback\" in item) {\n lab.setAttribute('data-feedback', item.feedback);\n }\n lab.setAttribute('data-answered', 0);\n\n aDiv.append(lab);\n\n });\n\n if (num_correct > 1) {\n outerqDiv.className = \"ManyChoiceQn\";\n } else {\n outerqDiv.className = \"MultipleChoiceQn\";\n }\n\n return num_correct;\n\n}\nfunction check_numeric(ths, event) {\n\n if (event.keyCode === 13) {\n ths.blur();\n\n var id = ths.id.split('-')[0];\n\n var submission = ths.value;\n if (submission.indexOf('/') != -1) {\n var sub_parts = submission.split('/');\n //console.log(sub_parts);\n submission = sub_parts[0] / sub_parts[1];\n }\n //console.log(\"Reader entered\", submission);\n\n if (\"precision\" in ths.dataset) {\n var precision = ths.dataset.precision;\n submission = Number(Number(submission).toPrecision(precision));\n }\n\n\n //console.log(\"In check_numeric(), id=\"+id);\n //console.log(event.srcElement.id) \n //console.log(event.srcElement.dataset.feedback)\n\n var fb = document.getElementById(\"fb\" + id);\n fb.style.display = \"none\";\n fb.textContent = \"Incorrect -- try again.\";\n\n var answers = JSON.parse(ths.dataset.answers);\n //console.log(answers);\n\n var defaultFB = \"\";\n var correct;\n var done = false;\n answers.every(answer => {\n //console.log(answer.type);\n\n correct = false;\n // if (answer.type==\"value\"){\n if ('value' in answer) {\n if (submission == answer.value) {\n if (\"feedback\" in answer) {\n fb.textContent = jaxify(answer.feedback);\n } else {\n fb.textContent = jaxify(\"Correct\");\n }\n correct = answer.correct;\n //console.log(answer.correct);\n done = true;\n }\n // } else if (answer.type==\"range\") {\n } else if ('range' in answer) {\n console.log(answer.range);\n console.log(submission, submission >=answer.range[0], submission < answer.range[1])\n if ((submission >= answer.range[0]) && (submission < answer.range[1])) {\n fb.textContent = jaxify(answer.feedback);\n correct = answer.correct;\n console.log(answer.correct);\n done = true;\n }\n } else if (answer.type == \"default\") {\n defaultFB = answer.feedback;\n }\n if (done) {\n return false; // Break out of loop if this has been marked correct\n } else {\n return true; // Keep looking for case that includes this as a correct answer\n }\n });\n console.log(\"done:\", done);\n\n if ((!done) && (defaultFB != \"\")) {\n fb.innerHTML = jaxify(defaultFB);\n //console.log(\"Default feedback\", defaultFB);\n }\n\n fb.style.display = \"block\";\n if (correct) {\n ths.className = \"Input-text\";\n ths.classList.add(\"correctButton\");\n fb.className = \"Feedback\";\n fb.classList.add(\"correct\");\n } else {\n ths.className = \"Input-text\";\n ths.classList.add(\"incorrectButton\");\n fb.className = \"Feedback\";\n fb.classList.add(\"incorrect\");\n }\n\n // What follows is for the saved responses stuff\n var outerContainer = fb.parentElement.parentElement;\n var responsesContainer = document.getElementById(\"responses\" + outerContainer.id);\n if (responsesContainer) {\n console.log(submission);\n var qnum = document.getElementById(\"quizWrap\"+id).dataset.qnum;\n //console.log(\"Question \" + qnum);\n //console.log(id, \", got numcorrect=\",fb.dataset.numcorrect);\n var responses=JSON.parse(responsesContainer.dataset.responses);\n console.log(responses);\n if (submission == ths.value){\n responses[qnum]= submission;\n } else {\n responses[qnum]= ths.value + \"(\" + submission +\")\";\n }\n responsesContainer.setAttribute('data-responses', JSON.stringify(responses));\n printResponses(responsesContainer);\n }\n // End code to preserve responses\n\n if (typeof MathJax != 'undefined') {\n var version = MathJax.version;\n console.log('MathJax version', version);\n if (version[0] == \"2\") {\n MathJax.Hub.Queue([\"Typeset\", MathJax.Hub]);\n } else if (version[0] == \"3\") {\n MathJax.typeset([fb]);\n }\n } else {\n console.log('MathJax not detected');\n }\n return false;\n }\n\n}\n\nfunction isValid(el, charC) {\n //console.log(\"Input char: \", charC);\n if (charC == 46) {\n if (el.value.indexOf('.') === -1) {\n return true;\n } else if (el.value.indexOf('/') != -1) {\n var parts = el.value.split('/');\n if (parts[1].indexOf('.') === -1) {\n return true;\n }\n }\n else {\n return false;\n }\n } else if (charC == 47) {\n if (el.value.indexOf('/') === -1) {\n if ((el.value != \"\") && (el.value != \".\")) {\n return true;\n } else {\n return false;\n }\n } else {\n return false;\n }\n } else if (charC == 45) {\n var edex = el.value.indexOf('e');\n if (edex == -1) {\n edex = el.value.indexOf('E');\n }\n\n if (el.value == \"\") {\n return true;\n } else if (edex == (el.value.length - 1)) { // If just after e or E\n return true;\n } else {\n return false;\n }\n } else if (charC == 101) { // \"e\"\n if ((el.value.indexOf('e') === -1) && (el.value.indexOf('E') === -1) && (el.value.indexOf('/') == -1)) {\n // Prev symbol must be digit or decimal point:\n if (el.value.slice(-1).search(/\\d/) >= 0) {\n return true;\n } else if (el.value.slice(-1).search(/\\./) >= 0) {\n return true;\n } else {\n return false;\n }\n } else {\n return false;\n }\n } else {\n if (charC > 31 && (charC < 48 || charC > 57))\n return false;\n }\n return true;\n}\n\nfunction numeric_keypress(evnt) {\n var charC = (evnt.which) ? evnt.which : evnt.keyCode;\n\n if (charC == 13) {\n check_numeric(this, evnt);\n } else {\n return isValid(this, charC);\n }\n}\n\n\n\n\n\nfunction make_numeric(qa, outerqDiv, qDiv, aDiv, id) {\n\n\n\n //console.log(answer);\n\n\n outerqDiv.className = \"NumericQn\";\n aDiv.style.display = 'block';\n\n var lab = document.createElement(\"label\");\n lab.className = \"InpLabel\";\n lab.textContent = \"Type numeric answer here:\";\n aDiv.append(lab);\n\n var inp = document.createElement(\"input\");\n inp.type = \"text\";\n //inp.id=\"input-\"+id;\n inp.id = id + \"-0\";\n inp.className = \"Input-text\";\n inp.setAttribute('data-answers', JSON.stringify(qa.answers));\n if (\"precision\" in qa) {\n inp.setAttribute('data-precision', qa.precision);\n }\n aDiv.append(inp);\n //console.log(inp);\n\n //inp.addEventListener(\"keypress\", check_numeric);\n //inp.addEventListener(\"keypress\", numeric_keypress);\n /*\n inp.addEventListener(\"keypress\", function(event) {\n return numeric_keypress(this, event);\n }\n );\n */\n //inp.onkeypress=\"return numeric_keypress(this, event)\";\n inp.onkeypress = numeric_keypress;\n inp.onpaste = event => false;\n\n inp.addEventListener(\"focus\", function (event) {\n this.value = \"\";\n return false;\n }\n );\n\n\n}\nfunction jaxify(string) {\n var mystring = string;\n\n var count = 0;\n var loc = mystring.search(/([^\\\\]|^)(\\$)/);\n\n var count2 = 0;\n var loc2 = mystring.search(/([^\\\\]|^)(\\$\\$)/);\n\n //console.log(loc);\n\n while ((loc >= 0) || (loc2 >= 0)) {\n\n /* Have to replace all the double $$ first with current implementation */\n if (loc2 >= 0) {\n if (count2 % 2 == 0) {\n mystring = mystring.replace(/([^\\\\]|^)(\\$\\$)/, \"$1\\\\[\");\n } else {\n mystring = mystring.replace(/([^\\\\]|^)(\\$\\$)/, \"$1\\\\]\");\n }\n count2++;\n } else {\n if (count % 2 == 0) {\n mystring = mystring.replace(/([^\\\\]|^)(\\$)/, \"$1\\\\(\");\n } else {\n mystring = mystring.replace(/([^\\\\]|^)(\\$)/, \"$1\\\\)\");\n }\n count++;\n }\n loc = mystring.search(/([^\\\\]|^)(\\$)/);\n loc2 = mystring.search(/([^\\\\]|^)(\\$\\$)/);\n //console.log(mystring,\", loc:\",loc,\", loc2:\",loc2);\n }\n\n //console.log(mystring);\n return mystring;\n}\n\n\nfunction show_questions(json, mydiv) {\n console.log('show_questions');\n //var mydiv=document.getElementById(myid);\n var shuffle_questions = mydiv.dataset.shufflequestions;\n var num_questions = mydiv.dataset.numquestions;\n var shuffle_answers = mydiv.dataset.shuffleanswers;\n var max_width = mydiv.dataset.maxwidth;\n\n if (num_questions > json.length) {\n num_questions = json.length;\n }\n\n var questions;\n if ((num_questions < json.length) || (shuffle_questions == \"True\")) {\n //console.log(num_questions+\",\"+json.length);\n questions = getRandomSubarray(json, num_questions);\n } else {\n questions = json;\n }\n\n //console.log(\"SQ: \"+shuffle_questions+\", NQ: \" + num_questions + \", SA: \", shuffle_answers);\n\n // Iterate over questions\n questions.forEach((qa, index, array) => {\n //console.log(qa.question); \n\n var id = makeid(8);\n //console.log(id);\n\n\n // Create Div to contain question and answers\n var iDiv = document.createElement('div');\n //iDiv.id = 'quizWrap' + id + index;\n iDiv.id = 'quizWrap' + id;\n iDiv.className = 'Quiz';\n iDiv.setAttribute('data-qnum', index);\n iDiv.style.maxWidth =max_width+\"px\";\n mydiv.appendChild(iDiv);\n // iDiv.innerHTML=qa.question;\n \n var outerqDiv = document.createElement('div');\n outerqDiv.id = \"OuterquizQn\" + id + index;\n // Create div to contain question part\n var qDiv = document.createElement('div');\n qDiv.id = \"quizQn\" + id + index;\n \n if (qa.question) {\n iDiv.append(outerqDiv);\n\n //qDiv.textContent=qa.question;\n qDiv.innerHTML = jaxify(qa.question);\n outerqDiv.append(qDiv);\n }\n\n // Create div for code inside question\n var codeDiv;\n if (\"code\" in qa) {\n codeDiv = document.createElement('div');\n codeDiv.id = \"code\" + id + index;\n codeDiv.className = \"QuizCode\";\n var codePre = document.createElement('pre');\n codeDiv.append(codePre);\n var codeCode = document.createElement('code');\n codePre.append(codeCode);\n codeCode.innerHTML = qa.code;\n outerqDiv.append(codeDiv);\n //console.log(codeDiv);\n }\n\n\n // Create div to contain answer part\n var aDiv = document.createElement('div');\n aDiv.id = \"quizAns\" + id + index;\n aDiv.className = 'Answer';\n iDiv.append(aDiv);\n\n //console.log(qa.type);\n\n var num_correct;\n if ((qa.type == \"multiple_choice\") || (qa.type == \"many_choice\") ) {\n num_correct = make_mc(qa, shuffle_answers, outerqDiv, qDiv, aDiv, id);\n if (\"answer_cols\" in qa) {\n //aDiv.style.gridTemplateColumns = 'auto '.repeat(qa.answer_cols);\n aDiv.style.gridTemplateColumns = 'repeat(' + qa.answer_cols + ', 1fr)';\n }\n } else if (qa.type == \"numeric\") {\n //console.log(\"numeric\");\n make_numeric(qa, outerqDiv, qDiv, aDiv, id);\n }\n\n\n //Make div for feedback\n var fb = document.createElement(\"div\");\n fb.id = \"fb\" + id;\n //fb.style=\"font-size: 20px;text-align:center;\";\n fb.className = \"Feedback\";\n fb.setAttribute(\"data-answeredcorrect\", 0);\n fb.setAttribute(\"data-numcorrect\", num_correct);\n iDiv.append(fb);\n\n\n });\n var preserveResponses = mydiv.dataset.preserveresponses;\n console.log(preserveResponses);\n console.log(preserveResponses == \"true\");\n if (preserveResponses == \"true\") {\n console.log(preserveResponses);\n // Create Div to contain record of answers\n var iDiv = document.createElement('div');\n iDiv.id = 'responses' + mydiv.id;\n iDiv.className = 'JCResponses';\n // Create a place to store responses as an empty array\n iDiv.setAttribute('data-responses', '[]');\n\n // Dummy Text\n iDiv.innerHTML=\"Select your answers and then follow the directions that will appear here.\"\n //iDiv.className = 'Quiz';\n mydiv.appendChild(iDiv);\n }\n//console.log(\"At end of show_questions\");\n if (typeof MathJax != 'undefined') {\n console.log(\"MathJax version\", MathJax.version);\n var version = MathJax.version;\n setTimeout(function(){\n var version = MathJax.version;\n console.log('After sleep, MathJax version', version);\n if (version[0] == \"2\") {\n MathJax.Hub.Queue([\"Typeset\", MathJax.Hub]);\n } else if (version[0] == \"3\") {\n if (MathJax.hasOwnProperty('typeset') ) {\n MathJax.typeset([mydiv]);\n } else {\n console.log('WARNING: Trying to force load MathJax 3');\n window.MathJax = {\n tex: {\n inlineMath: [['$', '$'], ['\\\\(', '\\\\)']]\n },\n svg: {\n fontCache: 'global'\n }\n };\n\n (function () {\n var script = document.createElement('script');\n script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js';\n script.async = true;\n document.head.appendChild(script);\n })();\n }\n }\n }, 500);\nif (typeof version == 'undefined') {\n } else\n {\n if (version[0] == \"2\") {\n MathJax.Hub.Queue([\"Typeset\", MathJax.Hub]);\n } else if (version[0] == \"3\") {\n if (MathJax.hasOwnProperty('typeset') ) {\n MathJax.typeset([mydiv]);\n } else {\n console.log('WARNING: Trying to force load MathJax 3');\n window.MathJax = {\n tex: {\n inlineMath: [['$', '$'], ['\\\\(', '\\\\)']]\n },\n svg: {\n fontCache: 'global'\n }\n };\n\n (function () {\n var script = document.createElement('script');\n script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js';\n script.async = true;\n document.head.appendChild(script);\n })();\n }\n } else {\n console.log(\"MathJax not found\");\n }\n }\n }\n return false;\n}\n/* This is to handle asynchrony issues in loading Jupyter notebooks\n where the quiz has been previously run. The Javascript was generally\n being run before the div was added to the DOM. I tried to do this\n more elegantly using Mutation Observer, but I didn't get it to work.\n\n Someone more knowledgeable could make this better ;-) */\n\n function try_show() {\n if(document.getElementById(\"TDDPZXphBhqN\")) {\n show_questions(questionsTDDPZXphBhqN, TDDPZXphBhqN); \n } else {\n setTimeout(try_show, 200);\n }\n };\n \n {\n // console.log(element);\n\n //console.log(\"TDDPZXphBhqN\");\n // console.log(document.getElementById(\"TDDPZXphBhqN\"));\n\n try_show();\n }\n " - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 2 - }, - { - "cell_type": "markdown", - "source": [ - "Next, solve this crossword puzzle.\n", - "\n", - "![Crossword Puzzle](../images/crossword_puzzle_sigma_algebra.svg)" - ], - "metadata": { - "collapsed": false - }, - "id": "d0f6cf92e9b8c44a" - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.5" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/src/random_events/interval.py b/src/random_events/interval.py index 413d106..cc99c2a 100644 --- a/src/random_events/interval.py +++ b/src/random_events/interval.py @@ -163,7 +163,7 @@ def center(self) -> float: """ :return: The center point of the interval """ - return ((self.lower + self.upper) / 2) + self.lower + return (self.lower + self.upper) / 2 class Interval(sigma_algebra.AbstractCompositeSet): diff --git a/src/random_events/sigma_algebra.py b/src/random_events/sigma_algebra.py index d2a5cc8..f11dc57 100644 --- a/src/random_events/sigma_algebra.py +++ b/src/random_events/sigma_algebra.py @@ -303,7 +303,7 @@ def to_string(self): """ if self.is_empty(): return EMPTY_SET_SYMBOL - return "{" + " u ".join([simple_set.to_string() for simple_set in self.simple_sets]) + "}" + return " u ".join([simple_set.to_string() for simple_set in self.simple_sets]) def __str__(self): return self.to_string() @@ -360,7 +360,7 @@ def split_into_disjoint_and_non_disjoint(self) -> Tuple[Self, Self]: # get the intersection of a and b intersection_a_b: AbstractSimpleSet = simple_set_a.intersection_with(simple_set_b) - # if the intersection is not empty add it to the non-disjoint set + # if the intersection is not empty, add it to the non-disjoint set non_disjoint.add_simple_set(intersection_a_b) # get the difference of the simple set with the intersection.