abcpmc icon indicating copy to clipboard operation
abcpmc copied to clipboard

random seeds are now perturbed with time. and can now give random str…

Open ffinger opened this issue 9 years ago • 16 comments

…eam to postfn

ffinger avatar Apr 07 '16 18:04 ffinger

By using time the entire system becomes non-deterministic i.e. it will be impossible to reproduce the exact same result.

jakeret avatar Apr 18 '16 07:04 jakeret

yes, I do agree. On the other hand I think it is quite important that the seed is not the same (1...N) in every calibration run. How about seeding the main process, drawing k random numbers (k=number of workers in the pool), which then serve to seed the generators of all workers? in this way the system is deterministic but still depends on the main seed, which can be changed.

also, I think it is very important to pass on the Random Stream to the postfn function, so that random numbers needed to compute the likelihood come from the same stream. otherwise they come from numpy.random, whose state random state (in Unix) is inherited from the main process, and thus the random numbers in the postfn function on different processes are identical.

ffinger avatar Apr 18 '16 09:04 ffinger

Ah, now I see the issue that the current reseeding causes. Creating the seeds in the main process is actually a good idea. I need to think about what happens when paralellizing with MPI but at the moment I think it could do the trick.

I would like to keep the function signature of postfn as simple as possible. One has the option to perturb numpy's seed using the passed theta values or time.

jakeret avatar Apr 18 '16 09:04 jakeret

I would like to keep the function signature of postfn as simple as possible. One has the option to perturb numpy's seed using the passed theta values or time.

How about making random state an optional argument then?

ffinger avatar Apr 18 '16 10:04 ffinger

Do you see an other way to do this than wrapping the postfn-call in a try-except? This is not very elegant, in particular because in 99% of the applications it will fall in the except block

jakeret avatar Apr 19 '16 11:04 jakeret

I do not have experience with this, but the inspect module might be an option. You can get the number of arguments a function takes as well as the names of kwargs. http://stackoverflow.com/questions/4674875/python-function-parameter-count

ffinger avatar Apr 19 '16 13:04 ffinger

Inspecting the callable before the call to identify the number of params feels a bit like overkill and not very pythonic

jakeret avatar Apr 21 '16 08:04 jakeret

right. maybe use a parameter that can be True or False when you setup the sampler object? it can be False by default, so no random state object is given to postfn, but if it is True you give one.

2016-04-21 10:23 GMT+02:00 jakeret [email protected]:

Inspecting the callable before the call to identify the number of params feels a bit like overkill and not very pythonic

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/jakeret/abcpmc/pull/10#issuecomment-212802404

ffinger avatar Apr 21 '16 13:04 ffinger

I just implemented what I wrote in my last comment. Up to you if you like it and want to include it in your version. For my application it is necessary.

ffinger avatar Apr 21 '16 14:04 ffinger

Could you give me some information on your application so that I can understand why it's neccessary?

jakeret avatar Apr 22 '16 06:04 jakeret

Coverage Status

Coverage decreased (-0.6%) to 91.571% when pulling 3bad25006ac6b73244da4c8aeec35cc2c4212426 on ffinger:master into bd4e22f5e84ed0941e6cfccf589390986700e0e4 on jakeret:master.

coveralls avatar Apr 22 '16 08:04 coveralls

Because I am using it to calibrate a stochastic model (that means I make extensive use of random numbers in the model) and I would like to be able to control the rng state of the model too, otherwise the calibration is not reproducible.

ffinger avatar Apr 22 '16 08:04 ffinger

Can't you use the theta values passed to your function to seed the RandomState in your model?

jakeret avatar Apr 22 '16 08:04 jakeret

You mean a seed depending on the parameter values? I don't get it.

2016-04-22 10:45 GMT+02:00 jakeret [email protected]:

Can't you use the theta values passed to your function to seed the RandomState in your model?

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/jakeret/abcpmc/pull/10#issuecomment-213332786

ffinger avatar Apr 22 '16 10:04 ffinger

Exactly, e.g. define the seed to be the sum or product over all the parameters. In principle the proposed parameters all come from a reproducible rng stream. It's not perfect but simple

jakeret avatar Apr 22 '16 11:04 jakeret

But then the seed is the same for a given parameter set. Not a good idea for a stochastic model, where you want to have variability among different runs of the same model with the same parameters.

2016-04-22 13:28 GMT+02:00 jakeret [email protected]:

Exactly, e.g. define the seed to be the sum or product over all the parameters. In principle the proposed parameters all come from a reproducible rng stream. It's not perfect but simple

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/jakeret/abcpmc/pull/10#issuecomment-213386535

ffinger avatar Apr 22 '16 11:04 ffinger