scipy.integrate 和 mpmath.quad 的积分结果不同
我正在集成一个函数来实现本文中的功能,并且我观察到不同的scipy.integrate.quad
和 mpmath.quad
的输出如下:
import mpmath as mp
from scipy import integrate
print(mp.quad(lambda x: x**58 * (1-x)**167 * (x+0.07053941908706418)**86, [0,1]))
print(integrate.quad(lambda x: x**58 * (1-x)**167 * (x+0.07053941908706418)**86, 0, 1))
# Results
# 3.99873917020827e-90
# (1.0583370200366968e-89, 1.5341117982755304e-89)
基于外部考虑到这一点,我有理由相信 SciPy 结果是正确的(我对返回的 PDF 进行了检查,SciPy 结果返回的值是一个有效的 PDF,在支持上积分为 1)。
我是否错误地调用了任一函数,或者具体是 mp.quad
?
I am integrating a function to implement the functions in this paper and I observe different outputs from scipy.integrate.quad
and mpmath.quad
as per the following:
import mpmath as mp
from scipy import integrate
print(mp.quad(lambda x: x**58 * (1-x)**167 * (x+0.07053941908706418)**86, [0,1]))
print(integrate.quad(lambda x: x**58 * (1-x)**167 * (x+0.07053941908706418)**86, 0, 1))
# Results
# 3.99873917020827e-90
# (1.0583370200366968e-89, 1.5341117982755304e-89)
Based on external considerations, I have reason to believe that the SciPy result is correct (I performed checks on the PDF returned and the values returned by SciPy result is a valid PDF that integrates to 1 over the support).
Am I calling either function, or specifically mp.quad
incorrectly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正确地调用了这些函数,但是
mpmath.quad
是为任意精度编写的,因此当您将精度设置得更高时,它是一个更可靠的参考。另外,您可以尝试它的两种方法;我通常会相信结果彼此一致。所以
scipy.integrate.quad
与默认设置接近,但仅与其他前七位一致。请注意,它对其结果不是很有信心:第二个数字是绝对误差估计,因此即使它相当准确,但它并没有声称如此。
您可以尝试使用
epsabs
和epsrel
收紧其容差,但在这种情况下它们没有任何效果。You are calling the functions correctly, but
mpmath.quad
is written for arbitrary precision, so it is a more reliable reference when you set the precision to be higher. Also, you can try both of itsmethod
s; I would typically trust the results to the extent that they agree with one another.So
scipy.integrate.quad
is close with default settings, but only agrees with the others in the first seven digits. Note that it is not very confident about its result:The second number is an absolute error estimate, so even though it was reasonably accurate, it wasn't claiming to be.
You can try tightening its tolerances using
epsabs
andepsrel
, but they don't have any effect in this case.