Note that there are some explanatory texts on larger screens.

plurals
  1. POparallel randomForest with different results using doSNOW
    primarykey
    data
    text
    <p>I thought I found a way to make a reproducible <code>foreach</code> loop with <code>doSNOW</code> with the following code </p> <pre><code>library(foreach) library(doSNOW) library(parallel) ncores &lt;- 2 cl &lt;- makeCluster(ncores) registerDoSNOW(cl) foreach(i=1:ncores) %dopar% { set.seed(i) rnorm(1) } stopCluster(cl) </code></pre> <p>Because I used a seed inside the foreach loop, I always get the same results (independent from the computer/OS), namely</p> <pre><code>[[1]] [1] -0.6264538 [[2]] [1] -0.8969145 </code></pre> <p>But if I use the randomForest function, I get different results depending on the OS:</p> <pre><code>library(foreach) library(doSNOW) library(parallel) library(randomForest) set.seed(123) ncores &lt;- 2 cl &lt;- makeCluster(ncores) registerDoSNOW(cl) nr &lt;- 1000 x &lt;- matrix(runif(100000), nr) y &lt;- gl(4, nr/4) trainX &lt;- x[1:800,] trainY &lt;- y[1:800] testX &lt;- x[801:nrow(x),] testY &lt;- y[801:length(y)] rf &lt;- foreach(i=1:ncores, ntree=rep(100, ncores), .packages='randomForest', .combine=combine) %dopar% { set.seed(i) randomForest(trainX, trainY, ntree=ntree) } stopCluster(cl) pred &lt;- predict(rf, new=testX) </code></pre> <p>Each windows computer (I have tried 2 windows computers) with </p> <pre><code>R version 3.0.1 (2013-05-16) Platform: i386-w64-mingw32/i386 (32-bit) </code></pre> <p>gave me the following output</p> <pre><code>table(pred) 1 2 3 4 60 68 72 0 </code></pre> <p>Running the same code on a linux computer (I have tried 2 linux computers) with </p> <pre><code>R version 2.15.3 (2013-03-01) Platform: x86_64-pc-linux-gnu (64-bit) </code></pre> <p>gave me the following output</p> <pre><code>table(pred) 1 2 3 4 69 58 73 0 </code></pre> <p>I used a seed inside the foreach loop, so I thought it should give me the same results, but it gives me only the same results for computers with the same OS. Why does this happen only with <code>randomForest</code> and not with <code>rnorm</code>? Can I do something using <code>doSNOW</code> to get the same results between windows and linux computers? I know that using <code>doRNG</code> is better, but I would like to get the same results with <code>doSNOW</code>, if it is possible...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload