jeudi 2 février 2023

How to use different RNGs in different parts of a simulation?

This question arises from my attempt to mix two different RNGs. I'd like to mix them to achieve better performance choosing the best of the two according to the operations I need to carry out. More concretely, the two RNGs are:

  • The Mersenne Twister (MT19937) coming from the random module of Python;
  • Another RNG that can be any of the Numpy RNGs, listed here.

I'm restricted to use the Mersenne Twister of the random module since in some situations it is better than any of the others in Numpy.

So far I've only been able to implement the "safer" solution which is to use a MT19937 also in Numpy so that each time I need to use it, I pass the state from the Mersenne Twister of the random module (here for example you can obtain it with random.getstate()), do some operations with it and then pass the state back to the other. The problem with this solution is that passing the state creates a relevant overhead.

I'm unsure if other solutions can be problematic in terms of the quality/correlation of the sequence generated since I read here that using two differently seeded Mersenne Twister is not very good because the two sequences of pseudo-random numbers can be more correlated than one generated from a single one. However, in my situation I can use any of the Numpy RNG (a PCG-64 generator for example) in combination with the Python Mersenne Twister from the random module, so this is what I'd like to ask: is using a different RNG (with a different seed if useful) good enough? And also, what would be the best choice in Numpy to mix with a MT19937? Thank you in advance.




Aucun commentaire:

Enregistrer un commentaire