[R-sig-hpc] How to attain randomness and reproducibility

Vladimir Dergachev vo|ody@ @end|ng |rom m|nd@pr|ng@com
Fri Dec 8 21:35:49 CET 2023


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 using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
>



More information about the R-sig-hpc mailing list