-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrbm_dream.py
33 lines (24 loc) · 977 Bytes
/
rbm_dream.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from rbmLib.rbm import *
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
if __name__ == "__main__":
rbm = RBM(filename="trainedRBMs/mnist_100.rbm")
fig = plt.figure()
hidden = np.random.random_integers(0, 1, size=rbm.nHidden)
visible = rbm.sampleVisible(hidden)
hidden = rbm.sampleHidden(visible)
visiblesReal = rbm.probVisibleGivenHidden(1, hidden).reshape((28,28))
im = plt.imshow(visiblesReal, animated=True)
plt.axis('off')
def updatefig(*args):
global visible, hidden, visiblesReal
visible = rbm.sampleVisible(hidden)
hidden = rbm.sampleHidden(visible)
# flipSelection = np.random.uniform(0, 1, size=hidden.shape) < 0.05
# hidden[flipSelection] = 1 - hidden[flipSelection]
visiblesReal = rbm.probVisibleGivenHidden(1, hidden).reshape((28,28))
im.set_array(visiblesReal)
return im,
ani = animation.FuncAnimation(fig, updatefig, interval=5, blit=True)
plt.show()