-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample-ishigami.py
More file actions
34 lines (27 loc) · 917 Bytes
/
example-ishigami.py
File metadata and controls
34 lines (27 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from SALib.sample import saltelli
from SALib.analyze import sobol
import numpy as np
# function to define model
# in this case it's a test function (Ishigami)
def run_model(x):
A = 7
B = 0.1
y = np.sin(x[0]) + A * np.sin(x[1])**2 + \
B * x[2]**4 * np.sin(x[0])
return y
problem = {
'num_vars': 3,
'names': ['x1', 'x2', 'x3'],
'bounds': [[-np.pi, np.pi]]*3
}
# Generate samples
param_values = saltelli.sample(problem, 10000)
N = len(param_values) # number of parameter samples
Y = np.zeros(N)
# Run model for each parameter set, save the output in array Y
for i in range(N):
Y[i] = run_model(param_values[i])
# Perform sensitivity analysis using the model output
Si = sobol.analyze(problem, Y, print_to_console=True)
# Returns a dictionary with keys 'S1', 'S1_conf', 'ST', and 'ST_conf'
# (first and total-order indices with bootstrap confidence intervals)