.. 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-33 .. code-block:: default from __future__ import annotations import pprint from gemseo.uncertainty.sensitivity.morris.analysis import MorrisAnalysis from gemseo.uncertainty.use_cases.ishigami.ishigami_discipline import IshigamiDiscipline from gemseo.uncertainty.use_cases.ishigami.ishigami_space import IshigamiSpace .. GENERATED FROM PYTHON SOURCE LINES 34-46 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 46-50 .. code-block:: default discipline = IshigamiDiscipline() uncertain_space = IshigamiSpace() .. GENERATED FROM PYTHON SOURCE LINES 51-53 Then, we run sensitivity analysis of type :class:`.MorrisAnalysis`: .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: default sensitivity_analysis = MorrisAnalysis([discipline], uncertain_space, 10) sensitivity_analysis.compute_indices() .. rst-class:: sphx-glr-script-out .. code-block:: none {'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 57-59 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 59-61 .. code-block:: default pprint.pprint(sensitivity_analysis.indices) .. rst-class:: sphx-glr-script-out .. code-block:: none {'MAX': {'y': [{'x1': array([1.50302741]), 'x2': array([2.14550491]), 'x3': array([3.19229192])}]}, 'MIN': {'y': [{'x1': array([0.03237925]), 'x2': array([2.04319692]), 'x3': array([0.01260487])}]}, '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])}]}, 'RELATIVE_SIGMA': {'y': [{'x1': array([1.]), 'x2': array([1.]), 'x3': array([0.99213399])}]}, 'SIGMA': {'y': [{'x1': array([0.76770333]), 'x2': array([2.09435091]), 'x3': array([1.58984353])}]}} .. GENERATED FROM PYTHON SOURCE LINES 62-64 The main indices corresponds to these empirical means (this main method can be changed with :attr:`.MorrisAnalysis.main_method`): .. GENERATED FROM PYTHON SOURCE LINES 64-66 .. code-block:: default pprint.pprint(sensitivity_analysis.main_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y': [{'x1': array([0.76770333]), 'x2': array([2.09435091]), 'x3': array([1.6024484])}]} .. GENERATED FROM PYTHON SOURCE LINES 67-68 and can be interpreted with respect to the empirical bounds of the outputs: .. GENERATED FROM PYTHON SOURCE LINES 68-70 .. code-block:: default pprint.pprint(sensitivity_analysis.outputs_bounds) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y': [array([0.3861887]), array([14.38383568])]} .. GENERATED FROM PYTHON SOURCE LINES 71-72 We can also get the input parameters sorted by decreasing order of influence: .. GENERATED FROM PYTHON SOURCE LINES 72-74 .. code-block:: default sensitivity_analysis.sort_parameters("y") .. rst-class:: sphx-glr-script-out .. code-block:: none ['x2', 'x3', 'x1'] .. GENERATED FROM PYTHON SOURCE LINES 75-77 We can use the method :meth:`.MorrisAnalysis.plot` to visualize the different series of indices: .. GENERATED FROM PYTHON SOURCE LINES 77-79 .. code-block:: default 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=2) - Relative step: 0.05 - Output: y :srcset: /examples/uncertainty/sensitivity/images/sphx_glr_plot_morris_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 80-82 Lastly, the sensitivity indices can be exported to a :class:`.Dataset`: .. GENERATED FROM PYTHON SOURCE LINES 82-83 .. code-block:: default 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.735324 0.767703 0.767703 1.000000 0.032379 1.503027
x2 -0.051154 2.094351 2.094351 1.000000 2.043197 2.145505
x3 -1.602448 1.602448 1.589844 0.992134 0.012605 3.192292


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.477 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-python :download:`Download Python source code: plot_morris.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_morris.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_