.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/uncertainty/sensitivity/plot_sobol.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_sobol.py: Sobol' analysis =============== .. GENERATED FROM PYTHON SOURCE LINES 25-33 .. code-block:: default from __future__ import annotations import pprint from gemseo.uncertainty.sensitivity.sobol.analysis import SobolAnalysis 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-49 .. code-block:: default discipline = IshigamiDiscipline() uncertain_space = IshigamiSpace() .. GENERATED FROM PYTHON SOURCE LINES 50-52 Then, we run sensitivity analysis of type :class:`.SobolAnalysis`: .. GENERATED FROM PYTHON SOURCE LINES 52-56 .. code-block:: default sensitivity_analysis = SobolAnalysis([discipline], uncertain_space, 10000) sensitivity_analysis.main_method = "total" sensitivity_analysis.compute_indices() .. rst-class:: sphx-glr-script-out .. code-block:: none {'first': {'y': [{'x1': array([0.33668934]), 'x2': array([0.48974171]), 'x3': array([0.01387372])}]}, 'second': {'y': [{'x1': {'x1': array([[0.]]), 'x2': array([[-0.06556589]]), 'x3': array([[0.17784496]])}, 'x2': {'x1': array([[-0.06556589]]), 'x2': array([[0.]]), 'x3': array([[-0.05604046]])}, 'x3': {'x1': array([[0.17784496]]), 'x2': array([[-0.05604046]]), 'x3': array([[0.]])}}]}, 'total': {'y': [{'x1': array([0.49769038]), 'x2': array([0.46903493]), 'x3': array([0.23786094])}]}} .. GENERATED FROM PYTHON SOURCE LINES 57-58 The resulting indices are the first-order and total Sobol' indices: .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: default pprint.pprint(sensitivity_analysis.indices) .. rst-class:: sphx-glr-script-out .. code-block:: none {'first': {'y': [{'x1': array([0.33668934]), 'x2': array([0.48974171]), 'x3': array([0.01387372])}]}, 'second': {'y': [{'x1': {'x1': array([[0.]]), 'x2': array([[-0.06556589]]), 'x3': array([[0.17784496]])}, 'x2': {'x1': array([[-0.06556589]]), 'x2': array([[0.]]), 'x3': array([[-0.05604046]])}, 'x3': {'x1': array([[0.17784496]]), 'x2': array([[-0.05604046]]), 'x3': array([[0.]])}}]}, 'total': {'y': [{'x1': array([0.49769038]), 'x2': array([0.46903493]), 'x3': array([0.23786094])}]}} .. GENERATED FROM PYTHON SOURCE LINES 61-62 They can also be accessed separately: .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: default pprint.pprint(sensitivity_analysis.first_order_indices) pprint.pprint(sensitivity_analysis.total_order_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y': [{'x1': array([0.33668934]), 'x2': array([0.48974171]), 'x3': array([0.01387372])}]} {'y': [{'x1': array([0.49769038]), 'x2': array([0.46903493]), 'x3': array([0.23786094])}]} .. GENERATED FROM PYTHON SOURCE LINES 66-67 One can also obtain their confidence intervals: .. GENERATED FROM PYTHON SOURCE LINES 67-70 .. code-block:: default pprint.pprint(sensitivity_analysis.get_intervals()) pprint.pprint(sensitivity_analysis.get_intervals(first_order=False)) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y': [{'x1': (array([0.27106596]), array([0.40231271])), 'x2': (array([0.42038752]), array([0.55909591])), 'x3': (array([-0.06311772]), array([0.09086516]))}]} {'y': [{'x1': (array([0.42529255]), array([0.57008822])), 'x2': (array([0.42022722]), array([0.51784263])), 'x3': (array([0.19308657]), array([0.2826353]))}]} .. GENERATED FROM PYTHON SOURCE LINES 71-74 The main indices are the total Sobol' indices (:attr:`.SobolAnalysis.main_method` can also be set to ``"first"`` to use the first-order indices as main indices): .. GENERATED FROM PYTHON SOURCE LINES 74-76 .. code-block:: default pprint.pprint(sensitivity_analysis.main_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y': [{'x1': array([0.49769038]), 'x2': array([0.46903493]), 'x3': array([0.23786094])}]} .. GENERATED FROM PYTHON SOURCE LINES 77-79 These main indices are used to sort the input parameters by decreasing order of influence: .. GENERATED FROM PYTHON SOURCE LINES 79-81 .. code-block:: default print(sensitivity_analysis.sort_parameters("y")) .. rst-class:: sphx-glr-script-out .. code-block:: none ['x1', 'x2', 'x3'] .. GENERATED FROM PYTHON SOURCE LINES 82-85 Lastly, we can use the method :meth:`.SobolAnalysis.plot` to visualize both first-order and total Sobol' indices: .. GENERATED FROM PYTHON SOURCE LINES 85-86 .. code-block:: default sensitivity_analysis.plot("y", save=False, show=True) .. image-sg:: /examples/uncertainty/sensitivity/images/sphx_glr_plot_sobol_001.png :alt: Sobol indices for the output y :srcset: /examples/uncertainty/sensitivity/images/sphx_glr_plot_sobol_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 15.799 seconds) .. _sphx_glr_download_examples_uncertainty_sensitivity_plot_sobol.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_sobol.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sobol.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_