.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_reliability_sensitivity/sensitivity_analysis/plot_sensitivity_sobol_multivariate.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_auto_reliability_sensitivity_sensitivity_analysis_plot_sensitivity_sobol_multivariate.py: Estimate Sobol' indices for a function with multivariate output =============================================================== .. GENERATED FROM PYTHON SOURCE LINES 7-10 In this example, we estimate the Sobol' indices of a function by sampling methods. This function has several outputs, which leads to the need of aggregated Sobol' indices. .. GENERATED FROM PYTHON SOURCE LINES 13-20 Introduction ------------ In this example we quantify the sensitivity of a function's outputs to its inputs with Sobol' indices. The function we consider has 5 outputs. In this case, it may be convenient to consider each output separately. It may also be interesting to aggregate the sensitivity indices to get a global understanding of the sensitivity of the inputs to the average output. .. GENERATED FROM PYTHON SOURCE LINES 22-24 Define the model ---------------- .. GENERATED FROM PYTHON SOURCE LINES 26-32 .. code-block:: Python import openturns as ot import openturns.viewer import openturns.viewer as viewer ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 33-34 We define a linear model with 5 independent Gaussian inputs and 2 outputs. .. GENERATED FROM PYTHON SOURCE LINES 34-41 .. code-block:: Python inputDistribution = ot.Normal(5) function = ot.SymbolicFunction( ["x0", "x1", "x2", "x3", "x4"], ["x0 + 4.0 * x1 ^ 2 + 3.0 * x2", "-7.0 * x2 - 4.0 * x3 + x4"], ) .. GENERATED FROM PYTHON SOURCE LINES 42-44 Estimate the Sobol' indices --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 46-47 We first create a design of experiments with `SobolIndicesExperiment`. .. GENERATED FROM PYTHON SOURCE LINES 49-56 .. code-block:: Python size = 1000 sie = ot.SobolIndicesExperiment(inputDistribution, size) inputDesign = sie.generate() input_names = inputDistribution.getDescription() inputDesign.setDescription(input_names) print("Sample size: ", inputDesign.getSize()) .. rst-class:: sphx-glr-script-out .. code-block:: none Sample size: 7000 .. GENERATED FROM PYTHON SOURCE LINES 57-59 We see that 7000 function evaluations are required to estimate the first order and total Sobol' indices. Then we evaluate the outputs corresponding to this design of experiments. .. GENERATED FROM PYTHON SOURCE LINES 61-63 .. code-block:: Python outputDesign = function(inputDesign) .. GENERATED FROM PYTHON SOURCE LINES 64-65 Then we estimate the Sobol' indices with the `SaltelliSensitivityAlgorithm`. .. GENERATED FROM PYTHON SOURCE LINES 67-69 .. code-block:: Python sensitivityAnalysis = ot.SaltelliSensitivityAlgorithm(inputDesign, outputDesign, size) .. GENERATED FROM PYTHON SOURCE LINES 70-73 The `getFirstOrderIndices` and `getTotalOrderIndices` method respectively return estimates of first order and total Sobol' indices with a given output. Since these depend on the output marginal, the index of the output must be specified (the default is to return the index for the first output). .. GENERATED FROM PYTHON SOURCE LINES 75-88 .. code-block:: Python output_dimension = function.getOutputDimension() for i in range(output_dimension): print("Output #", i) first_order = sensitivityAnalysis.getFirstOrderIndices(i) total_order = sensitivityAnalysis.getTotalOrderIndices(i) print(" First order indices: ", first_order) print(" Total order indices: ", total_order) agg_first_order = sensitivityAnalysis.getAggregatedFirstOrderIndices() agg_total_order = sensitivityAnalysis.getAggregatedTotalOrderIndices() print("Agg. first order indices: ", agg_first_order) print("Agg. total order indices: ", agg_total_order) .. rst-class:: sphx-glr-script-out .. code-block:: none Output # 0 First order indices: [-0.0248738,0.601745,0.132095,-0.0447529,-0.0447529] Total order indices: [0.0172432,0.83259,0.197363,-6.99325e-07,-6.99325e-07] Output # 1 First order indices: [-0.00826858,-0.00826858,0.777015,0.248207,0.0137737] Total order indices: [-1.3404e-06,-1.3404e-06,0.719766,0.281065,0.0121219] Agg. first order indices: [-0.0153095,0.25039,0.503556,0.123986,-0.0110427] Agg. total order indices: [0.00731069,0.353034,0.498257,0.161887,0.00698166] .. GENERATED FROM PYTHON SOURCE LINES 89-98 We see that: * `x1` has a rather large first order index on the first output, but a small index on the second output, * `x2` has a rather large first order index on the first output on both outputs, * the largest aggregated Sobol' index is `x2`, * `x0` and `x5` have Sobol' indices which are close to zero regardless of whether the indices are aggregated or not. .. GENERATED FROM PYTHON SOURCE LINES 100-101 The `draw` method produces the following graph. The vertical bars represent the 95% confidence intervals of the estimates. .. GENERATED FROM PYTHON SOURCE LINES 103-106 .. code-block:: Python graph = sensitivityAnalysis.draw() view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/sensitivity_analysis/images/sphx_glr_plot_sensitivity_sobol_multivariate_001.png :alt: Aggregated Sobol' indices - SaltelliSensitivityAlgorithm :srcset: /auto_reliability_sensitivity/sensitivity_analysis/images/sphx_glr_plot_sensitivity_sobol_multivariate_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 107-109 Since there are several outputs, the graph presents the aggregated Sobol' indices. The aggregated Sobol' indices indicate that the input variable which has the largest impact on the variability of the several outputs is `x2`. .. _sphx_glr_download_auto_reliability_sensitivity_sensitivity_analysis_plot_sensitivity_sobol_multivariate.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sensitivity_sobol_multivariate.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sensitivity_sobol_multivariate.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_sensitivity_sobol_multivariate.zip `