gpt4 book ai didi

c - DEoptim 似乎在 R 中卡住

转载 作者:太空宇宙 更新时间:2023-11-04 01:53:29 24 4
gpt4 key购买 nike

我遇到过 DEoptim 似乎卡住的情况。我不明白为什么,希望有更多 C 语言经验的人可以看看它。

创建可重现的示例相当困难,因此我只是在 DEoptim 卡住之前将整个环境保存了 50 次迭代。可以找到下面的文件 'Envir650.Rdata' 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.

非常感谢!

编辑:我希望问题现在可以重现。

最佳答案

问题出在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 次迭代时完成,没有循环或崩溃。我有 notifiedrtdists 作者;修复程序现在在 github version 中包的。

关于c - DEoptim 似乎在 R 中卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38803871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com