Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample with seed=0 and seed=1 gives identical draws #1241

Closed
nsiccha opened this issue Jan 18, 2024 · 3 comments
Closed

Sample with seed=0 and seed=1 gives identical draws #1241

nsiccha opened this issue Jan 18, 2024 · 3 comments

Comments

@nsiccha
Copy link

nsiccha commented Jan 18, 2024

Reproducible Steps:

In e.g. ~/.cmdstan/cmdstan-2.34.0/examples/bernoulli:

./bernoulli sample data file=bernoulli.data.json random seed=0 output file=0.csv
./bernoulli sample data file=bernoulli.data.json random seed=1 output file=1.csv
diff *.csv

Current Output:

< # start_datetime = 2024-01-18 07:05:35 UTC
---
> # start_datetime = 2024-01-18 07:05:39 UTC
37c37
< #   seed = 0
---
> #   seed = 1
39c39
< #   file = 0.csv
---
> #   file = 1.csv
1054,1056c1054,1056
< #  Elapsed Time: 0.013 seconds (Warm-up)
< #                0.022 seconds (Sampling)
< #                0.035 seconds (Total)
---
> #  Elapsed Time: 0.003 seconds (Warm-up)
> #                0.008 seconds (Sampling)
> #                0.011 seconds (Total)

Expected Output:

I'd expect the draws to be different. The cmdstan help (e.g. bernoulli help-all) says 0 is a valid input:

  random
    Random number configuration
    Valid subarguments: seed

    seed=<x>
      Random number generator seed
      Valid values: non-negative integer < 4294967296  or -1 to generate seed from system time
      Defaults to -1

Additional Information:

Same behavior happens for v2.33.1

Current Version:

v2.34.0

@WardBrian
Copy link
Member

This is not a Stan bug. The boost::ecuyer1988 RNG has this behavior all on its own: https://godbolt.org/z/acKhd41Pj

After stan-dev/stan#3167 last year it was recommended we stop using this generator: boostorg/random#92

@nsiccha
Copy link
Author

nsiccha commented Jan 19, 2024

Makes sense. I also had a very quick look at cmdstan's cpp, but nothing there jumped out to me as the source of this behavior :)

@WardBrian
Copy link
Member

I opened stan-dev/stan#3256, so I think we can close this one now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants