random_events.product_algebra
=============================

.. py:module:: random_events.product_algebra


Attributes
----------

.. autoapisummary::

   random_events.product_algebra.VariableMapSuperClassType
   random_events.product_algebra.VariableMapKey
   random_events.product_algebra.VariableSet


Classes
-------

.. autoapisummary::

   random_events.product_algebra.VariableMap
   random_events.product_algebra.SimpleEvent
   random_events.product_algebra.Event


Module Contents
---------------

.. py:data:: VariableMapSuperClassType

.. py:data:: VariableMapKey

.. py:data:: VariableSet

.. py:class:: VariableMap(*args, **kwargs)

   Bases: :py:obj:`VariableMapSuperClassType`


   A map from variables to values.

   Accessing a variable by name is also supported.


   .. py:property:: variables
      :type: random_events.variable.Iterable[random_events.variable.Variable]



   .. py:property:: assignments
      :type: sortedcontainers.SortedValuesView



   .. py:method:: get_variable(key: VariableMapKey) -> random_events.variable.Variable

      Get the variable matching the key.

      :param key: The variable or its name.
      :return: The matching variable.



   .. py:method:: __getitem__(key: typing_extensions.Union[str, random_events.variable.Variable])

      x.__getitem__(y) <==> x[y]



   .. py:method:: __setitem__(key: typing_extensions.Union[str, random_events.variable.Variable], value: random_events.variable.Any)

      Store item in sorted dict with `key` and corresponding `value`.

      ``sd.__setitem__(key, value)`` <==> ``sd[key] = value``

      Runtime complexity: `O(log(n))` -- approximate.

      >>> sd = SortedDict()
      >>> sd['c'] = 3
      >>> sd['a'] = 1
      >>> sd['b'] = 2
      >>> sd
      SortedDict({'a': 1, 'b': 2, 'c': 3})

      :param key: key for item
      :param value: value for item




   .. py:method:: __copy__()


.. py:class:: SimpleEvent(*args, **kwargs)

   Bases: :py:obj:`random_events.sigma_algebra.AbstractSimpleSet`, :py:obj:`VariableMap`


   A simple event is a set of assignments of variables to values.

   A simple event is logically equivalent to a conjunction of assignments.


   .. py:attribute:: _cpp_object
      :type:  random_events.variable.rl.SimpleEvent

      The C++ object that this class wraps.



   .. py:method:: _update_cpp_object()


   .. py:method:: _setitem_without_cpp(key: VariableMapKey, value: random_events.variable.Any)

      See __setitem__ for more information.



   .. py:method:: _from_cpp(cpp_object: random_events.variable.rl.SimpleEvent)

      Create a new instance of this class from a C++ object.

      This method should also add fields that are python only to the instance that is created.
      This cannot be a class method since the values of the python-only fields are instance-specific.



   .. py:method:: as_composite_set() -> Event

      Convert this simple set to a composite set.

      :return: The composite set



   .. py:method:: contains(item: random_events.sigma_algebra.Tuple) -> bool

      Check if this set contains an item.
      :param item: The item to check
      :return: Rather if the item is in the set or not



   .. py:method:: __setitem__(key: VariableMapKey, value: random_events.variable.Any)

      Set the value of a variable in the event.
      Also allows for assigning variables to values outside the classes of this package.
      If this is the case, this tries to convert the value to a CompositeSet.

      :param key: The variable (or its name) to set the value for
      :param value: The value to set



   .. py:method:: marginal(variables: VariableSet) -> SimpleEvent

      Create the marginal event, that only contains the variables given.

      :param variables: The variables to contain in the marginal event
      :return: The marginal event



   .. py:method:: non_empty_to_string() -> str

      :return: A string representation of this set if it is not empty.



   .. py:method:: variables_to_json() -> typing_extensions.List


   .. py:method:: assignments_to_json() -> typing_extensions.List


   .. py:method:: to_json() -> random_events.variable.Dict[str, random_events.variable.Any]


   .. py:method:: to_json_assignments_only() -> random_events.variable.Dict[str, random_events.variable.Any]


   .. py:method:: _from_json(data: random_events.variable.Dict[str, random_events.variable.Any]) -> random_events.variable.Self
      :classmethod:


      Create a variable from a json dict.
      This method is called from the from_json method after the correct subclass is determined and should be
      overwritten by the respective subclass.

      :param data: The json dict
      :return: The deserialized object



   .. py:method:: from_json_given_variables(data: random_events.variable.Dict[str, random_events.variable.Any], variables: typing_extensions.List[random_events.variable.Variable]) -> random_events.variable.Self
      :classmethod:



   .. py:method:: update_variables(new_variables: random_events.variable.Dict[random_events.variable.Variable, random_events.variable.Variable]) -> random_events.variable.Self

      Construct a new simple event where the own variables are replaced with the new variables.
      If the new variables are missing mappings, the old variables are kept for the missing updates.

      :param new_variables: A dictionary mapping current variables to new variables
      :return: A new SimpleEvent with the updated variables



   .. py:method:: plot() -> typing_extensions.Union[typing_extensions.List[plotly.graph_objects.Scatter], typing_extensions.List[plotly.graph_objects.Mesh3d]]

      Plot the event.



   .. py:method:: plot_1d() -> typing_extensions.List[plotly.graph_objects.Scatter]

      Plot the event in 1D.



   .. py:method:: plot_2d() -> typing_extensions.List[plotly.graph_objects.Scatter]

      Plot the event in 2D.



   .. py:method:: plot_3d() -> typing_extensions.List[plotly.graph_objects.Mesh3d]

      Plot the event in 3D.



   .. py:method:: plotly_layout() -> random_events.variable.Dict

      Create a layout for the plotly plot.



   .. py:method:: fill_missing_variables(variables: random_events.variable.Iterable[random_events.variable.Variable])

      Fill this with the variables that are not in self but in `variables` in-place.
      The variables are mapped to their domain.

      :param variables: The variables to fill the event with



   .. py:method:: fill_missing_variables_pure(variables: random_events.variable.Iterable[random_events.variable.Variable])

      Fill this with the variables that are not in self but in `variables`.
      The variables are mapped to their domain.



   .. py:method:: __deepcopy__()


.. py:class:: Event(*simple_sets)

   Bases: :py:obj:`random_events.variable.AbstractCompositeSet`


   An event is a disjoint set of simple events.

   Every simple event added to this event that is missing variables that any other event in this event has, will be
   extended with the missing variable. The missing variables are mapped to their domain.



   .. py:attribute:: _cpp_object
      :type:  random_events.variable.rl.Event

      The C++ object that this class wraps.



   .. py:attribute:: simple_set_example
      :type:  SimpleEvent

      An example of a simple set that is used to create new simple sets. 
      Fields that are python only are read from this instance when reading from cpp.



   .. py:method:: _from_cpp(cpp_object)

      Create a new instance of this class from a C++ object.

      This method should also add fields that are python only to the instance that is created.
      This cannot be a class method since the values of the python-only fields are instance-specific.



   .. py:property:: simple_sets
      :type: random_events.sigma_algebra.Tuple[SimpleEvent, Ellipsis]


      :return: The simple sets contained in the union described by this set.



   .. py:property:: variables
      :type: sortedcontainers.SortedSet



   .. py:method:: get_variable(key: VariableMapKey) -> random_events.variable.Variable

      Get the variable matching the key.

      :param key: The variable or its name.
      :return: The matching variable.



   .. py:method:: update_simple_set_example()

      Update the simple set example to the first simple set in the event.
      Use this whenever the simple sets change in-place



   .. py:method:: fill_missing_variables(variables: random_events.variable.Optional[random_events.variable.Iterable[random_events.variable.Variable]] = None)

      Fill all simple sets with the missing variables in-place.

      :param variables: The variables to fill the event with. If None, all variables are used.



   .. py:method:: fill_missing_variables_pure(variables: random_events.variable.Optional[random_events.variable.Iterable[random_events.variable.Variable]] = None)

      Fill all simple sets with the missing variables.

      :param variables: The variables to fill the event with.



   .. py:method:: marginal(variables: VariableSet) -> Event

      Create the marginal event, that only contains the variables given.

      :param variables: The variables to contain in the marginal event
      :return: The marginal event



   .. py:method:: bounding_box() -> SimpleEvent

      Compute the bounding box of the event.
      The bounding box is the smallest simple event that contains this event. It is computed by taking the union
      of all simple events variable wise.

      :return: The bounding box as a simple event



   .. py:method:: update_variables(new_variables: random_events.variable.Dict[random_events.variable.Variable, random_events.variable.Variable]) -> Event

      see :func:`~random_events.product_algebra.SimpleEvent.update_variables`



   .. py:method:: plot(color='#636EFA') -> typing_extensions.Union[typing_extensions.List[plotly.graph_objects.Scatter], typing_extensions.List[plotly.graph_objects.Mesh3d]]

      Plot the complex event.

      :param color: The color to use for this event



   .. py:method:: plotly_layout() -> random_events.variable.Dict

      Create a layout for the plotly plot.



   .. py:method:: add_simple_set(simple_set: random_events.sigma_algebra.AbstractSimpleSet)

      Add a simple set to this event.

      :param simple_set: The simple set to add



   .. py:method:: to_json() -> random_events.variable.Dict[str, random_events.variable.Any]


   .. py:method:: _from_json(data: random_events.variable.Dict[str, random_events.variable.Any]) -> random_events.variable.Self
      :classmethod:


      Create a variable from a json dict.
      This method is called from the from_json method after the correct subclass is determined and should be
      overwritten by the respective subclass.

      :param data: The json dict
      :return: The deserialized object



