Note
Go to the end to download the full example code.
Create sensitivity analysis#
create_sensitivity_analysis() is a top-level function
to create a sensitivity analysis from a sensitivity analysis class name,
e.g. "MorrisAnalysis".
from __future__ import annotations
from gemseo.problems.uncertainty.ishigami.ishigami_discipline import IshigamiDiscipline
from gemseo.problems.uncertainty.ishigami.ishigami_space import IshigamiSpace
from gemseo.uncertainty import create_sensitivity_analysis
There are two ways of using create_sensitivity_analysis().
The first one is to perform a sensitivity analysis from a collection of disciplines and an uncertain space:
analysis = create_sensitivity_analysis("MorrisAnalysis")
uncertain_space = IshigamiSpace()
discipline = IshigamiDiscipline()
samples = analysis.compute_samples([discipline], uncertain_space, n_samples=0)
indices = analysis.compute_indices()
indices
INFO - 16:16:37: *** Start MorrisAnalysisSamplingPhase execution ***
INFO - 16:16:37: MorrisAnalysisSamplingPhase
INFO - 16:16:37: Disciplines: IshigamiDiscipline
INFO - 16:16:37: MDO formulation: MDF
INFO - 16:16:37: Running the algorithm MorrisDOE:
INFO - 16:16:37: 5%|▌ | 1/20 [00:00<00:00, 414.99 it/sec]
INFO - 16:16:37: 10%|█ | 2/20 [00:00<00:00, 668.26 it/sec]
INFO - 16:16:37: 15%|█▌ | 3/20 [00:00<00:00, 847.39 it/sec]
INFO - 16:16:37: 20%|██ | 4/20 [00:00<00:00, 976.27 it/sec]
INFO - 16:16:37: 25%|██▌ | 5/20 [00:00<00:00, 1071.62 it/sec]
INFO - 16:16:37: 30%|███ | 6/20 [00:00<00:00, 1161.91 it/sec]
INFO - 16:16:37: 35%|███▌ | 7/20 [00:00<00:00, 1222.27 it/sec]
INFO - 16:16:37: 40%|████ | 8/20 [00:00<00:00, 1262.01 it/sec]
INFO - 16:16:37: 45%|████▌ | 9/20 [00:00<00:00, 1311.81 it/sec]
INFO - 16:16:37: 50%|█████ | 10/20 [00:00<00:00, 1364.62 it/sec]
INFO - 16:16:37: 55%|█████▌ | 11/20 [00:00<00:00, 1400.90 it/sec]
INFO - 16:16:37: 60%|██████ | 12/20 [00:00<00:00, 1431.01 it/sec]
INFO - 16:16:37: 65%|██████▌ | 13/20 [00:00<00:00, 1462.17 it/sec]
INFO - 16:16:37: 70%|███████ | 14/20 [00:00<00:00, 1496.97 it/sec]
INFO - 16:16:37: 75%|███████▌ | 15/20 [00:00<00:00, 1517.26 it/sec]
INFO - 16:16:37: 80%|████████ | 16/20 [00:00<00:00, 1539.62 it/sec]
INFO - 16:16:37: 85%|████████▌ | 17/20 [00:00<00:00, 1561.85 it/sec]
INFO - 16:16:37: 90%|█████████ | 18/20 [00:00<00:00, 1586.31 it/sec]
INFO - 16:16:37: 95%|█████████▌| 19/20 [00:00<00:00, 1599.11 it/sec]
INFO - 16:16:37: 100%|██████████| 20/20 [00:00<00:00, 1597.04 it/sec]
INFO - 16:16:37: *** End MorrisAnalysisSamplingPhase execution ***
MorrisAnalysis.SensitivityIndices(mu={'y': [{'x1': array([-0.60047199]), 'x2': array([0.51230435]), 'x3': array([-0.89800793])}]}, mu_star={'y': [{'x1': array([0.69887482]), 'x2': array([0.65136343]), 'x3': array([0.89805157])}]}, sigma={'y': [{'x1': array([0.96395158]), 'x2': array([0.6549141]), 'x3': array([0.79878356])}]}, relative_sigma={'y': [{'x1': array([1.37929075]), 'x2': array([1.00545113]), 'x3': array([0.88946291])}]}, min={'y': [{'x1': array([0.0338188]), 'x2': array([0.11821721]), 'x3': array([8.72820113e-05])}]}, max={'y': [{'x1': array([2.2360336]), 'x2': array([1.25769934]), 'x3': array([2.12052546])}]})
The samples can be saved on the disk using the to_pickle() function,
e.g. to_pickle(sample, "my_samples.p"),
in order to use them later to compute sensitivity indices.
The other way is to perform a sensitivity analysis from samples computed from another sensitivity analysis:
analysis = create_sensitivity_analysis("MorrisAnalysis", samples=samples)
indices = analysis.compute_indices()
indices
MorrisAnalysis.SensitivityIndices(mu={'y': [{'x1': array([-0.60047199]), 'x2': array([0.51230435]), 'x3': array([-0.89800793])}]}, mu_star={'y': [{'x1': array([0.69887482]), 'x2': array([0.65136343]), 'x3': array([0.89805157])}]}, sigma={'y': [{'x1': array([0.96395158]), 'x2': array([0.6549141]), 'x3': array([0.79878356])}]}, relative_sigma={'y': [{'x1': array([1.37929075]), 'x2': array([1.00545113]), 'x3': array([0.88946291])}]}, min={'y': [{'x1': array([0.0338188]), 'x2': array([0.11821721]), 'x3': array([8.72820113e-05])}]}, max={'y': [{'x1': array([2.2360336]), 'x2': array([1.25769934]), 'x3': array([2.12052546])}]})
The argument samples of create_sensitivity_analysis()
can be either an IODataset as above or a pickle file path,
e.g. create_sensitivity_analysis("MorrisAnalysis", samples="my_samples.p").
Total running time of the script: (0 minutes 0.049 seconds)