probabilistic_model.distributions

Contents

probabilistic_model.distributions#

Submodules#

Attributes#

Classes#

DrawIOInterface

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

ProbabilisticModel

Abstract base class for probabilistic models.

MissingDict

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

UnivariateDistribution

Abstract Base class for Univariate distributions.

ContinuousDistribution

Abstract base class for continuous distributions.

ContinuousDistributionWithFiniteSupport

Abstract base class for continuous distributions with finite support.

DiscreteDistribution

Abstract base class for univariate discrete distributions.

SymbolicDistribution

Class for symbolic (categorical) distributions.

IntegerDistribution

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

DiracDeltaDistribution

Class for Dirac delta distributions.

UniformDistribution

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

DrawIOInterface

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

ProbabilisticModel

Abstract base class for probabilistic models.

MissingDict

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

UnivariateDistribution

Abstract Base class for Univariate distributions.

ContinuousDistribution

Abstract base class for continuous distributions.

ContinuousDistributionWithFiniteSupport

Abstract base class for continuous distributions with finite support.

DiscreteDistribution

Abstract base class for univariate discrete distributions.

SymbolicDistribution

Class for symbolic (categorical) distributions.

IntegerDistribution

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

DiracDeltaDistribution

Class for Dirac delta distributions.

GaussianDistribution

Class for Gaussian distributions.

TruncatedGaussianDistribution

Class for Truncated Gaussian distributions.

DrawIOInterface

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

ProbabilisticModel

Abstract base class for probabilistic models.

MissingDict

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

UnivariateDistribution

Abstract Base class for Univariate distributions.

ContinuousDistribution

Abstract base class for continuous distributions.

ContinuousDistributionWithFiniteSupport

Abstract base class for continuous distributions with finite support.

DiscreteDistribution

Abstract base class for univariate discrete distributions.

SymbolicDistribution

Class for symbolic (categorical) distributions.

IntegerDistribution

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

DiracDeltaDistribution

Class for Dirac delta distributions.

Functions#

interval_as_array(→ numpy.ndarray)

Convert an interval to a numpy array.

interval_as_array(→ numpy.ndarray)

Convert an interval to a numpy array.

simple_interval_as_array(→ numpy.ndarray)

Convert a simple interval to a numpy array.

interval_as_array(→ numpy.ndarray)

Convert an interval to a numpy array.

Package Contents#

probabilistic_model.distributions.SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT = 1.05#
class probabilistic_model.distributions.DrawIOInterface#

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

property drawio_label: str#
Abstractmethod:

The label of the object as a drawio compatible string.

property drawio_style: typing_extensions.Dict[str, typing_extensions.Any]#
Abstractmethod:

The style of the object.

class probabilistic_model.distributions.ProbabilisticModel#

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

property representation: str#

The symbol used to represent this distribution.

property variables: random_events.set.Tuple[random_events.variable.Variable, Ellipsis]#
Abstractmethod:

Returns:

The variables of the model.

property support: random_events.product_algebra.Event#
Abstractmethod:

Returns:

The support of the model.

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 [CVVdB20]

or watch the video tutorial. [US20]

Parameters:

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,).

abstract log_likelihood(events: random_events.product_algebra.np.array) random_events.product_algebra.np.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

abstract cdf(events: random_events.product_algebra.np.array) random_events.product_algebra.np.array#

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.

Parameters:

events – The array of full evidence events. The shape of the array has to be (n, len(self.variables)).

Returns:

The cumulative distribution function of the event as an array of shape (n,).

probability(event: random_events.product_algebra.Event) float#

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

Parameters:

event – The event.

Returns:

The probability of the event.

abstract 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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

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 [CVVdB20] or watch the video tutorial. [US20]

Returns:

The mode and its likelihood.

abstract log_mode() random_events.set.Tuple[random_events.product_algebra.Event, float]#

Calculate the mode of the model.

Check the documentation of mode for more information.

Returns:

The mode and its log-likelihood.

abstract marginal(variables: random_events.variable.Iterable[random_events.variable.Variable]) random_events.variable.Optional[random_events.variable.Self]#

Calculate the marginal distribution of a set of variables.

Parameters:

variables – The variables to calculate the marginal distribution on.

Returns:

The marginal distribution over the variables.

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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the probability of the event.

abstract 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]#

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

Check the documentation of truncated for more information.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

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.

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

abstract 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]#

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

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

abstract sample(amount: int) random_events.product_algebra.np.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

abstract moment(order: OrderType, center: CenterType) MomentType#

Calculate the (centralized) moment of the distribution.

\[\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`_. [US20]

Parameters:
  • order – The orders of the moment as a variable map for every continuous and integer variable.

  • center – The center of the moment as a variable map for every continuous and integer variable.

Returns:

The moments of the variables in order.

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.

Parameters:

variables – The variable to calculate the expectation of.

Returns:

The expectation of the variable.

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.

Parameters:

variables – The variable to calculate the variance of.

Returns:

The variance of the variable.

universal_simple_event() random_events.product_algebra.SimpleEvent#
Returns:

A simple event that contains every possible value.

abstract translate(translation: random_events.variable.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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

abstract __copy__()#
plotly_layout() random_events.variable.Dict[str, random_events.variable.Any]#

Create a layout for the plotly plot.

Returns:

The layout.

plotly_layout_1d() random_events.variable.Dict[str, random_events.variable.Any]#
Returns:

The layout argument for plotly figures as dict

plotly_layout_2d() random_events.variable.Dict[str, random_events.variable.Any]#
Returns:

The layout argument for plotly figures as dict

plotly_layout_3d() random_events.variable.Dict[str, random_events.variable.Any]#
Returns:

The layout argument for plotly figures as dict

plot(number_of_samples: int = 1000, surface=False, mode=False) random_events.product_algebra.List#

Generate traces that can be plotted with plotly.

Parameters:
  • number_of_samples – The number of samples to draw.

  • surface – If True, plot the model as a surface plot.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

plot_1d_symbolic() random_events.product_algebra.List#
plot_1d_numeric(number_of_samples: int, mode=False) random_events.product_algebra.List#

Plot a one-dimensional model using samples.

Parameters:
  • number_of_samples – The number of samples to draw.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

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.

univariate_mode_traces(mode: random_events.variable.Optional[random_events.product_algebra.Event], height: float)#
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.

plot_2d(number_of_samples: int, mode=False) random_events.product_algebra.List#

Plot a two-dimensional model.

Parameters:
  • number_of_samples – The number of samples to draw.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

plot_2d_surface(number_of_samples: int) random_events.product_algebra.List#

Plot a two-dimensional model as a surface plot.

Parameters:

number_of_samples – The number of samples to draw.

Returns:

The traces.

expectation_trace_2d_surface(height: float) random_events.product_algebra.go.Scatter3d#
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.

Returns:

The trace.

plot_2d_surface_of_simple_event(simple_event: random_events.product_algebra.SimpleEvent, samples: random_events.product_algebra.np.array)#
plot_3d(number_of_samples: int, mode=False) random_events.product_algebra.List#

Plot a three-dimensional model using samples.

Parameters:
  • number_of_samples – The number of samples to draw.

  • mode – If True, plot the mode of the model.

Returns:

The traces.s

multivariate_mode_traces()#
Returns:

traces for the mode of a multivariate model.

probabilistic_model.distributions.OrderType#
class probabilistic_model.distributions.MissingDict#

Bases: collections.defaultdict

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

__missing__(key)#
probabilistic_model.distributions.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

class probabilistic_model.distributions.UnivariateDistribution#

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

Abstract Base class for Univariate distributions.

variable: random_events.variable.Variable#
property variables: typing_extensions.Tuple[random_events.variable.Variable, Ellipsis]#
Returns:

The variables of the model.

property support: random_events.product_algebra.Event#
Returns:

The support of the model.

property univariate_support: random_events.variable.AbstractCompositeSet#
Abstractmethod:

Returns:

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

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.

Returns:

The mode and its log-likelihood.

abstract univariate_log_mode() typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]#
Returns:

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

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.

Parameters:

variables – The variables to calculate the marginal distribution on.

Returns:

The marginal distribution over the variables.

__eq__(other: typing_extensions.Self)#
to_json() typing_extensions.Dict[str, typing_extensions.Any]#
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

property abbreviated_symbol: str#
property drawio_style: typing_extensions.Dict[str, typing_extensions.Any]#

The style of the object.

class probabilistic_model.distributions.ContinuousDistribution#

Bases: UnivariateDistribution

Abstract base class for continuous distributions.

variable: random_events.variable.Continuous#
property univariate_support: random_events.variable.Interval#
Abstractmethod:

Returns:

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

abstract cdf(x: numpy.array) numpy.array#

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

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

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.

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

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

Parameters:

interval – The simple interval

Returns:

The truncated distribution and the log-probability of the interval.

abstract log_conditional_from_interval(interval) typing_extensions.Tuple[typing_extensions.Self, float]#

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.

class probabilistic_model.distributions.ContinuousDistributionWithFiniteSupport#

Bases: ContinuousDistribution

Abstract base class for continuous distributions with finite support.

interval: random_events.variable.SimpleInterval#

The interval of the distribution.

property lower: float#
property upper: float#
property univariate_support: random_events.variable.Interval#
Returns:

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

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

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

included_condition(x: numpy.array) numpy.array#

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

log_likelihood(x: numpy.array) numpy.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

abstract log_likelihood_without_bounds_check(x: numpy.array) numpy.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))

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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

class probabilistic_model.distributions.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: UnivariateDistribution

Abstract base class for univariate discrete distributions.

variable: typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer]#
probabilities: probabilistic_model.utils.MissingDict[int, float]#

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

__eq__(other)#
__hash__()#
log_likelihood(events: numpy.array) numpy.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

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

Parameters:

data – The data.

Returns:

The fitted distribution

abstract probabilities_for_plotting() typing_extensions.Dict[typing_extensions.Union[int, str], float]#
Returns:

The probabilities as dict that can be plotted.

plot(**kwargs) typing_extensions.List[plotly.graph_objects.Bar]#

Plot the distribution.

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

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

Parameters:

data – The json dict

Returns:

The deserialized object

normalize()#

Normalize the distribution.

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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

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.

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]#
__copy__() typing_extensions.Self#
__deepcopy__(memo=None) typing_extensions.Self#
__repr__()#
sample(amount: int) numpy.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

class probabilistic_model.distributions.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: DiscreteDistribution

Class for symbolic (categorical) distributions.

variable: random_events.variable.Symbolic#
univariate_log_mode() typing_extensions.Tuple[random_events.variable.Set, float]#
Returns:

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

log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]#
probabilities_for_plotting() typing_extensions.Dict[typing_extensions.Union[int, str], float]#
Returns:

The probabilities as dict that can be plotted.

property univariate_support: random_events.variable.Set#
Returns:

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

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

property representation#

The symbol used to represent this distribution.

property drawio_label#

The label of the object as a drawio compatible string.

property image#
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).

Parameters:

data – The data.

Returns:

The fitted distribution

fit_from_indices(data: numpy.array) typing_extensions.Self#
to_json() typing_extensions.Dict[str, typing_extensions.Any]#
classmethod _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) typing_extensions.Self#

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

Parameters:

data – The json dict

Returns:

The deserialized object

class probabilistic_model.distributions.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: ContinuousDistribution, DiscreteDistribution

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

variable: random_events.variable.Integer#
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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

univariate_log_mode() typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]#
Returns:

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

probabilities_for_plotting() typing_extensions.Dict[typing_extensions.Union[int, str], float]#
Returns:

The probabilities as dict that can be plotted.

property univariate_support: random_events.variable.Interval#
Returns:

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

cdf(x: numpy.array) numpy.array#

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

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

property representation#

The symbol used to represent this distribution.

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.

\[\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`_. [US20]

Parameters:
  • order – The orders of the moment as a variable map for every continuous and integer variable.

  • center – The center of the moment as a variable map for every continuous and integer variable.

Returns:

The moments of the variables in order.

plot(**kwargs) typing_extensions.List[plotly.graph_objects.Bar]#

Generate traces that can be plotted with plotly.

Parameters:
  • number_of_samples – The number of samples to draw.

  • surface – If True, plot the model as a surface plot.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

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

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

variable: random_events.variable.Continuous#
location: float#

The location of the Dirac delta distribution.

density_cap: float#

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

tolerance: float = 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.

log_likelihood(events: numpy.array) numpy.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

cdf(x: numpy.array) numpy.array#

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

property abbreviated_symbol: str#
property univariate_support: random_events.variable.Interval#
Returns:

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

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.

Parameters:

interval – The simple interval

Returns:

The truncated distribution and the log-probability of the interval.

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

univariate_log_mode() typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]#
Returns:

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

sample(amount: int) numpy.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

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.

\[\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`_. [US20]

Parameters:
  • order – The orders of the moment as a variable map for every continuous and integer variable.

  • center – The center of the moment as a variable map for every continuous and integer variable.

Returns:

The moments of the variables in order.

__eq__(other)#
__hash__()#
property representation#

The symbol used to represent this distribution.

__repr__()#
__copy__()#
__deepcopy__(memo=None)#
to_json() typing_extensions.Dict[str, typing_extensions.Any]#
classmethod _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) typing_extensions.Self#

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

Parameters:

data – The json dict

Returns:

The deserialized object

plot(**kwargs) typing_extensions.List#

Generate traces that can be plotted with plotly.

Parameters:
  • number_of_samples – The number of samples to draw.

  • surface – If True, plot the model as a surface plot.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

probabilistic_model.distributions.PADDING_FACTOR_FOR_X_AXIS_IN_PLOT = 0.05#
probabilistic_model.distributions.EXPECTATION_TRACE_NAME = 'Expectation'#
probabilistic_model.distributions.MODE_TRACE_NAME = 'Mode'#
probabilistic_model.distributions.MODE_TRACE_COLOR = '#AB63FA'#
probabilistic_model.distributions.PDF_TRACE_NAME = 'Probability Density Function'#
probabilistic_model.distributions.CDF_TRACE_NAME = 'Cumulative Distribution Function'#
probabilistic_model.distributions.CDF_TRACE_COLOR = '#EF553B'#
probabilistic_model.distributions.PDF_TRACE_COLOR = '#636EFA'#
class probabilistic_model.distributions.UniformDistribution(variable: probabilistic_model.distributions.distributions.Continuous, interval: probabilistic_model.distributions.distributions.SimpleInterval)#

Bases: probabilistic_model.distributions.distributions.ContinuousDistributionWithFiniteSupport

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

variable#
interval#

The interval of the distribution.

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))

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

univariate_log_mode() probabilistic_model.distributions.distributions.Tuple[probabilistic_model.distributions.distributions.AbstractCompositeSet, float]#
Returns:

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

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.

Parameters:

interval – The simple interval

Returns:

The truncated distribution and the log-probability of the interval.

sample(amount: int) probabilistic_model.distributions.distributions.np.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

pdf_value() float#

Calculate the density of the uniform distribution.

log_pdf_value() float#

Calculate the log-density of the uniform distribution.

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.

\[\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`_. [US20]

Parameters:
  • order – The orders of the moment as a variable map for every continuous and integer variable.

  • center – The center of the moment as a variable map for every continuous and integer variable.

Returns:

The moments of the variables in order.

__eq__(other)#
property drawio_label#

The label of the object as a drawio compatible string.

property representation#

The symbol used to represent this distribution.

property abbreviated_symbol: str#
__repr__()#
property image#
__copy__()#
__deepcopy__(memo=None)#
to_json() probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]#
classmethod _from_json(data: probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]) probabilistic_model.distributions.distributions.Self#

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

Parameters:

data – The json dict

Returns:

The deserialized object

x_axis_points_for_plotly() probabilistic_model.distributions.distributions.List[probabilistic_model.distributions.distributions.Union[None, float]]#
pdf_trace() probabilistic_model.distributions.distributions.go.Scatter#
cdf_trace() probabilistic_model.distributions.distributions.go.Scatter#
plot(**kwargs) probabilistic_model.distributions.distributions.List#

Generate traces that can be plotted with plotly.

Parameters:
  • number_of_samples – The number of samples to draw.

  • surface – If True, plot the model as a surface plot.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

__hash__()#
probabilistic_model.distributions.SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT = 1.05#
class probabilistic_model.distributions.DrawIOInterface#

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

property drawio_label: str#
Abstractmethod:

The label of the object as a drawio compatible string.

property drawio_style: typing_extensions.Dict[str, typing_extensions.Any]#
Abstractmethod:

The style of the object.

class probabilistic_model.distributions.ProbabilisticModel#

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

property representation: str#

The symbol used to represent this distribution.

property variables: random_events.set.Tuple[random_events.variable.Variable, Ellipsis]#
Abstractmethod:

Returns:

The variables of the model.

property support: random_events.product_algebra.Event#
Abstractmethod:

Returns:

The support of the model.

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 [CVVdB20]

or watch the video tutorial. [US20]

Parameters:

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,).

abstract log_likelihood(events: random_events.product_algebra.np.array) random_events.product_algebra.np.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

abstract cdf(events: random_events.product_algebra.np.array) random_events.product_algebra.np.array#

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.

Parameters:

events – The array of full evidence events. The shape of the array has to be (n, len(self.variables)).

Returns:

The cumulative distribution function of the event as an array of shape (n,).

probability(event: random_events.product_algebra.Event) float#

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

Parameters:

event – The event.

Returns:

The probability of the event.

abstract 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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

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 [CVVdB20] or watch the video tutorial. [US20]

Returns:

The mode and its likelihood.

abstract log_mode() random_events.set.Tuple[random_events.product_algebra.Event, float]#

Calculate the mode of the model.

Check the documentation of mode for more information.

Returns:

The mode and its log-likelihood.

abstract marginal(variables: random_events.variable.Iterable[random_events.variable.Variable]) random_events.variable.Optional[random_events.variable.Self]#

Calculate the marginal distribution of a set of variables.

Parameters:

variables – The variables to calculate the marginal distribution on.

Returns:

The marginal distribution over the variables.

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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the probability of the event.

abstract 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]#

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

Check the documentation of truncated for more information.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

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.

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

abstract 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]#

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

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

abstract sample(amount: int) random_events.product_algebra.np.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

abstract moment(order: OrderType, center: CenterType) MomentType#

Calculate the (centralized) moment of the distribution.

\[\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`_. [US20]

Parameters:
  • order – The orders of the moment as a variable map for every continuous and integer variable.

  • center – The center of the moment as a variable map for every continuous and integer variable.

Returns:

The moments of the variables in order.

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.

Parameters:

variables – The variable to calculate the expectation of.

Returns:

The expectation of the variable.

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.

Parameters:

variables – The variable to calculate the variance of.

Returns:

The variance of the variable.

universal_simple_event() random_events.product_algebra.SimpleEvent#
Returns:

A simple event that contains every possible value.

abstract translate(translation: random_events.variable.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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

abstract __copy__()#
plotly_layout() random_events.variable.Dict[str, random_events.variable.Any]#

Create a layout for the plotly plot.

Returns:

The layout.

plotly_layout_1d() random_events.variable.Dict[str, random_events.variable.Any]#
Returns:

The layout argument for plotly figures as dict

plotly_layout_2d() random_events.variable.Dict[str, random_events.variable.Any]#
Returns:

The layout argument for plotly figures as dict

plotly_layout_3d() random_events.variable.Dict[str, random_events.variable.Any]#
Returns:

The layout argument for plotly figures as dict

plot(number_of_samples: int = 1000, surface=False, mode=False) random_events.product_algebra.List#

Generate traces that can be plotted with plotly.

Parameters:
  • number_of_samples – The number of samples to draw.

  • surface – If True, plot the model as a surface plot.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

plot_1d_symbolic() random_events.product_algebra.List#
plot_1d_numeric(number_of_samples: int, mode=False) random_events.product_algebra.List#

Plot a one-dimensional model using samples.

Parameters:
  • number_of_samples – The number of samples to draw.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

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.

univariate_mode_traces(mode: random_events.variable.Optional[random_events.product_algebra.Event], height: float)#
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.

plot_2d(number_of_samples: int, mode=False) random_events.product_algebra.List#

Plot a two-dimensional model.

Parameters:
  • number_of_samples – The number of samples to draw.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

plot_2d_surface(number_of_samples: int) random_events.product_algebra.List#

Plot a two-dimensional model as a surface plot.

Parameters:

number_of_samples – The number of samples to draw.

Returns:

The traces.

expectation_trace_2d_surface(height: float) random_events.product_algebra.go.Scatter3d#
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.

Returns:

The trace.

plot_2d_surface_of_simple_event(simple_event: random_events.product_algebra.SimpleEvent, samples: random_events.product_algebra.np.array)#
plot_3d(number_of_samples: int, mode=False) random_events.product_algebra.List#

Plot a three-dimensional model using samples.

Parameters:
  • number_of_samples – The number of samples to draw.

  • mode – If True, plot the mode of the model.

Returns:

The traces.s

multivariate_mode_traces()#
Returns:

traces for the mode of a multivariate model.

probabilistic_model.distributions.OrderType#
class probabilistic_model.distributions.MissingDict#

Bases: collections.defaultdict

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

__missing__(key)#
probabilistic_model.distributions.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

class probabilistic_model.distributions.UnivariateDistribution#

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

Abstract Base class for Univariate distributions.

variable: random_events.variable.Variable#
property variables: typing_extensions.Tuple[random_events.variable.Variable, Ellipsis]#
Returns:

The variables of the model.

property support: random_events.product_algebra.Event#
Returns:

The support of the model.

property univariate_support: random_events.variable.AbstractCompositeSet#
Abstractmethod:

Returns:

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

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.

Returns:

The mode and its log-likelihood.

abstract univariate_log_mode() typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]#
Returns:

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

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.

Parameters:

variables – The variables to calculate the marginal distribution on.

Returns:

The marginal distribution over the variables.

__eq__(other: typing_extensions.Self)#
to_json() typing_extensions.Dict[str, typing_extensions.Any]#
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

property abbreviated_symbol: str#
property drawio_style: typing_extensions.Dict[str, typing_extensions.Any]#

The style of the object.

class probabilistic_model.distributions.ContinuousDistribution#

Bases: UnivariateDistribution

Abstract base class for continuous distributions.

variable: random_events.variable.Continuous#
property univariate_support: random_events.variable.Interval#
Abstractmethod:

Returns:

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

abstract cdf(x: numpy.array) numpy.array#

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

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

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.

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

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

Parameters:

interval – The simple interval

Returns:

The truncated distribution and the log-probability of the interval.

abstract log_conditional_from_interval(interval) typing_extensions.Tuple[typing_extensions.Self, float]#

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.

class probabilistic_model.distributions.ContinuousDistributionWithFiniteSupport#

Bases: ContinuousDistribution

Abstract base class for continuous distributions with finite support.

interval: random_events.variable.SimpleInterval#

The interval of the distribution.

property lower: float#
property upper: float#
property univariate_support: random_events.variable.Interval#
Returns:

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

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

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

included_condition(x: numpy.array) numpy.array#

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

log_likelihood(x: numpy.array) numpy.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

abstract log_likelihood_without_bounds_check(x: numpy.array) numpy.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))

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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

class probabilistic_model.distributions.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: UnivariateDistribution

Abstract base class for univariate discrete distributions.

variable: typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer]#
probabilities: probabilistic_model.utils.MissingDict[int, float]#

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

__eq__(other)#
__hash__()#
log_likelihood(events: numpy.array) numpy.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

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

Parameters:

data – The data.

Returns:

The fitted distribution

abstract probabilities_for_plotting() typing_extensions.Dict[typing_extensions.Union[int, str], float]#
Returns:

The probabilities as dict that can be plotted.

plot(**kwargs) typing_extensions.List[plotly.graph_objects.Bar]#

Plot the distribution.

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

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

Parameters:

data – The json dict

Returns:

The deserialized object

normalize()#

Normalize the distribution.

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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

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.

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]#
__copy__() typing_extensions.Self#
__deepcopy__(memo=None) typing_extensions.Self#
__repr__()#
sample(amount: int) numpy.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

class probabilistic_model.distributions.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: DiscreteDistribution

Class for symbolic (categorical) distributions.

variable: random_events.variable.Symbolic#
univariate_log_mode() typing_extensions.Tuple[random_events.variable.Set, float]#
Returns:

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

log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]#
probabilities_for_plotting() typing_extensions.Dict[typing_extensions.Union[int, str], float]#
Returns:

The probabilities as dict that can be plotted.

property univariate_support: random_events.variable.Set#
Returns:

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

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

property representation#

The symbol used to represent this distribution.

property drawio_label#

The label of the object as a drawio compatible string.

property image#
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).

Parameters:

data – The data.

Returns:

The fitted distribution

fit_from_indices(data: numpy.array) typing_extensions.Self#
to_json() typing_extensions.Dict[str, typing_extensions.Any]#
classmethod _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) typing_extensions.Self#

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

Parameters:

data – The json dict

Returns:

The deserialized object

class probabilistic_model.distributions.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: ContinuousDistribution, DiscreteDistribution

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

variable: random_events.variable.Integer#
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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

univariate_log_mode() typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]#
Returns:

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

probabilities_for_plotting() typing_extensions.Dict[typing_extensions.Union[int, str], float]#
Returns:

The probabilities as dict that can be plotted.

property univariate_support: random_events.variable.Interval#
Returns:

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

cdf(x: numpy.array) numpy.array#

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

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

property representation#

The symbol used to represent this distribution.

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.

\[\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`_. [US20]

Parameters:
  • order – The orders of the moment as a variable map for every continuous and integer variable.

  • center – The center of the moment as a variable map for every continuous and integer variable.

Returns:

The moments of the variables in order.

plot(**kwargs) typing_extensions.List[plotly.graph_objects.Bar]#

Generate traces that can be plotted with plotly.

Parameters:
  • number_of_samples – The number of samples to draw.

  • surface – If True, plot the model as a surface plot.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

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

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

variable: random_events.variable.Continuous#
location: float#

The location of the Dirac delta distribution.

density_cap: float#

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

tolerance: float = 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.

log_likelihood(events: numpy.array) numpy.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

cdf(x: numpy.array) numpy.array#

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

property abbreviated_symbol: str#
property univariate_support: random_events.variable.Interval#
Returns:

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

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.

Parameters:

interval – The simple interval

Returns:

The truncated distribution and the log-probability of the interval.

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

univariate_log_mode() typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]#
Returns:

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

sample(amount: int) numpy.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

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.

\[\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`_. [US20]

Parameters:
  • order – The orders of the moment as a variable map for every continuous and integer variable.

  • center – The center of the moment as a variable map for every continuous and integer variable.

Returns:

The moments of the variables in order.

__eq__(other)#
__hash__()#
property representation#

The symbol used to represent this distribution.

__repr__()#
__copy__()#
__deepcopy__(memo=None)#
to_json() typing_extensions.Dict[str, typing_extensions.Any]#
classmethod _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) typing_extensions.Self#

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

Parameters:

data – The json dict

Returns:

The deserialized object

plot(**kwargs) typing_extensions.List#

Generate traces that can be plotted with plotly.

Parameters:
  • number_of_samples – The number of samples to draw.

  • surface – If True, plot the model as a surface plot.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

probabilistic_model.distributions.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

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

Bases: probabilistic_model.distributions.distributions.ContinuousDistribution

Class for Gaussian distributions.

location: float#

The mean of the Gaussian distribution.

scale: float#

The standard deviation of the Gaussian distribution.

variable#
property univariate_support: probabilistic_model.distributions.distributions.Interval#
Returns:

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

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.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

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

univariate_log_mode() probabilistic_model.distributions.distributions.Tuple[probabilistic_model.distributions.distributions.AbstractCompositeSet, float]#
Returns:

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

sample(amount: int) probabilistic_model.distributions.distributions.np.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

ppf(value)#
raw_moment(order: int) float#

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

The raw moment is given by:

\[E(X^n) = \sum_{j=0}^{\lfloor \frac{n}{2}\rfloor}\binom{n}{2j}\dfrac{\mu^{n-2j}\sigma^{2j}(2j)!}{j!2^j}.\]
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:

\[E(X-center)^i = \sum_{i=0}^{order} \binom{order}{i} E[X^i] * (- center)^{(order-i)}\]
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.

Parameters:

interval – The simple interval

Returns:

The truncated distribution and the log-probability of the interval.

__eq__(other: probabilistic_model.distributions.distributions.Self)#
property representation#

The symbol used to represent this distribution.

__repr__()#
__copy__()#
__deepcopy__(memo=None)#
to_json() probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]#
classmethod _from_json(data: probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]) probabilistic_model.distributions.distributions.Self#

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

Parameters:

data – The json dict

Returns:

The deserialized object

property abbreviated_symbol: str#
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.

Parameters:

translation – The variable value pairs to translate the model by.

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

Bases: probabilistic_model.distributions.distributions.ContinuousDistributionWithFiniteSupport, GaussianDistribution

Class for Truncated Gaussian distributions.

interval#

The interval of the distribution.

property normalizing_constant: float#

Helper method to calculate

\[\]

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

property cdf_of_lower#
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))

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

univariate_log_mode() probabilistic_model.distributions.distributions.Tuple[probabilistic_model.distributions.distributions.Interval, float]#
Returns:

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

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.

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.

This method follows the equation (2.8) in [Oga22].

\[ \begin{align}\begin{aligned}\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]\end{aligned}\end{align} \]
Returns:

The moment of the distribution.

__eq__(other)#
property representation#

The symbol used to represent this distribution.

__copy__()#
__deepcopy__(memo=None)#
to_json() probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]#
classmethod _from_json(data: probabilistic_model.distributions.distributions.Dict[str, probabilistic_model.distributions.distributions.Any]) probabilistic_model.distributions.distributions.Self#

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

Parameters:

data – The json dict

Returns:

The deserialized object

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

robert_rejection_sample(amount: int) probabilistic_model.distributions.distributions.np.ndarray#

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

Parameters:

amount – The amount of samples to generate

Returns:

The samples

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.

Parameters:

amount – The amount of samples to generate

Returns:

The samples

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.

Parameters:

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

Returns:

The samples

sample(amount: int) probabilistic_model.distributions.distributions.np.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

probabilistic_model.distributions.SCALING_FACTOR_FOR_EXPECTATION_IN_PLOT = 1.05#
class probabilistic_model.distributions.DrawIOInterface#

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

property drawio_label: str#
Abstractmethod:

The label of the object as a drawio compatible string.

property drawio_style: typing_extensions.Dict[str, typing_extensions.Any]#
Abstractmethod:

The style of the object.

class probabilistic_model.distributions.ProbabilisticModel#

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

property representation: str#

The symbol used to represent this distribution.

property variables: random_events.set.Tuple[random_events.variable.Variable, Ellipsis]#
Abstractmethod:

Returns:

The variables of the model.

property support: random_events.product_algebra.Event#
Abstractmethod:

Returns:

The support of the model.

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 [CVVdB20]

or watch the video tutorial. [US20]

Parameters:

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,).

abstract log_likelihood(events: random_events.product_algebra.np.array) random_events.product_algebra.np.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

abstract cdf(events: random_events.product_algebra.np.array) random_events.product_algebra.np.array#

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.

Parameters:

events – The array of full evidence events. The shape of the array has to be (n, len(self.variables)).

Returns:

The cumulative distribution function of the event as an array of shape (n,).

probability(event: random_events.product_algebra.Event) float#

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

Parameters:

event – The event.

Returns:

The probability of the event.

abstract 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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

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 [CVVdB20] or watch the video tutorial. [US20]

Returns:

The mode and its likelihood.

abstract log_mode() random_events.set.Tuple[random_events.product_algebra.Event, float]#

Calculate the mode of the model.

Check the documentation of mode for more information.

Returns:

The mode and its log-likelihood.

abstract marginal(variables: random_events.variable.Iterable[random_events.variable.Variable]) random_events.variable.Optional[random_events.variable.Self]#

Calculate the marginal distribution of a set of variables.

Parameters:

variables – The variables to calculate the marginal distribution on.

Returns:

The marginal distribution over the variables.

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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the probability of the event.

abstract 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]#

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

Check the documentation of truncated for more information.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

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.

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

abstract 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]#

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

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

abstract sample(amount: int) random_events.product_algebra.np.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

abstract moment(order: OrderType, center: CenterType) MomentType#

Calculate the (centralized) moment of the distribution.

\[\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`_. [US20]

Parameters:
  • order – The orders of the moment as a variable map for every continuous and integer variable.

  • center – The center of the moment as a variable map for every continuous and integer variable.

Returns:

The moments of the variables in order.

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.

Parameters:

variables – The variable to calculate the expectation of.

Returns:

The expectation of the variable.

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.

Parameters:

variables – The variable to calculate the variance of.

Returns:

The variance of the variable.

universal_simple_event() random_events.product_algebra.SimpleEvent#
Returns:

A simple event that contains every possible value.

abstract translate(translation: random_events.variable.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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

abstract __copy__()#
plotly_layout() random_events.variable.Dict[str, random_events.variable.Any]#

Create a layout for the plotly plot.

Returns:

The layout.

plotly_layout_1d() random_events.variable.Dict[str, random_events.variable.Any]#
Returns:

The layout argument for plotly figures as dict

plotly_layout_2d() random_events.variable.Dict[str, random_events.variable.Any]#
Returns:

The layout argument for plotly figures as dict

plotly_layout_3d() random_events.variable.Dict[str, random_events.variable.Any]#
Returns:

The layout argument for plotly figures as dict

plot(number_of_samples: int = 1000, surface=False, mode=False) random_events.product_algebra.List#

Generate traces that can be plotted with plotly.

Parameters:
  • number_of_samples – The number of samples to draw.

  • surface – If True, plot the model as a surface plot.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

plot_1d_symbolic() random_events.product_algebra.List#
plot_1d_numeric(number_of_samples: int, mode=False) random_events.product_algebra.List#

Plot a one-dimensional model using samples.

Parameters:
  • number_of_samples – The number of samples to draw.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

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.

univariate_mode_traces(mode: random_events.variable.Optional[random_events.product_algebra.Event], height: float)#
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.

plot_2d(number_of_samples: int, mode=False) random_events.product_algebra.List#

Plot a two-dimensional model.

Parameters:
  • number_of_samples – The number of samples to draw.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

plot_2d_surface(number_of_samples: int) random_events.product_algebra.List#

Plot a two-dimensional model as a surface plot.

Parameters:

number_of_samples – The number of samples to draw.

Returns:

The traces.

expectation_trace_2d_surface(height: float) random_events.product_algebra.go.Scatter3d#
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.

Returns:

The trace.

plot_2d_surface_of_simple_event(simple_event: random_events.product_algebra.SimpleEvent, samples: random_events.product_algebra.np.array)#
plot_3d(number_of_samples: int, mode=False) random_events.product_algebra.List#

Plot a three-dimensional model using samples.

Parameters:
  • number_of_samples – The number of samples to draw.

  • mode – If True, plot the mode of the model.

Returns:

The traces.s

multivariate_mode_traces()#
Returns:

traces for the mode of a multivariate model.

probabilistic_model.distributions.OrderType#
class probabilistic_model.distributions.MissingDict#

Bases: collections.defaultdict

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

__missing__(key)#
probabilistic_model.distributions.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

class probabilistic_model.distributions.UnivariateDistribution#

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

Abstract Base class for Univariate distributions.

variable: random_events.variable.Variable#
property variables: typing_extensions.Tuple[random_events.variable.Variable, Ellipsis]#
Returns:

The variables of the model.

property support: random_events.product_algebra.Event#
Returns:

The support of the model.

property univariate_support: random_events.variable.AbstractCompositeSet#
Abstractmethod:

Returns:

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

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.

Returns:

The mode and its log-likelihood.

abstract univariate_log_mode() typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]#
Returns:

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

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.

Parameters:

variables – The variables to calculate the marginal distribution on.

Returns:

The marginal distribution over the variables.

__eq__(other: typing_extensions.Self)#
to_json() typing_extensions.Dict[str, typing_extensions.Any]#
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

property abbreviated_symbol: str#
property drawio_style: typing_extensions.Dict[str, typing_extensions.Any]#

The style of the object.

class probabilistic_model.distributions.ContinuousDistribution#

Bases: UnivariateDistribution

Abstract base class for continuous distributions.

variable: random_events.variable.Continuous#
property univariate_support: random_events.variable.Interval#
Abstractmethod:

Returns:

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

abstract cdf(x: numpy.array) numpy.array#

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

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

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.

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

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

Parameters:

interval – The simple interval

Returns:

The truncated distribution and the log-probability of the interval.

abstract log_conditional_from_interval(interval) typing_extensions.Tuple[typing_extensions.Self, float]#

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.

class probabilistic_model.distributions.ContinuousDistributionWithFiniteSupport#

Bases: ContinuousDistribution

Abstract base class for continuous distributions with finite support.

interval: random_events.variable.SimpleInterval#

The interval of the distribution.

property lower: float#
property upper: float#
property univariate_support: random_events.variable.Interval#
Returns:

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

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

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

included_condition(x: numpy.array) numpy.array#

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

log_likelihood(x: numpy.array) numpy.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

abstract log_likelihood_without_bounds_check(x: numpy.array) numpy.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))

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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

class probabilistic_model.distributions.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: UnivariateDistribution

Abstract base class for univariate discrete distributions.

variable: typing_extensions.Union[random_events.variable.Symbolic, random_events.variable.Integer]#
probabilities: probabilistic_model.utils.MissingDict[int, float]#

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

__eq__(other)#
__hash__()#
log_likelihood(events: numpy.array) numpy.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

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

Parameters:

data – The data.

Returns:

The fitted distribution

abstract probabilities_for_plotting() typing_extensions.Dict[typing_extensions.Union[int, str], float]#
Returns:

The probabilities as dict that can be plotted.

plot(**kwargs) typing_extensions.List[plotly.graph_objects.Bar]#

Plot the distribution.

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

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

Parameters:

data – The json dict

Returns:

The deserialized object

normalize()#

Normalize the distribution.

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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

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.

Parameters:

point – A partial point to calculate the truncated distribution on.

Returns:

The truncated distribution and the log-probability of the point.

log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]#
__copy__() typing_extensions.Self#
__deepcopy__(memo=None) typing_extensions.Self#
__repr__()#
sample(amount: int) numpy.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

class probabilistic_model.distributions.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: DiscreteDistribution

Class for symbolic (categorical) distributions.

variable: random_events.variable.Symbolic#
univariate_log_mode() typing_extensions.Tuple[random_events.variable.Set, float]#
Returns:

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

log_conditional_of_composite_set(event: random_events.variable.AbstractCompositeSet) typing_extensions.Tuple[random_events.variable.Optional[typing_extensions.Self], float]#
probabilities_for_plotting() typing_extensions.Dict[typing_extensions.Union[int, str], float]#
Returns:

The probabilities as dict that can be plotted.

property univariate_support: random_events.variable.Set#
Returns:

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

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

property representation#

The symbol used to represent this distribution.

property drawio_label#

The label of the object as a drawio compatible string.

property image#
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).

Parameters:

data – The data.

Returns:

The fitted distribution

fit_from_indices(data: numpy.array) typing_extensions.Self#
to_json() typing_extensions.Dict[str, typing_extensions.Any]#
classmethod _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) typing_extensions.Self#

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

Parameters:

data – The json dict

Returns:

The deserialized object

class probabilistic_model.distributions.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: ContinuousDistribution, DiscreteDistribution

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

variable: random_events.variable.Integer#
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.

Parameters:

event – The event to condition on.

Returns:

The truncated distribution and the log-probability of the event.

univariate_log_mode() typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]#
Returns:

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

probabilities_for_plotting() typing_extensions.Dict[typing_extensions.Union[int, str], float]#
Returns:

The probabilities as dict that can be plotted.

property univariate_support: random_events.variable.Interval#
Returns:

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

cdf(x: numpy.array) numpy.array#

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

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

property representation#

The symbol used to represent this distribution.

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.

\[\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`_. [US20]

Parameters:
  • order – The orders of the moment as a variable map for every continuous and integer variable.

  • center – The center of the moment as a variable map for every continuous and integer variable.

Returns:

The moments of the variables in order.

plot(**kwargs) typing_extensions.List[plotly.graph_objects.Bar]#

Generate traces that can be plotted with plotly.

Parameters:
  • number_of_samples – The number of samples to draw.

  • surface – If True, plot the model as a surface plot.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.

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

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

variable: random_events.variable.Continuous#
location: float#

The location of the Dirac delta distribution.

density_cap: float#

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

tolerance: float = 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.

log_likelihood(events: numpy.array) numpy.array#

Calculate the log-likelihood of an event.

Check the documentation of likelihood for more information.

Parameters:

events – The full evidence event with shape (#events, #variables)

Returns:

The log-likelihood of the event with shape (#events).

cdf(x: numpy.array) numpy.array#

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

property abbreviated_symbol: str#
property univariate_support: random_events.variable.Interval#
Returns:

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

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.

Parameters:

interval – The simple interval

Returns:

The truncated distribution and the log-probability of the interval.

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 [CVVdB20] or watch the video tutorial. [US20]

Parameters:

event – The event.

Returns:

The probability of the event.

univariate_log_mode() typing_extensions.Tuple[random_events.variable.AbstractCompositeSet, float]#
Returns:

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

sample(amount: int) numpy.array#

Sample from the model.

Parameters:

amount – The number of samples to draw.

Returns:

The samples.

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.

\[\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`_. [US20]

Parameters:
  • order – The orders of the moment as a variable map for every continuous and integer variable.

  • center – The center of the moment as a variable map for every continuous and integer variable.

Returns:

The moments of the variables in order.

__eq__(other)#
__hash__()#
property representation#

The symbol used to represent this distribution.

__repr__()#
__copy__()#
__deepcopy__(memo=None)#
to_json() typing_extensions.Dict[str, typing_extensions.Any]#
classmethod _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) typing_extensions.Self#

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

Parameters:

data – The json dict

Returns:

The deserialized object

plot(**kwargs) typing_extensions.List#

Generate traces that can be plotted with plotly.

Parameters:
  • number_of_samples – The number of samples to draw.

  • surface – If True, plot the model as a surface plot.

  • mode – If True, plot the mode of the model.

Returns:

The traces.

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.

Parameters:

translation – The variable value pairs to translate the model by.

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.

Parameters:

scaling – The variable value pairs to scale the model by.