使用python执行敏感性分析 [英] Performing a sensitivity analysis with python

查看:1148
本文介绍了使用python执行敏感性分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行敏感性分析,因此我开始学习python,所以我想在python中完成这项工作.我找到了一个名为SALib的程序包,但实际上并没有真正了解如何实现自己的方程式. 例如,这是我的方程式:

I'm trying to perform a sensitivity analysis and I started to learn python so I wanted to accomplish this in python. I found a package called SALib but I don't really get how to implement my own equation. For example this is my equation:

ET = 0,0031*C*(R+209)*(t*(t+15)**-1)

首先,我必须定义我的问题:

At first I have to define my problem:

problem = {'num_vars': 3,
           'names': ['C', 'R', 't'],
           'bounds': [[10, 100],
                     [3, 7],
                     [-10, 30]]
           }

此后,我必须生成输入样本,但是如何用自己的方程式生成这些样本?也许有人对SALib有经验,可以为我提供帮助.我发现包装文件没有真正的帮助.

After this I have to generae Input Samples but I how do I generate these with my own equation? Maybe someone has expierience with SALib and can help me. I don't find the package documentation really helpful.

推荐答案

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

The function saltelli.sample() will generate a matrix with each column representing a variable defined in problem and sampled in the corresponding bounds defined in problem. After that, you can define your model as a function, as shown below, and compute the value of the function ET() for these inputs. The result is a vector of function values, which can be sent the the other SALib functions as given in the documentation (https://github.com/SALib/SALib).

from SALib.sample import saltelli
from SALib.analyze import sobol

def ET(X):
    # column 0 = C, column 1 = R, column 2 = t
    return(0.0031*X[:,0]*(X[:,1]+209)*(X[:,2]*(X[:,2]+15))**-1)

problem = {'num_vars': 3,
           'names': ['C', 'R', 't'],
           'bounds': [[10, 100],
                     [3, 7],
                     [-10, 30]]
           }

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

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

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

这篇关于使用python执行敏感性分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆