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 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 distribution.
Warning
The 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).
Classes:
|
OpenTURNS probability distribution. |
- class gemseo.uncertainty.distributions.openturns.distribution.OTDistribution(variable, interfaced_distribution, parameters, dimension=1, standard_parameters=None, transformation=None, lower_bound=None, upper_bound=None, threshold=0.5)[source]¶
Bases:
gemseo.uncertainty.distributions.distribution.Distribution
OpenTURNS probability distribution.
Create a probability distribution for an uncertain variable from its dimension and distribution names and properties.
- Attributes
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.
distribution (InterfacedDistributionClass) – The probability distribution of the random variable.
marginals (list(InterfacedDistributionClass)) – The marginal distributions of the components of the random variable.
dimension (int) – The number of dimensions of the random variable.
variable_name (str) – The name of the random variable.
distribution_name (str) – The name of the probability distribution.
transformation (str) – The transformation applied to the random variable, e.g. ‘sin(x)’.
parameters (tuple or dict) – The parameters of the probability distribution.
standard_parameters (dict, optional) – The standard representation of the parameters of the distribution, used for its string representation.
- Parameters
variable (str) –
interfaced_distribution (str) –
parameters (ParametersType) –
dimension (int) –
standard_parameters (Optional[StandardParametersType]) –
transformation (Optional[str]) –
lower_bound (Optional[float]) –
upper_bound (Optional[float]) –
threshold (float) –
- Return type
None
Example
>>> from gemseo.uncertainty.distributions.openturns.distribution import ( ... OTDistribution ... ) >>> distribution = OTDistribution('x', 'Exponential', (3, 2)) >>> print(distribution) Exponential(3, 2)
Parameters: variable: The name of the random variable. interfaced_distribution: 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.
- parameters: The parameters of the class
related to distribution.
dimension: The dimension of the random variable. standard_parameters: The standard representation
of the parameters of the probability distribution.
variable: The name of the random variable. distribution: 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.
parameters: The parameters of the probability distribution. dimension: The dimension of the random variable. standard_parameters: The standard representation
of the parameters of the probability distribution.
- transformation: A transformation applied
to the random variable, e.g. ‘sin(x)’. If None, no transformation.
- lower_bound: A lower bound to truncate the distribution.
If None, no lower truncation.
- upper_bound: An upper bound to truncate the distribution.
If None, no upper truncation.
threshold: A threshold in [0,1].
Methods:
compute_cdf
(vector)Evaluate the cumulative density function (CDF).
compute_inverse_cdf
(vector)Evaluate the inverse of the cumulative density function (ICDF).
compute_samples
([n_samples])Sample the random variable.
plot
([index, show, save, file_path, …])Plot both probability and cumulative density functions for a given component.
plot_all
([show, save, file_path, …])Plot both probability and cumulative density functions for all components.
Attributes:
The analytical mean of the random variable.
The numerical range.
The analytical standard deviation of the random variable.
The mathematical support.
- 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
numpy.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
numpy.ndarray
- compute_samples(n_samples=1)[source]¶
Sample the random variable.
- Parameters
n_samples (int) – The number of samples.
- 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
numpy.ndarray
- property mean¶
The analytical mean of the random variable.
- plot(index=0, show=True, save=False, file_path=None, directory_path=None, file_name=None, file_extension=None)¶
Plot both probability and cumulative density functions for a given component.
- Parameters
index (int) – The index of a component of the random variable.
save (bool) – If True, save the figure.
show (bool) – If True, display the figure.
file_path (Optional[Union[str, pathlib.Path]]) – The path of the file to save the figures. If the extension is missing, use
file_extension
. If None, create a file path fromdirectory_path
,file_name
andfile_extension
.directory_path (Optional[Union[str, pathlib.Path]]) – The path of the directory to save the figures. If None, use the current working directory.
file_name (Optional[str]) – The name of the file to save the figures. If None, use a default one generated by the post-processing.
file_extension (Optional[str]) – A file extension, e.g. ‘png’, ‘pdf’, ‘svg’, … If None, use a default file extension.
- Returns
The figure.
- Return type
matplotlib.figure.Figure
- plot_all(show=True, save=False, file_path=None, directory_path=None, file_name=None, file_extension=None)¶
Plot both probability and cumulative density functions for all components.
- Parameters
save (bool) – If True, save the figure.
show (bool) – If True, display the figure.
file_path (Optional[Union[str, pathlib.Path]]) – The path of the file to save the figures. If the extension is missing, use
file_extension
. If None, create a file path fromdirectory_path
,file_name
andfile_extension
.directory_path (Optional[Union[str, pathlib.Path]]) – The path of the directory to save the figures. If None, use the current working directory.
file_name (Optional[str]) – The name of the file to save the figures. If None, use a default one generated by the post-processing.
file_extension (Optional[str]) – A file extension, e.g. ‘png’, ‘pdf’, ‘svg’, … If None, use a default file extension.
- Returns
The figures.
- Return type
List[matplotlib.figure.Figure]
- property range¶
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.
- property standard_deviation¶
The analytical standard deviation of the random variable.
- property support¶
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.