Note
Go to the end to download the full example code
Sensitivity Analysis
Quantifying the sensitivity of a model output
Sobol Indices
Any function
or more compactly
where
The functions
where
The first-order terms
The terms of the ANOVA expansion are orthogonal, i.e. the weighted
inner product , for . This orthogonality facilitates the following decomposition of the variance of the function
where
The quantities
where
Sobol indices can be computed different ways. In the following we will use polynomial chaos expansions, as in [SRESS2008].
import matplotlib.pyplot as plt
from pyapprox.benchmarks import setup_benchmark
from pyapprox.surrogates import approximate
from pyapprox import analysis
benchmark = setup_benchmark("ishigami", a=7, b=0.1)
num_samples = 1000
train_samples = benchmark.variable.rvs(num_samples)
train_vals = benchmark.fun(train_samples)
approx_res = approximate(
train_samples, train_vals, 'polynomial_chaos',
{'basis_type': 'hyperbolic_cross', 'variable': benchmark.variable,
'options': {'max_degree': 8}})
pce = approx_res.approx
res = analysis.gpc_sobol_sensitivities(pce, benchmark.variable)
Now lets compare the estimated values with the exact value
print(res.main_effects[:, 0])
print(benchmark.main_effects[:, 0])
[3.13751427e-01 4.42645977e-01 6.47617333e-08]
[0.31390519 0.44241114 0. ]
We can visualize the sensitivity indices using the following
fig, axs = plt.subplots(1, 3, figsize=(3*8, 6))
analysis.plot_main_effects(benchmark.main_effects, axs[0])
analysis.plot_total_effects(benchmark.total_effects, axs[1])
analysis.plot_interaction_values(benchmark.sobol_indices,
benchmark.sobol_interaction_indices, axs[2])
axs[0].set_title(r'$\mathrm{Main\;Effects}$')
axs[1].set_title(r'$\mathrm{Total\;Effects}$')
axs[2].set_title(r'$\mathrm{Sobol\;Indices}$')
plt.show()

References
#..
# .. [MT1991] `M.D. Morris. Factorial Sampling Plans for Preliminary Computational Experiments, Technometrics, 33:2, 161-174, 1991 <https://doi.org/10.1080/00401706.1991.10484804>`_
Total running time of the script: ( 0 minutes 2.777 seconds)