SALib: Sensitivity Analysis Library
SALib is an open-source Python library providing implementations of various global sensitivity analysis methods, including Sobol', Morris, FAST, DGSM, PAWN, HDMR, Moment Independent, and fractional factorial. It is currently at version 1.5.2 and maintains an active development status with somewhat regular releases.
Warnings
- breaking SALib version 1.2 and onwards officially dropped support for Python 2. Users must use Python 3 or later versions.
- breaking Starting with SALib 1.0.0, the Python API for sampling and analysis methods expects NumPy matrices directly as input for model runs and results, rather than file paths. The command-line interface remains unchanged.
- breaking SALib 1.5.2 introduced an updated NumPy dependency, requiring NumPy version 2.0 or higher.
- gotcha Mismatching sampling and analysis methods can lead to incorrect sensitivity indices. For example, Sobol' analysis requires samples generated by a Sobol' sampler (like Saltelli's).
- gotcha Sobol' index estimates can be biased if model outputs are not centered. SALib normalizes outputs by default to mitigate this. If using non-normalized outputs, larger sample sizes may be required for convergence.
Install
-
pip install SALib -
conda install conda-forge::salib
Imports
- sample_method
from SALib.sample import saltelli
- analyze_method
from SALib.analyze import sobol
- ProblemSpec
from SALib import ProblemSpec
Quickstart
import numpy as np
from SALib.sample import saltelli
from SALib.analyze import sobol
from SALib.test_functions import Ishigami
# 1. Define the model inputs
problem = {
'num_vars': 3,
'names': ['x1', 'x2', 'x3'],
'bounds': [[-np.pi, np.pi]] * 3
}
# 2. Generate samples
param_values = saltelli.sample(problem, 1024)
# 3. Run model (example: Ishigami function)
Y = Ishigami.evaluate(param_values)
# 4. Perform analysis
Si = sobol.analyze(problem, Y, print_to_console=True)
print(f"First-order sensitivity indices: {Si['S1']}")
print(f"Total-order sensitivity indices: {Si['ST']}")