probabilistic_model.probabilistic_model

Contents

probabilistic_model.probabilistic_model#

Attributes#

Classes#

ProbabilisticModel

Abstract base class for probabilistic models.

Module Contents#

probabilistic_model.probabilistic_model.FullEvidenceType#
probabilistic_model.probabilistic_model.OrderType#
class probabilistic_model.probabilistic_model.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.