similar to: Best way to reset random seed when using set.seed() in a function?

Displaying 20 results from an estimated 30000 matches similar to: "Best way to reset random seed when using set.seed() in a function?"

2005 Jun 08
6
Random seed problem in MCMC coupling of chains
Hello! I am performing coupling of chains in MCMC and I need the same value of seed for two chains. I will show demo of what I want: R code, which might show my example is: niter <- 3 nchain <- 2 tmpSeed <- 123 for (i in 1:niter) { # iterations for (j in 1:nchain) { # chains set.seed(tmpSeed) a <- runif(1) cat("iter:", i, "chain:", j,
2019 Oct 30
2
set.seed() in a package
> On 30/10/2019 9:08 a.m., peter dalgaard wrote: > > You can fairly easily work around that by saving and restoring .Random.seed. This is actually quite tedious to get correct; it requires you to under how and when .Random.seed is set, and what are valid values on .Random.seed. For instance, a common mistake (me too) is to reset to .GlobalEnv$.Random.seed <- NULL in a fresh R
2019 Jun 07
1
Parallel number stream: clusterSetRNGStream
Dear All, Is the following expected behaviour? set.seed(1) library(parallel) cl = makeCluster(5) clusterSetRNGStream(cl, iseed = NULL) parSapply(cl, 1:5, function(i) sample(1:10, 1)) # 7 4 2 10 10 clusterSetRNGStream(cl, iseed = NULL) # 7 4 2 10 10 parSapply(cl, 1:5, function(i) sample(1:10, 1)) stopCluster(cl) The documentation could be read either way, e.g. * iseed: An integer to be
2009 Nov 16
2
(Parallel) Random number seed question...
Hi All, I have k identical parallel pieces of code running, each using n.rand random numbers.? I would like to use the same RNG (for now), and set the seeds so that I can guarantee that there are no overlaps in the random numbers sampled by the k pieces of code.? Another side goal is to have reproducibility of my results.? In?the past I have used C with SPRNG for this task, but I'm hoping
2011 Jul 19
4
Randomness not due to seed
I am working on a reproducible computing platform for which I would like to be able to _exactly_ reproduce an R object. However, I am experiencing unexpected randomness in some calculations. I have a hard time finding out exactly how it occurs. The code below illustrates the issue. mylm1 <- lm(dist~speed, data=cars); mylm2 <- lm(dist~speed, data=cars); identical(mylm1, mylm2); #TRUE
2008 Jul 11
1
Suggestion: 20% speed up of which() with two-character mod
Hi, by replacing 'll' with 'wh' in the source code for base::which() one gets ~20% speed up for *named logical vectors*. CURRENT CODE: which <- function(x, arr.ind = FALSE) { if(!is.logical(x)) stop("argument to 'which' is not logical") wh <- seq_along(x)[ll <- x & !is.na(x)] m <- length(wh) dl <- dim(x) if (is.null(dl)
2014 Mar 22
2
Varying results of package checks due to random seed
> From: Philippe GROSJEAN <Philippe.GROSJEAN at umons.ac.be> > > ... for latest CRAN version, we have successfully installed 4999 > packages among the 5321 CRAN package on our platform. ... It is > strange that a large portion of R CMD check errors on CRAN occur and > disappear *without any version update* of a package or any of its > direct or indirect dependencies!
2005 Sep 21
2
about set.seed
Hi there, I have some question about set.seed these days which I may need your help. I'm working on some sampling project which need to generate random numbers by some distributions(like bivariate normal). I noticed that in different computers to run my code,I got very significant different results. Then I started to try set.seed command which I wish to see by fixing the same random numbers
2019 Oct 30
2
set.seed() in a package
We commit a similar sin in the help pages, e.g. example(set.seed) ; runif(2) example(set.seed) ; runif(2) gives you the same random uniforms both times. (Of course it isn't that much of an issue, since you would rarely be running examples before any serious simulations.) You can fairly easily work around that by saving and restoring .Random.seed. I wonder if that isn't also true of the
2010 Aug 24
3
How to obtain seed after generating random number?
Dear all, I was doing an experiment to disprove some theory therefore performing lot of random simulation. Goal is to show the audience that although something has very rare chance to occur but it doesn't mean that event would be impossible. In this case after getting that rare event I need to show that same scenario for multiple times to explain other audience. Hence I need to somehow
2005 Jun 08
1
FW: Random seed problem in MCMC coupling of chains
And a last post from Paul Gilbert. Thanks to all! This disscusion was really beneficial for me! -----Original Message----- From: Paul Gilbert [mailto:pgilbert at bank-banque-canada.ca] Sent: sre 2005-06-08 21:01 To: Gorjanc Gregor Subject: Re: [R] Random seed problem in MCMC coupling of chains Gorjanc Gregor wrote: > Thanks to Paul and Gabor for additional tips/examples. Actually, I find
2011 Dec 10
0
clusterSetRNGStream() question
In a vanilla R 2.14.0 GUI session (on Windows XP SP3): > library(parallel) > cl<-makePSOCKcluster(2) > RNGkind() [1] "Mersenne-Twister" "Inversion" > clusterSetRNGStream(cl) > RNGkind() [1] "L'Ecuyer-CMRG" "Inversion" > stopCluster(cl) Is it intentional that clusterSetRNGStream() changes the RNG kind in the master process?
2018 Mar 04
0
Random Seed Location
On 04/03/2018 5:54 PM, Henrik Bengtsson wrote: > The following helps identify when .GlobalEnv$.Random.seed has changed: > > rng_tracker <- local({ > last <- .GlobalEnv$.Random.seed > function(...) { > curr <- .GlobalEnv$.Random.seed > if (!identical(curr, last)) { > warning(".Random.seed changed") > last <<- curr
2008 Apr 05
1
Random seed not reset when starting R (PR#11089)
Full_Name: Pall Melsted Version: 2.3.1 OS: WinXP Submission from: (NULL) (71.240.25.175) Random set is not reset when starting R again. When R starts with a [Previously saved workspace restored] it seems that the .Random.seed variable is already set. If you quit R (and don't save your workspace) the next time you start R .Random.seed will be set to the same value again. Steps to
2018 Mar 04
2
Random Seed Location
The following helps identify when .GlobalEnv$.Random.seed has changed: rng_tracker <- local({ last <- .GlobalEnv$.Random.seed function(...) { curr <- .GlobalEnv$.Random.seed if (!identical(curr, last)) { warning(".Random.seed changed") last <<- curr } TRUE } }) addTaskCallback(rng_tracker, name = "RNG tracker") EXAMPLE: >
2018 Mar 05
1
Random Seed Location
On Sun, Mar 4, 2018 at 3:23 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote: > On 04/03/2018 5:54 PM, Henrik Bengtsson wrote: >> >> The following helps identify when .GlobalEnv$.Random.seed has changed: >> >> rng_tracker <- local({ >> last <- .GlobalEnv$.Random.seed >> function(...) { >> curr <- .GlobalEnv$.Random.seed
2012 May 22
2
how to remove the 'promise' attribute of an R object (.Random.seed)?
Hi, The problem arises when I lazyLoad() the .Random.seed from a previously saved database. To simplify the process of reproducing the problem, see the example below: ## this assignment may not really make sense, but illustrates the problem delayedAssign('.Random.seed', 1L) typeof(.Random.seed) # [1] "integer" rnorm(1) # Error in rnorm(1) : # .Random.seed is not an integer
2012 May 22
2
how to remove the 'promise' attribute of an R object (.Random.seed)?
Hi, The problem arises when I lazyLoad() the .Random.seed from a previously saved database. To simplify the process of reproducing the problem, see the example below: ## this assignment may not really make sense, but illustrates the problem delayedAssign('.Random.seed', 1L) typeof(.Random.seed) # [1] "integer" rnorm(1) # Error in rnorm(1) : # .Random.seed is not an integer
2018 Mar 04
0
Random Seed Location
Thank you, everybody, who replied! I appreciate your valuable advise! I will move the location of the set.seed() command to after all packages have been installed and loaded. Best regards, Gary Sent from my iPad > On Mar 4, 2018, at 12:18 PM, Paul Gilbert <pgilbert902 at gmail.com> wrote: > > On Mon, Feb 26, 2018 at 3:25 PM, Gary Black <gwblack001 at sbcglobal.net> >
2018 Mar 04
3
Random Seed Location
On Mon, Feb 26, 2018 at 3:25 PM, Gary Black <gwblack001 at sbcglobal.net> wrote: (Sorry to be a bit slow responding.) You have not supplied a complete example, which would be good in this case because what you are suggesting could be a serious bug in R or a package. Serious journals require reproducibility these days. For example, JSS is very clear on this point. To your question >