api module¶
The API for uncertainty quantification and management.
- gemseo.uncertainty.api.create_distribution(variable, distribution_name, dimension=1, **options)[source]¶
Create a distribution.
- Parameters:
variable (str) – The name of the random variable.
distribution_name (str) – The name of a class implementing a probability distribution, e.g. ‘OTUniformDistribution’ or ‘SPDistribution’.
dimension (int) –
The dimension of the random variable.
By default it is set to 1.
**options – The distribution options.
- Return type:
Examples
>>> from gemseo.uncertainty.api import create_distribution >>> >>> distribution = create_distribution( ... "x", "OTNormalDistribution", dimension=2, mu=1, sigma=2 ... ) >>> print(distribution) Normal(mu=1, sigma=2) >>> print(distribution.mean, distribution.standard_deviation) [1. 1.] [2. 2.] >>> samples = distribution.compute_samples(10) >>> print(samples.shape) (10, 2)
- gemseo.uncertainty.api.create_sensitivity_analysis(analysis, disciplines, parameter_space, **options)[source]¶
Create the sensitivity analysis.
- Parameters:
analysis (str) – The name of a sensitivity analysis class.
disciplines (Collection[MDODiscipline]) – The disciplines.
parameter_space (ParameterSpace) – A parameter space.
**options – The DOE algorithm options.
- Returns:
The toolbox for these sensitivity indices.
- Return type:
Examples
>>> from gemseo.api import create_discipline, create_parameter_space >>> from gemseo.uncertainty.api import create_sensitivity_analysis >>> >>> expressions = {"y1": "x1+2*x2", "y2": "x1-3*x2"} >>> discipline = create_discipline( ... "AnalyticDiscipline", expressions=expressions ... ) >>> >>> parameter_space = create_parameter_space() >>> parameter_space.add_random_variable( ... "x1", "OTUniformDistribution", minimum=-1, maximum=1 ... ) >>> parameter_space.add_random_variable( ... "x2", "OTNormalDistribution", mu=0.5, sigma=2 ... ) >>> >>> analysis = create_sensitivity_analysis( ... "CorrelationIndices", [discipline], parameter_space, n_samples=1000 ... ) >>> indices = analysis.compute_indices()
- gemseo.uncertainty.api.create_statistics(dataset, variables_names=None, tested_distributions=None, fitting_criterion='BIC', selection_criterion='best', level=0.05, name=None)[source]¶
Create a statistics toolbox, either parametric or empirical.
If parametric, the toolbox selects a distribution from candidates, based on a fitting criterion and on a selection strategy.
- Parameters:
dataset (Dataset) – A dataset.
variables_names (Iterable[str] | None) – The variables of interest. If None, consider all the variables from dataset.
tested_distributions (Sequence[str] | None) – The names of the tested distributions.
fitting_criterion (str) –
The name of a goodness-of-fit criterion, measuring how the distribution fits the data. Use
ParametricStatistics.get_criteria()
to get the available criteria.By default it is set to “BIC”.
selection_criterion –
The name of a selection criterion to select a distribution from candidates. Either ‘first’ or ‘best’.
By default it is set to “best”.
level (float) –
A test level, i.e. the risk of committing a Type 1 error, that is an incorrect rejection of a true null hypothesis, for criteria based on a test hypothesis.
By default it is set to 0.05.
name (str | None) – A name for the statistics toolbox instance. If None, use the concatenation of class and dataset names.
- Returns:
A statistics toolbox.
- Return type:
Examples
>>> from gemseo.api import ( ... create_discipline, ... create_parameter_space, ... create_scenario ... ) >>> from gemseo.uncertainty.api import create_statistics >>> >>> expressions = {"y1": "x1+2*x2", "y2": "x1-3*x2"} >>> discipline = create_discipline( ... "AnalyticDiscipline", expressions=expressions ... ) >>> >>> parameter_space = create_parameter_space() >>> parameter_space.add_random_variable( ... "x1", "OTUniformDistribution", minimum=-1, maximum=1 ... ) >>> parameter_space.add_random_variable( ... "x2", "OTNormalDistribution", mu=0.5, sigma=2 ... ) >>> >>> scenario = create_scenario( ... [discipline], ... "DisciplinaryOpt", ... "y1", ... parameter_space, ... scenario_type="DOE" ... ) >>> scenario.execute({'algo': 'OT_MONTE_CARLO', 'n_samples': 100}) >>> >>> dataset = scenario.export_to_dataset(opt_naming=False) >>> >>> statistics = create_statistics(dataset) >>> mean = statistics.compute_mean()
- gemseo.uncertainty.api.get_available_sensitivity_analyses()[source]¶
Get the available sensitivity analyses.