.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/sampler/plot_saltelli.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_auto_examples_sampler_plot_saltelli.py: Saltelli sampling ================= .. GENERATED FROM PYTHON SOURCE LINES 8-11 This example shows how to draw samples using Saltelli sampling. Assume that there is a three-dimensional problem where X, Y, and Z are the three random variables. .. GENERATED FROM PYTHON SOURCE LINES 12-19 .. code-block:: default import numpy as np ndim = 3 # range of X is 10 to 20, range of Y is 100 to 200, range of Z is 1000 to 2000 bounds = np.array([[10,20], [100,200], [1000,2000]]) .. GENERATED FROM PYTHON SOURCE LINES 20-22 Given this setting, we can import :class:`.Saltelli`, create an instance, and call the :py:meth:`.Saltelli.sample` method to draw required number of samples. .. GENERATED FROM PYTHON SOURCE LINES 23-29 .. code-block:: default from psimpy.sampler import Saltelli saltelli_sampler = Saltelli(ndim, bounds, calc_second_order=False) saltelli_samples = saltelli_sampler.sample(nbase=128) .. GENERATED FROM PYTHON SOURCE LINES 30-34 In above codes, we set ``calc_second_order`` to `False`. It means that picked samples can be used in following Sobol' analysis to compute first-order and total-effect Sobol' indices but not second-order Sobol' indices. It leads to :math:`nbase*(ndim+2)` samples as shown below .. GENERATED FROM PYTHON SOURCE LINES 35-51 .. code-block:: default import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(projection='3d') ax.scatter(saltelli_samples[:,0], saltelli_samples[:,1], saltelli_samples[:,2], marker='o') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') plt.tight_layout() print('Number of samples: ', f'{len(saltelli_samples)}') .. image-sg:: /auto_examples/sampler/images/sphx_glr_plot_saltelli_001.png :alt: plot saltelli :srcset: /auto_examples/sampler/images/sphx_glr_plot_saltelli_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Number of samples: 640 .. GENERATED FROM PYTHON SOURCE LINES 52-55 If we want to draw samples which can also be used to compute second-order Sobol' indices, we need to set ``calc_second_order`` to `True`. It leads to :math:`nbase*(2*ndim+2)` samples. .. GENERATED FROM PYTHON SOURCE LINES 56-73 .. code-block:: default saltelli_sampler = Saltelli(ndim, bounds, calc_second_order=True) saltelli_samples = saltelli_sampler.sample(nbase=128) fig = plt.figure() ax = fig.add_subplot(projection='3d') ax.scatter(saltelli_samples[:,0], saltelli_samples[:,1], saltelli_samples[:,2], marker='o') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') plt.tight_layout() print('Number of samples: ', f'{len(saltelli_samples)}') .. image-sg:: /auto_examples/sampler/images/sphx_glr_plot_saltelli_002.png :alt: plot saltelli :srcset: /auto_examples/sampler/images/sphx_glr_plot_saltelli_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Number of samples: 1024 .. GENERATED FROM PYTHON SOURCE LINES 74-78 .. note:: If one has a two-dimensional problem, there is no need to set ``calc_second_order`` to `True`. The reason is that the second-order Sobol' index can be directly computed based on the first-order and total-effect Sobol' index in that case. .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.355 seconds) .. _sphx_glr_download_auto_examples_sampler_plot_saltelli.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_saltelli.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_saltelli.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_