I'm building a monte carlo simulation using python, and have thus far been using numpy to generate my random variates. However, I've just learned that numpy uses the Mersenne Twister algorithm to produce its random numbers, which based on my limited understanding is not desireable in monte carlo simulations. I'd much prefer to use MRG32k3a, but I'd also like to take advantage of numpy's distribution functions. Is there any way to make numpy use a generator of my choice, or is there another library that will give me the same functionality with the option of using my preferred generator?
1 Answers
Why don't you code it up yourself in python?
I found an example implementation of the algorithm at http://simul.iro.umontreal.ca/rng/MRG32k3a.c (with many others at http://www-labs.iro.umontreal.ca/~simul/rng)
If you are worried about speed (but profile it first!) you could wrap the C or F code and call it directly from python using e.g. CFFI, f2py etc - see e.g.
https://scipy-lectures.org/advanced/interfacing_with_c/interfacing_with_c.html
But given it's only a few lines of C coding it in python shouldn't be too challenging, right?
You could also submit a pull request at https://github.com/bashtage/randomgen (or ask the author nicely to include your chosen generator).
I'm sorry this doesn't address your need for distributions, but perhaps it's a start and a better answer will come along.
Also perhaps work out why Mersenne is no good for your own purposes - have you tested it and what figures of merit are you using to decide?
https://scicomp.stackexchange.com/questions/23547/parallel-mersenne-twister-for-monte-carlo might be a useful reference for you.
Can you do any precomputation?
Hope that helps in some small way.
which based on my limited understanding is not desireable in monte carlo simulations
not sure why do you think this is true. MT is quite ok for a lot of uses. Anyway, if you want alternative, take a look at github.com/bashtage/randomgen – Severin Pappadeux