Note
Go to the end to download the full example code.
Comparing sensitivity indices#
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.sensitivity.correlation_analysis import CorrelationAnalysis
from gemseo.uncertainty.sensitivity.morris_analysis import MorrisAnalysis
In this example, we consider the Ishigami function [IH90]
implemented as an Discipline by the IshigamiDiscipline.
It is commonly used
with the independent random variables \(X_1\), \(X_2\) and \(X_3\)
uniformly distributed between \(-\pi\) and \(\pi\)
and defined in the IshigamiSpace.
discipline = IshigamiDiscipline()
uncertain_space = IshigamiSpace()
We would like to carry out two sensitivity analyses, e.g. a first one based on correlation coefficients and a second one based on the Morris methodology, and compare the results,
Firstly,
we create a CorrelationAnalysis and compute the sensitivity indices:
correlation = CorrelationAnalysis()
correlation.compute_samples([discipline], uncertain_space, 10)
correlation.compute_indices()
INFO - 16:22:30: *** Start CorrelationAnalysisSamplingPhase execution ***
INFO - 16:22:30: CorrelationAnalysisSamplingPhase
INFO - 16:22:30: Disciplines: IshigamiDiscipline
INFO - 16:22:30: MDO formulation: MDF
INFO - 16:22:30: Running the algorithm OT_MONTE_CARLO:
INFO - 16:22:30: 10%|█ | 1/10 [00:00<00:00, 504.43 it/sec]
INFO - 16:22:30: 20%|██ | 2/10 [00:00<00:00, 848.45 it/sec]
INFO - 16:22:30: 30%|███ | 3/10 [00:00<00:00, 1138.21 it/sec]
INFO - 16:22:30: 40%|████ | 4/10 [00:00<00:00, 1369.23 it/sec]
INFO - 16:22:30: 50%|█████ | 5/10 [00:00<00:00, 1574.56 it/sec]
INFO - 16:22:30: 60%|██████ | 6/10 [00:00<00:00, 1755.06 it/sec]
INFO - 16:22:30: 70%|███████ | 7/10 [00:00<00:00, 1915.08 it/sec]
INFO - 16:22:30: 80%|████████ | 8/10 [00:00<00:00, 2042.14 it/sec]
INFO - 16:22:30: 90%|█████████ | 9/10 [00:00<00:00, 2167.60 it/sec]
INFO - 16:22:30: 100%|██████████| 10/10 [00:00<00:00, 2238.39 it/sec]
INFO - 16:22:30: *** End CorrelationAnalysisSamplingPhase execution ***
CorrelationAnalysis.SensitivityIndices(kendall={'y': [{'x1': array([0.55555556]), 'x2': array([0.02222222]), 'x3': array([-0.11111111])}]}, pcc={'y': [{'x1': array([0.84696461]), 'x2': array([0.68814608]), 'x3': array([-0.29846394])}]}, pearson={'y': [{'x1': array([0.685388]), 'x2': array([0.09681897]), 'x3': array([-0.23027298])}]}, prcc={'y': [{'x1': array([0.90374102]), 'x2': array([0.76539572]), 'x3': array([-0.02232206])}]}, spearman={'y': [{'x1': array([0.74545455]), 'x2': array([0.04242424]), 'x3': array([-0.09090909])}]}, src={'y': [{'x1': array([0.94001308]), 'x2': array([0.55748872]), 'x3': array([-0.16157012])}]}, srrc={'y': [{'x1': array([1.06252802]), 'x2': array([0.60167726]), 'x3': array([-0.00959941])}]}, ssrc={'y': [{'x1': array([0.88362459]), 'x2': array([0.31079367]), 'x3': array([0.0261049])}]})
Then,
we create an MorrisAnalysis and compute the sensitivity indices:
morris = MorrisAnalysis()
morris.compute_samples([discipline], uncertain_space, 10)
morris.compute_indices()
INFO - 16:22:30: *** Start MorrisAnalysisSamplingPhase execution ***
INFO - 16:22:30: MorrisAnalysisSamplingPhase
INFO - 16:22:30: Disciplines: IshigamiDiscipline
INFO - 16:22:30: MDO formulation: MDF
INFO - 16:22:30: Running the algorithm MorrisDOE:
INFO - 16:22:30: 12%|█▎ | 1/8 [00:00<00:00, 3994.58 it/sec]
INFO - 16:22:30: 25%|██▌ | 2/8 [00:00<00:00, 3536.51 it/sec]
INFO - 16:22:30: 38%|███▊ | 3/8 [00:00<00:00, 3431.39 it/sec]
INFO - 16:22:30: 50%|█████ | 4/8 [00:00<00:00, 3405.16 it/sec]
INFO - 16:22:30: 62%|██████▎ | 5/8 [00:00<00:00, 3501.67 it/sec]
INFO - 16:22:30: 75%|███████▌ | 6/8 [00:00<00:00, 3577.23 it/sec]
INFO - 16:22:30: 88%|████████▊ | 7/8 [00:00<00:00, 3550.63 it/sec]
INFO - 16:22:30: 100%|██████████| 8/8 [00:00<00:00, 3453.52 it/sec]
INFO - 16:22:30: *** End MorrisAnalysisSamplingPhase execution ***
MorrisAnalysis.SensitivityIndices(mu={'y': [{'x1': array([0.73532408]), 'x2': array([-0.05115399]), 'x3': array([-1.6024484])}]}, mu_star={'y': [{'x1': array([0.76770333]), 'x2': array([2.09435091]), 'x3': array([1.6024484])}]}, sigma={'y': [{'x1': array([0.76770333]), 'x2': array([2.09435091]), 'x3': array([1.58984353])}]}, relative_sigma={'y': [{'x1': array([1.]), 'x2': array([1.]), 'x3': array([0.99213399])}]}, min={'y': [{'x1': array([0.03237925]), 'x2': array([2.04319692]), 'x3': array([0.01260487])}]}, max={'y': [{'x1': array([1.50302741]), 'x2': array([2.14550491]), 'x3': array([3.19229192])}]})
Lastly,
we compare these analyses
with the graphical method BaseSensitivityAnalysis.plot_comparison(),
either using a bar chart:
morris.plot_comparison(correlation, "y", use_bar_plot=True, save=False, show=True)

<gemseo.post.dataset.bars.BarPlot object at 0x72a4f26d5a60>
or a radar plot:
morris.plot_comparison(correlation, "y", use_bar_plot=False, save=False, show=True)

<gemseo.post.dataset.radar_chart.RadarChart object at 0x72a4f26b0c50>
Tip
The comparison method can use plotly to generate an interactive web-based figure.
Just set the execution option file_format to "html".
Total running time of the script: (0 minutes 0.177 seconds)