【发布时间】:2016-11-04 00:15:04
【问题描述】:
在计算双重集成时,我遇到了来自包“R2Cuba”的集成() 和 suave() 的不一致结果。
在哪里
与此主题相关的类似问题可以找到here,让我们设置f(x)=6*sin(x)和g(x)=1以及上时间T=3。
以下代码使用integrate() 和suave() 计算目标2 倍积分:
library(R2Cuba)
integrand = function(x){6*sin(x)}
phi = function(x){integrate(integrand,lower=x,upper = 3)[["value"]]^2}
NDIM=1
NCOMP=1
phicuba= function(x){suave(NDIM,NCOMP,integrand,lower=x,upper=3)$value^2}
foldintegral = integrate(Vectorize(phi),lower = 0,upper = 3)
foldintegralcuba = suave(NDIM,NCOMP,phicuba,lower = 0,upper = 3)
结果:
> foldintegral
167.3934 with absolute error < 1.9e-12
> foldintegralcuba
integral: 6.365749 (+-0.0057)
nregions: 8; number of evaluations: 10000; probability: 1
这是不一致的。但是,如果我们只比较phi和phicuba
> phi(2)
[1] 11.85476
> phicuba(2)
Iteration 1: 1000 integrand evaluations so far
[1] 3.44367 +- 0.0429822 chisq 0 (0 df)
Iteration 2: 2000 integrand evaluations so far
[1] 3.4436 +- 0.00866171 chisq 0.00513973 (2 df)
Iteration 3: 3000 integrand evaluations so far
[1] 3.44181 +- 0.00386046 chisq 5.38913 (5 df)
Iteration 4: 4000 integrand evaluations so far
[1] 3.44283 +- 0.00206345 chisq 23.0816 (8 df)
[1] 11.85309
我们得到了一个可以被视为一致的结果。此外,如果我们使用替换 suave() 内的被积函数
> suave(NDIM,NCOMP,phi,lower = 0,upper = 3)
Iteration 1: 1000 integrand evaluations so far
[1] 167.426 +- 4.91983 chisq 0 (0 df)
Iteration 2: 2000 integrand evaluations so far
[1] 167.315 +- 0.771248 chisq 0.00208764 (2 df)
Iteration 3: 3000 integrand evaluations so far
[1] 167.357 +- 0.432941 chisq 5.50239 (5 df)
Iteration 4: 4000 integrand evaluations so far
[1] 167.362 +- 0.129012 chisq 5.51661 (8 df)
integral: 167.3621 (+-0.13)
nregions: 4; number of evaluations: 4000; probability: 0.2988006
我们仍然有一致的结果。
我希望我可以使用 suave(),因为它在处理复杂积分时要快得多,但为什么会存在这种不一致?
=========================更新===================== ==========
似乎是因为suave()中使用的算法,From the Cuba Documentation,suave使用了全局自适应细分+重要性采样。如果将 suave() 更改为 cuhre(),只使用全局自适应细分,那么一切都应该是一致的。
【问题讨论】:
-
@ZheyuanLi 谢谢提醒!