.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/uncertainty/sensitivity/plot_morris.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_morris.py: Morris analysis =============== .. GENERATED FROM PYTHON SOURCE LINES 25-37 .. code-block:: Python from __future__ import annotations import pprint 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.morris.analysis import MorrisAnalysis configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 38-50 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:`.MDODiscipline` 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 50-54 .. code-block:: Python discipline = IshigamiDiscipline() uncertain_space = IshigamiSpace() .. GENERATED FROM PYTHON SOURCE LINES 55-57 Then, we run sensitivity analysis of type :class:`.MorrisAnalysis`: .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. code-block:: Python sensitivity_analysis = MorrisAnalysis([discipline], uncertain_space, n_samples=None) sensitivity_analysis.compute_indices() .. rst-class:: sphx-glr-script-out .. code-block:: none WARNING - 08:55:22: No coupling in MDA, switching chain_linearize to True. WARNING - 08:55:22: No coupling in MDA, switching chain_linearize to True. INFO - 08:55:22: INFO - 08:55:22: *** Start MorrisAnalysisSamplingPhase execution *** INFO - 08:55:22: MorrisAnalysisSamplingPhase INFO - 08:55:22: Disciplines: _OATSensitivity INFO - 08:55:22: MDO formulation: MDF INFO - 08:55:22: Running the algorithm lhs: INFO - 08:55:22: 20%|██ | 1/5 [00:00<00:00, 55.75 it/sec] INFO - 08:55:22: 40%|████ | 2/5 [00:00<00:00, 90.19 it/sec] INFO - 08:55:22: 60%|██████ | 3/5 [00:00<00:00, 114.55 it/sec] INFO - 08:55:22: 80%|████████ | 4/5 [00:00<00:00, 132.27 it/sec] INFO - 08:55:22: 100%|██████████| 5/5 [00:00<00:00, 146.04 it/sec] INFO - 08:55:22: *** End MorrisAnalysisSamplingPhase execution (time: 0:00:00.046215) *** {'MU': {'y': [{'x1': array([-0.36000398]), 'x2': array([0.77781853]), 'x3': array([-0.70990541])}]}, 'MU_STAR': {'y': [{'x1': array([0.67947346]), 'x2': array([0.88906579]), 'x3': array([0.72694219])}]}, 'SIGMA': {'y': [{'x1': array([0.98724949]), 'x2': array([0.79064599]), 'x3': array([0.8074493])}]}, 'RELATIVE_SIGMA': {'y': [{'x1': array([1.45296254]), 'x2': array([0.88929976]), 'x3': array([1.11074761])}]}, 'MIN': {'y': [{'x1': array([0.0338188]), 'x2': array([0.11821721]), 'x3': array([8.72820113e-05])}]}, 'MAX': {'y': [{'x1': array([2.2360336]), 'x2': array([1.83987522]), 'x3': array([2.12052546])}]}} .. GENERATED FROM PYTHON SOURCE LINES 61-63 The resulting indices are the empirical means and the standard deviations of the absolute output variations due to input changes. .. GENERATED FROM PYTHON SOURCE LINES 63-65 .. code-block:: Python pprint.pprint(sensitivity_analysis.indices) .. rst-class:: sphx-glr-script-out .. code-block:: none {'MAX': {'y': [{'x1': array([2.2360336]), 'x2': array([1.83987522]), 'x3': array([2.12052546])}]}, 'MIN': {'y': [{'x1': array([0.0338188]), 'x2': array([0.11821721]), 'x3': array([8.72820113e-05])}]}, 'MU': {'y': [{'x1': array([-0.36000398]), 'x2': array([0.77781853]), 'x3': array([-0.70990541])}]}, 'MU_STAR': {'y': [{'x1': array([0.67947346]), 'x2': array([0.88906579]), 'x3': array([0.72694219])}]}, 'RELATIVE_SIGMA': {'y': [{'x1': array([1.45296254]), 'x2': array([0.88929976]), 'x3': array([1.11074761])}]}, 'SIGMA': {'y': [{'x1': array([0.98724949]), 'x2': array([0.79064599]), 'x3': array([0.8074493])}]}} .. GENERATED FROM PYTHON SOURCE LINES 66-68 The main indices corresponds to these empirical means (this main method can be changed with :attr:`.MorrisAnalysis.main_method`): .. GENERATED FROM PYTHON SOURCE LINES 68-70 .. code-block:: Python pprint.pprint(sensitivity_analysis.main_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y': [{'x1': array([0.67947346]), 'x2': array([0.88906579]), 'x3': array([0.72694219])}]} .. GENERATED FROM PYTHON SOURCE LINES 71-72 and can be interpreted with respect to the empirical bounds of the outputs: .. GENERATED FROM PYTHON SOURCE LINES 72-74 .. code-block:: Python pprint.pprint(sensitivity_analysis.outputs_bounds) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y': [array([-1.00881748]), array([14.89344259])]} .. GENERATED FROM PYTHON SOURCE LINES 75-76 We can also get the input parameters sorted by decreasing order of influence: .. GENERATED FROM PYTHON SOURCE LINES 76-78 .. code-block:: Python sensitivity_analysis.sort_parameters("y") .. rst-class:: sphx-glr-script-out .. code-block:: none ['x2', 'x3', 'x1'] .. GENERATED FROM PYTHON SOURCE LINES 79-81 We can use the method :meth:`.MorrisAnalysis.plot` to visualize the different series of indices: .. GENERATED FROM PYTHON SOURCE LINES 81-83 .. code-block:: Python sensitivity_analysis.plot("y", save=False, show=True, lower_mu=0, lower_sigma=0) .. image-sg:: /examples/uncertainty/sensitivity/images/sphx_glr_plot_morris_001.png :alt: Sampling: lhs(size=5) - Relative step: 0.05 - Output: y :srcset: /examples/uncertainty/sensitivity/images/sphx_glr_plot_morris_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 84-86 Lastly, the sensitivity indices can be exported to a :class:`.Dataset`: .. GENERATED FROM PYTHON SOURCE LINES 86-87 .. code-block:: Python sensitivity_analysis.to_dataset() .. raw:: html
GROUP MU MU_STAR SIGMA RELATIVE_SIGMA MIN MAX
VARIABLE y y y y y y
COMPONENT 0 0 0 0 0 0
x1 -0.360004 0.679473 0.987249 1.452963 0.033819 2.236034
x2 0.777819 0.889066 0.790646 0.889300 0.118217 1.839875
x3 -0.709905 0.726942 0.807449 1.110748 0.000087 2.120525


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.462 seconds) .. _sphx_glr_download_examples_uncertainty_sensitivity_plot_morris.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_morris.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_morris.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_