SA using Scatter Plots
Take for example the following:
Suppose now we have a function with two inputs, y = f(x1, x2) + ε. Like before, we sample x1 and x2 independently and generate the scatter plot. The black points show the output caused by varying x1 and the red points show the output caused by varying x2.
Using SALib
- First-order indices: measures the contribution to the output variance by a single model input alone.
- Second-order indices: measures the contribution to the output variance caused by the interaction of two model inputs.
- Total-order index: measures the contribution to the output variance caused by a model input, including both its first-order effects (the input varying alone) and all higher-order interactions.
git clone https://github.com/SALib/SALib.git cd SALib python setup.py develop
To demonstrate the use of SALib, we will perform a Sobol’ sensitivity analysis of the Ishigami function, shown below. The Ishigami function is commonly used to test uncertainty and sensitivity analysis methods because it exhibits strong nonlinearity and nonmonotonicity.
Next, we must define the model inputs. The Ishigami function has three inputs, x1, x2, and x3, where x ∈ [-π, π]. In SALib, we use a dict defining the number of inputs, the names of the inputs, and the bounds on each input, as shown below.
Next, we generate the samples. Since we are performing a Sobol’ sensitivity analysis, we need to generate samples using the Saltelli sampler, as shown below.
Here, param_values is a NumPy matrix. If we run param_values.shape, we see that the matrix is 8000 by 3. The Saltelli sampler generated 8000 samples. The Saltelli sampler generates N*(2D+2) samples, where in this example N is 1000 (the argument we supplied) and D is 3 (the number of model inputs).
Next, we must evaluate the model using our generated samples. In this example, we are using the Ishigami function provided by SALib. We can evaluate these test functions as shown below:
With the model outputs computed, we can finally compute the sensitivity indices. In this example, we use sobol.analyze, which will compute first, second, and total-order indices.
Si is a Python dict with the keys "S1", "S2", "ST", "S1_conf", "S2_conf", and "ST_conf". The _conf keys store the corresponding confidence intervals, typically with a confidence level of 95%. We can print the values as shown below.
>>> # Print the first-order indices >>> print Si['S1'] [ 0.30644324 0.44776661 -0.00104936 ] >>> # Print the total-order indices >>> print Si['ST'] [ 0.56013728 0.4387225 0.24284474] >>> # Print the interactive effects >>> print "x1-x2:", Si['S2'][0,1] >>> print "x1-x3:", Si['S2'][0,2] >>> print "x2-x3:", Si['S2'][1,2] x1-x2: 0.0155279 x1-x3: 0.25484902 x2-x3: -0.00995392
Conclusion
We also want to note that while SALib is a Python library, it is designed to work with models in any form. SALib includes a convenient command line interface for generating the model inputs and analyzing the model outputs. Additional documentation for SALib is available online at ReadTheDocs.