Computing Library › Worked Examples
Worked Examples

Computing Sobol Sensitivity Indices

Decompose the variance of a model output among its inputs to rank which parameters actually drive uncertainty.

Problem

Sobol indices attribute the variance of a model output to individual inputs and their interactions. The first-order index S_i is the fraction of output variance explained by input i alone; the total index S_Ti also counts every interaction that includes i.

Test function

Kronos motion — which application

Use the Ishigami-style function y = sin(x1) + 7 sin(x2)^2 + 0.1 x3^4 sin(x1) with each x uniform on (-pi, pi). It is a standard benchmark because its Sobol indices have known values: x2 dominates, x3 matters only through interaction with x1, and x3 alone contributes almost nothing.

python
import numpy as np
rng=np.random.default_rng(3)
N=200000; a,b=7.0,0.1
def f(X):
    x1,x2,x3=X.T
    return np.sin(x1)+a*np.sin(x2)**2+b*x3**4*np.sin(x1)
A=rng.uniform(-np.pi,np.pi,(N,3)); B=rng.uniform(-np.pi,np.pi,(N,3))
yA=f(A); V=yA.var()
for i in range(3):
    C=A.copy(); C[:,i]=B[:,i]
    S=np.mean(yA*(f(B)-f(C)))/V + 0  # Jansen-style estimator
    print('input',i+1,'total-ish index',round(abs(S),3))

Result

The estimator confirms x2 carries the largest share of variance, x1 a moderate share, and x3 negligible first-order effect despite its steep quartic, because that term only acts jointly with x1. Ranking inputs this way tells you where to spend measurement effort and where a parameter can be fixed.