[Dream-commits] r21 - in pkg: . R demo man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 12 08:37:35 CET 2010


Author: josephguillaume
Date: 2010-03-12 08:37:35 +0100 (Fri, 12 Mar 2010)
New Revision: 21

Modified:
   pkg/DESCRIPTION
   pkg/R/CompDensity.R
   pkg/R/dream.R
   pkg/demo/FME.nonlinear.model.R
   pkg/man/dream.Rd
Log:
Added control$use.foreach option, and made it the default
Suggested foreach, and made parallel backends enhances.
Added registration of a SNOW socket cluster to FME example.
Updated dream help to fit.

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2010-03-12 06:40:09 UTC (rev 20)
+++ pkg/DESCRIPTION	2010-03-12 07:37:35 UTC (rev 21)
@@ -7,7 +7,8 @@
 Description: Efficient global MCMC even in high-dimensional spaces.
   Based on the original MATLAB code written by Jasper Vrugt.
 Depends: coda
-Suggests: multicore
+Suggests: multicore, foreach
 Imports: stats, utils
+Enhances: doSNOW, doMPI, doMC
 License: file LICENSE
 URL: http://dream.r-forge.r-project.org/

Modified: pkg/R/CompDensity.R
===================================================================
--- pkg/R/CompDensity.R	2010-03-12 06:40:09 UTC (rev 20)
+++ pkg/R/CompDensity.R	2010-03-12 07:37:35 UTC (rev 21)
@@ -90,6 +90,7 @@
   }
   
   if (control$use.multicore) temp <- mclapply(1:nrow(pars),do.calc,mc.preschedule=FALSE)
+  else if (control$use.foreach) temp <- foreach(ii=1:nrow(pars)) %do% do.calc(ii)
   else temp <- lapply(1:nrow(pars),do.calc)
   
   p <- sapply(temp,function(x) x[1])

Modified: pkg/R/dream.R
===================================================================
--- pkg/R/dream.R	2010-03-12 06:40:09 UTC (rev 20)
+++ pkg/R/dream.R	2010-03-12 07:37:35 UTC (rev 21)
@@ -18,7 +18,8 @@
          thin.t=NA,            ## parameter for reduced sample collection
 ### Efficiency improvements
          REPORT = 1000,            ## approximate number of function evaluations between reports. >0. 0=none
-         use.multicore=TRUE,
+         use.multicore=FALSE,
+         use.foreach=TRUE,
 ### Parameters with auto-set values
          ndim=NA,			 ## number of parameters (automatically set from length of pars)
          DEpairs = NA,          ## Number of DEpairs. defaults to max val floor((nseq-1)/2)
@@ -135,6 +136,7 @@
   if (control$burnin.length<1) control$burnin.length <- control$burnin.length*control$ndraw
 
   if (control$use.multicore) control$use.multicore <- require(multicore)
+  if (control$use.foreach) control$use.foreach <- require(foreach)
   
   ## Check validity of settings
   if (control$DEpairs==0) stop("control$DEpairs set to 0. Increase nseq?")

Modified: pkg/demo/FME.nonlinear.model.R
===================================================================
--- pkg/demo/FME.nonlinear.model.R	2010-03-12 06:40:09 UTC (rev 20)
+++ pkg/demo/FME.nonlinear.model.R	2010-03-12 07:37:35 UTC (rev 21)
@@ -50,8 +50,7 @@
 set.seed(456)
 
 control <- list(
-                nseq=4,
-                use.multicore=FALSE
+                nseq=4
                 ##                REPORT=0
                 ##                ndraw=1000
                 ##                Rthres=1+1e-3
@@ -59,6 +58,16 @@
 
 pars <- list(p1=c(0,1),p2=c(0,100))
 
+
+## Optional parallelisation of function evaluations
+## Uses foreach, which allows Rmpi, SNOW or multicore to be registered,
+##   or just normal sequential evaluation
+## Example here is for SNOW with a socket cluster, which doesn't require any other software or setup
+if (require(doSNOW)){
+  cl <- makeCluster(c("localhost","localhost"), type = "SOCK")
+  registerDoSNOW(cl)
+}
+  
 dd <- dream(
             FUN=Model.y, func.type="calc.rmse",
             pars = pars,
@@ -70,6 +79,8 @@
             control = control
             )
 
+if (require(doSNOW))  stopCluster(cl)
+
 dd
 
 summary(dd)

Modified: pkg/man/dream.Rd
===================================================================
--- pkg/man/dream.Rd	2010-03-12 06:40:09 UTC (rev 20)
+++ pkg/man/dream.Rd	2010-03-12 07:37:35 UTC (rev 21)
@@ -64,7 +64,11 @@
     Frequent calculation is likely to slow performance. The summary
     function can use \code{\link{gelman.diag}} to calculate convergence statistic after completion
     \cr
-    \code{use.multicore} \tab \code{TRUE} \tab Whether to use multicore
+    \code{use.foreach} \tab \code{TRUE} \tab Whether to use foreach
+    package if available. For parallelisation of function evaluations, a
+    parallel backend must be registered from one of the doMC, doMPI,
+    doSNOW packages. \cr
+    \code{use.multicore} \tab \code{FALSE} \tab Whether to use multicore
     package if available. Parallelises function evaluations. \cr
     \code{ndraw} \tab  1e5 \tab Maximum number of function evaluations. May
     terminate before convergence. \cr



More information about the Dream-commits mailing list