random_events.product_algebra#

Attributes#

Classes#

VariableMap

A map from variables to values.

SimpleEvent

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

Event

An event is a disjoint set of simple events.

Module Contents#

random_events.product_algebra.VariableMapSuperClassType#
random_events.product_algebra.VariableMapKey#
random_events.product_algebra.VariableSet#
class random_events.product_algebra.VariableMap(*args, **kwargs)#

Bases: VariableMapSuperClassType

A map from variables to values.

Accessing a variable by name is also supported.

property variables: random_events.variable.Iterable[random_events.variable.Variable]#
property assignments: sortedcontainers.SortedValuesView#
get_variable(key: VariableMapKey) random_events.variable.Variable#

Get the variable matching the key.

Parameters:

key – The variable or its name.

Returns:

The matching variable.

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

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

__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})
Parameters:
  • key – key for item

  • value – value for item

__copy__()#
class random_events.product_algebra.SimpleEvent(*args, **kwargs)#

Bases: random_events.sigma_algebra.AbstractSimpleSet, VariableMap

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

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

_cpp_object: random_events.variable.rl.SimpleEvent#

The C++ object that this class wraps.

_update_cpp_object()#
_setitem_without_cpp(key: VariableMapKey, value: random_events.variable.Any)#

See __setitem__ for more information.

_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.

as_composite_set() Event#

Convert this simple set to a composite set.

Returns:

The composite set

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

__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.

Parameters:
  • key – The variable (or its name) to set the value for

  • value – The value to set

marginal(variables: VariableSet) SimpleEvent#

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

Parameters:

variables – The variables to contain in the marginal event

Returns:

The marginal event

non_empty_to_string() str#
Returns:

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

variables_to_json() typing_extensions.List#
assignments_to_json() typing_extensions.List#
to_json() random_events.variable.Dict[str, random_events.variable.Any]#
to_json_assignments_only() random_events.variable.Dict[str, random_events.variable.Any]#
classmethod _from_json(data: random_events.variable.Dict[str, random_events.variable.Any]) random_events.variable.Self#

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.

Parameters:

data – The json dict

Returns:

The deserialized object

classmethod 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#
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.

Parameters:

new_variables – A dictionary mapping current variables to new variables

Returns:

A new SimpleEvent with the updated variables

plot() typing_extensions.Union[typing_extensions.List[plotly.graph_objects.Scatter], typing_extensions.List[plotly.graph_objects.Mesh3d]]#

Plot the event.

plot_1d() typing_extensions.List[plotly.graph_objects.Scatter]#

Plot the event in 1D.

plot_2d() typing_extensions.List[plotly.graph_objects.Scatter]#

Plot the event in 2D.

plot_3d() typing_extensions.List[plotly.graph_objects.Mesh3d]#

Plot the event in 3D.

plotly_layout() random_events.variable.Dict#

Create a layout for the plotly plot.

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.

Parameters:

variables – The variables to fill the event with

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.

__deepcopy__()#
class random_events.product_algebra.Event(*simple_sets)#

Bases: 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.

_cpp_object: random_events.variable.rl.Event#

The C++ object that this class wraps.

simple_set_example: 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.

_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.

property simple_sets: random_events.sigma_algebra.Tuple[SimpleEvent, Ellipsis]#
Returns:

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

property variables: sortedcontainers.SortedSet#
get_variable(key: VariableMapKey) random_events.variable.Variable#

Get the variable matching the key.

Parameters:

key – The variable or its name.

Returns:

The matching variable.

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

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.

Parameters:

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

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.

Parameters:

variables – The variables to fill the event with.

marginal(variables: VariableSet) Event#

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

Parameters:

variables – The variables to contain in the marginal event

Returns:

The marginal event

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.

Returns:

The bounding box as a simple event

update_variables(new_variables: random_events.variable.Dict[random_events.variable.Variable, random_events.variable.Variable]) Event#

see update_variables()

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

Plot the complex event.

Parameters:

color – The color to use for this event

plotly_layout() random_events.variable.Dict#

Create a layout for the plotly plot.

add_simple_set(simple_set: random_events.sigma_algebra.AbstractSimpleSet)#

Add a simple set to this event.

Parameters:

simple_set – The simple set to add

to_json() random_events.variable.Dict[str, random_events.variable.Any]#
classmethod _from_json(data: random_events.variable.Dict[str, random_events.variable.Any]) random_events.variable.Self#

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.

Parameters:

data – The json dict

Returns:

The deserialized object