gemseo / uncertainty / distributions / scipy

# distribution module¶

The interface to SciPy-based probability distributions.

The SPDistribution class is a concrete class inheriting from BaseDistribution which is an abstract one. SP stands for scipy which is the library it relies on.

The SPDistribution of a given uncertain variable is built from mandatory arguments:

• a variable name,

• a distribution name recognized by SciPy,

• a set of parameters provided as a dictionary of keyword arguments named as the arguments of the scipy constructor of this distribution.

Warning

The distribution parameters must be provided according to the signature of the scipy classes. Access the scipy documentation.

The constructor has also optional arguments:

• a variable dimension (default: 1),

• a standard representation of these parameters (default: use parameters).

class gemseo.uncertainty.distributions.scipy.distribution.SPDistribution(variable='x', interfaced_distribution='uniform', parameters=mappingproxy({}), dimension=1, standard_parameters=None)[source]

A SciPy-based probability distribution.

Create a probability distribution for an uncertain variable from its dimension and distribution names and properties.

Examples

>>> from gemseo.uncertainty.distributions.scipy.distribution import (
...     SPDistribution,
... )
>>> distribution = SPDistribution("x", "expon", {"loc": 3, "scale": 1 / 2.0})
>>> print(distribution)
expon(loc=3, scale=0.5)

Parameters:
• variable (str) –

The name of the random variable.

By default it is set to “x”.

• interfaced_distribution (str) –

The name of the probability distribution, typically the name of a class wrapped from an external library, such as "Normal" for OpenTURNS or "norm" for SciPy.

By default it is set to “uniform”.

• parameters (StrKeyMapping) –

The parameters of the probability distribution.

By default it is set to {}.

• dimension (int) –

The dimension of the random variable. If greater than 1, the probability distribution is applied to all components of the random variable under the hypothesis that these components are stochastically independent. To be removed in a future version; use a BaseJointDistribution instead.

By default it is set to 1.

• standard_parameters (StandardParametersType | None) – The parameters of the probability distribution used for string representation only (use parameters for computation). If None, use parameters instead. For instance, let us consider the interfaced SciPy distribution "uniform". Then, the string representation of SPDistribution("x", "uniform", parameters, 1, {"min": 1, "max": 3}) with parameters={"loc": 1, "scale": 2} is "uniform(max=3, min=1)" while the string representation of SPDistribution("x", "uniform", parameters) is "uniform(loc=1, scale=2)".

JOINT_DISTRIBUTION_CLASS

alias of SPJointDistribution

compute_cdf(vector)[source]

Evaluate the cumulative density function (CDF).

Evaluate the CDF of the components of the random variable for a given realization of this random variable.

Parameters:

vector (Iterable[float]) – A realization of the random variable.

Returns:

The CDF values of the components of the random variable.

Return type:

ndarray

compute_inverse_cdf(vector)[source]

Evaluate the inverse of the cumulative density function (ICDF).

Parameters:

vector (Iterable[float]) – A vector of values comprised between 0 and 1 whose length is equal to the dimension of the random variable.

Returns:

The ICDF values of the components of the random variable.

Return type:

ndarray

compute_samples(n_samples=1, random_state=None)[source]

Sample the random variable.

Parameters:
• n_samples (int) –

The number of samples.

By default it is set to 1.

• random_state (None | int | Generator | RandomState) – The SciPy random state.

Returns:

The samples of the random variable,

The number of columns is equal to the dimension of the variable and the number of lines is equal to the number of samples.

Return type:

ndarray

dimension: int

The number of dimensions of the random variable.

distribution: type

The probability distribution of the random variable.

distribution_name: str

The name of the probability distribution.

marginals: list[type]

The marginal distributions of the components of the random variable.

math_lower_bound: ndarray

The mathematical lower bound of the random variable.

math_upper_bound: ndarray

The mathematical upper bound of the random variable.

property mean: ndarray

The analytical mean of the random variable.

num_lower_bound: ndarray

The numerical lower bound of the random variable.

num_upper_bound: ndarray

The numerical upper bound of the random variable.

parameters: tuple[Any] | dict[str, Any]

The parameters of the probability distribution.

property standard_deviation: ndarray

The analytical standard deviation of the random variable.

standard_parameters: dict[str, str] | None

The standard representation of the parameters of the distribution, used for its string representation.

transformation: str

The transformation applied to the random variable, e.g. ‘sin(x)’.

variable_name: str

The name of the random variable.

## Examples using SPDistribution¶

Probability distributions based on SciPy

Probability distributions based on SciPy