[英]DEoptim appears to freeze in R
I have encountered a situation where DEoptim
appears to freeze. 我遇到了DEoptim
似乎冻结的情况。 I can't figure out why and was hoping somebody with more experience in C could take a look at it. 我无法弄清楚为什么,并希望有更多C经验的人可以看看它。
It is rather difficult to create a reproducible example, so I simply saved the entire environment 50 iterations before the DEoptim freezes. 创建可重现的示例相当困难,因此我只是在DEOPtim冻结之前保存了整个环境50次迭代。 The file below, 'Envir650.Rdata'
can be found here . 下面的文件'Envir650.Rdata'
可以在这里找到。
rm(list = ls())
library(DstarM)
library(DEoptim)
load('Envir650.Rdata') # load the environment
# Adjust one function
argsList$fun.density = DstarM::Voss.density
argsList$control$trace = 1 # show intermediate output
argsList$control$parallelType = 0 # don't use parallel processing
.Random.seed = randomseed # set seed
out = do.call(DEoptim, argsList) # freezes at iteration 21 and crashes R.
Many thanks in advance! 提前谢谢了!
EDIT: I hope the problem is now reproducible. 编辑:我希望问题现在可以重现。
The problem is in rtdists package, source file density.c, function integrate. 问题在于rtdists包,源文件密度.c,函数集成。 The loop 循环
for(x = a+0.5*step; x < b; x += step) {
result += step * F->f(x, F->data);
}
becomes infinite because step
is too small. 变得无限,因为step
太小。 It is so small that x+step==x
and x
never reaches b
. 它是如此之小,以至于x+step==x
和x
永远不会达到b
。 The code of integrate
should be changed so that step
is never smaller than EPSILON
: 应该更改integrate
代码,以便step
永远不会小于EPSILON
:
--- orig/rtdists/src/density.c 2016-07-15 10:28:56.000000000 +0200
+++ mine/rtdists/src/density.c 2016-08-29 17:41:53.831078335 +0200
@@ -72 +72 @@
- double step = width / N;
+ double step = fmax(width / N, EPSILON);
With this change applied, your example finishes at iteration 51 without looping or crashing. 应用此更改后,您的示例将在迭代51结束,而不会循环或崩溃。 I've notified the rtdists authors; 我已通知 rtdists作者; the fix is now in the github version of the package. 修复程序现在在包的github版本中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.