.. 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 Click :ref:here  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 27-36 .. code-block:: default import pprint from matplotlib import pyplot as plt from numpy import pi from gemseo.algos.parameter_space import ParameterSpace from gemseo.api import create_discipline from gemseo.uncertainty.sensitivity.morris.analysis import MorrisAnalysis .. GENERATED FROM PYTHON SOURCE LINES 37-45 In this example, we consider a function from :math:[-\pi,\pi]^3 to :math:\mathbb{R}^3: .. math:: (y_1,y_2)=\left(f(x_1,x_2,x_3),f(x_2,x_1,x_3)\right) where :math:f(a,b,c)=\sin(a)+7\sin(b)^2+0.1*c^4\sin(a) is the Ishigami function: .. GENERATED FROM PYTHON SOURCE LINES 45-54 .. code-block:: default expressions = { "y1": "sin(x1)+7*sin(x2)**2+0.1*x3**4*sin(x1)", "y2": "sin(x2)+7*sin(x1)**2+0.1*x3**4*sin(x2)", } discipline = create_discipline( "AnalyticDiscipline", expressions_dict=expressions, name="Ishigami2" ) .. GENERATED FROM PYTHON SOURCE LINES 55-61 Then, we consider the case where the deterministic variables :math:x_1, :math:x_2 and :math:x_3 are replaced with the uncertain variables :math:X_1, :math:X_2 and :math:X_3. The latter are independent and identically distributed according to an uniform distribution between :math:-\pi and :math:\pi: .. GENERATED FROM PYTHON SOURCE LINES 61-67 .. code-block:: default space = ParameterSpace() for variable in ["x1", "x2", "x3"]: space.add_random_variable( variable, "OTUniformDistribution", minimum=-pi, maximum=pi ) .. GENERATED FROM PYTHON SOURCE LINES 68-73 From that, we would like to carry out a sensitivity analysis with the random outputs :math:Y_1=f(X_1,X_2,X_3) and :math:Y_2=f(X_2,X_1,X_3). For that, we can compute the correlation coefficients from a :class:.MorrisAnalysis: .. GENERATED FROM PYTHON SOURCE LINES 73-76 .. code-block:: default morris = MorrisAnalysis(discipline, space, 10) morris.compute_indices() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none {'mu': {'y1': [{'x1': array([-0.36000398]), 'x2': array([0.77781853]), 'x3': array([-0.70990541])}], 'y2': [{'x1': array([-0.29766709]), 'x2': array([0.26848457]), 'x3': array([-0.7755748])}]}, 'mu_star': {'y1': [{'x1': array([0.67947346]), 'x2': array([0.88906579]), 'x3': array([0.72694219])}], 'y2': [{'x1': array([1.33011973]), 'x2': array([0.38907897]), 'x3': array([1.00221431])}]}, 'sigma': {'y1': [{'x1': array([0.98724949]), 'x2': array([0.79064599]), 'x3': array([0.8074493])}], 'y2': [{'x1': array([1.46392293]), 'x2': array([0.39387241]), 'x3': array([1.38465263])}]}} .. GENERATED FROM PYTHON SOURCE LINES 77-79 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 79-81 .. code-block:: default pprint.pprint(morris.indices) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none {'mu': {'y1': [{'x1': array([-0.36000398]), 'x2': array([0.77781853]), 'x3': array([-0.70990541])}], 'y2': [{'x1': array([-0.29766709]), 'x2': array([0.26848457]), 'x3': array([-0.7755748])}]}, 'mu_star': {'y1': [{'x1': array([0.67947346]), 'x2': array([0.88906579]), 'x3': array([0.72694219])}], 'y2': [{'x1': array([1.33011973]), 'x2': array([0.38907897]), 'x3': array([1.00221431])}]}, 'sigma': {'y1': [{'x1': array([0.98724949]), 'x2': array([0.79064599]), 'x3': array([0.8074493])}], 'y2': [{'x1': array([1.46392293]), 'x2': array([0.39387241]), 'x3': array([1.38465263])}]}} .. GENERATED FROM PYTHON SOURCE LINES 82-84 The main indices corresponds to the Spearman correlation indices (this main method can be changed with :attr:.MorrisAnalysis.main_method): .. GENERATED FROM PYTHON SOURCE LINES 84-86 .. code-block:: default pprint.pprint(morris.main_indices) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none {'y1': [{'x1': array([0.67947346]), 'x2': array([0.88906579]), 'x3': array([0.72694219])}], 'y2': [{'x1': array([1.33011973]), 'x2': array([0.38907897]), 'x3': array([1.00221431])}]} .. GENERATED FROM PYTHON SOURCE LINES 87-89 We can also sort the input parameters by decreasing order of influence and observe that this ranking is not the same for both outputs: .. GENERATED FROM PYTHON SOURCE LINES 89-92 .. code-block:: default print(morris.sort_parameters("y1")) print(morris.sort_parameters("y2")) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ['x2', 'x3', 'x1'] ['x1', 'x3', 'x2'] .. GENERATED FROM PYTHON SOURCE LINES 93-96 Lastly, we can use the method :meth:.MorrisAnalysis.plot to visualize the different series of indices: .. GENERATED FROM PYTHON SOURCE LINES 96-100 .. code-block:: default morris.plot("y1", save=False, show=False, lower_mu=0, lower_sigma=0) morris.plot("y2", save=False, show=False, lower_mu=0, lower_sigma=0) # Workaround for HTML rendering, instead of show=True plt.show() .. rst-class:: sphx-glr-horizontal * .. image:: /examples/uncertainty/sensitivity/images/sphx_glr_plot_morris_001.png :alt: Sampling: lhs(size=2) - Relative step: 0.05 - Output: y1(0) :class: sphx-glr-multi-img * .. image:: /examples/uncertainty/sensitivity/images/sphx_glr_plot_morris_002.png :alt: Sampling: lhs(size=2) - Relative step: 0.05 - Output: y2(0) :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.480 seconds) .. _sphx_glr_download_examples_uncertainty_sensitivity_plot_morris.py: .. only :: html .. container:: sphx-glr-footer :class: 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 _