Sensitivity analysis is used to determine the impact of a collection of independent factors on a dependent variable under certain conditions.
It is a strong approach for determining how the model’s output is impacted by the model’s inputs in general terms. In this post, I’ll give a quick overview of sensitivity analysis using SALib, a free Python sensitivity analysis package.
A numerical value known as the sensitivity index, frequently represents each input’s sensitivity. There are numerous types of sensitivity indices:
- First-order indices: calculates the contribution of a single model input to the output variance.
- Second-order indices: calculates the contribution of two model inputs to output variance.
- Total-order index: quantifies a model input’s contribution to output variance, encompassing both first-order effects (the input fluctuating alone) and any higher-order interactions.
What is SALib?
SALib is a Python-based open-source toolkit for doing sensitivity assessments. It has a detached workflow, which means it does not interact directly with the mathematical or computational model. Instead, SALib is in charge of producing the model inputs (through one of the sample functions) and computing the sensitivity indices (via one of the analyze functions) from the model outputs.
A typical SALib sensitivity analysis consists of four steps:
- Determine the model inputs (parameters) and the sample range for each.
- To create model inputs, run the sample function.
- Evaluate the model using the generated inputs and save the model results.
- To compute the sensitivity indices, use the analyze function on the outputs.
Sobol, Morris, and FAST are just a few of the sensitivity analysis methods provided by SALib. Many factors influence which approach is best for a given application, as we’ll see later. For the time being, keep in mind that you only need to utilize two functions, sample and analyze, regardless of whatever technique you employ. We will guide you through a basic example to illustrate how to utilize SALib.
SALib Example – Sobol’ Sensitivity Analysis
In this example, we will examine the Sobol’ sensitivity of the Ishigami function, as shown below. Because of its high nonlinearity and nonmonotonicity, the Ishigami function is widely used to evaluate uncertainty and sensitivity analysis methodologies.
The steps go as follows:
1. Importing SALib
The first step is to add the required libraries. The sample and analyze functions of SALib are kept distinct in Python modules. Importing the satellite sample and Sobol analyzing functions, for example, is shown below.
We also use the Ishigami function, which is available as a test function in SALib. Finally, we import NumPy as SALib uses it to store model inputs and outputs in a matrix.
2. Model Input
The model inputs must then be defined. The Ishigami function accepts three inputs: x1, x2, and x3. In SALib, we construct a dict that specifies the number of inputs, their names, and the limits on each input, as seen below.
3. Generate Samples and the Model
The samples are then generated. We need to create samples using the Saltelli sampler since we are doing a Sobol sensitivity analysis. In this case, param values are a NumPy matrix. We can observe that the matrix is 8000 by 3 by running param values.shape. 8000 samples were created with the Saltelli sampler. The Saltelli sampler creates samples, where N is 1024 (the parameter we provided) and D is 3. (the number of model inputs).
As previously stated, SALib is not engaged in mathematical or computational model evaluation. If the model is written in Python, you will typically loop through each sample input and assess the model:
The samples can be saved to a text file if the model is not developed in Python:
Each line in param values.txt represents one model input. The model’s output should be saved to another file in a similar style, with one output on each line. After that, the outputs may be loaded with:
In this example, we’re going to use the Ishigami function from SALib. These test functions can be evaluated as follows:
4. Perform Analysis
We can finally compute the sensitivity indices after loading the model results into Python. In this example, we will use sobol.analyze to compute the first, second, and total-order indices.
Si is a Python dictionary having the keys “S1,” “S2,” “ST,” “S1 conf,” “S2 conf,” and “ST conf.” The _conf keys hold the associated confidence intervals, which are generally set to 95 percent. To output, all indices, use the keyword parameter print to console=True. Alternatively, as illustrated below, we may print the individual values from Si.
We can see that x1 and x2 have first-order sensitivity, but x3 does not appear to have any first-order impacts.
If the total-order indices are significantly bigger than the first-order indices, higher-order interactions are most certainly taking place. We can see these higher-order interactions by looking at the second-order indices:
We can observe that x1 and x3 have significant interactions. After that, the result may be transformed to a Pandas DataFrame for further study.
5. Plotting
For your convenience, basic charting facilities are provided. The plot() function produces matplotlib axis objects for subsequent manipulation.
Conclusion
SALib is a sophisticated sensitivity analysis toolkit. Other techniques in SALib include the Fourier Amplitude Sensitivity Test (FAST), Morris Method, and Delta-Moment Independent Measure. While it is a Python library, it is intended to operate with models of any kind.
SALib offers an easy-to-use command-line interface for creating model inputs and assessing model outputs. Check out SALib documentation to learn more.
Leave a Reply