Beispiel #1
0
 def test_all_finite_raises(self):
     with self.test_session():
         x = tf.constant([12.5, np.inf])
         with self.assertRaisesOpError('Inf'):
             to_simplex(x).eval()
         x = tf.constant([12.5, np.nan])
         with self.assertRaisesOpError('NaN'):
             to_simplex(x).eval()
Beispiel #2
0
 def test_to_simplex_1d(self):
     with self.test_session():
         x = tf.constant([0.0])
         self.assertAllClose(to_simplex(x).eval(), [0.5, 0.5])
         x = tf.constant([0.0, 10.0])
         self.assertAllClose(
             to_simplex(x).eval(),
             [3.333333e-01, 6.666363e-01, 3.027916e-05])
Beispiel #3
0
 def test_all_finite_raises(self):
   with self.test_session():
     x = tf.constant([12.5, np.inf])
     with self.assertRaisesOpError('Inf'):
       to_simplex(x).eval()
     x = tf.constant([12.5, np.nan])
     with self.assertRaisesOpError('NaN'):
       to_simplex(x).eval()
Beispiel #4
0
 def test_to_simplex_1d(self):
   with self.test_session():
     x = tf.constant([0.0])
     self.assertAllClose(to_simplex(x).eval(),
                         [0.5, 0.5])
     x = tf.constant([0.0, 10.0])
     self.assertAllClose(to_simplex(x).eval(),
                         [3.333333e-01, 6.666363e-01, 3.027916e-05])
Beispiel #5
0
    def __init__(self, shape, pi=None):
        if shape[-1] == 1:
            raise ValueError("Multinomial is not supported for K=1. Use Bernoulli.")

        Distribution.__init__(self, shape)
        self.num_params = np.prod(shape[:-1]) * (shape[-1] -1)
        self.sample_tensor = False
        self.is_multivariate = True

        if pi is None:
            real_shape = self.shape[:-1]
            K_minus_one = self.shape[-1] - 1
            pi_unconst = tf.Variable(tf.random_normal([real_shape + (K_minus_one, )]))
            pi = to_simplex(pi_unconst)

        self.pi = pi
Beispiel #6
0
    def __init__(self, shape, pi=None):
        super(Multinomial, self).__init__(shape)
        if self.shape[-1] == 1:
            raise ValueError("Multinomial is not supported for K=1. Use Bernoulli.")

        self.n_params = np.prod(self.shape[:-1]) * (self.shape[-1] -1)
        self.is_differentiable = False
        self.is_multivariate = True
        self.is_reparameterized = False

        if pi is None:
            real_shape = self.shape[:-1]
            K_minus_one = self.shape[-1] - 1
            pi_unconst = tf.Variable(tf.random_normal([real_shape + (K_minus_one, )]))
            pi = to_simplex(pi_unconst)

        self.pi = pi
Beispiel #7
0
    def __init__(self, shape, pi=None):
        super(Multinomial, self).__init__(shape)
        if self.shape[-1] == 1:
            raise ValueError(
                "Multinomial is not supported for K=1. Use Bernoulli.")

        self.n_params = np.prod(self.shape[:-1]) * (self.shape[-1] - 1)
        self.is_differentiable = False
        self.is_multivariate = True
        self.is_reparameterized = False

        if pi is None:
            real_shape = self.shape[:-1]
            K_minus_one = self.shape[-1] - 1
            pi_unconst = tf.Variable(
                tf.random_normal([real_shape + (K_minus_one, )]))
            pi = to_simplex(pi_unconst)

        self.pi = pi