.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/uncertainty/sensitivity/plot_correlation.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_correlation.py: Correlation analysis ==================== .. GENERATED FROM PYTHON SOURCE LINES 25-33 .. code-block:: default from __future__ import annotations import pprint from gemseo.uncertainty.sensitivity.correlation.analysis import CorrelationAnalysis 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:`.CorrelationAnalysis`: .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: default sensitivity_analysis = CorrelationAnalysis([discipline], uncertain_space, 1000) sensitivity_analysis.compute_indices() .. rst-class:: sphx-glr-script-out .. code-block:: none {'pearson': {'y': [{'x1': array([0.46230446]), 'x2': array([0.02059071]), 'x3': array([0.04979026])}]}, 'spearman': {'y': [{'x1': array([0.47177886]), 'x2': array([0.03220921]), 'x3': array([0.04128518])}]}, 'pcc': {'y': [{'x1': array([0.46282123]), 'x2': array([0.0306214]), 'x3': array([0.0512473])}]}, 'prcc': {'y': [{'x1': array([0.47248718]), 'x2': array([0.04368652]), 'x3': array([0.0419606])}]}, 'src': {'y': [{'x1': array([0.46220697]), 'x2': array([0.027121]), 'x3': array([0.04542585])}]}, 'srrc': {'y': [{'x1': array([0.4718925]), 'x2': array([0.03849088]), 'x3': array([0.03696642])}]}, 'ssrrc': {'y': [{'x1': array([0.46220697]), 'x2': array([0.027121]), 'x3': array([0.04542585])}]}} .. GENERATED FROM PYTHON SOURCE LINES 57-66 The resulting indices are - the Pearson correlation coefficients, - the Spearman correlation coefficients, - the Partial Correlation Coefficients (PCC), - the Partial Rank Correlation Coefficients (PRCC), - the Standard Regression Coefficients (SRC), - the Standard Rank Regression Coefficient (SRRC), - the Signed Standard Rank Regression Coefficient (SSRRC): .. GENERATED FROM PYTHON SOURCE LINES 66-68 .. code-block:: default pprint.pprint(sensitivity_analysis.indices) .. rst-class:: sphx-glr-script-out .. code-block:: none {'pcc': {'y': [{'x1': array([0.46282123]), 'x2': array([0.0306214]), 'x3': array([0.0512473])}]}, 'pearson': {'y': [{'x1': array([0.46230446]), 'x2': array([0.02059071]), 'x3': array([0.04979026])}]}, 'prcc': {'y': [{'x1': array([0.47248718]), 'x2': array([0.04368652]), 'x3': array([0.0419606])}]}, 'spearman': {'y': [{'x1': array([0.47177886]), 'x2': array([0.03220921]), 'x3': array([0.04128518])}]}, 'src': {'y': [{'x1': array([0.46220697]), 'x2': array([0.027121]), 'x3': array([0.04542585])}]}, 'srrc': {'y': [{'x1': array([0.4718925]), 'x2': array([0.03849088]), 'x3': array([0.03696642])}]}, 'ssrrc': {'y': [{'x1': array([0.46220697]), 'x2': array([0.027121]), 'x3': array([0.04542585])}]}} .. GENERATED FROM PYTHON SOURCE LINES 69-71 The main indices corresponds to the Spearman correlation indices (this main method can be changed with :attr:`.CorrelationAnalysis.main_method`): .. GENERATED FROM PYTHON SOURCE LINES 71-73 .. code-block:: default pprint.pprint(sensitivity_analysis.main_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y': [{'x1': array([0.47177886]), 'x2': array([0.03220921]), 'x3': array([0.04128518])}]} .. GENERATED FROM PYTHON SOURCE LINES 74-75 We can also sort the input parameters by decreasing order of influence: .. GENERATED FROM PYTHON SOURCE LINES 75-77 .. code-block:: default print(sensitivity_analysis.sort_parameters("y")) .. rst-class:: sphx-glr-script-out .. code-block:: none ['x1', 'x3', 'x2'] .. GENERATED FROM PYTHON SOURCE LINES 78-81 Lastly, we can use the method :meth:`.CorrelationAnalysis.plot` to visualize the different correlation coefficients: .. GENERATED FROM PYTHON SOURCE LINES 81-82 .. code-block:: default sensitivity_analysis.plot("y", save=False, show=True) .. image-sg:: /examples/uncertainty/sensitivity/images/sphx_glr_plot_correlation_001.png :alt: Correlation indices for the output y :srcset: /examples/uncertainty/sensitivity/images/sphx_glr_plot_correlation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.589 seconds) .. _sphx_glr_download_examples_uncertainty_sensitivity_plot_correlation.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_correlation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_correlation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_