1

I am rewriting a Python module in C++ using Boost Python. The Python module samples numbers from various random distributions, using numpy.random. For the C++ version, I am using the GSL.

I would like to test my new module to ensure parity with the old version. I understand that to do this, the random number generators (which are Mersenne Twisters in both cases) should have their seeds set identically.

However, from this question, it seems that just setting the seed is not sufficient, the random state should set shared as well.

Is it possible to do this between these two libraries?

user5697101
  • 571
  • 4
  • 12
  • 1
    If you can get the state from GSL, you can set it in numpy with [this](https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.random.RandomState.set_state.html). – Reti43 Feb 09 '19 at 16:30
  • Does your Python module rely on reproducible "randomness"? That is, does your Python module meet the criteria I give in "[When to Use a Seeded PRNG](https://peteroupc.github.io/random.html#When_to_Use_a_Seeded_PRNG)"? – Peter O. Feb 09 '19 at 18:28
  • The point of the answer you linked is that for the same PRNG algorithm but a different seeding algorithm, the seed is not really relevant for sharing, only the state. See [this conceptual explanation](https://stackoverflow.com/a/48505649/2166798). It looks like Python and GSL are using different `f()`'s in that notation. – pjs Feb 09 '19 at 18:57
  • @PeterO. The application is a Monte-Carlo tree search. I am trying to reproduce the same result in both the Python module and C++ module, so yes I believe it meets the criteria set out. – user5697101 Feb 09 '19 at 20:27
  • @pjs Does that mean that what is required is to obtain the internal state_0 from GSL and set it as the numpy generator's initial state? – user5697101 Feb 09 '19 at 20:30
  • It doesn't matter which way it goes, but yes, it means that the two Mersenne Twisters have to start from the same state. That's not the same thing as starting with the same seed if they use different seeding algorithms. – pjs Feb 09 '19 at 21:28

0 Answers0