gemseo / uncertainty / distributions

Show inherited members

factory module

Module containing a factory to create an instance of Distribution.

class gemseo.uncertainty.distributions.factory.DistributionFactory[source]

Bases: BaseFactory

Factory to build instances of Distribution.

At initialization, this factory scans the following modules to search for subclasses of this class:

  • the modules located in gemseo.uncertainty.distributions and its sub-packages,

  • the modules referenced in the GEMSEO_PATH,

  • the modules referenced in the PYTHONPATH and starting with gemseo_.

Then, it can check if a class is present or return the list of available classes.

Lastly, it can create an instance of a class.

Examples

>>> from gemseo.uncertainty.distributions.factory import DistributionFactory
>>> factory = DistributionFactory()
>>> factory.is_available("OTNormalDistribution")
True
>>> factory.available_distributions[-3:]
['SPNormalDistribution', 'SPTriangularDistribution', 'SPUniformDistribution']
>>> distribution = factory.create("OTNormalDistribution", "x")
>>> print(distribution)
Normal(mu=0.0, sigma=1.0)
Return type:

Any

create(distribution_name, variable, **parameters)

Create a marginal probability distribution for a given random variable.

Parameters:
  • distribution_name (str) – The name of a class defining a distribution.

  • variable (str) – The name of the random variable.

  • **parameters (Any) – The parameters of the distribution.

Returns:

The marginal probability distribution.

Raises:

TypeError – If the class cannot be instantiated.

Return type:

Distribution

create_composed_distribution(distributions, copula=None, variable='')[source]

Create a composed probability distribution from marginal ones.

Parameters:
  • distributions (Sequence[Distribution]) – The marginal distributions.

  • copula (Any) – A copula distribution defining the dependency structure between random variables; if None, consider an independent copula.

  • variable (str) –

    The name of the variable, if any; otherwise, concatenate the names of the random variables defined by distributions.

    By default it is set to “”.

Returns:

The composed probability distribution.

Return type:

ComposedDistribution

create_marginal_distribution(distribution_name, variable, **parameters)[source]

Create a marginal probability distribution for a given random variable.

Parameters:
  • distribution_name (str) – The name of a class defining a distribution.

  • variable (str) – The name of the random variable.

  • **parameters (Any) – The parameters of the distribution.

Returns:

The marginal probability distribution.

Raises:

TypeError – If the class cannot be instantiated.

Return type:

Distribution

property available_distributions: list[str]

The available probability distributions.

failed_imports: dict[str, str]

The class names bound to the import errors.