jaberg / pyll

3 stars 5 forks source link

how do I sample a consistent random seem in pyll? #4

Open yamins81 opened 12 years ago

yamins81 commented 12 years ago

e.g. the replacement of

genson_template.sample(seed)

?

Right now,

 stochastic.sample(template, np.random.RandomState(seed))

does NOT yield the same result on each call with a fixed seed, e.g. 0. Is it supposed to? If so, I'll submit a test

jaberg commented 12 years ago

True, that function makes no attempt to replicate the traversal order of genSON.

See #2 for the need for genson-compatible sampling and grid iteration.

jaberg commented 12 years ago

The ticket is worded ambiguously and suggests that calling sample twice with the same seed yields two different results. This would be terrible, but it is not what happens. There are unit tests protecting against this behaviour. Given the scary suggestion of the issue's wording and the redundancy with #2, I'm closing it.

yamins81 commented 12 years ago

The situation described above IS what happens, in some sense In other words, two calls of exactly this: stochastic.sample(T, np.random.RandomState(0)) one right after the other, yield different results. It seems to be required that one re-initialize the T object to get back to the original state ... I was expecting a different behavior, one in which the passed RandomState object somehow is the only source of randomness -- and not some state that is set/saved in the T object.

jaberg commented 12 years ago

Need an example then, because test_repeatable passes, as expected. There's something subtler going on.

yamins81 commented 12 years ago

eccv12.lfw.MainBandit has this issue. e.g.

In [124]: L = eccv12.lfw.MainBandit()

In [125]: pyll.stochastic.sample(L.template, np.random.RandomState(0))['slm'][-1][-1][-1]['kwargs']['stretch'] Out[125]: array(6.527903170054908)

In [126]: pyll.stochastic.sample(L.template, np.random.RandomState(0))['slm'][-1][-1][-1]['kwargs']['stretch'] Out[126]: array(3.1720174206929608)