distribution module¶
Class to create a probability distribution from the OpenTURNS library.
The OTDistribution
class is a concrete class
inheriting from Distribution
which is an abstract one.
OT stands for OpenTURNS
which is the library it relies on.
The OTDistribution
of a given uncertain variable is built
from mandatory arguments:
a variable name,
a probability distribution name recognized by OpenTURNS,
a set of parameters provided as a tuple of positional arguments filled in the order specified by the OpenTURNS constructor of this probability distribution.
Warning
The probability distribution parameters must be provided according to the signature of the openTURNS classes. Access the openTURNS documentation.
The constructor has also optional arguments:
a variable dimension (default: 1),
a standard representation of these parameters (default: use the parameters provided in the tuple),
a transformation of the variable (default: no transformation),
lower and upper bounds for truncation (default: no truncation),
a threshold for the OpenTURNS truncation tool (more details).
- class gemseo.uncertainty.distributions.openturns.distribution.OTDistribution(variable='x', interfaced_distribution='Uniform', parameters=(), dimension=1, standard_parameters=None, transformation=None, lower_bound=None, upper_bound=None, threshold=0.5)[source]¶
Bases:
Distribution
OpenTURNS probability distribution.
Create a probability distribution for an uncertain variable from its dimension and probability distribution name and properties.
Examples
>>> from gemseo.uncertainty.distributions.openturns.distribution import ( ... OTDistribution ... ) >>> distribution = OTDistribution('x', 'Exponential', (3, 2)) >>> print(distribution) Exponential(3, 2)
- 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 (tuple[Any]) –
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
ComposedDistribution
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). IfNone
, useparameters
instead. For instance, let us consider the interfaced OpenTURNS distribution"Dirac"
. Then, the string representation ofOTDistribution("x", "Dirac", (1,), 1, {"loc": 1})
is"Dirac(loc=1)"
while the string representation ofOTDistribution("x", "Dirac", (1,))
is"Dirac(1)"
.transformation (str | None) – A transformation applied to the random variable, e.g. \(\sin(x)\). If
None
, no transformation.lower_bound (float | None) – A lower bound to truncate the probability distribution. If
None
, no lower truncation.upper_bound (float | None) – An upper bound to truncate the probability distribution. If
None
, no upper truncation.threshold (float) –
A threshold in [0,1].
By default it is set to 0.5.
- COMPOSED_DISTRIBUTION_CLASS¶
alias of
OTComposedDistribution
- 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.
- compute_inverse_cdf(vector)[source]¶
Evaluate the inverse of the cumulative density function (ICDF).
- plot(index=0, show=True, save=False, file_path='', directory_path='', file_name='', file_extension='')¶
Plot both probability and cumulative density functions for a given component.
- Parameters:
index (int) –
The index of a component of the random variable.
By default it is set to 0.
save (bool) –
If
True
, save the figure.By default it is set to False.
show (bool) –
If
True
, display the figure.By default it is set to True.
file_path (str | Path) –
The path of the file to save the figures. If the extension is missing, use
file_extension
. If empty, create a file path fromdirectory_path
,file_name
andfile_extension
.By default it is set to “”.
directory_path (str | Path) –
The path of the directory to save the figures. If empty, use the current working directory.
By default it is set to “”.
file_name (str) –
The name of the file to save the figures. If empty, use a default one generated by the post-processing.
By default it is set to “”.
file_extension (str) –
A file extension, e.g.
'png'
,'pdf'
,'svg'
, … If empty, use a default file extension.By default it is set to “”.
- Returns:
The figure.
- Return type:
Figure
- plot_all(show=True, save=False, file_path='', directory_path='', file_name='', file_extension='')¶
Plot both probability and cumulative density functions for all components.
- Parameters:
save (bool) –
If
True
, save the figure.By default it is set to False.
show (bool) –
If
True
, display the figure.By default it is set to True.
file_path (str | Path) –
The path of the file to save the figures. If the extension is missing, use
file_extension
. If empty, create a file path fromdirectory_path
,file_name
andfile_extension
.By default it is set to “”.
directory_path (str | Path) –
The path of the directory to save the figures. If empty, use the current working directory.
By default it is set to “”.
file_name (str) –
The name of the file to save the figures. If empty, use a default one generated by the post-processing.
By default it is set to “”.
file_extension (str) –
A file extension, e.g.
'png'
,'pdf'
,'svg'
, … If empty, use a default file extension.By default it is set to “”.
- Returns:
The figures.
- Return type:
list[Figure]
- distribution: ot.ComposedDistribution¶
The probability distribution of the random variable.
- marginals: list[ot.Distribution]¶
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.
- num_lower_bound: ndarray¶
The numerical lower bound of the random variable.
- num_upper_bound: ndarray¶
The numerical upper bound of the random variable.
- property range: list[numpy.ndarray]¶
The numerical range.
The numerical range is the interval defined by the lower and upper bounds numerically reachable by the random variable.
Here, the numerical range of the random variable is defined by one array for each component of the random variable, whose first element is the lower bound of this component while the second one is its upper bound.
- standard_parameters: dict[str, str] | None¶
The standard representation of the parameters of the distribution, used for its string representation.
- property support: list[numpy.ndarray]¶
The mathematical support.
The mathematical support is the interval defined by the theoretical lower and upper bounds of the random variable.
Here, the mathematical range of the random variable is defined by one array for each component of the random variable, whose first element is the lower bound of this component while the second one is its upper bound.
Examples using OTDistribution¶
Fitting a distribution from data based on OpenTURNS
Probability distributions based on OpenTURNS