Beispiel #1
0
 def get_h_and_v(self, num_samples):
     z = sample_from_bernoulli(
         tf.constant(.5,
                     shape=(num_samples, self.dim_z2h[0]),
                     dtype=tf.float32))
     h = gumbel_sigmoid_sample(self.z2h(z), self.temp, self.hard)
     v = gumbel_sigmoid_sample(self.h2v(h), self.temp, self.hard)
     return h, v
Beispiel #2
0
 def sample(self, num_samples):
     z = sample_from_bernoulli(
         tf.constant(.5,
                     shape=(num_samples, self.dims[0]),
                     dtype=tf.float32))
     h2 = gumbel_sigmoid_sample(self.inference(z), self.temp, self.hard)
     return h2
Beispiel #3
0
 def logprobs_all(self, num_samples):
     z = sample_from_bernoulli(
         tf.constant(.5,
                     shape=(num_samples, self.dims[0]),
                     dtype=tf.float32))
     mu = self.inference(z)
     h = gumbel_sigmoid_sample(mu, self.temp, self.hard)
     logp_z = bernoulli_log_likelihood(
         z, tf.constant(.5, shape=z.shape, dtype=tf.float32))
     logp_h_given_z = bernoulli_log_likelihood(h, mu)
     return logp_z + logp_h_given_z, z, h
Beispiel #4
0
 def _test_gumbel(self, num_samples=1):
     z = sample_from_bernoulli(
         tf.constant(.5,
                     shape=(num_samples, self.dim_z2h[0]),
                     dtype=tf.float32))
     h_mu = self.z2h(z)
     h_hard = gumbel_sigmoid_sample(h_mu, self.temp, True)
     h_soft = gumbel_sigmoid_sample(h_mu, self.temp, False)
     print 'h_mu\n', h_mu, 'h_hard\n', h_hard, 'h_soft\n', h_soft
     v_mu = self.h2v(h_hard)
     v_hard = gumbel_sigmoid_sample(v_mu, self.temp, True)
     v_soft = gumbel_sigmoid_sample(v_mu, self.temp, False)
     print 'v_mu\n', v_mu, 'v_hard\n', v_hard, 'v_soft\n', v_soft
     v_mu = self.h2v(h_soft)
     v_hard = gumbel_sigmoid_sample(v_mu, self.temp, True)
     v_soft = gumbel_sigmoid_sample(v_mu, self.temp, False)
     print 'v_mu\n', v_mu, 'v_hard\n', v_hard, 'v_soft\n', v_soft
     exit()
 def log_conditional_prob(self, x):
     # E_{Q(h|x)} log Q(h|x)
     h_mu = self.inference(x)
     h = gumbel_sigmoid_sample(h_mu, self.temp, self.hard)
     logp_h_given_x = bernoulli_log_likelihood(h, h_mu)
     return logp_h_given_x, h
 def get_h_soft(self, x):
     return gumbel_sigmoid_sample(self.inference(x), self.temp, self.hard)
Beispiel #7
0
 def get_h_and_v(self, num_samples):
     h = self.prior_h.sample(num_samples)
     v = gumbel_sigmoid_sample(self.h2v(h), self.temp, self.hard)
     return h, v
Beispiel #8
0
 def sample(self, num_samples):
     index = gumbel_softmax_sample(
         tf.tile(self.pi_logits, [num_samples, 1]), self.temp)
     sample_mus = tf.matmul(index, self.mus)
     return gumbel_sigmoid_sample(sample_mus, self.temp, self.hard)