.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/sensitivity/sobol/sobol_additive.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 or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_sensitivity_sobol_sobol_additive.py: Additive function ============================================== We introduce the variance-based Sobol indices using an elementary example. For more details, refer [1]_. .. math:: f(x) = a \cdot X_1 + b \cdot X_2, \quad X_1, X_2 \sim \mathcal{N}(0, 1), \quad a,b \in \mathbb{R} .. [1] Saltelli A, T. (2008). Global sensitivity analysis: The primer. John Wiley. .. GENERATED FROM PYTHON SOURCE LINES 17-28 .. code-block:: default import numpy as np from UQpy.run_model.RunModel import RunModel from UQpy.run_model.model_execution.PythonModel import PythonModel from UQpy.distributions import Normal from UQpy.distributions.collection.JointIndependent import JointIndependent from UQpy.sensitivity.SobolSensitivity import SobolSensitivity from UQpy.sensitivity.PostProcess import * np.random.seed(123) .. GENERATED FROM PYTHON SOURCE LINES 29-30 **Define the model and input distributions** .. GENERATED FROM PYTHON SOURCE LINES 30-50 .. code-block:: default # Create Model object a, b = 1, 2 model = PythonModel( model_script="local_additive.py", model_object_name="evaluate", var_names=[ "X_1", "X_2", ], delete_files=True, params=[a, b], ) runmodel_obj = RunModel(model=model) # Define distribution object dist_object = JointIndependent([Normal(0, 1)] * 2) .. GENERATED FROM PYTHON SOURCE LINES 51-52 **Compute Sobol indices** .. GENERATED FROM PYTHON SOURCE LINES 54-58 .. code-block:: default SA = SobolSensitivity(runmodel_obj, dist_object) SA.run(n_samples=50_000) .. GENERATED FROM PYTHON SOURCE LINES 59-66 **First order Sobol indices** Expected first order Sobol indices: :math:`\mathrm{S}_1 = \frac{a^2 \cdot \mathbb{V}[X_1]}{a^2 \cdot \mathbb{V}[X_1] + b^2 \cdot \mathbb{V}[X_2]} = \frac{1^2 \cdot 1}{1^2 \cdot 1 + 2^2 \cdot 1} = 0.2` :math:`\mathrm{S}_2 = \frac{b^2 \cdot \mathbb{V}[X_2]}{a^2 \cdot \mathbb{V}[X_1] + b^2 \cdot \mathbb{V}[X_2]} = \frac{2^2 \cdot 1}{1^2 \cdot 1 + 2^2 \cdot 1} = 0.8` .. GENERATED FROM PYTHON SOURCE LINES 68-70 .. code-block:: default SA.first_order_indices .. GENERATED FROM PYTHON SOURCE LINES 71-72 **Plot the first and total order sensitivity indices** .. GENERATED FROM PYTHON SOURCE LINES 72-79 .. code-block:: default fig1, ax1 = plot_index_comparison( SA.first_order_indices[:, 0], SA.total_order_indices[:, 0], label_1="First order Sobol indices", label_2="Total order Sobol indices", plot_title="First and Total order Sobol indices", ) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_sensitivity_sobol_sobol_additive.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/SURGroup/UQpy/master?urlpath=lab/tree/notebooks/auto_examples/sensitivity/sobol/sobol_additive.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sobol_additive.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sobol_additive.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_