R:DEoptim并行优化

编程入门 行业动态 更新时间:2024-10-27 03:43:48
R:DEoptim并行优化 - 核心数量(R: DEoptim parallel optimization - number of cores)

我正在尝试在R中使用DEoptim优化包来解决连续优化问题,并且由于我的成本函数需要很长时间来评估(2分钟),我正在尝试使用并行计算。 我的问题是:

paralleltype=1 ( parallel )和2 ( foreach )选项有什么区别? 什么时候使用其中一个?

是否可以指定paralleltype=1的核心数,以便不占用所有可用的核心进行计算(例如,64个核心上有50个核心可用)?

I'm trying to use DEoptim optimization package in R on a continuous optimization problem, and as my cost function takes a long time to evaluate (2min), I'm trying to use parallel computation. My questions are:

What's the difference between paralleltype=1 (parallel) and 2 (foreach) option ? When to use one of the two ?

Is it possible to specify the number of cores with paralleltype=1, in order not to take all the available cores for computing (50 cores on 64 cores available, for instance)?

最满意答案

广告。 1 - 包文档中对此进行了解释。

广告。 2 - 需要对两个函数进行修改:DEoptim.control和DEoptim

首先,将一个变量 - 例如limitCores - 添加到DEoptim.control函数,该函数控制DE优化的执行参数。

其次,对DEOPtim包装函数进行修改,以对limitCores设置的限制进行操作。

if (ctrl$parallelType == 1) { if (!is.na(ctrl$limitCores)) { if (ctrl$limitCores<1) useCores <- round(parallel::detectCores()*ctrl$limitCores) else useCores <- ctrl$limitCores cl <- parallel::makeCluster(parallel::detectCores()) } else { cl <- parallel::makeCluster(parallel::detectCores()) }

完整代码: http : //pastebin.com/NumDx4ae

ad. 1 - It is explained in the package documentation.

ad. 2 - Requires some tinkering with two functions: DEoptim.control and DEoptim

First, add a variable - say limitCores - to DEoptim.control function, which controls execution parameters of the DE optimization.

Second, introduce modification to the DEoptim wrapper function to act on the limitation set by limitCores.

if (ctrl$parallelType == 1) { if (!is.na(ctrl$limitCores)) { if (ctrl$limitCores<1) useCores <- round(parallel::detectCores()*ctrl$limitCores) else useCores <- ctrl$limitCores cl <- parallel::makeCluster(parallel::detectCores()) } else { cl <- parallel::makeCluster(parallel::detectCores()) }

Complete code: http://pastebin.com/NumDx4ae

更多推荐

本文发布于:2023-08-06 13:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1448650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:DEoptim

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!