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

Andrew Ekstrom @ek@trom @end|ng |rom um|ch@edu
Fri Dec 8 20:20:00 CET 2023


Each random seed will give you the same values in the same order, if you collect a string of values. But, when you change random seeds, you are guaranteed to get different values.... if you collect a string of values.

By setting the seed to a different number each time, you only get the first random value. Depending upon the application, that first seed number might come up many times. And, those numbers will come up the same every time.

Normally, you set the seed and let it ride. Neither method gives you "truely" random numbers. You can create more random data by combining some randomly generated numbers together. Say, i=(Randbetween(1,1000000)+randbetween(1, 1000000))�randbetween(1, 100000)

What type of randomness are you looking for?

Drew Ekstrom

Analytics Expert and Math Lecturer
________________________________
From: R-sig-hpc <r-sig-hpc-bounces using r-project.org> on behalf of David Lundquist <davidpatricklundquist using gmail.com>
Sent: Friday, December 8, 2023 1:49:31 PM
To: r-sig-hpc using r-project.org <r-sig-hpc using r-project.org>
Subject: [R-sig-hpc] How to attain randomness and reproducibility

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

	[[alternative HTML version deleted]]



More information about the R-sig-hpc mailing list