Last active
August 29, 2015 14:08
-
-
Save mgermain/2ceba111d93cdb717b28 to your computer and use it in GitHub Desktop.
Theano MRG_RandomStreams backup test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from theano.sandbox.rng_mrg import MRG_RandomStreams | |
rng = MRG_RandomStreams(seed=1234) | |
mult = rng.multinomial(pvals=[[.3,.3,.3]]) | |
# Backup random state | |
rst = rng.rstate.copy() | |
rst_upd = [s[0].get_value() for s in rng.state_updates] | |
# Use the random | |
print "Using random" | |
for i in range(5): | |
print mult.eval() | |
# Reset random state | |
rng.rstate = rst | |
for i in range(len(rng.state_updates)): | |
rng.state_updates[i][0].set_value(rst_upd[i]) | |
# Re-Use the random to make sure it was reseted | |
print "Re-Using random" | |
for i in range(5): | |
print mult.eval() | |
# Find Nan | |
# len(np.where(np.isnan(rst_upd) == True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
Using random
[[0 1 0]]
[[0 1 0]]
[[1 0 0]]
[[0 1 0]]
[[0 1 0]]
Re-Using random
[[0 1 0]]
[[0 1 0]]
[[1 0 0]]
[[0 1 0]]
[[0 1 0]]