-
Notifications
You must be signed in to change notification settings - Fork 761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Seeding breaks random variate generation via copy #501
Comments
Thanks for this catch. This doesn't break when explicitly copying random variables (and not their tensors). This is what import tensorflow as tf
import edward as ed
from edward.models import Normal
do_seed = True
if do_seed:
ed.set_seed(42)
op = Normal(tf.zeros(3), tf.ones(3))
copy_op = ed.copy(op)
print(ed.get_session().run([op.value(), copy_op.value()]))
# do_seed == True: [
# array([ 0.1395757 , 1.83572245, -0.27154389], dtype=float32),
# array([-1.425722 , -1.01437879, 0.39387721], dtype=float32)
# ] The consequence of random |
Interesting. I didn't see this, since I was experimenting with bypassing edward and setting the value of the random variable directly (via value=...). In this case, the variates end up the same also - I guess unsurprising given the implementation :). My theory of why this happens: I assume the seed for the value is copied as well, when performing the copy. Whereas, copying a random variable without a fixed value at construction only copies the parameters, since its value was never added to the For reference: I'm trying something akin to |
* rename ret to new_op * rename python variables in copy; update docstrings * change op-level seed during copy; fix #501
Edward relies on
edward.copy
to generate new variates of random variables (to quote klqp.py:Copy q(z) to obtain new set of posterior samples
). Callingedward.set_seed
does seem to prevent this mechanism from working properly. Minimal example:A similar behavior can be observed when replacing op with
ed.models.Normal(0.0, 1.0).value()
. With seed it generates both two equal numbers (for example:0.1395757
and0.1395757
). Without seed two different variates are generated (for example:-0.64106858
,0.47237226
).Versions:
The text was updated successfully, but these errors were encountered: