def build_vae(d_z=2, d_hidden=256, d_x=784, N=100, total_N=60000): # MODEL z = Gaussian(mean=0, std=1.0, shape=(N, d_z), name="z", local=True) X = neural_bernoulli(z, d_hidden=d_hidden, d_out=d_x, name="X", local=True) # OBSERVED DATA x_placeholder = X.observe_placeholder() # VARIATIONAL MODEL q_z = neural_gaussian(X=x_placeholder, d_hidden=d_hidden, d_out=d_z, name="q_z") z.attach_q(q_z) jm = Model(X, minibatch_ratio=total_N / float(N)) return jm, x_placeholder
def autoencoder(): d_z = 2 d_hidden=256 d_x = 28*28 N=100 from util import get_mnist Xdata, ydata = get_mnist() Xbatch = tf.constant(np.float32(Xdata[0:N])) z = Gaussian(mean=0, std=1.0, shape=(N,d_z), name="z") X = neural_bernoulli(z, d_hidden=d_hidden, d_out=d_x, name="X") X.observe(Xbatch) q_z = neural_gaussian(X=Xbatch, d_hidden=d_hidden, d_out=d_z, name="q_z") z.attach_q(q_z) jm = Model(X) return jm