2

I have encountered a situation where DEoptim appears to freeze. I can't figure out why and was hoping somebody with more experience in C could take a look at it.

It is rather difficult to create a reproducible example, so I simply saved the entire environment 50 iterations before the DEoptim freezes. The file below, 'Envir650.Rdata' can be found here.

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.

4

1 回答 1

4

问题出在 rtdists 包、源文件 density.c、函数集成中。循环

for(x = a+0.5*step; x < b; x += step) {
    result += step * F->f(x, F->data);
}

step因为太小而变得无限。它太小了x+step==xx永远也达不到b。的代码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);

应用此更改后,您的示例将在迭代 51 处结束,而不会循环或崩溃。我已经 通知 了 rtdists 的作者;该修复程序现在位于包的github 版本中。

于 2016-08-29T16:00:09.673 回答