[R] Random seed problem in MCMC coupling of chains
Jan T. Kim
jtk at cmp.uea.ac.uk
Wed Jun 8 21:45:21 CEST 2005
On Wed, Jun 08, 2005 at 12:55:07PM -0400, Gabor Grothendieck wrote:
> That could be addressed like this (where changing the offset
> changes the experiment).
>
> offset <- 123
>
> niter <- 3
> nchain <- 2
> for (i in 1:niter) { # iterations
> for (j in 1:nchain) { # chains
> set.seed(i+offset)
> a <- runif(1)
> cat("iter:", i, "chain:", j, "runif:", a, "\n")
> }
> }
>
> On 6/8/05, Paul Gilbert <pgilbert at bank-banque-canada.ca> wrote:
> > Beware that your easy trick will give you the same result every time you
> > run it. You need a better scheme if you actually intend to get a new
> > experiment each time you run it.
That's not a bad thing per se; in fact, it's a good thing to be able
to exactly reproduce the results you obtained with your software.
Personally, I dislike the "convenience" feature of random number
generators of generating a seed, frequently based on the system time,
if none has been set explicitly; I always set a seed and frequently
make the seed a commandline option or part of the control parameter
file or the like.
>From this perspective, Gabor's solution seems perfect to me.
> > Paul
> >
> > Gorjanc Gregor wrote:
> >
> > > Thanks to Duncan, Dimitris as well as James for answers. I'll provide
> > > here also example from James, which seems to be the easiest of them
> > > all and was not posted to the list:
> > >
> > > niter <- 3
> > > nchain <- 2
> > > for (i in 1:niter) { # iterations
> > > for (j in 1:nchain) { # chains
> > > set.seed(i)
> > > a <- runif(1)
> > > cat("iter:", i, "chain:", j, "runif:", a, "\n")
> > > }
> > > }
> > >
> > > Note that seed is set with iteration counter. This is really neat and
> > > simple. I am just wondering if this is OK from "RNG point of view". Can
> > > someone comment on that?
The only concern I could think about is the case of a bad random number
generator, in which the first couple of values are not entirely
uncorrelated to the seed. But I'd be very surprised if that was a
problem with R's RNGs -- I guess it's memories of lousy implementations
C library rand() functions that make me write this remark.
Best regards, Jan
--
+- Jan T. Kim -------------------------------------------------------+
| *NEW* email: jtk at cmp.uea.ac.uk |
| *NEW* WWW: http://www.cmp.uea.ac.uk/people/jtk |
*-----=< hierarchical systems are for files, not for humans >=-----*
More information about the R-help
mailing list