mattja / sdeint

Numerical integration of Ito or Stratonovich SDEs
GNU General Public License v3.0
154 stars 25 forks source link

Random seed for reproducibility #14

Closed PHTHK closed 5 years ago

PHTHK commented 5 years ago

It is possible to have random seed input as an argument (e.g. itoEuler(f, G, y0, tspan, random_state=1)) for reproducibility purpose?

Thanks

mattja commented 5 years ago

It is not necessary to add that functionality to sdeint.

sdeint uses numpy to generate random numbers.

If you want to use a known random seed, just call numpy.random.seed(1234) at the start of your code. This takes an integer seed between 0 and 2**32-1 inclusive.

N.B. If you are running multiple python processes or threads to get many realizations of a random process, such as on a cluster, then you need to make sure that each python process uses a different seed.

superconvergence commented 5 years ago

Formally, different seeds will ensure independence of the random generator instances but not necessarily independent random number sequences. If this is important for your setup, you can use an external random generator that supports a method to produce independent streams (see e.g. github/randomgen). Note that sdeint integrators already allow easy input of random increments via the dW argument.

mattja commented 5 years ago

This is a good point. Thanks for pointing out the randomgen project.