2016-04-14 5 views
0

snow::clusterApplyを使用して並列に関数を適用したい。私の関数は、関数の一部で一時的な(事前定義された)シードを使用しますが、一般的に独立した乱数を保持する必要があります。一時的な種は、それぞれの「仕事」ごとに異なります。R snow rlecuyer:テンポラリーシード付き関数を適用する

私は、次の操作を行うことができます

# setting up cluster of type="SOCK" 
library(snow) 
cl <- makeSOCKcluster(2) 

# this is my function 
myfu <- function(seed){ 
    # temporary seed: 
    x <- R.utils::withSeed(rnorm(10),seed) 
    # more calculation with independent RNG: 
    y <- x*rnorm(10) 
    return(list(stays=x,changes=y)) 
} 

# run example: 
seed <- 1:4 
data.frame(clusterApply(cl,seed,myfu)) 
# reproduce 
data.frame(clusterApply(cl,seed,myfu)) 

stopCluster(cl) 

しかし、雪のパッケージのドキュメント(http://homepage.stat.uiowa.edu/~luke/R/cluster/cluster.html)での「SNOW Clustersでの一様乱数の生成」に与えられたリンク以下、私はデフォルトの「という読み乱数ジェネレータは非常に関連性があると思われます。 "パッケージrlecuyer。今

、私は私のコードでは、set.seedまたはwithSeedがこれ以上何も使用されていないことなどがしようとした場合:

私は上でそれらを呼び出す必要があるとき、私は、並列に set.seedwithSeedを回避するにはどうすればよい
# setting up cluster of type="SOCK" 
library(snow) 
library(rlecuyer) 
cl <- makeSOCKcluster(2) 

# setup RNG Stream 
clusterSetupRNGstream(cl,seed=1:6) 

# run example: 
seed <- 1:4 
data.frame(clusterApply(cl,seed,myfu)) 
# can't reproduce 
data.frame(clusterApply(cl,seed,myfu)) 

stopCluster(cl) 

仕事をしていて、clusterApplyに電話する前ではありませんか?

答えて

0

愚かな私。 kind="L'Ecuyer-CMRG"を使用してset.seed/withSeedを呼び出すと(もちろん)私の問題は解決します。

関連する問題