我想对此进行编码:

哪里
params = (-0.00019942774322628663, 0.017096351295537309)
functions = {'1': lambda x:norm.cdf(x,loc=params[0],scale=params[1]), '2': lambda x:laplace.cdf(x,loc=params[0],scale=params[1])}所以我写了这个:
print integrate.quad(lambda x : ((108*numpy.exp(x))-150)*functions[selection](), 0.322411516161, numpy.inf)选择是由用户提供的。我知道这个错误:
TypeError: <lambda>() takes exactly 1 argument (0 given)编辑:我在阅读答案时做了以下修改:
print integrate.quad(lambda x : ((108*numpy.exp(x))-150)*functions[selection](x), 0.322411516161, numpy.inf)我得到了
IntegrationWarning: The occurrence of roundoff error is detected, which prevents the requested tolerance from being achieved. The error may be underestimated.warnings.warn(msg, IntegrationWarning)
(inf, nan)发布于 2016-04-10 15:11:57
得到错误的原因是因为您的lambda是
lambda x : ((108*numpy.exp(x))-150)*functions[selection]()当它应该是
lambda x : ((108*numpy.exp(x))-150)*functions[selection](your_arg_here)其中,your_arg_here是要传递给选择函数的内容。
换句话说,生成关于没有足够多的arg的错误的lambda是您引用selection的任何lambda,而不是您为integrate.quad定义的lambda。
不知道你想把什么arg传递给你的选择函数,或者我会给出一个更完整的答案。不过,我假设是x,在这种情况下,您的lambda应该是:
lambda x : ((108*numpy.exp(x))-150)*functions[selection](x)回答更新的问题:
IntegrationWarning: The occurrence of roundoff error is detected, which prevents the requested tolerance from being achieved. The error may be underestimated.warnings.warn(msg, IntegrationWarning)
(inf, nan)就是让你知道积分发散(到无穷远),就会出现一些浮点错误。积分发散是有意义的,因为e^x作为x-> inf是无界的,而function[selection]正在计算cdf值,这意味着它是以0,1为界的。根据一些快速测试,对于大于1的值,function[selection]总是等于1。因此,当x->inf时,function[selection]是1,e^x是无穷大的,因此发散。
https://stackoverflow.com/questions/36531206
复制相似问题