.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/uncertainty/sensitivity/plot_sensitivity_comparison.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_uncertainty_sensitivity_plot_sensitivity_comparison.py: Comparing sensitivity indices ============================= .. GENERATED FROM PYTHON SOURCE LINES 25-36 .. code-block:: Python from __future__ import annotations from gemseo import configure_logger 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 configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 37-49 In this example, we consider the Ishigami function :cite:`ishigami1990` .. math:: f(x_1,x_2,x_3)=\sin(x_1)+7\sin(x_2)^2+0.1x_3^4\sin(x_1) implemented as an :class:`.Discipline` by the :class:`.IshigamiDiscipline`. It is commonly used with the independent random variables :math:`X_1`, :math:`X_2` and :math:`X_3` uniformly distributed between :math:`-\pi` and :math:`\pi` and defined in the :class:`.IshigamiSpace`. .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: Python discipline = IshigamiDiscipline() uncertain_space = IshigamiSpace() .. GENERATED FROM PYTHON SOURCE LINES 53-60 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 :class:`.CorrelationAnalysis` and compute the sensitivity indices: .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python correlation = CorrelationAnalysis() correlation.compute_samples([discipline], uncertain_space, 10) correlation.compute_indices() .. rst-class:: sphx-glr-script-out .. code-block:: none WARNING - 16:11:07: No coupling in MDA, switching chain_linearize to True. INFO - 16:11:07: INFO - 16:11:07: *** Start CorrelationAnalysisSamplingPhase execution *** INFO - 16:11:07: CorrelationAnalysisSamplingPhase INFO - 16:11:07: Disciplines: IshigamiDiscipline INFO - 16:11:07: MDO formulation: MDF INFO - 16:11:07: Running the algorithm OT_MONTE_CARLO: INFO - 16:11:07: 10%|█ | 1/10 [00:00<00:00, 350.08 it/sec] INFO - 16:11:07: 20%|██ | 2/10 [00:00<00:00, 575.51 it/sec] INFO - 16:11:07: 30%|███ | 3/10 [00:00<00:00, 728.85 it/sec] INFO - 16:11:07: 40%|████ | 4/10 [00:00<00:00, 852.67 it/sec] INFO - 16:11:07: 50%|█████ | 5/10 [00:00<00:00, 951.09 it/sec] INFO - 16:11:07: 60%|██████ | 6/10 [00:00<00:00, 1030.88 it/sec] INFO - 16:11:07: 70%|███████ | 7/10 [00:00<00:00, 1097.04 it/sec] INFO - 16:11:07: 80%|████████ | 8/10 [00:00<00:00, 1152.64 it/sec] INFO - 16:11:07: 90%|█████████ | 9/10 [00:00<00:00, 1199.82 it/sec] INFO - 16:11:07: 100%|██████████| 10/10 [00:00<00:00, 1232.13 it/sec] INFO - 16:11:07: *** End CorrelationAnalysisSamplingPhase execution (time: 0:00:00.013647) *** 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])}]}) .. GENERATED FROM PYTHON SOURCE LINES 65-67 Then, we create an :class:`.MorrisAnalysis` and compute the sensitivity indices: .. GENERATED FROM PYTHON SOURCE LINES 67-71 .. code-block:: Python morris = MorrisAnalysis() morris.compute_samples([discipline], uncertain_space, 10) morris.compute_indices() .. rst-class:: sphx-glr-script-out .. code-block:: none WARNING - 16:11:07: No coupling in MDA, switching chain_linearize to True. INFO - 16:11:07: INFO - 16:11:07: *** Start MorrisAnalysisSamplingPhase execution *** INFO - 16:11:07: MorrisAnalysisSamplingPhase INFO - 16:11:07: Disciplines: IshigamiDiscipline INFO - 16:11:07: MDO formulation: MDF INFO - 16:11:07: Running the algorithm MorrisDOE: INFO - 16:11:07: 12%|█▎ | 1/8 [00:00<00:00, 2041.02 it/sec] INFO - 16:11:07: 25%|██▌ | 2/8 [00:00<00:00, 1842.84 it/sec] INFO - 16:11:07: 38%|███▊ | 3/8 [00:00<00:00, 1787.09 it/sec] INFO - 16:11:07: 50%|█████ | 4/8 [00:00<00:00, 1749.08 it/sec] INFO - 16:11:07: 62%|██████▎ | 5/8 [00:00<00:00, 1752.45 it/sec] INFO - 16:11:07: 75%|███████▌ | 6/8 [00:00<00:00, 1756.29 it/sec] INFO - 16:11:07: 88%|████████▊ | 7/8 [00:00<00:00, 1728.08 it/sec] INFO - 16:11:07: 100%|██████████| 8/8 [00:00<00:00, 1711.87 it/sec] INFO - 16:11:07: *** End MorrisAnalysisSamplingPhase execution (time: 0:00:00.010400) *** 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])}]}) .. GENERATED FROM PYTHON SOURCE LINES 72-76 Lastly, we compare these analyses with the graphical method :meth:`.BaseSensitivityAnalysis.plot_comparison`, either using a bar chart: .. GENERATED FROM PYTHON SOURCE LINES 76-78 .. code-block:: Python morris.plot_comparison(correlation, "y", use_bar_plot=True, save=False, show=True) .. image-sg:: /examples/uncertainty/sensitivity/images/sphx_glr_plot_sensitivity_comparison_001.png :alt: plot sensitivity comparison :srcset: /examples/uncertainty/sensitivity/images/sphx_glr_plot_sensitivity_comparison_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 79-80 or a radar plot: .. GENERATED FROM PYTHON SOURCE LINES 80-81 .. code-block:: Python morris.plot_comparison(correlation, "y", use_bar_plot=False, save=False, show=True) .. image-sg:: /examples/uncertainty/sensitivity/images/sphx_glr_plot_sensitivity_comparison_002.png :alt: plot sensitivity comparison :srcset: /examples/uncertainty/sensitivity/images/sphx_glr_plot_sensitivity_comparison_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.430 seconds) .. _sphx_glr_download_examples_uncertainty_sensitivity_plot_sensitivity_comparison.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sensitivity_comparison.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sensitivity_comparison.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_sensitivity_comparison.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_