From savicky at cs.cas.cz  Fri Mar  2 14:51:30 2012
From: savicky at cs.cas.cz (Petr Savicky)
Date: Fri, 2 Mar 2012 14:51:30 +0100
Subject: [Rd] portable parallel seeds project: request for critiques
In-Reply-To: <CAMd4_Ae_Lpr_S_oQH-voUSaymoqBpWBAw71M6ufRgLHV2BEBtQ@mail.gmail.com>
References: <CAErODj-KZo+Am6a30pnVrPC-STw++500=QOi-rZaMsXYWzeX+Q@mail.gmail.com>
	<20120217230633.GA19243@cs.cas.cz>
	<CAMd4_AdVia=Ur530VEyqUxH9vf52E6-SyzgakGZm9K1ncD2GYg@mail.gmail.com>
	<20120302112441.GA28122@cs.cas.cz>
	<CAMd4_Ae_Lpr_S_oQH-voUSaymoqBpWBAw71M6ufRgLHV2BEBtQ@mail.gmail.com>
Message-ID: <20120302135129.GA11697@cs.cas.cz>

On Fri, Mar 02, 2012 at 01:36:34PM +0100, Karl Forner wrote:
> Thanks for your quick reply.
> 
> About the rngSetSeed package: is it usable at c/c++ level ?

Not directly. The rngSetSeed package is meant to provide an R-level
alternative to set.seed() for Mersenne-Twister with a better guarantee
that different seeds provide unrelated streams. In particular, with
rngSetSeed, it should be safe to reseed quite often, for example
in each iteration of a loop like

  for (i in 1:n) {
      setVectorSeed(c(base.seed, i))
      # some code
  }

Otherwise everything remains the same as with set.seed(). In order
to maintain several streams, one has to maintain copies of .Random.seed
and use them, when required.

> Hmm I had not paid attention to the last paragraph:
> 
> > The seeding procedure used in the
> > present software use*s a separate random number* generator of a different
> > design in order to
> > avoid any interference. An extra feature is the RandomInitByArray function
> > which makes
> > it possible to initialize the random number generator with multiple seeds.
> > We can make sure
> > that the streams have different starting points by using the thread id as
> > one of the seeds.
> >
> 
> So it means that I am already using this solution ! (in the RcppRandomSFTM,
> see other post).
> and that I should be reasonably safe.

If RcppRandomSFTM uses the initialization for SFMT provided by the
authors of SFMT, then you should be reasonably safe. I do not know
exactly the SFMT initializations, but for the original Mersenne-Twister,
the initializations from 2002, both the single number seed and a vector
seed avoid known problems with the previous initializations. It should
be pointed out, however, that the initialization by array from 2002 is
more careful than the single number initialization, So, it is better to
use the array initialization even for a single number seed.

Petr Savicky.



[Rd] portable parallel seeds project: request for critiques
Petr Savicky