使用python执行敏感性分析

函数saltelli.sample()将生成一个矩阵,每列代表problem中定义的变量,并在problem中定义的相应边界中采样。之后,您可以将模型定义为函数,如下所示,并计算这些输入的函数ET()的值。结果是函数值的向量,可以通过文档(https://github.com/SALib/SALib)中给出的其他SALib函数发送。

from SALib.sample import saltelli 
from SALib.analyze import sobol 
import matplotlib.pyplot as plt 

def ET(X): 
    # column 0 = x1, column 1 = x2, column 2 = x3 
    return(0.0031*X[:,0]*(X[:,1]+209)*(X[:,2]*(X[:,2]+15))**-1) 

problem = {'num_vars': 3, 
      'names': ['x1', 'x2', 'x3'],
      'bounds': [[10, 100], 
        [3, 7], 
        [-10, 30]] 
      } 

# Generate samples 
param_values = saltelli.sample(problem, 1000, calc_second_order=False) 

# Run model (example) 
Y = ET(param_values) 

# Perform analysis 
Si = sobol.analyze(problem, Y, print_to_console=True) 

# Print the first-order sensitivity indices
print (Si['S1'])
plt.subplots(figsize=(9, 9)) # 设置画面大小
plt.barh(range(len(Si['S1'])), Si['S1'])
plt.show()

转载自:https://stackoverrun.com/cn/q/11299095

你可能感兴趣的:(python,机器学习)