Supplying seed to Stan doesn't guarantee the same chains

1.2k views Asked by At

I was trying to compare the run time of two very much equivalent but slightly different models. But the chains will always take very different time based on the random numbers sampled. So I tried to fix this supplying the same seed parameter to stan().

I tried this running the same model two times. Unfortunatelly, I found out that even the same seed will not guarantee that the process will produce the same samples! And the run time of the chains in both runs is also very different!

100 iterations, 50 warmup, 15 chains

1st run: total 57.42 seconds, chain 14: 4.515 seconds, chain 15: 2.782 seconds; 
2nd run: total 76.99 seconds, chain 14: 2.703 seconds, chain 15: 4.125 seconds.
  1. How is it possible that seed doesn't guarantee the same chains in Stan?

  2. How can this be guaranteed?

The following options were used to run Stan (rstan version 2.5.0):

t1 <- proc.time()
out7.5b <- out <- stan(fit = fit7.5b, data = win.data, init = inits,
    pars = params,
      iter = ni, warmup = nb, chains = nc, seed = 123)
t2 <- proc.time()
print(t2 - t1)
0

There are 0 answers