probabilistic_model.distributions.gaussian

Contents

probabilistic_model.distributions.gaussian#

Classes#

GaussianDistribution

Class for Gaussian distributions.

TruncatedGaussianDistribution

Class for Truncated Gaussian distributions.

Module Contents#

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