probabilistic_model.distributions
=================================

.. py:module:: probabilistic_model.distributions


Submodules
----------

.. toctree::
   :maxdepth: 1

   /autoapi/probabilistic_model/distributions/distributions/index
   /autoapi/probabilistic_model/distributions/gaussian/index
   /autoapi/probabilistic_model/distributions/helper/index
   /autoapi/probabilistic_model/distributions/multinomial/index
   /autoapi/probabilistic_model/distributions/uniform/index


Attributes
----------

.. autoapisummary::

   probabilistic_model.distributions.SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT
   probabilistic_model.distributions.OrderType
   probabilistic_model.distributions.PADDING_FACTOR_FOR_X_AXIS_IN_PLOT
   probabilistic_model.distributions.EXPECTATION_TRACE_NAME
   probabilistic_model.distributions.MODE_TRACE_NAME
   probabilistic_model.distributions.MODE_TRACE_COLOR
   probabilistic_model.distributions.PDF_TRACE_NAME
   probabilistic_model.distributions.CDF_TRACE_NAME
   probabilistic_model.distributions.CDF_TRACE_COLOR
   probabilistic_model.distributions.PDF_TRACE_COLOR
   probabilistic_model.distributions.SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT
   probabilistic_model.distributions.OrderType
   probabilistic_model.distributions.SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT
   probabilistic_model.distributions.OrderType


Classes
-------

.. autoapisummary::

   probabilistic_model.distributions.DrawIOInterface
   probabilistic_model.distributions.ProbabilisticModel
   probabilistic_model.distributions.MissingDict
   probabilistic_model.distributions.UnivariateDistribution
   probabilistic_model.distributions.ContinuousDistribution
   probabilistic_model.distributions.ContinuousDistributionWithFiniteSupport
   probabilistic_model.distributions.DiscreteDistribution
   probabilistic_model.distributions.SymbolicDistribution
   probabilistic_model.distributions.IntegerDistribution
   probabilistic_model.distributions.DiracDeltaDistribution
   probabilistic_model.distributions.UniformDistribution
   probabilistic_model.distributions.DrawIOInterface
   probabilistic_model.distributions.ProbabilisticModel
   probabilistic_model.distributions.MissingDict
   probabilistic_model.distributions.UnivariateDistribution
   probabilistic_model.distributions.ContinuousDistribution
   probabilistic_model.distributions.ContinuousDistributionWithFiniteSupport
   probabilistic_model.distributions.DiscreteDistribution
   probabilistic_model.distributions.SymbolicDistribution
   probabilistic_model.distributions.IntegerDistribution
   probabilistic_model.distributions.DiracDeltaDistribution
   probabilistic_model.distributions.GaussianDistribution
   probabilistic_model.distributions.TruncatedGaussianDistribution
   probabilistic_model.distributions.DrawIOInterface
   probabilistic_model.distributions.ProbabilisticModel
   probabilistic_model.distributions.MissingDict
   probabilistic_model.distributions.UnivariateDistribution
   probabilistic_model.distributions.ContinuousDistribution
   probabilistic_model.distributions.ContinuousDistributionWithFiniteSupport
   probabilistic_model.distributions.DiscreteDistribution
   probabilistic_model.distributions.SymbolicDistribution
   probabilistic_model.distributions.IntegerDistribution
   probabilistic_model.distributions.DiracDeltaDistribution


Functions
---------

.. autoapisummary::

   probabilistic_model.distributions.interval_as_array
   probabilistic_model.distributions.interval_as_array
   probabilistic_model.distributions.simple_interval_as_array
   probabilistic_model.distributions.interval_as_array


Package Contents
----------------

.. py:data:: SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT
   :value: 1.05


.. py:class:: DrawIOInterface

   Mixin class for objects that can be used with a drawio exporter.


   .. py:property:: drawio_label
      :type: str

      :abstractmethod:


      The label of the object as a drawio compatible string.



   .. py:property:: drawio_style
      :type: typing_extensions.Dict[str, typing_extensions.Any]

      :abstractmethod:


      The style of the object.



.. py:class:: ProbabilisticModel

   Bases: :py:obj:`abc.ABC`


   Abstract base class for probabilistic models.

   The definition of events follows the definition of events in the random_events package.
   The definition of functions is motivated by the background knowledge provided in the probabilistic circuits.

   This class can be used as an interface to any kind of probabilistic model, tractable or not.



   .. py:property:: representation
      :type: str


      The symbol used to represent this distribution.



   .. py:property:: variables
      :type: random_events.set.Tuple[random_events.variable.Variable, Ellipsis]

      :abstractmethod:


      :return: The variables of the model.



   .. py:property:: support
      :type: random_events.product_algebra.Event

      :abstractmethod:


      :return: The support of the model.



   .. py:method:: likelihood(events: random_events.product_algebra.np.array) -> random_events.product_algebra.np.array

      Calculate the likelihood of an array of events.

      The likelihood is a full evidence query, i.e., an assignment to all variables in the model.
      The order of elements in the event has to correspond to the order of variables in the model.

      The event belongs to the class of full evidence queries.

      ..
      Note:: You can read more about this query class in Definition 1 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=TAfIX2LmOWM-Fd2B&t=785>`_.
          :cite:p:`youtube2020probabilistic`

      :param events: The array of full evidence events.
      The shape of the array has to be (n, len(self.variables)).
      :return: The likelihood of the events as an array with shape (n,).



   .. py:method:: log_likelihood(events: random_events.product_algebra.np.array) -> random_events.product_algebra.np.array
      :abstractmethod:


      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: cdf(events: random_events.product_algebra.np.array) -> random_events.product_algebra.np.array
      :abstractmethod:


      Calculate the cumulative distribution function of an event-array.

      The event belongs to the class of full evidence queries.

      ..Note:: The cdf only exists if all variables are continuous or integers.

      :param events: The array of full evidence events.
                     The shape of the array has to be (n, len(self.variables)).
      :return: The cumulative distribution function of the event as an array of shape (n,).



   .. py:method:: probability(event: random_events.product_algebra.Event) -> float

      Calculate the probability of an event.
      The event is richly described by the random_events package.

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float
      :abstractmethod:


      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: mode() -> random_events.set.Tuple[random_events.product_algebra.Event, float]

      Calculate the mode of the model.
      The mode is the **set** of most likely events.

      The calculation belongs to the map query class.

      .. Note:: You can read more about queries of this class in Definition 26 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=FjREKNtAV0owm27A&t=1962>`_.
          :cite:p:`youtube2020probabilistic`

      :return: The mode and its likelihood.



   .. py:method:: log_mode() -> random_events.set.Tuple[random_events.product_algebra.Event, float]
      :abstractmethod:


      Calculate the mode of the model.

      Check the documentation of `mode` for more information.

      :return: The mode and its log-likelihood.



   .. py:method:: marginal(variables: random_events.variable.Iterable[random_events.variable.Variable]) -> random_events.variable.Optional[random_events.variable.Self]
      :abstractmethod:


      Calculate the marginal distribution of a set of variables.

      :param variables: The variables to calculate the marginal distribution on.
      :return: The marginal distribution over the variables.



   .. py:method:: truncated(event: random_events.product_algebra.Event) -> random_events.set.Tuple[random_events.variable.Optional[random_events.product_algebra.Union[ProbabilisticModel, random_events.variable.Self]], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      If the event is impossible, the truncated distribution is None and the probability is 0.

      :param event: The event to condition on.
      :return: The truncated distribution and the probability of the event.



   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> random_events.set.Tuple[random_events.variable.Optional[random_events.product_algebra.Union[ProbabilisticModel, random_events.variable.Self]], float]
      :abstractmethod:


      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: conditional(point: random_events.variable.Dict[random_events.variable.Variable, random_events.variable.Any]) -> random_events.set.Tuple[random_events.variable.Optional[random_events.variable.Self], float]

      Calculate the truncated distribution P(*| point) and the probability of the event.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: log_conditional(point: random_events.variable.Dict[random_events.variable.Variable, random_events.variable.Any]) -> random_events.set.Tuple[random_events.variable.Optional[random_events.variable.Self], float]
      :abstractmethod:


      Calculate the truncated distribution P(*| point) and the probability of the event.
      Check the documentation of `conditional` for more information.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: sample(amount: int) -> random_events.product_algebra.np.array
      :abstractmethod:


      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



   .. py:method:: moment(order: OrderType, center: CenterType) -> MomentType
      :abstractmethod:


      Calculate the (centralized) moment of the distribution.

      .. math::

          \int_{-\infty}^{\infty} (x - center)^{order} pdf(x) dx

      .. Note:: You can read more about queries of this class in Definition 22 in :cite:p:`choi2020probabilistic`_.
          :cite:p:`youtube2020probabilistic`


      :param order: The orders of the moment as a variable map for every continuous and integer variable.
      :param center: The center of the moment as a variable map for every continuous and integer variable.
      :return: The moments of the variables in `order`.



   .. py:method:: expectation(variables: random_events.variable.Optional[random_events.variable.Iterable[random_events.variable.Variable]] = None) -> MomentType

      Calculate the expectation of the numeric variables in `variables`.

      :param variables: The variable to calculate the expectation of.
      :return: The expectation of the variable.



   .. py:method:: variance(variables: random_events.variable.Optional[random_events.variable.Iterable[random_events.variable.Variable]] = None) -> MomentType

      Calculate the variance of the numeric variables in `variables`.

      :param variables: The variable to calculate the variance of.
      :return: The variance of the variable.



   .. py:method:: universal_simple_event() -> random_events.product_algebra.SimpleEvent

      :return: A simple event that contains every possible value.



   .. py:method:: translate(translation: random_events.variable.Dict[random_events.variable.Variable, float])
      :abstractmethod:


      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: random_events.variable.Dict[random_events.variable.Variable, float])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



   .. py:method:: __copy__()
      :abstractmethod:



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

      Create a layout for the plotly plot.

      :return: The layout.



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

      :return: The layout argument for plotly figures as dict



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

      :return: The layout argument for plotly figures as dict



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

      :return: The layout argument for plotly figures as dict



   .. py:method:: plot(number_of_samples: int = 1000, surface=False, mode=False) -> random_events.product_algebra.List

      Generate traces that can be plotted with plotly.

      :param number_of_samples: The number of samples to draw.
      :param surface: If True, plot the model as a surface plot.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: plot_1d_symbolic() -> random_events.product_algebra.List


   .. py:method:: plot_1d_numeric(number_of_samples: int, mode=False) -> random_events.product_algebra.List

      Plot a one-dimensional model using samples.

      :param number_of_samples: The number of samples to draw.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: univariate_expectation_trace(height: float) -> random_events.product_algebra.go.Scatter

      Create a trace for the expectation of the model in 1d.
      :param height: The height of the trace.
      :return: The trace.



   .. py:method:: univariate_mode_traces(mode: random_events.variable.Optional[random_events.product_algebra.Event], height: float)


   .. py:method:: univariate_complement_of_support_trace(min_of_samples: float, max_of_samples: float) -> random_events.product_algebra.List

      Create a trace for the complement of the support of the model in 1d.
      :param min_of_samples: The minimum value of the samples.
      :param max_of_samples: The maximum value of the samples.
      :return: A list of traces for the support of the model.



   .. py:method:: plot_2d(number_of_samples: int, mode=False) -> random_events.product_algebra.List

      Plot a two-dimensional model.

      :param number_of_samples: The number of samples to draw.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: plot_2d_surface(number_of_samples: int) -> random_events.product_algebra.List

      Plot a two-dimensional model as a surface plot.

      :param number_of_samples: The number of samples to draw.
      :return: The traces.



   .. py:method:: expectation_trace_2d_surface(height: float) -> random_events.product_algebra.go.Scatter3d


   .. py:method:: bounding_box_trace_of_simple_event(simple_event: random_events.product_algebra.SimpleEvent, samples: random_events.product_algebra.np.array, fill_value=0.0) -> random_events.product_algebra.go.Surface

      Create a bounding box trace for a simple event.
      :param simple_event: The simple event.
      :param samples: The samples to read from if bounds are infinite.
      :param fill_value: The height of the box.

      :return: The trace.



   .. py:method:: plot_2d_surface_of_simple_event(simple_event: random_events.product_algebra.SimpleEvent, samples: random_events.product_algebra.np.array)


   .. py:method:: plot_3d(number_of_samples: int, mode=False) -> random_events.product_algebra.List

      Plot a three-dimensional model using samples.

      :param number_of_samples: The number of samples to draw.
      :param mode: If True, plot the mode of the model.
      :return: The traces.s



   .. py:method:: multivariate_mode_traces()

      :return: traces for the mode of a multivariate model.



.. py:data:: OrderType

.. py:class:: MissingDict

   Bases: :py:obj:`collections.defaultdict`


   A defaultdict that returns the default value when the key is missing and does **not** add the key to the dict.


   .. py:method:: __missing__(key)


.. py:function:: interval_as_array(interval: random_events.interval.Interval) -> numpy.ndarray

   Convert an interval to a numpy array.
   The resulting array has shape (n, 2) where n is the number of simple intervals in the interval.
   The first column contains the lower bounds and the second column the upper bounds of the simple intervals.
   :param interval: The interval
   :return:  as numpy array


.. py:class:: UnivariateDistribution

   Bases: :py:obj:`probabilistic_model.probabilistic_model.ProbabilisticModel`, :py:obj:`random_events.variable.SubclassJSONSerializer`, :py:obj:`probabilistic_model.interfaces.drawio.drawio.DrawIOInterface`


   Abstract Base class for Univariate distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Variable


   .. py:property:: variables
      :type: typing_extensions.Tuple[random_events.variable.Variable, Ellipsis]


      :return: The variables of the model.



   .. py:property:: support
      :type: random_events.product_algebra.Event


      :return: The support of the model.



   .. py:property:: univariate_support
      :type: random_events.variable.AbstractCompositeSet

      :abstractmethod:


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: log_mode() -> typing_extensions.Tuple[random_events.product_algebra.Event, float]

      Calculate the mode of the model.

      Check the documentation of `mode` for more information.

      :return: The mode and its log-likelihood.



   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]
      :abstractmethod:


      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: marginal(variables: typing_extensions.Iterable[random_events.variable.Variable]) -> random_events.variable.Optional[typing_extensions.Self]

      Calculate the marginal distribution of a set of variables.

      :param variables: The variables to calculate the marginal distribution on.
      :return: The marginal distribution over the variables.



   .. py:method:: __eq__(other: typing_extensions.Self)


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


   .. py:method:: composite_set_from_event(event: random_events.product_algebra.Event) -> random_events.variable.AbstractCompositeSet

      Extract the composite set from the event that is relevant for this distribution.
      :param event: The event
      :return: The composite set



   .. py:property:: abbreviated_symbol
      :type: str



   .. py:property:: drawio_style
      :type: typing_extensions.Dict[str, typing_extensions.Any]


      The style of the object.



.. py:class:: ContinuousDistribution

   Bases: :py:obj:`UnivariateDistribution`


   Abstract base class for continuous distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Continuous


   .. py:property:: univariate_support
      :type: random_events.variable.Interval

      :abstractmethod:


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: cdf(x: numpy.array) -> numpy.array
      :abstractmethod:


      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: log_conditional(point: typing_extensions.Dict[random_events.variable.Variable, typing_extensions.Any]) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Union[probabilistic_model.probabilistic_model.ProbabilisticModel, typing_extensions.Self]], float]

      Calculate the truncated distribution P(*| point) and the probability of the event.
      Check the documentation of `conditional` for more information.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: log_conditional_from_simple_interval(interval: random_events.variable.SimpleInterval) -> typing_extensions.Tuple[typing_extensions.Self, float]
      :abstractmethod:


      Calculate the truncated distribution given a simple interval.

      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



   .. py:method:: log_conditional_from_interval(interval) -> typing_extensions.Tuple[typing_extensions.Self, float]
      :abstractmethod:


      Calculate the truncated distribution given an interval with p(interval) > 0.
      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



.. py:class:: ContinuousDistributionWithFiniteSupport

   Bases: :py:obj:`ContinuousDistribution`


   Abstract base class for continuous distributions with finite support.


   .. py:attribute:: interval
      :type:  random_events.variable.SimpleInterval

      The interval of the distribution.



   .. py:property:: lower
      :type: float



   .. py:property:: upper
      :type: float



   .. py:property:: univariate_support
      :type: random_events.variable.Interval


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: left_included_condition(x: numpy.array) -> numpy.array

      Check if x is included in the left bound of the interval.
      :param x: The data
      :return: A boolean array



   .. py:method:: right_included_condition(x: numpy.array) -> numpy.array

      Check if x is included in the right bound of the interval.
      :param x: The data
      :return: A boolean array



   .. py:method:: included_condition(x: numpy.array) -> numpy.array

      Check if x is included in interval.
      :param x: The data
      :return: A boolean array



   .. py:method:: log_likelihood(x: numpy.array) -> numpy.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: log_likelihood_without_bounds_check(x: numpy.array) -> numpy.array
      :abstractmethod:


      Evaluate the logarithmic likelihood function at `x` without checking the inclusion into the interval.
      :param x: x where p(x) > 0
      :return: log(p(x))



   .. py:method:: translate(translation: typing_extensions.Dict[random_events.variable.Variable, float])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: typing_extensions.Dict[random_events.variable.Variable, float])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



.. py:class:: DiscreteDistribution(variable: typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer], probabilities: random_events.variable.Optional[probabilistic_model.utils.MissingDict[typing_extensions.Union[int, random_events.variable.SetElement], float]])

   Bases: :py:obj:`UnivariateDistribution`


   Abstract base class for univariate discrete distributions.


   .. py:attribute:: variable
      :type:  typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer]


   .. py:attribute:: probabilities
      :type:  probabilistic_model.utils.MissingDict[int, float]

      A dict that maps from integers (hash(symbol) for symbols) to probabilities.



   .. py:method:: __eq__(other)


   .. py:method:: __hash__()


   .. py:method:: log_likelihood(events: numpy.array) -> numpy.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: fit(data: numpy.array) -> typing_extensions.Self

      Fit the distribution to the data.

      The probabilities are set equal to the frequencies in the data.
      The data contains the indices of the domain elements (if symbolic) or the values (if integer).

      :param data: The data.
      :return: The fitted distribution



   .. py:method:: probabilities_for_plotting() -> typing_extensions.Dict[typing_extensions.Union[int, str], float]
      :abstractmethod:


      :return: The probabilities as dict that can be plotted.



   .. py:method:: plot(**kwargs) -> typing_extensions.List[plotly.graph_objects.Bar]

      Plot the distribution.



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


   .. py:method:: _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) -> typing_extensions.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:: normalize()

      Normalize the distribution.



   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: log_conditional(point: typing_extensions.Dict[random_events.variable.Variable, typing_extensions.Any]) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| point) and the probability of the event.
      Check the documentation of `conditional` for more information.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]


   .. py:method:: __copy__() -> typing_extensions.Self


   .. py:method:: __deepcopy__(memo=None) -> typing_extensions.Self


   .. py:method:: __repr__()


   .. py:method:: sample(amount: int) -> numpy.array

      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



.. py:class:: SymbolicDistribution(variable: typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer], probabilities: random_events.variable.Optional[probabilistic_model.utils.MissingDict[typing_extensions.Union[int, random_events.variable.SetElement], float]])

   Bases: :py:obj:`DiscreteDistribution`


   Class for symbolic (categorical) distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Symbolic


   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.Set, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]


   .. py:method:: probabilities_for_plotting() -> typing_extensions.Dict[typing_extensions.Union[int, str], float]

      :return: The probabilities as dict that can be plotted.



   .. py:property:: univariate_support
      :type: random_events.variable.Set


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:property:: drawio_label

      The label of the object as a drawio compatible string.



   .. py:property:: image


   .. py:method:: fit(data: numpy.array) -> typing_extensions.Self

      Fit the distribution to the data.

      The probabilities are set equal to the frequencies in the data.
      The data contains the indices of the domain elements (if symbolic) or the values (if integer).

      :param data: The data.
      :return: The fitted distribution



   .. py:method:: fit_from_indices(data: numpy.array) -> typing_extensions.Self


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


   .. py:method:: _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) -> typing_extensions.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:class:: IntegerDistribution(variable: random_events.variable.Integer, probabilities: random_events.variable.Optional[probabilistic_model.utils.MissingDict[typing_extensions.Union[int, random_events.variable.SetElement], float]])

   Bases: :py:obj:`ContinuousDistribution`, :py:obj:`DiscreteDistribution`


   Abstract base class for integer distributions. Integer distributions also implement the methods of continuous
   distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Integer


   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: probabilities_for_plotting() -> typing_extensions.Dict[typing_extensions.Union[int, str], float]

      :return: The probabilities as dict that can be plotted.



   .. py:property:: univariate_support
      :type: random_events.variable.Interval


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: cdf(x: numpy.array) -> numpy.array

      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:method:: moment(order: probabilistic_model.probabilistic_model.OrderType, center: probabilistic_model.probabilistic_model.CenterType) -> probabilistic_model.probabilistic_model.MomentType

      Calculate the (centralized) moment of the distribution.

      .. math::

          \int_{-\infty}^{\infty} (x - center)^{order} pdf(x) dx

      .. Note:: You can read more about queries of this class in Definition 22 in :cite:p:`choi2020probabilistic`_.
          :cite:p:`youtube2020probabilistic`


      :param order: The orders of the moment as a variable map for every continuous and integer variable.
      :param center: The center of the moment as a variable map for every continuous and integer variable.
      :return: The moments of the variables in `order`.



   .. py:method:: plot(**kwargs) -> typing_extensions.List[plotly.graph_objects.Bar]

      Generate traces that can be plotted with plotly.

      :param number_of_samples: The number of samples to draw.
      :param surface: If True, plot the model as a surface plot.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: translate(translation: typing_extensions.Dict[random_events.variable.Variable, int])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: typing_extensions.Dict[random_events.variable.Variable, int])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



.. py:class:: DiracDeltaDistribution(variable: random_events.variable.Continuous, location: float, density_cap: float = np.inf, tolerance: float = 1e-06)

   Bases: :py:obj:`ContinuousDistribution`


   Class for Dirac delta distributions.
   The Dirac measure is used whenever evidence is given as a singleton instance.

   https://en.wikipedia.org/wiki/Dirac_delta_function


   .. py:attribute:: variable
      :type:  random_events.variable.Continuous


   .. py:attribute:: location
      :type:  float

      The location of the Dirac delta distribution.



   .. py:attribute:: density_cap
      :type:  float

      The density cap of the Dirac delta distribution.
      This value will be used to replace infinity in likelihood.



   .. py:attribute:: tolerance
      :type:  float
      :value: 1e-06


      The tolerance of deviations of the `location` of the Dirac delta distribution.
      This is used during calculations to take precision problems into account.



   .. py:method:: log_likelihood(events: numpy.array) -> numpy.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: cdf(x: numpy.array) -> numpy.array

      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:property:: abbreviated_symbol
      :type: str



   .. py:property:: univariate_support
      :type: random_events.variable.Interval


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: log_conditional_from_simple_interval(interval: random_events.variable.SimpleInterval) -> typing_extensions.Tuple[typing_extensions.Self, float]

      Calculate the truncated distribution given a simple interval.

      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: sample(amount: int) -> numpy.array

      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



   .. py:method:: moment(order: probabilistic_model.probabilistic_model.OrderType, center: probabilistic_model.probabilistic_model.CenterType) -> probabilistic_model.probabilistic_model.MomentType

      Calculate the (centralized) moment of the distribution.

      .. math::

          \int_{-\infty}^{\infty} (x - center)^{order} pdf(x) dx

      .. Note:: You can read more about queries of this class in Definition 22 in :cite:p:`choi2020probabilistic`_.
          :cite:p:`youtube2020probabilistic`


      :param order: The orders of the moment as a variable map for every continuous and integer variable.
      :param center: The center of the moment as a variable map for every continuous and integer variable.
      :return: The moments of the variables in `order`.



   .. py:method:: __eq__(other)


   .. py:method:: __hash__()


   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:method:: __repr__()


   .. py:method:: __copy__()


   .. py:method:: __deepcopy__(memo=None)


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


   .. py:method:: _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) -> typing_extensions.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:: plot(**kwargs) -> typing_extensions.List

      Generate traces that can be plotted with plotly.

      :param number_of_samples: The number of samples to draw.
      :param surface: If True, plot the model as a surface plot.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: translate(translation: random_events.product_algebra.VariableMap[random_events.variable.Variable, float])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: random_events.product_algebra.VariableMap[random_events.variable.Variable, float])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



.. py:data:: PADDING_FACTOR_FOR_X_AXIS_IN_PLOT
   :value: 0.05


.. py:data:: EXPECTATION_TRACE_NAME
   :value: 'Expectation'


.. py:data:: MODE_TRACE_NAME
   :value: 'Mode'


.. py:data:: MODE_TRACE_COLOR
   :value: '#AB63FA'


.. py:data:: PDF_TRACE_NAME
   :value: 'Probability Density Function'


.. py:data:: CDF_TRACE_NAME
   :value: 'Cumulative Distribution Function'


.. py:data:: CDF_TRACE_COLOR
   :value: '#EF553B'


.. py:data:: PDF_TRACE_COLOR
   :value: '#636EFA'


.. py:class:: UniformDistribution(variable: probabilistic_model.distributions.distributions.Continuous, interval: probabilistic_model.distributions.distributions.SimpleInterval)

   Bases: :py:obj:`probabilistic_model.distributions.distributions.ContinuousDistributionWithFiniteSupport`


   Class for uniform distributions over the half-open interval [lower, upper).


   .. py:attribute:: variable


   .. py:attribute:: interval

      The interval of the distribution.



   .. py:method:: log_likelihood_without_bounds_check(x: probabilistic_model.distributions.distributions.np.array) -> probabilistic_model.distributions.distributions.np.array

      Evaluate the logarithmic likelihood function at `x` without checking the inclusion into the interval.
      :param x: x where p(x) > 0
      :return: log(p(x))



   .. py:method:: cdf(x: probabilistic_model.distributions.distributions.np.array) -> probabilistic_model.distributions.distributions.np.array

      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:method:: univariate_log_mode() -> probabilistic_model.distributions.distributions.Tuple[probabilistic_model.distributions.distributions.AbstractCompositeSet, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: log_conditional_from_simple_interval(interval: probabilistic_model.distributions.distributions.SimpleInterval) -> probabilistic_model.distributions.distributions.Tuple[probabilistic_model.distributions.distributions.Self, float]

      Calculate the truncated distribution given a simple interval.

      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



   .. py:method:: sample(amount: int) -> probabilistic_model.distributions.distributions.np.array

      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



   .. py:method:: pdf_value() -> float

      Calculate the density of the uniform distribution.



   .. py:method:: log_pdf_value() -> float

      Calculate the log-density of the uniform distribution.



   .. py:method:: moment(order: probabilistic_model.distributions.distributions.OrderType, center: probabilistic_model.distributions.distributions.CenterType) -> probabilistic_model.distributions.distributions.MomentType

      Calculate the (centralized) moment of the distribution.

      .. math::

          \int_{-\infty}^{\infty} (x - center)^{order} pdf(x) dx

      .. Note:: You can read more about queries of this class in Definition 22 in :cite:p:`choi2020probabilistic`_.
          :cite:p:`youtube2020probabilistic`


      :param order: The orders of the moment as a variable map for every continuous and integer variable.
      :param center: The center of the moment as a variable map for every continuous and integer variable.
      :return: The moments of the variables in `order`.



   .. py:method:: __eq__(other)


   .. py:property:: drawio_label

      The label of the object as a drawio compatible string.



   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:property:: abbreviated_symbol
      :type: str



   .. py:method:: __repr__()


   .. py:property:: image


   .. py:method:: __copy__()


   .. py:method:: __deepcopy__(memo=None)


   .. py:method:: to_json() -> probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]


   .. py:method:: _from_json(data: probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]) -> probabilistic_model.distributions.distributions.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:: x_axis_points_for_plotly() -> probabilistic_model.distributions.distributions.List[probabilistic_model.distributions.distributions.Union[None, float]]


   .. py:method:: pdf_trace() -> probabilistic_model.distributions.distributions.go.Scatter


   .. py:method:: cdf_trace() -> probabilistic_model.distributions.distributions.go.Scatter


   .. py:method:: plot(**kwargs) -> probabilistic_model.distributions.distributions.List

      Generate traces that can be plotted with plotly.

      :param number_of_samples: The number of samples to draw.
      :param surface: If True, plot the model as a surface plot.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: __hash__()


.. py:data:: SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT
   :value: 1.05


.. py:class:: DrawIOInterface

   Mixin class for objects that can be used with a drawio exporter.


   .. py:property:: drawio_label
      :type: str

      :abstractmethod:


      The label of the object as a drawio compatible string.



   .. py:property:: drawio_style
      :type: typing_extensions.Dict[str, typing_extensions.Any]

      :abstractmethod:


      The style of the object.



.. py:class:: ProbabilisticModel

   Bases: :py:obj:`abc.ABC`


   Abstract base class for probabilistic models.

   The definition of events follows the definition of events in the random_events package.
   The definition of functions is motivated by the background knowledge provided in the probabilistic circuits.

   This class can be used as an interface to any kind of probabilistic model, tractable or not.



   .. py:property:: representation
      :type: str


      The symbol used to represent this distribution.



   .. py:property:: variables
      :type: random_events.set.Tuple[random_events.variable.Variable, Ellipsis]

      :abstractmethod:


      :return: The variables of the model.



   .. py:property:: support
      :type: random_events.product_algebra.Event

      :abstractmethod:


      :return: The support of the model.



   .. py:method:: likelihood(events: random_events.product_algebra.np.array) -> random_events.product_algebra.np.array

      Calculate the likelihood of an array of events.

      The likelihood is a full evidence query, i.e., an assignment to all variables in the model.
      The order of elements in the event has to correspond to the order of variables in the model.

      The event belongs to the class of full evidence queries.

      ..
      Note:: You can read more about this query class in Definition 1 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=TAfIX2LmOWM-Fd2B&t=785>`_.
          :cite:p:`youtube2020probabilistic`

      :param events: The array of full evidence events.
      The shape of the array has to be (n, len(self.variables)).
      :return: The likelihood of the events as an array with shape (n,).



   .. py:method:: log_likelihood(events: random_events.product_algebra.np.array) -> random_events.product_algebra.np.array
      :abstractmethod:


      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: cdf(events: random_events.product_algebra.np.array) -> random_events.product_algebra.np.array
      :abstractmethod:


      Calculate the cumulative distribution function of an event-array.

      The event belongs to the class of full evidence queries.

      ..Note:: The cdf only exists if all variables are continuous or integers.

      :param events: The array of full evidence events.
                     The shape of the array has to be (n, len(self.variables)).
      :return: The cumulative distribution function of the event as an array of shape (n,).



   .. py:method:: probability(event: random_events.product_algebra.Event) -> float

      Calculate the probability of an event.
      The event is richly described by the random_events package.

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float
      :abstractmethod:


      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: mode() -> random_events.set.Tuple[random_events.product_algebra.Event, float]

      Calculate the mode of the model.
      The mode is the **set** of most likely events.

      The calculation belongs to the map query class.

      .. Note:: You can read more about queries of this class in Definition 26 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=FjREKNtAV0owm27A&t=1962>`_.
          :cite:p:`youtube2020probabilistic`

      :return: The mode and its likelihood.



   .. py:method:: log_mode() -> random_events.set.Tuple[random_events.product_algebra.Event, float]
      :abstractmethod:


      Calculate the mode of the model.

      Check the documentation of `mode` for more information.

      :return: The mode and its log-likelihood.



   .. py:method:: marginal(variables: random_events.variable.Iterable[random_events.variable.Variable]) -> random_events.variable.Optional[random_events.variable.Self]
      :abstractmethod:


      Calculate the marginal distribution of a set of variables.

      :param variables: The variables to calculate the marginal distribution on.
      :return: The marginal distribution over the variables.



   .. py:method:: truncated(event: random_events.product_algebra.Event) -> random_events.set.Tuple[random_events.variable.Optional[random_events.product_algebra.Union[ProbabilisticModel, random_events.variable.Self]], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      If the event is impossible, the truncated distribution is None and the probability is 0.

      :param event: The event to condition on.
      :return: The truncated distribution and the probability of the event.



   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> random_events.set.Tuple[random_events.variable.Optional[random_events.product_algebra.Union[ProbabilisticModel, random_events.variable.Self]], float]
      :abstractmethod:


      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: conditional(point: random_events.variable.Dict[random_events.variable.Variable, random_events.variable.Any]) -> random_events.set.Tuple[random_events.variable.Optional[random_events.variable.Self], float]

      Calculate the truncated distribution P(*| point) and the probability of the event.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: log_conditional(point: random_events.variable.Dict[random_events.variable.Variable, random_events.variable.Any]) -> random_events.set.Tuple[random_events.variable.Optional[random_events.variable.Self], float]
      :abstractmethod:


      Calculate the truncated distribution P(*| point) and the probability of the event.
      Check the documentation of `conditional` for more information.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: sample(amount: int) -> random_events.product_algebra.np.array
      :abstractmethod:


      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



   .. py:method:: moment(order: OrderType, center: CenterType) -> MomentType
      :abstractmethod:


      Calculate the (centralized) moment of the distribution.

      .. math::

          \int_{-\infty}^{\infty} (x - center)^{order} pdf(x) dx

      .. Note:: You can read more about queries of this class in Definition 22 in :cite:p:`choi2020probabilistic`_.
          :cite:p:`youtube2020probabilistic`


      :param order: The orders of the moment as a variable map for every continuous and integer variable.
      :param center: The center of the moment as a variable map for every continuous and integer variable.
      :return: The moments of the variables in `order`.



   .. py:method:: expectation(variables: random_events.variable.Optional[random_events.variable.Iterable[random_events.variable.Variable]] = None) -> MomentType

      Calculate the expectation of the numeric variables in `variables`.

      :param variables: The variable to calculate the expectation of.
      :return: The expectation of the variable.



   .. py:method:: variance(variables: random_events.variable.Optional[random_events.variable.Iterable[random_events.variable.Variable]] = None) -> MomentType

      Calculate the variance of the numeric variables in `variables`.

      :param variables: The variable to calculate the variance of.
      :return: The variance of the variable.



   .. py:method:: universal_simple_event() -> random_events.product_algebra.SimpleEvent

      :return: A simple event that contains every possible value.



   .. py:method:: translate(translation: random_events.variable.Dict[random_events.variable.Variable, float])
      :abstractmethod:


      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: random_events.variable.Dict[random_events.variable.Variable, float])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



   .. py:method:: __copy__()
      :abstractmethod:



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

      Create a layout for the plotly plot.

      :return: The layout.



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

      :return: The layout argument for plotly figures as dict



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

      :return: The layout argument for plotly figures as dict



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

      :return: The layout argument for plotly figures as dict



   .. py:method:: plot(number_of_samples: int = 1000, surface=False, mode=False) -> random_events.product_algebra.List

      Generate traces that can be plotted with plotly.

      :param number_of_samples: The number of samples to draw.
      :param surface: If True, plot the model as a surface plot.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: plot_1d_symbolic() -> random_events.product_algebra.List


   .. py:method:: plot_1d_numeric(number_of_samples: int, mode=False) -> random_events.product_algebra.List

      Plot a one-dimensional model using samples.

      :param number_of_samples: The number of samples to draw.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: univariate_expectation_trace(height: float) -> random_events.product_algebra.go.Scatter

      Create a trace for the expectation of the model in 1d.
      :param height: The height of the trace.
      :return: The trace.



   .. py:method:: univariate_mode_traces(mode: random_events.variable.Optional[random_events.product_algebra.Event], height: float)


   .. py:method:: univariate_complement_of_support_trace(min_of_samples: float, max_of_samples: float) -> random_events.product_algebra.List

      Create a trace for the complement of the support of the model in 1d.
      :param min_of_samples: The minimum value of the samples.
      :param max_of_samples: The maximum value of the samples.
      :return: A list of traces for the support of the model.



   .. py:method:: plot_2d(number_of_samples: int, mode=False) -> random_events.product_algebra.List

      Plot a two-dimensional model.

      :param number_of_samples: The number of samples to draw.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: plot_2d_surface(number_of_samples: int) -> random_events.product_algebra.List

      Plot a two-dimensional model as a surface plot.

      :param number_of_samples: The number of samples to draw.
      :return: The traces.



   .. py:method:: expectation_trace_2d_surface(height: float) -> random_events.product_algebra.go.Scatter3d


   .. py:method:: bounding_box_trace_of_simple_event(simple_event: random_events.product_algebra.SimpleEvent, samples: random_events.product_algebra.np.array, fill_value=0.0) -> random_events.product_algebra.go.Surface

      Create a bounding box trace for a simple event.
      :param simple_event: The simple event.
      :param samples: The samples to read from if bounds are infinite.
      :param fill_value: The height of the box.

      :return: The trace.



   .. py:method:: plot_2d_surface_of_simple_event(simple_event: random_events.product_algebra.SimpleEvent, samples: random_events.product_algebra.np.array)


   .. py:method:: plot_3d(number_of_samples: int, mode=False) -> random_events.product_algebra.List

      Plot a three-dimensional model using samples.

      :param number_of_samples: The number of samples to draw.
      :param mode: If True, plot the mode of the model.
      :return: The traces.s



   .. py:method:: multivariate_mode_traces()

      :return: traces for the mode of a multivariate model.



.. py:data:: OrderType

.. py:class:: MissingDict

   Bases: :py:obj:`collections.defaultdict`


   A defaultdict that returns the default value when the key is missing and does **not** add the key to the dict.


   .. py:method:: __missing__(key)


.. py:function:: interval_as_array(interval: random_events.interval.Interval) -> numpy.ndarray

   Convert an interval to a numpy array.
   The resulting array has shape (n, 2) where n is the number of simple intervals in the interval.
   The first column contains the lower bounds and the second column the upper bounds of the simple intervals.
   :param interval: The interval
   :return:  as numpy array


.. py:class:: UnivariateDistribution

   Bases: :py:obj:`probabilistic_model.probabilistic_model.ProbabilisticModel`, :py:obj:`random_events.variable.SubclassJSONSerializer`, :py:obj:`probabilistic_model.interfaces.drawio.drawio.DrawIOInterface`


   Abstract Base class for Univariate distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Variable


   .. py:property:: variables
      :type: typing_extensions.Tuple[random_events.variable.Variable, Ellipsis]


      :return: The variables of the model.



   .. py:property:: support
      :type: random_events.product_algebra.Event


      :return: The support of the model.



   .. py:property:: univariate_support
      :type: random_events.variable.AbstractCompositeSet

      :abstractmethod:


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: log_mode() -> typing_extensions.Tuple[random_events.product_algebra.Event, float]

      Calculate the mode of the model.

      Check the documentation of `mode` for more information.

      :return: The mode and its log-likelihood.



   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]
      :abstractmethod:


      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: marginal(variables: typing_extensions.Iterable[random_events.variable.Variable]) -> random_events.variable.Optional[typing_extensions.Self]

      Calculate the marginal distribution of a set of variables.

      :param variables: The variables to calculate the marginal distribution on.
      :return: The marginal distribution over the variables.



   .. py:method:: __eq__(other: typing_extensions.Self)


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


   .. py:method:: composite_set_from_event(event: random_events.product_algebra.Event) -> random_events.variable.AbstractCompositeSet

      Extract the composite set from the event that is relevant for this distribution.
      :param event: The event
      :return: The composite set



   .. py:property:: abbreviated_symbol
      :type: str



   .. py:property:: drawio_style
      :type: typing_extensions.Dict[str, typing_extensions.Any]


      The style of the object.



.. py:class:: ContinuousDistribution

   Bases: :py:obj:`UnivariateDistribution`


   Abstract base class for continuous distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Continuous


   .. py:property:: univariate_support
      :type: random_events.variable.Interval

      :abstractmethod:


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: cdf(x: numpy.array) -> numpy.array
      :abstractmethod:


      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: log_conditional(point: typing_extensions.Dict[random_events.variable.Variable, typing_extensions.Any]) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Union[probabilistic_model.probabilistic_model.ProbabilisticModel, typing_extensions.Self]], float]

      Calculate the truncated distribution P(*| point) and the probability of the event.
      Check the documentation of `conditional` for more information.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: log_conditional_from_simple_interval(interval: random_events.variable.SimpleInterval) -> typing_extensions.Tuple[typing_extensions.Self, float]
      :abstractmethod:


      Calculate the truncated distribution given a simple interval.

      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



   .. py:method:: log_conditional_from_interval(interval) -> typing_extensions.Tuple[typing_extensions.Self, float]
      :abstractmethod:


      Calculate the truncated distribution given an interval with p(interval) > 0.
      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



.. py:class:: ContinuousDistributionWithFiniteSupport

   Bases: :py:obj:`ContinuousDistribution`


   Abstract base class for continuous distributions with finite support.


   .. py:attribute:: interval
      :type:  random_events.variable.SimpleInterval

      The interval of the distribution.



   .. py:property:: lower
      :type: float



   .. py:property:: upper
      :type: float



   .. py:property:: univariate_support
      :type: random_events.variable.Interval


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: left_included_condition(x: numpy.array) -> numpy.array

      Check if x is included in the left bound of the interval.
      :param x: The data
      :return: A boolean array



   .. py:method:: right_included_condition(x: numpy.array) -> numpy.array

      Check if x is included in the right bound of the interval.
      :param x: The data
      :return: A boolean array



   .. py:method:: included_condition(x: numpy.array) -> numpy.array

      Check if x is included in interval.
      :param x: The data
      :return: A boolean array



   .. py:method:: log_likelihood(x: numpy.array) -> numpy.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: log_likelihood_without_bounds_check(x: numpy.array) -> numpy.array
      :abstractmethod:


      Evaluate the logarithmic likelihood function at `x` without checking the inclusion into the interval.
      :param x: x where p(x) > 0
      :return: log(p(x))



   .. py:method:: translate(translation: typing_extensions.Dict[random_events.variable.Variable, float])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: typing_extensions.Dict[random_events.variable.Variable, float])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



.. py:class:: DiscreteDistribution(variable: typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer], probabilities: random_events.variable.Optional[probabilistic_model.utils.MissingDict[typing_extensions.Union[int, random_events.variable.SetElement], float]])

   Bases: :py:obj:`UnivariateDistribution`


   Abstract base class for univariate discrete distributions.


   .. py:attribute:: variable
      :type:  typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer]


   .. py:attribute:: probabilities
      :type:  probabilistic_model.utils.MissingDict[int, float]

      A dict that maps from integers (hash(symbol) for symbols) to probabilities.



   .. py:method:: __eq__(other)


   .. py:method:: __hash__()


   .. py:method:: log_likelihood(events: numpy.array) -> numpy.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: fit(data: numpy.array) -> typing_extensions.Self

      Fit the distribution to the data.

      The probabilities are set equal to the frequencies in the data.
      The data contains the indices of the domain elements (if symbolic) or the values (if integer).

      :param data: The data.
      :return: The fitted distribution



   .. py:method:: probabilities_for_plotting() -> typing_extensions.Dict[typing_extensions.Union[int, str], float]
      :abstractmethod:


      :return: The probabilities as dict that can be plotted.



   .. py:method:: plot(**kwargs) -> typing_extensions.List[plotly.graph_objects.Bar]

      Plot the distribution.



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


   .. py:method:: _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) -> typing_extensions.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:: normalize()

      Normalize the distribution.



   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: log_conditional(point: typing_extensions.Dict[random_events.variable.Variable, typing_extensions.Any]) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| point) and the probability of the event.
      Check the documentation of `conditional` for more information.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]


   .. py:method:: __copy__() -> typing_extensions.Self


   .. py:method:: __deepcopy__(memo=None) -> typing_extensions.Self


   .. py:method:: __repr__()


   .. py:method:: sample(amount: int) -> numpy.array

      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



.. py:class:: SymbolicDistribution(variable: typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer], probabilities: random_events.variable.Optional[probabilistic_model.utils.MissingDict[typing_extensions.Union[int, random_events.variable.SetElement], float]])

   Bases: :py:obj:`DiscreteDistribution`


   Class for symbolic (categorical) distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Symbolic


   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.Set, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]


   .. py:method:: probabilities_for_plotting() -> typing_extensions.Dict[typing_extensions.Union[int, str], float]

      :return: The probabilities as dict that can be plotted.



   .. py:property:: univariate_support
      :type: random_events.variable.Set


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:property:: drawio_label

      The label of the object as a drawio compatible string.



   .. py:property:: image


   .. py:method:: fit(data: numpy.array) -> typing_extensions.Self

      Fit the distribution to the data.

      The probabilities are set equal to the frequencies in the data.
      The data contains the indices of the domain elements (if symbolic) or the values (if integer).

      :param data: The data.
      :return: The fitted distribution



   .. py:method:: fit_from_indices(data: numpy.array) -> typing_extensions.Self


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


   .. py:method:: _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) -> typing_extensions.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:class:: IntegerDistribution(variable: random_events.variable.Integer, probabilities: random_events.variable.Optional[probabilistic_model.utils.MissingDict[typing_extensions.Union[int, random_events.variable.SetElement], float]])

   Bases: :py:obj:`ContinuousDistribution`, :py:obj:`DiscreteDistribution`


   Abstract base class for integer distributions. Integer distributions also implement the methods of continuous
   distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Integer


   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: probabilities_for_plotting() -> typing_extensions.Dict[typing_extensions.Union[int, str], float]

      :return: The probabilities as dict that can be plotted.



   .. py:property:: univariate_support
      :type: random_events.variable.Interval


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: cdf(x: numpy.array) -> numpy.array

      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:method:: moment(order: probabilistic_model.probabilistic_model.OrderType, center: probabilistic_model.probabilistic_model.CenterType) -> probabilistic_model.probabilistic_model.MomentType

      Calculate the (centralized) moment of the distribution.

      .. math::

          \int_{-\infty}^{\infty} (x - center)^{order} pdf(x) dx

      .. Note:: You can read more about queries of this class in Definition 22 in :cite:p:`choi2020probabilistic`_.
          :cite:p:`youtube2020probabilistic`


      :param order: The orders of the moment as a variable map for every continuous and integer variable.
      :param center: The center of the moment as a variable map for every continuous and integer variable.
      :return: The moments of the variables in `order`.



   .. py:method:: plot(**kwargs) -> typing_extensions.List[plotly.graph_objects.Bar]

      Generate traces that can be plotted with plotly.

      :param number_of_samples: The number of samples to draw.
      :param surface: If True, plot the model as a surface plot.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: translate(translation: typing_extensions.Dict[random_events.variable.Variable, int])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: typing_extensions.Dict[random_events.variable.Variable, int])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



.. py:class:: DiracDeltaDistribution(variable: random_events.variable.Continuous, location: float, density_cap: float = np.inf, tolerance: float = 1e-06)

   Bases: :py:obj:`ContinuousDistribution`


   Class for Dirac delta distributions.
   The Dirac measure is used whenever evidence is given as a singleton instance.

   https://en.wikipedia.org/wiki/Dirac_delta_function


   .. py:attribute:: variable
      :type:  random_events.variable.Continuous


   .. py:attribute:: location
      :type:  float

      The location of the Dirac delta distribution.



   .. py:attribute:: density_cap
      :type:  float

      The density cap of the Dirac delta distribution.
      This value will be used to replace infinity in likelihood.



   .. py:attribute:: tolerance
      :type:  float
      :value: 1e-06


      The tolerance of deviations of the `location` of the Dirac delta distribution.
      This is used during calculations to take precision problems into account.



   .. py:method:: log_likelihood(events: numpy.array) -> numpy.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: cdf(x: numpy.array) -> numpy.array

      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:property:: abbreviated_symbol
      :type: str



   .. py:property:: univariate_support
      :type: random_events.variable.Interval


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: log_conditional_from_simple_interval(interval: random_events.variable.SimpleInterval) -> typing_extensions.Tuple[typing_extensions.Self, float]

      Calculate the truncated distribution given a simple interval.

      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: sample(amount: int) -> numpy.array

      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



   .. py:method:: moment(order: probabilistic_model.probabilistic_model.OrderType, center: probabilistic_model.probabilistic_model.CenterType) -> probabilistic_model.probabilistic_model.MomentType

      Calculate the (centralized) moment of the distribution.

      .. math::

          \int_{-\infty}^{\infty} (x - center)^{order} pdf(x) dx

      .. Note:: You can read more about queries of this class in Definition 22 in :cite:p:`choi2020probabilistic`_.
          :cite:p:`youtube2020probabilistic`


      :param order: The orders of the moment as a variable map for every continuous and integer variable.
      :param center: The center of the moment as a variable map for every continuous and integer variable.
      :return: The moments of the variables in `order`.



   .. py:method:: __eq__(other)


   .. py:method:: __hash__()


   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:method:: __repr__()


   .. py:method:: __copy__()


   .. py:method:: __deepcopy__(memo=None)


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


   .. py:method:: _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) -> typing_extensions.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:: plot(**kwargs) -> typing_extensions.List

      Generate traces that can be plotted with plotly.

      :param number_of_samples: The number of samples to draw.
      :param surface: If True, plot the model as a surface plot.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: translate(translation: random_events.product_algebra.VariableMap[random_events.variable.Variable, float])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: random_events.product_algebra.VariableMap[random_events.variable.Variable, float])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



.. py:function:: simple_interval_as_array(interval: random_events.interval.SimpleInterval) -> numpy.ndarray

   Convert a simple interval to a numpy array.
   :param interval:  The interval
   :return:  [lower, upper] as numpy array


.. py:class:: GaussianDistribution(variable: probabilistic_model.distributions.distributions.Continuous, location: float, scale: float)

   Bases: :py:obj:`probabilistic_model.distributions.distributions.ContinuousDistribution`


   Class for Gaussian distributions.


   .. py:attribute:: location
      :type:  float

      The mean of the Gaussian distribution.



   .. py:attribute:: scale
      :type:  float

      The standard deviation of the Gaussian distribution.



   .. py:attribute:: variable


   .. py:property:: univariate_support
      :type: probabilistic_model.distributions.distributions.Interval


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: log_likelihood(x: probabilistic_model.distributions.distributions.np.array) -> probabilistic_model.distributions.distributions.np.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: cdf(x: probabilistic_model.distributions.distributions.np.array) -> probabilistic_model.distributions.distributions.np.array

      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:method:: univariate_log_mode() -> probabilistic_model.distributions.distributions.Tuple[probabilistic_model.distributions.distributions.AbstractCompositeSet, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: sample(amount: int) -> probabilistic_model.distributions.distributions.np.array

      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



   .. py:method:: ppf(value)


   .. py:method:: raw_moment(order: int) -> float

      Helper method to calculate the raw moment of a Gaussian distribution.

      The raw moment is given by:

      .. math::

          E(X^n) = \sum_{j=0}^{\lfloor \frac{n}{2}\rfloor}\binom{n}{2j}\dfrac{\mu^{n-2j}\sigma^{2j}(2j)!}{j!2^j}.





   .. py:method:: moment(order: probabilistic_model.distributions.distributions.OrderType, center: probabilistic_model.distributions.distributions.CenterType) -> probabilistic_model.distributions.distributions.MomentType

      Calculate the moment of the distribution using Alessandro's (made up) Equation:

      .. math::

          E(X-center)^i = \sum_{i=0}^{order} \binom{order}{i} E[X^i] * (- center)^{(order-i)}



   .. py:method:: log_conditional_from_simple_interval(interval: probabilistic_model.distributions.distributions.SimpleInterval) -> probabilistic_model.distributions.distributions.Tuple[probabilistic_model.distributions.distributions.Optional[TruncatedGaussianDistribution], float]

      Calculate the truncated distribution given a simple interval.

      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



   .. py:method:: __eq__(other: probabilistic_model.distributions.distributions.Self)


   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:method:: __repr__()


   .. py:method:: __copy__()


   .. py:method:: __deepcopy__(memo=None)


   .. py:method:: to_json() -> probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]


   .. py:method:: _from_json(data: probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]) -> probabilistic_model.distributions.distributions.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:property:: abbreviated_symbol
      :type: str



   .. py:method:: translate(translation: probabilistic_model.distributions.distributions.VariableMap[probabilistic_model.distributions.distributions.Variable, float])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



.. py:class:: TruncatedGaussianDistribution(variable: probabilistic_model.distributions.distributions.Continuous, interval: probabilistic_model.distributions.distributions.SimpleInterval, location: float, scale: float)

   Bases: :py:obj:`probabilistic_model.distributions.distributions.ContinuousDistributionWithFiniteSupport`, :py:obj:`GaussianDistribution`


   Class for Truncated Gaussian distributions.


   .. py:attribute:: interval

      The interval of the distribution.



   .. py:property:: normalizing_constant
      :type: float


      Helper method to calculate

      .. math::

      Z = {\mathbf{\Phi}\left ( \frac{self.interval.upper-\mu}{\sigma} \right )-\mathbf{\Phi}
      \left( \frac{self.interval.lower-\mu}{\sigma} \right )}




   .. py:property:: cdf_of_lower


   .. py:method:: log_likelihood_without_bounds_check(x: probabilistic_model.distributions.distributions.np.array) -> probabilistic_model.distributions.distributions.np.array

      Evaluate the logarithmic likelihood function at `x` without checking the inclusion into the interval.
      :param x: x where p(x) > 0
      :return: log(p(x))



   .. py:method:: cdf(x: probabilistic_model.distributions.distributions.np.array) -> probabilistic_model.distributions.distributions.np.array

      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:method:: univariate_log_mode() -> probabilistic_model.distributions.distributions.Tuple[probabilistic_model.distributions.distributions.Interval, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: rejection_sample(amount: int) -> probabilistic_model.distributions.distributions.np.array

      .. note::
          This uses rejection sampling and hence is inefficient.
          The acceptance probability is self.normalizing_constant.




   .. py:method:: moment(order: probabilistic_model.distributions.distributions.OrderType, center: probabilistic_model.distributions.distributions.CenterType) -> probabilistic_model.distributions.distributions.MomentType

      Helper method to calculate the moment of a Truncated Gaussian distribution.

      .. note::
      This method follows the equation (2.8) in :cite:p:`ogasawara2022moments`.

      .. math::

          \mathbb{E} \left[ \left( X-center \right)^{order} \right]\mathds{1}_{\left[ lower , upper \right]}(x)
          = \sigma^{order} \frac{1}{\Phi(upper)-\Phi(lower)} \sum_{k=0}^{order} \binom{order}{k} I_k (-center)^{(order-k)}.

          where:

          .. math::

              I_k = \frac{2^{\frac{k}{2}}}{\sqrt{\pi}}\Gamma \left( \frac{k+1}{2} \right) \left[ sgn \left(upper\right)
               \mathds{1}\left \{ k=2 \nu \right \} + \mathds{1} \left\{k = 2\nu -1 \right\} \frac{1}{2}
                F_{\Gamma} \left( \frac{upper^2}{2},\frac{k+1}{2} \right) - sgn \left(lower\right) \mathds{1}\left \{ k=2 \nu \right \}
               + \mathds{1} \left\{k = 2\nu -1 \right\} \frac{1}{2} F_{\Gamma} \left( \frac{lower^2}{2},\frac{k+1}{2} \right) \right]

      :return: The moment of the distribution.




   .. py:method:: __eq__(other)


   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:method:: __copy__()


   .. py:method:: __deepcopy__(memo=None)


   .. py:method:: to_json() -> probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]


   .. py:method:: _from_json(data: probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]) -> probabilistic_model.distributions.distributions.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:: transform_to_standard_normal(number: float) -> float

      Transform the number to the standard normal distribution.
      :param number: The number to transform
      :return: The transformed bound



   .. py:method:: robert_rejection_sample(amount: int) -> probabilistic_model.distributions.distributions.np.ndarray

      Use robert rejection sampling to sample from the truncated Gaussian distribution.

      :param amount: The amount of samples to generate
      :return: The samples



   .. py:method:: robert_rejection_sample_from_standard_normal_with_double_truncation(amount: int) -> probabilistic_model.distributions.distributions.np.ndarray

      Use robert rejection sampling to sample from the truncated standard normal distribution.
      Resamples as long as the amount of samples is not reached.

      :param amount: The amount of samples to generate
      :return: The samples



   .. py:method:: robert_rejection_sample_from_standard_normal_with_double_truncation_helper(amount: int) -> probabilistic_model.distributions.distributions.np.ndarray

      Use robert rejection sampling to sample from the truncated standard normal distribution.

      :param amount: The maximum number of samples to generate. The actual number of samples can be lower due to
          rejection sampling.
      :return: The samples



   .. py:method:: sample(amount: int) -> probabilistic_model.distributions.distributions.np.array

      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



   .. py:method:: translate(translation: probabilistic_model.distributions.distributions.VariableMap[probabilistic_model.distributions.distributions.Variable, float])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scale: probabilistic_model.distributions.distributions.VariableMap[probabilistic_model.distributions.distributions.Variable, float])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



.. py:data:: SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT
   :value: 1.05


.. py:class:: DrawIOInterface

   Mixin class for objects that can be used with a drawio exporter.


   .. py:property:: drawio_label
      :type: str

      :abstractmethod:


      The label of the object as a drawio compatible string.



   .. py:property:: drawio_style
      :type: typing_extensions.Dict[str, typing_extensions.Any]

      :abstractmethod:


      The style of the object.



.. py:class:: ProbabilisticModel

   Bases: :py:obj:`abc.ABC`


   Abstract base class for probabilistic models.

   The definition of events follows the definition of events in the random_events package.
   The definition of functions is motivated by the background knowledge provided in the probabilistic circuits.

   This class can be used as an interface to any kind of probabilistic model, tractable or not.



   .. py:property:: representation
      :type: str


      The symbol used to represent this distribution.



   .. py:property:: variables
      :type: random_events.set.Tuple[random_events.variable.Variable, Ellipsis]

      :abstractmethod:


      :return: The variables of the model.



   .. py:property:: support
      :type: random_events.product_algebra.Event

      :abstractmethod:


      :return: The support of the model.



   .. py:method:: likelihood(events: random_events.product_algebra.np.array) -> random_events.product_algebra.np.array

      Calculate the likelihood of an array of events.

      The likelihood is a full evidence query, i.e., an assignment to all variables in the model.
      The order of elements in the event has to correspond to the order of variables in the model.

      The event belongs to the class of full evidence queries.

      ..
      Note:: You can read more about this query class in Definition 1 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=TAfIX2LmOWM-Fd2B&t=785>`_.
          :cite:p:`youtube2020probabilistic`

      :param events: The array of full evidence events.
      The shape of the array has to be (n, len(self.variables)).
      :return: The likelihood of the events as an array with shape (n,).



   .. py:method:: log_likelihood(events: random_events.product_algebra.np.array) -> random_events.product_algebra.np.array
      :abstractmethod:


      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: cdf(events: random_events.product_algebra.np.array) -> random_events.product_algebra.np.array
      :abstractmethod:


      Calculate the cumulative distribution function of an event-array.

      The event belongs to the class of full evidence queries.

      ..Note:: The cdf only exists if all variables are continuous or integers.

      :param events: The array of full evidence events.
                     The shape of the array has to be (n, len(self.variables)).
      :return: The cumulative distribution function of the event as an array of shape (n,).



   .. py:method:: probability(event: random_events.product_algebra.Event) -> float

      Calculate the probability of an event.
      The event is richly described by the random_events package.

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float
      :abstractmethod:


      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: mode() -> random_events.set.Tuple[random_events.product_algebra.Event, float]

      Calculate the mode of the model.
      The mode is the **set** of most likely events.

      The calculation belongs to the map query class.

      .. Note:: You can read more about queries of this class in Definition 26 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=FjREKNtAV0owm27A&t=1962>`_.
          :cite:p:`youtube2020probabilistic`

      :return: The mode and its likelihood.



   .. py:method:: log_mode() -> random_events.set.Tuple[random_events.product_algebra.Event, float]
      :abstractmethod:


      Calculate the mode of the model.

      Check the documentation of `mode` for more information.

      :return: The mode and its log-likelihood.



   .. py:method:: marginal(variables: random_events.variable.Iterable[random_events.variable.Variable]) -> random_events.variable.Optional[random_events.variable.Self]
      :abstractmethod:


      Calculate the marginal distribution of a set of variables.

      :param variables: The variables to calculate the marginal distribution on.
      :return: The marginal distribution over the variables.



   .. py:method:: truncated(event: random_events.product_algebra.Event) -> random_events.set.Tuple[random_events.variable.Optional[random_events.product_algebra.Union[ProbabilisticModel, random_events.variable.Self]], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      If the event is impossible, the truncated distribution is None and the probability is 0.

      :param event: The event to condition on.
      :return: The truncated distribution and the probability of the event.



   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> random_events.set.Tuple[random_events.variable.Optional[random_events.product_algebra.Union[ProbabilisticModel, random_events.variable.Self]], float]
      :abstractmethod:


      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: conditional(point: random_events.variable.Dict[random_events.variable.Variable, random_events.variable.Any]) -> random_events.set.Tuple[random_events.variable.Optional[random_events.variable.Self], float]

      Calculate the truncated distribution P(*| point) and the probability of the event.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: log_conditional(point: random_events.variable.Dict[random_events.variable.Variable, random_events.variable.Any]) -> random_events.set.Tuple[random_events.variable.Optional[random_events.variable.Self], float]
      :abstractmethod:


      Calculate the truncated distribution P(*| point) and the probability of the event.
      Check the documentation of `conditional` for more information.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: sample(amount: int) -> random_events.product_algebra.np.array
      :abstractmethod:


      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



   .. py:method:: moment(order: OrderType, center: CenterType) -> MomentType
      :abstractmethod:


      Calculate the (centralized) moment of the distribution.

      .. math::

          \int_{-\infty}^{\infty} (x - center)^{order} pdf(x) dx

      .. Note:: You can read more about queries of this class in Definition 22 in :cite:p:`choi2020probabilistic`_.
          :cite:p:`youtube2020probabilistic`


      :param order: The orders of the moment as a variable map for every continuous and integer variable.
      :param center: The center of the moment as a variable map for every continuous and integer variable.
      :return: The moments of the variables in `order`.



   .. py:method:: expectation(variables: random_events.variable.Optional[random_events.variable.Iterable[random_events.variable.Variable]] = None) -> MomentType

      Calculate the expectation of the numeric variables in `variables`.

      :param variables: The variable to calculate the expectation of.
      :return: The expectation of the variable.



   .. py:method:: variance(variables: random_events.variable.Optional[random_events.variable.Iterable[random_events.variable.Variable]] = None) -> MomentType

      Calculate the variance of the numeric variables in `variables`.

      :param variables: The variable to calculate the variance of.
      :return: The variance of the variable.



   .. py:method:: universal_simple_event() -> random_events.product_algebra.SimpleEvent

      :return: A simple event that contains every possible value.



   .. py:method:: translate(translation: random_events.variable.Dict[random_events.variable.Variable, float])
      :abstractmethod:


      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: random_events.variable.Dict[random_events.variable.Variable, float])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



   .. py:method:: __copy__()
      :abstractmethod:



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

      Create a layout for the plotly plot.

      :return: The layout.



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

      :return: The layout argument for plotly figures as dict



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

      :return: The layout argument for plotly figures as dict



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

      :return: The layout argument for plotly figures as dict



   .. py:method:: plot(number_of_samples: int = 1000, surface=False, mode=False) -> random_events.product_algebra.List

      Generate traces that can be plotted with plotly.

      :param number_of_samples: The number of samples to draw.
      :param surface: If True, plot the model as a surface plot.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: plot_1d_symbolic() -> random_events.product_algebra.List


   .. py:method:: plot_1d_numeric(number_of_samples: int, mode=False) -> random_events.product_algebra.List

      Plot a one-dimensional model using samples.

      :param number_of_samples: The number of samples to draw.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: univariate_expectation_trace(height: float) -> random_events.product_algebra.go.Scatter

      Create a trace for the expectation of the model in 1d.
      :param height: The height of the trace.
      :return: The trace.



   .. py:method:: univariate_mode_traces(mode: random_events.variable.Optional[random_events.product_algebra.Event], height: float)


   .. py:method:: univariate_complement_of_support_trace(min_of_samples: float, max_of_samples: float) -> random_events.product_algebra.List

      Create a trace for the complement of the support of the model in 1d.
      :param min_of_samples: The minimum value of the samples.
      :param max_of_samples: The maximum value of the samples.
      :return: A list of traces for the support of the model.



   .. py:method:: plot_2d(number_of_samples: int, mode=False) -> random_events.product_algebra.List

      Plot a two-dimensional model.

      :param number_of_samples: The number of samples to draw.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: plot_2d_surface(number_of_samples: int) -> random_events.product_algebra.List

      Plot a two-dimensional model as a surface plot.

      :param number_of_samples: The number of samples to draw.
      :return: The traces.



   .. py:method:: expectation_trace_2d_surface(height: float) -> random_events.product_algebra.go.Scatter3d


   .. py:method:: bounding_box_trace_of_simple_event(simple_event: random_events.product_algebra.SimpleEvent, samples: random_events.product_algebra.np.array, fill_value=0.0) -> random_events.product_algebra.go.Surface

      Create a bounding box trace for a simple event.
      :param simple_event: The simple event.
      :param samples: The samples to read from if bounds are infinite.
      :param fill_value: The height of the box.

      :return: The trace.



   .. py:method:: plot_2d_surface_of_simple_event(simple_event: random_events.product_algebra.SimpleEvent, samples: random_events.product_algebra.np.array)


   .. py:method:: plot_3d(number_of_samples: int, mode=False) -> random_events.product_algebra.List

      Plot a three-dimensional model using samples.

      :param number_of_samples: The number of samples to draw.
      :param mode: If True, plot the mode of the model.
      :return: The traces.s



   .. py:method:: multivariate_mode_traces()

      :return: traces for the mode of a multivariate model.



.. py:data:: OrderType

.. py:class:: MissingDict

   Bases: :py:obj:`collections.defaultdict`


   A defaultdict that returns the default value when the key is missing and does **not** add the key to the dict.


   .. py:method:: __missing__(key)


.. py:function:: interval_as_array(interval: random_events.interval.Interval) -> numpy.ndarray

   Convert an interval to a numpy array.
   The resulting array has shape (n, 2) where n is the number of simple intervals in the interval.
   The first column contains the lower bounds and the second column the upper bounds of the simple intervals.
   :param interval: The interval
   :return:  as numpy array


.. py:class:: UnivariateDistribution

   Bases: :py:obj:`probabilistic_model.probabilistic_model.ProbabilisticModel`, :py:obj:`random_events.variable.SubclassJSONSerializer`, :py:obj:`probabilistic_model.interfaces.drawio.drawio.DrawIOInterface`


   Abstract Base class for Univariate distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Variable


   .. py:property:: variables
      :type: typing_extensions.Tuple[random_events.variable.Variable, Ellipsis]


      :return: The variables of the model.



   .. py:property:: support
      :type: random_events.product_algebra.Event


      :return: The support of the model.



   .. py:property:: univariate_support
      :type: random_events.variable.AbstractCompositeSet

      :abstractmethod:


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: log_mode() -> typing_extensions.Tuple[random_events.product_algebra.Event, float]

      Calculate the mode of the model.

      Check the documentation of `mode` for more information.

      :return: The mode and its log-likelihood.



   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]
      :abstractmethod:


      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: marginal(variables: typing_extensions.Iterable[random_events.variable.Variable]) -> random_events.variable.Optional[typing_extensions.Self]

      Calculate the marginal distribution of a set of variables.

      :param variables: The variables to calculate the marginal distribution on.
      :return: The marginal distribution over the variables.



   .. py:method:: __eq__(other: typing_extensions.Self)


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


   .. py:method:: composite_set_from_event(event: random_events.product_algebra.Event) -> random_events.variable.AbstractCompositeSet

      Extract the composite set from the event that is relevant for this distribution.
      :param event: The event
      :return: The composite set



   .. py:property:: abbreviated_symbol
      :type: str



   .. py:property:: drawio_style
      :type: typing_extensions.Dict[str, typing_extensions.Any]


      The style of the object.



.. py:class:: ContinuousDistribution

   Bases: :py:obj:`UnivariateDistribution`


   Abstract base class for continuous distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Continuous


   .. py:property:: univariate_support
      :type: random_events.variable.Interval

      :abstractmethod:


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: cdf(x: numpy.array) -> numpy.array
      :abstractmethod:


      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: log_conditional(point: typing_extensions.Dict[random_events.variable.Variable, typing_extensions.Any]) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Union[probabilistic_model.probabilistic_model.ProbabilisticModel, typing_extensions.Self]], float]

      Calculate the truncated distribution P(*| point) and the probability of the event.
      Check the documentation of `conditional` for more information.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: log_conditional_from_simple_interval(interval: random_events.variable.SimpleInterval) -> typing_extensions.Tuple[typing_extensions.Self, float]
      :abstractmethod:


      Calculate the truncated distribution given a simple interval.

      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



   .. py:method:: log_conditional_from_interval(interval) -> typing_extensions.Tuple[typing_extensions.Self, float]
      :abstractmethod:


      Calculate the truncated distribution given an interval with p(interval) > 0.
      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



.. py:class:: ContinuousDistributionWithFiniteSupport

   Bases: :py:obj:`ContinuousDistribution`


   Abstract base class for continuous distributions with finite support.


   .. py:attribute:: interval
      :type:  random_events.variable.SimpleInterval

      The interval of the distribution.



   .. py:property:: lower
      :type: float



   .. py:property:: upper
      :type: float



   .. py:property:: univariate_support
      :type: random_events.variable.Interval


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: left_included_condition(x: numpy.array) -> numpy.array

      Check if x is included in the left bound of the interval.
      :param x: The data
      :return: A boolean array



   .. py:method:: right_included_condition(x: numpy.array) -> numpy.array

      Check if x is included in the right bound of the interval.
      :param x: The data
      :return: A boolean array



   .. py:method:: included_condition(x: numpy.array) -> numpy.array

      Check if x is included in interval.
      :param x: The data
      :return: A boolean array



   .. py:method:: log_likelihood(x: numpy.array) -> numpy.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: log_likelihood_without_bounds_check(x: numpy.array) -> numpy.array
      :abstractmethod:


      Evaluate the logarithmic likelihood function at `x` without checking the inclusion into the interval.
      :param x: x where p(x) > 0
      :return: log(p(x))



   .. py:method:: translate(translation: typing_extensions.Dict[random_events.variable.Variable, float])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: typing_extensions.Dict[random_events.variable.Variable, float])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



.. py:class:: DiscreteDistribution(variable: typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer], probabilities: random_events.variable.Optional[probabilistic_model.utils.MissingDict[typing_extensions.Union[int, random_events.variable.SetElement], float]])

   Bases: :py:obj:`UnivariateDistribution`


   Abstract base class for univariate discrete distributions.


   .. py:attribute:: variable
      :type:  typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer]


   .. py:attribute:: probabilities
      :type:  probabilistic_model.utils.MissingDict[int, float]

      A dict that maps from integers (hash(symbol) for symbols) to probabilities.



   .. py:method:: __eq__(other)


   .. py:method:: __hash__()


   .. py:method:: log_likelihood(events: numpy.array) -> numpy.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: fit(data: numpy.array) -> typing_extensions.Self

      Fit the distribution to the data.

      The probabilities are set equal to the frequencies in the data.
      The data contains the indices of the domain elements (if symbolic) or the values (if integer).

      :param data: The data.
      :return: The fitted distribution



   .. py:method:: probabilities_for_plotting() -> typing_extensions.Dict[typing_extensions.Union[int, str], float]
      :abstractmethod:


      :return: The probabilities as dict that can be plotted.



   .. py:method:: plot(**kwargs) -> typing_extensions.List[plotly.graph_objects.Bar]

      Plot the distribution.



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


   .. py:method:: _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) -> typing_extensions.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:: normalize()

      Normalize the distribution.



   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: log_conditional(point: typing_extensions.Dict[random_events.variable.Variable, typing_extensions.Any]) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| point) and the probability of the event.
      Check the documentation of `conditional` for more information.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]


   .. py:method:: __copy__() -> typing_extensions.Self


   .. py:method:: __deepcopy__(memo=None) -> typing_extensions.Self


   .. py:method:: __repr__()


   .. py:method:: sample(amount: int) -> numpy.array

      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



.. py:class:: SymbolicDistribution(variable: typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer], probabilities: random_events.variable.Optional[probabilistic_model.utils.MissingDict[typing_extensions.Union[int, random_events.variable.SetElement], float]])

   Bases: :py:obj:`DiscreteDistribution`


   Class for symbolic (categorical) distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Symbolic


   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.Set, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]


   .. py:method:: probabilities_for_plotting() -> typing_extensions.Dict[typing_extensions.Union[int, str], float]

      :return: The probabilities as dict that can be plotted.



   .. py:property:: univariate_support
      :type: random_events.variable.Set


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:property:: drawio_label

      The label of the object as a drawio compatible string.



   .. py:property:: image


   .. py:method:: fit(data: numpy.array) -> typing_extensions.Self

      Fit the distribution to the data.

      The probabilities are set equal to the frequencies in the data.
      The data contains the indices of the domain elements (if symbolic) or the values (if integer).

      :param data: The data.
      :return: The fitted distribution



   .. py:method:: fit_from_indices(data: numpy.array) -> typing_extensions.Self


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


   .. py:method:: _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) -> typing_extensions.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:class:: IntegerDistribution(variable: random_events.variable.Integer, probabilities: random_events.variable.Optional[probabilistic_model.utils.MissingDict[typing_extensions.Union[int, random_events.variable.SetElement], float]])

   Bases: :py:obj:`ContinuousDistribution`, :py:obj:`DiscreteDistribution`


   Abstract base class for integer distributions. Integer distributions also implement the methods of continuous
   distributions.


   .. py:attribute:: variable
      :type:  random_events.variable.Integer


   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: probabilities_for_plotting() -> typing_extensions.Dict[typing_extensions.Union[int, str], float]

      :return: The probabilities as dict that can be plotted.



   .. py:property:: univariate_support
      :type: random_events.variable.Interval


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: cdf(x: numpy.array) -> numpy.array

      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:method:: moment(order: probabilistic_model.probabilistic_model.OrderType, center: probabilistic_model.probabilistic_model.CenterType) -> probabilistic_model.probabilistic_model.MomentType

      Calculate the (centralized) moment of the distribution.

      .. math::

          \int_{-\infty}^{\infty} (x - center)^{order} pdf(x) dx

      .. Note:: You can read more about queries of this class in Definition 22 in :cite:p:`choi2020probabilistic`_.
          :cite:p:`youtube2020probabilistic`


      :param order: The orders of the moment as a variable map for every continuous and integer variable.
      :param center: The center of the moment as a variable map for every continuous and integer variable.
      :return: The moments of the variables in `order`.



   .. py:method:: plot(**kwargs) -> typing_extensions.List[plotly.graph_objects.Bar]

      Generate traces that can be plotted with plotly.

      :param number_of_samples: The number of samples to draw.
      :param surface: If True, plot the model as a surface plot.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: translate(translation: typing_extensions.Dict[random_events.variable.Variable, int])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: typing_extensions.Dict[random_events.variable.Variable, int])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



.. py:class:: DiracDeltaDistribution(variable: random_events.variable.Continuous, location: float, density_cap: float = np.inf, tolerance: float = 1e-06)

   Bases: :py:obj:`ContinuousDistribution`


   Class for Dirac delta distributions.
   The Dirac measure is used whenever evidence is given as a singleton instance.

   https://en.wikipedia.org/wiki/Dirac_delta_function


   .. py:attribute:: variable
      :type:  random_events.variable.Continuous


   .. py:attribute:: location
      :type:  float

      The location of the Dirac delta distribution.



   .. py:attribute:: density_cap
      :type:  float

      The density cap of the Dirac delta distribution.
      This value will be used to replace infinity in likelihood.



   .. py:attribute:: tolerance
      :type:  float
      :value: 1e-06


      The tolerance of deviations of the `location` of the Dirac delta distribution.
      This is used during calculations to take precision problems into account.



   .. py:method:: log_likelihood(events: numpy.array) -> numpy.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: cdf(x: numpy.array) -> numpy.array

      Calculate the cumulative distribution function at x.
      :param x: The data
      :return: The cumulative distribution function at x



   .. py:property:: abbreviated_symbol
      :type: str



   .. py:property:: univariate_support
      :type: random_events.variable.Interval


      :return: The univariate support of the distribution. This is not an Event.



   .. py:method:: log_conditional_from_simple_interval(interval: random_events.variable.SimpleInterval) -> typing_extensions.Tuple[typing_extensions.Self, float]

      Calculate the truncated distribution given a simple interval.

      :param interval: The simple interval
      :return: The truncated distribution and the log-probability of the interval.



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: univariate_log_mode() -> typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]

      :return: The univariate mode of the distribution and its log-likelihood. The mode is not an Event.



   .. py:method:: sample(amount: int) -> numpy.array

      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



   .. py:method:: moment(order: probabilistic_model.probabilistic_model.OrderType, center: probabilistic_model.probabilistic_model.CenterType) -> probabilistic_model.probabilistic_model.MomentType

      Calculate the (centralized) moment of the distribution.

      .. math::

          \int_{-\infty}^{\infty} (x - center)^{order} pdf(x) dx

      .. Note:: You can read more about queries of this class in Definition 22 in :cite:p:`choi2020probabilistic`_.
          :cite:p:`youtube2020probabilistic`


      :param order: The orders of the moment as a variable map for every continuous and integer variable.
      :param center: The center of the moment as a variable map for every continuous and integer variable.
      :return: The moments of the variables in `order`.



   .. py:method:: __eq__(other)


   .. py:method:: __hash__()


   .. py:property:: representation

      The symbol used to represent this distribution.



   .. py:method:: __repr__()


   .. py:method:: __copy__()


   .. py:method:: __deepcopy__(memo=None)


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


   .. py:method:: _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) -> typing_extensions.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:: plot(**kwargs) -> typing_extensions.List

      Generate traces that can be plotted with plotly.

      :param number_of_samples: The number of samples to draw.
      :param surface: If True, plot the model as a surface plot.
      :param mode: If True, plot the mode of the model.
      :return: The traces.



   .. py:method:: translate(translation: random_events.product_algebra.VariableMap[random_events.variable.Variable, float])

      Translate the model in-place.
      Translation is done by adding the translation to the variable location influencing values.
      The translation can be viewed as what happens
      when you shift the numeric variables of the model by a constant vector.

      :param translation: The variable value pairs to translate the model by.



   .. py:method:: scale(scaling: random_events.product_algebra.VariableMap[random_events.variable.Variable, float])

      Scale the model in-place.
      Scaling is done by multiplying the variable location influencing values.
      The scaling can be viewed as what happens
      when you multiply the numeric variables of the model by a constant vector.

      :param scaling: The variable value pairs to scale the model by.



