def test_logpdf_1d():
    x = tf.constant([0.5])
    val_true = stats.beta.logpdf([0.5], 0.5, 0.5)
    _assert_eq(beta.logpdf(x, tf.constant(0.5), tf.constant(0.5)), val_true)
    _assert_eq(beta.logpdf(x, tf.constant([0.5]), tf.constant(0.5)), val_true)
    _assert_eq(beta.logpdf(x, tf.constant(0.5), tf.constant([0.5])), val_true)
    _assert_eq(beta.logpdf(x, tf.constant([0.5]), tf.constant([0.5])), val_true)
示例#2
0
def _test_logpdf_scalar(x, a=0.5, b=0.5):
    xtf = tf.constant(x)
    val_true = stats.beta.logpdf(x, a, b)
    _assert_eq(beta.logpdf(xtf, tf.constant(a), tf.constant(b)), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant([a]), tf.constant(b)), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant(a), tf.constant([b])), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant([a]), tf.constant([b])), val_true)
示例#3
0
 def _test(self, x, a, b):
   xtf = tf.constant(x)
   val_true = stats.beta.logpdf(x, a, b)
   with self.test_session():
     self.assertAllClose(beta.logpdf(xtf, a, b).eval(), val_true)
     self.assertAllClose(beta.logpdf(xtf, tf.constant(a),
                                     tf.constant(b)).eval(), val_true)
def _test_logpdf_scalar(x, a=0.5, b=0.5):
    xtf = tf.constant(x)
    val_true = stats.beta.logpdf(x, a, b)
    _assert_eq(beta.logpdf(xtf, tf.constant(a), tf.constant(b)), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant([a]), tf.constant(b)), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant(a), tf.constant([b])), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant([a]), tf.constant([b])), val_true)
def _test_logpdf_scalar(scalar, a=.5, b=.5):
    x = tf.constant(scalar)
    val_true = stats.beta.logpdf(scalar, a, b)
    _assert_eq(beta.logpdf(x, tf.constant(a), tf.constant(b)), val_true)
    _assert_eq(beta.logpdf(x, tf.constant([a]), tf.constant(b)), val_true)
    _assert_eq(beta.logpdf(x, tf.constant(a), tf.constant([b])), val_true)
    _assert_eq(beta.logpdf(x, tf.constant([a]), tf.constant([b])), val_true)
示例#6
0
def _test(x, a, b):
    xtf = tf.constant(x)
    val_true = stats.beta.logpdf(x, a, b)
    _assert_eq(beta.logpdf(xtf, a, b), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant(a), tf.constant(b)), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant([a]), tf.constant(b)), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant(a), tf.constant([b])), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant([a]), tf.constant([b])), val_true)
示例#7
0
def _test(x, a, b):
    xtf = tf.constant(x)
    val_true = stats.beta.logpdf(x, a, b)
    _assert_eq(beta.logpdf(xtf, a, b), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant(a), tf.constant(b)), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant([a]), tf.constant(b)), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant(a), tf.constant([b])), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant([a]), tf.constant([b])), val_true)
示例#8
0
 def _test(self, x, a, b):
     xtf = tf.constant(x)
     val_true = stats.beta.logpdf(x, a, b)
     with self.test_session():
         self.assertAllClose(beta.logpdf(xtf, a, b).eval(), val_true)
         self.assertAllClose(beta.logpdf(xtf, tf.constant(a), tf.constant(b)).eval(), val_true)
         self.assertAllClose(beta.logpdf(xtf, tf.constant([a]), tf.constant(b)).eval(), val_true)
         self.assertAllClose(beta.logpdf(xtf, tf.constant(a), tf.constant([b])).eval(), val_true)
         self.assertAllClose(beta.logpdf(xtf, tf.constant([a]), tf.constant([b])).eval(), val_true)
def test_logpdf_1d():
    x = [0.5]
    xtf = tf.constant([0.5])
    val_true = stats.beta.logpdf(x, 0.5, 0.5)
    _assert_eq(beta.logpdf(xtf, tf.constant(0.5), tf.constant(0.5)), val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant([0.5]), tf.constant(0.5)),
               val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant(0.5), tf.constant([0.5])),
               val_true)
    _assert_eq(beta.logpdf(xtf, tf.constant([0.5]), tf.constant([0.5])),
               val_true)
示例#10
0
 def log_prob(self, xs, zs):
     log_prior = beta.logpdf(zs, a=1.0, b=1.0)
     log_lik = tf.pack([
         tf.reduce_sum(bernoulli.logpmf(xs['x'], z)) for z in tf.unpack(zs)
     ])
     return log_lik + log_prior
示例#11
0
 def log_prob_idx(self, idx, xs):
     full_idx = (slice(0, None), ) + idx # slice over batch size
     return beta.logpdf(xs[full_idx], self.alpha[idx], self.beta[idx])
示例#12
0
    def log_prob_zi(self, i, zs):
        """log q(z_i | lambda)"""
        if i >= self.num_factors:
            raise IndexError()

        return beta.logpdf(zs[:, i], self.a[i], self.b[i])
示例#13
0
    def log_prob_i(self, i, xs):
        """log p(x_i | params)"""
        if i >= self.num_factors:
            raise IndexError()

        return beta.logpdf(xs[:, i], self.alpha[i], self.beta[i])
示例#14
0
 def log_prob_idx(self, idx, xs):
     full_idx = (slice(0, None), ) + idx  # slice over sample size
     return beta.logpdf(xs[full_idx], self.alpha[idx], self.beta[idx])
示例#15
0
    def log_prob_zi(self, i, z):
        """log q(z_i | lambda_i)"""
        if i >= self.num_vars:
            raise

        return beta.logpdf(z[:, i], self.a[i], self.b[i])
示例#16
0
 def _test(self, x, a, b):
   val_true = stats.beta.logpdf(x, a, b)
   with self.test_session():
     self.assertAllClose(beta.logpdf(x, a=a, b=b).eval(), val_true)
示例#17
0
 def log_prob(self, xs, zs):
   log_prior = beta.logpdf(zs['p'], a=1.0, b=1.0)
   log_lik = tf.reduce_sum(bernoulli.logpmf(xs['x'], p=zs['p']))
   return log_lik + log_prior
示例#18
0
 def log_prob(self, xs, zs):
     log_prior = beta.logpdf(zs, a=1.0, b=1.0)
     log_lik = tf.pack([tf.reduce_sum(bernoulli.logpmf(xs['x'], z))
                        for z in tf.unpack(zs)])
     return log_lik + log_prior
 def _test(self, x, a, b):
     val_true = stats.beta.logpdf(x, a, b)
     with self.test_session():
         self.assertAllClose(beta.logpdf(x, a=a, b=b).eval(), val_true)
示例#20
0
    def log_prob_zi(self, i, zs):
        """log q(z_i | lambda)"""
        if i >= self.num_factors:
            raise IndexError()

        return beta.logpdf(zs[:, i], self.a[i], self.b[i])
示例#21
0
    def log_prob_zi(self, i, z):
        """log q(z_i | lambda_i)"""
        if i >= self.num_vars:
            raise

        return beta.logpdf(z[:, i], self.a[i], self.b[i])
示例#22
0
 def log_prob(self, xs, zs):
     log_prior = beta.logpdf(zs['p'], a=1.0, b=1.0)
     log_lik = tf.reduce_sum(bernoulli.logpmf(xs['x'], p=zs['p']))
     return log_lik + log_prior
示例#23
0
 def log_prob(self, xs, zs):
     log_prior = beta.logpdf(zs[:, 0], a=1.0, b=1.0)
     log_lik = tf.concat(0, [
         tf.reduce_sum(bernoulli.logpmf(xs, z)) \
         for z in tf.unpack(zs)])
     return log_lik + log_prior