Gorjanc Gregor
2005-Jun-08 19:58 UTC
FW: [R] Random seed problem in MCMC coupling of chains
And a last post from Paul Gilbert. Thanks to all! This disscusion was really beneficial for me! -----Original Message----- From: Paul Gilbert [mailto:pgilbert at bank-banque-canada.ca] Sent: sre 2005-06-08 21:01 To: Gorjanc Gregor Subject: Re: [R] Random seed problem in MCMC coupling of chains Gorjanc Gregor wrote:> Thanks to Paul and Gabor for additional tips/examples. Actually, I find > Pauls suggestion with setRNG also nice and is exactly what I wanted. > Paul, if I understand this correctly, your suggestion with setRNG does not > alter "RNG flow", it just takes care that chains really have equal seeds. > I remember that I have read somewhere that destroying "RNG flow over and > over to get real randomness" is not a good idea. Can someone confirm this?In general it is a bad idea to make up your own scheme for setting or resetting the RNG. People put a lot of work into studying the properties of a RNG. When you mess with it then it is unclear what the result will be. It certainly won't be tested unless you test it yourself. If your intention is to do research on RNGs then you may want to do that, but if your intention is to do other research and just use the RNG, then don't mess with it by resetting it with your own scheme. One additional thing you may want to do is record the initial setting of the RNG information so that you can reproduce the experiment if you want to (see modification below). The idea in setRNG is to not interfere with the flow, only add a few utilities to help record and reset everything when that is what is required. In your example it is important that you generate the same number of random numbers in each pass through the chain. If that is not the case then even with the setRNG utilities there is a subtle change that you are introducing. HTH, Paul> > niter <- 3 > nchain <- 2startingRNG <- setRNG()> for (i in 1:niter) { # iterations > tmpSeed <- setRNG() > for (j in 1:nchain) { # chains > setRNG(tmpSeed) > a <- runif(1) > cat("iter:", i, "chain:", j, "runif:", a, "\n") > } > } > > iter: 1 chain: 1 runif: 0.8160078 > iter: 1 chain: 2 runif: 0.8160078 > iter: 2 chain: 1 runif: 0.4909793 > iter: 2 chain: 2 runif: 0.4909793 > iter: 3 chain: 1 runif: 0.4425924 > iter: 3 chain: 2 runif: 0.4425924 > > [... removed other stuff ...] > > Lep pozdrav / With regards, > Gregor Gorjanc > > ---------------------------------------------------------------------- > University of Ljubljana > Biotechnical Faculty URI: http://www.bfro.uni-lj.si/MR/ggorjan > Zootechnical Department mail: gregor.gorjanc <at> bfro.uni-lj.si > Groblje 3 tel: +386 (0)1 72 17 861 > SI-1230 Domzale fax: +386 (0)1 72 17 888 > Slovenia, Europe > ---------------------------------------------------------------------- > "One must learn by doing the thing; for though you think you know it, > you have no certainty until you try." Sophocles ~ 450 B.C. > ---------------------------------------------------------------------- > > > > > >
Gabor Grothendieck
2005-Jun-08 22:26 UTC
FW: [R] Random seed problem in MCMC coupling of chains
On 6/8/05, Gorjanc Gregor <Gregor.Gorjanc at bfro.uni-lj.si> wrote:> And a last post from Paul Gilbert. > > -----Original Message----- > From: Paul Gilbert [mailto:pgilbert at bank-banque-canada.ca] > > In your example it is important that you generate the same number of > random numbers in each pass through the chain. If that is not the case > then even with the setRNG utilities there is a subtle change that you > are introducing. >Note that this is actually one of the advantages of the last solution I posted, namely the one with the chain list. It maintains the flow along each chain even if different chains use different number of calls to the random number generator.