def _test(x, n, p):
    xtf = tf.constant(x)
    val_true = multinomial_logpmf_vec(x, n, p)
    _assert_eq(multinomial.logpmf(xtf, n, p), val_true)
    _assert_eq(multinomial.logpmf(xtf, n, tf.constant(p, dtype=tf.float32)),
               val_true)
    _assert_eq(multinomial.logpmf(xtf, n, p), val_true)
    _assert_eq(multinomial.logpmf(xtf, n, tf.constant(p, dtype=tf.float32)),
               val_true)
def _test_logpdf(x, n, p):
    xtf = tf.constant(x)
    val_true = multinomial_logpmf(x, n, p)
    _assert_eq(multinomial.logpmf(xtf, n, p),
               val_true)
    _assert_eq(multinomial.logpmf(xtf, n, tf.constant(p, dtype=tf.float32)),
               val_true)
    _assert_eq(multinomial.logpmf(xtf, n, p),
               val_true)
    _assert_eq(multinomial.logpmf(xtf, n, tf.constant(p, dtype=tf.float32)),
               val_true)
 def _test(self, x, n, p):
     xtf = tf.constant(x)
     val_true = multinomial_logpmf_vec(x, n, p)
     with self.test_session():
         self.assertAllClose(multinomial.logpmf(xtf, n, p).eval(),
                    val_true)
         self.assertAllClose(multinomial.logpmf(xtf, n, tf.constant(p, dtype=tf.float32)).eval(),
                    val_true)
         self.assertAllClose(multinomial.logpmf(xtf, n, p).eval(),
                    val_true)
         self.assertAllClose(multinomial.logpmf(xtf, n, tf.constant(p, dtype=tf.float32)).eval(),
                    val_true)
Example #4
0
 def _test(self, x, n, p):
     xtf = tf.constant(x)
     val_true = multinomial_logpmf_vec(x, n, p)
     with self.test_session():
         self.assertAllClose(multinomial.logpmf(xtf, n, p).eval(), val_true)
         self.assertAllClose(
             multinomial.logpmf(xtf, n,
                                tf.constant(p, dtype=tf.float32)).eval(),
             val_true)
         self.assertAllClose(multinomial.logpmf(xtf, n, p).eval(), val_true)
         self.assertAllClose(
             multinomial.logpmf(xtf, n,
                                tf.constant(p, dtype=tf.float32)).eval(),
             val_true)
Example #5
0
 def log_prob_idx(self, idx, xs):
     """
     ``log p(xs[:, idx, :] | params[idx, :])``
     where ``idx`` is of dimension ``shape[:-1]``
     """
     idx_K = idx + (slice(0, None), ) # slice over multivariate dimension
     full_idx = (slice(0, None), ) + idx_K # slice over batch size
     return multinomial.logpmf(xs[full_idx], np.ones(self.shape[:-1])[idx], self.pi[idx_K])
Example #6
0
    def log_prob_zi(self, i, zs):
        """log q(z_i | lambda)"""
        # Note this calculates the log density with respect to z_i,
        # which is the ith factor and not the ith latent variable.
        if i >= self.num_factors:
            raise IndexError()

        return multinomial.logpmf(zs[:, (i * self.K):((i + 1) * self.K)], 1,
                                  self.pi[i, :])
Example #7
0
    def log_prob_zi(self, i, zs):
        """log q(z_i | lambda)"""
        # Note this calculates the log density with respect to z_i,
        # which is the ith factor and not the ith latent variable.
        if i >= self.num_factors:
            raise IndexError()

        return multinomial.logpmf(zs[:, (i*self.K):((i+1)*self.K)],
                                  1, self.pi[i, :])
Example #8
0
 def log_prob_idx(self, idx, xs):
     """
     ``log p(xs[:, idx, :] | params[idx, :])``
     where ``idx`` is of dimension ``shape[:-1]``
     """
     idx_K = idx + (slice(0, None), )  # slice over multivariate dimension
     full_idx = (slice(0, None), ) + idx_K  # slice over sample size
     return multinomial.logpmf(xs[full_idx],
                               np.ones(self.shape[:-1])[idx],
                               self.pi[idx_K])
 def _test(self, x, n, p):
   val_true = multinomial_logpmf_vec(x, n, p)
   with self.test_session():
     self.assertAllClose(multinomial.logpmf(x, n=n, p=p).eval(), val_true)