Skip to content
Back to formatted view

Raw Message

Message-ID: <alpine.DEB.2.22.394.2312081528170.8898@iridium>
Date: 2023-12-08T20:35:49Z
From: Vladimir Dergachev
Subject: How to attain randomness and reproducibility
In-Reply-To: <CAGL11=4pnGsjWK_=QNV4e8_PqNXm2rHxpGr2uFqN+Egn8T61bQ@mail.gmail.com>

One possibility to consider is using a hash function to get random 
numbers:

r = hash(GLOBAL_SEED, parameter1, parameter2, parameter3)

This way the random numbers r are the same for each combination of 
parameters. This stays so even when you change how many parameters you go 
over. And if you want to get a different realization you just change 
GLOBAL_SEED.

There is a implementation of hash function in RMVL package as 
"mvl_hash_vectors" that returns uniformly distributed values between 1.0 
and 2.0.

best

Vladimir Dergachev


On Fri, 8 Dec 2023, David Lundquist wrote:

> Currently, I am using the foreach package in R to do the following (in
> R-flavored pseudocode):
>
> *set.seed(1)*
> *foreach square in big grid of parameter combinations **%dopar%*
> *     foreach i in 1:replication_count **%do%*
> *            do some computation, output a row, and rbind it*
> *save the df generated by rbinding*
>
> Possible virtues of the preceding: seed is made clear
> Possible vices of the preceding: failure of randomness
>
> One might therefore try moving set.seed to the inner loop:
>
> *foreach square in big grid of parameter combinations %dopar%*
> *     foreach i in 1:replication_count **%do%*
>            *set.seed(i)*
> *            do some computation, output a row, and rbind it*
> *save the df generated by rbinding*
>
> Possible virtues of the preceding: seed sequence is explicit
> Possible vices of the preceding: we've programmed the seeds to be equal
>
> I'd appreciate any advice, especially if there's an easy reference/vignette
> that can be pointed to, a la
>
> https://cran.r-project.org/web/packages/doRNG/vignettes/doRNG.pdf
> https://cran.r-project.org/web/packages/dqrng/vignettes/parallel.html
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-hpc mailing list
> R-sig-hpc at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
>