Esempio n. 1
0
 def logpmf(self, x, n, p):
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     n = tf.cast(tf.squeeze(n), dtype=tf.float32)
     p = tf.cast(tf.squeeze(p), dtype=tf.float32)
     return log_gamma(n + 1.0) - log_gamma(x + 1.0) - \
            log_gamma(n - x + 1.0) + \
            tf.mul(x, tf.log(p)) + tf.mul(n - x, tf.log(1.0-p))
Esempio n. 2
0
 def logpdf(self, x, df, loc=0, scale=1):
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     df = tf.cast(tf.squeeze(df), dtype=tf.float32)
     loc = tf.cast(tf.squeeze(loc), dtype=tf.float32)
     scale = tf.cast(tf.squeeze(scale), dtype=tf.float32)
     z = (x - loc) / scale
     return log_gamma(0.5 * (df + 1.0)) - log_gamma(0.5 * df) - \
            0.5 * (tf.log(np.pi) + tf.log(df)) - tf.log(scale) - \
            0.5 * (df + 1.0) * tf.log(1.0 + (1.0/df) * tf.square(z))
Esempio n. 3
0
 def logpdf(self, x, df, loc=0, scale=1):
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     df = tf.squeeze(df)
     loc = tf.cast(tf.squeeze(loc), dtype=tf.float32)
     scale = tf.cast(tf.squeeze(scale), dtype=tf.float32)
     return 0.5 * log_gamma(df + 1.0) - \
            log_gamma(0.5 * df) - \
            0.5 * (np.log(np.pi) + tf.log(df)) +  tf.log(scale) - \
            0.5 * (df + 1.0) * \
                tf.log(1.0 + (1.0/df) * tf.square((x-loc)/scale))
Esempio n. 4
0
 def logpdf(self, x, df, loc=0, scale=1):
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     df = tf.squeeze(df)
     loc = tf.cast(tf.squeeze(loc), dtype=tf.float32)
     scale = tf.cast(tf.squeeze(scale), dtype=tf.float32)
     return 0.5 * log_gamma(df + 1.0) - \
            log_gamma(0.5 * df) - \
            0.5 * (np.log(np.pi) + tf.log(df)) +  tf.log(scale) - \
            0.5 * (df + 1.0) * \
                tf.log(1.0 + (1.0/df) * tf.square((x-loc)/scale))
Esempio n. 5
0
 def logpmf(self, x, n, p):
     """
     Arguments
     ----------
     x: np.array or tf.Tensor
         vector of length K, where x[i] is the number of outcomes
         in the ith bucket
     n: int or tf.Tensor
         number of outcomes equal to sum x[i]
     p: np.array or tf.Tensor
         vector of probabilities summing to 1
     """
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     n = tf.cast(tf.squeeze(n), dtype=tf.float32)
     p = tf.cast(tf.squeeze(p), dtype=tf.float32)
     one = tf.constant(1.0, dtype=tf.float32)
     return log_gamma(n + one) - tf.reduce_sum(log_gamma(x + one)) + tf.reduce_sum(tf.mul(x, tf.log(p)))
Esempio n. 6
0
 def logpmf(self, x, n, p):
     """
     Arguments
     ----------
     x: np.array or tf.Tensor
         vector of length K, where x[i] is the number of outcomes
         in the ith bucket
     n: int or tf.Tensor
         number of outcomes equal to sum x[i]
     p: np.array or tf.Tensor
         vector of probabilities summing to 1
     """
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     n = tf.cast(tf.squeeze(n), dtype=tf.float32)
     p = tf.cast(tf.squeeze(p), dtype=tf.float32)
     one = tf.constant(1.0, dtype=tf.float32)
     return log_gamma(n + one) - \
            tf.reduce_sum(log_gamma(x + one)) + \
            tf.reduce_sum(tf.mul(x, tf.log(p)))
Esempio n. 7
0
 def logpmf(self, x, n, p):
     """
     Parameters
     ----------
     x : np.array or tf.Tensor
         vector of length K, where x[i] is the number of outcomes
         in the ith bucket, or matrix with column length K
     n : int or tf.Tensor
         number of outcomes equal to sum x[i]
     p : np.array or tf.Tensor
         vector of probabilities summing to 1
     """
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     n = tf.cast(tf.squeeze(n), dtype=tf.float32)
     p = tf.cast(tf.squeeze(p), dtype=tf.float32)
     if len(get_dims(x)) == 1:
         return log_gamma(n + 1.0) - \
                tf.reduce_sum(log_gamma(x + 1.0)) + \
                tf.reduce_sum(tf.mul(x, tf.log(p)))
     else:
         return log_gamma(n + 1.0) - \
                tf.reduce_sum(log_gamma(x + 1.0), 1) + \
                tf.reduce_sum(tf.mul(x, tf.log(p)), 1)
Esempio n. 8
0
 def logpdf(self, x, df):
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     df = tf.cast(tf.squeeze(df), dtype=tf.float32)
     return tf.mul(0.5*df - 1, tf.log(x)) - 0.5*x - \
            tf.mul(0.5*df, tf.log(2.0)) - log_gamma(0.5*df)
Esempio n. 9
0
 def logpmf(self, x, mu):
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     mu = tf.cast(tf.squeeze(mu), dtype=tf.float32)
     return x * tf.log(mu) - mu - log_gamma(x + 1.0)
Esempio n. 10
0
 def logpdf(self, x, alpha, scale=1):
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     alpha = tf.cast(tf.squeeze(alpha), dtype=tf.float32)
     scale = tf.cast(tf.squeeze(scale), dtype=tf.float32)
     return tf.mul(alpha, tf.log(scale)) - log_gamma(alpha) + \
            tf.mul(-alpha-1, tf.log(x)) - tf.truediv(scale, x)
Esempio n. 11
0
 def logpdf(self, x, a, scale=1):
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     a = tf.cast(tf.squeeze(a), dtype=tf.float32)
     scale = tf.cast(tf.squeeze(scale), dtype=tf.float32)
     return (a - 1.0) * tf.log(x) - x/scale - a * tf.log(scale) - log_gamma(a)
Esempio n. 12
0
def _test(x):
    xtf = tf.constant(x)
    val_true = special.gammaln(x)
    _assert_eq(log_gamma(xtf), val_true)
Esempio n. 13
0
 def logpdf(self, x, a, scale=1):
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     a = tf.cast(tf.squeeze(a), dtype=tf.float32)
     scale = tf.cast(tf.squeeze(scale), dtype=tf.float32)
     return (a -
             1.0) * tf.log(x) - x / scale - a * tf.log(scale) - log_gamma(a)
Esempio n. 14
0
 def logpmf(self, x, mu):
     x = tf.squeeze(x)
     mu = tf.cast(tf.squeeze(mu), dtype=tf.float32)
     return x * tf.log(mu) - mu - log_gamma(x + 1.0)
Esempio n. 15
0
 def logpdf(self, x, alpha, scale=1):
     x = tf.cast(tf.squeeze(x), dtype=tf.float32)
     alpha = tf.cast(tf.squeeze(alpha), dtype=tf.float32)
     scale = tf.cast(tf.squeeze(scale), dtype=tf.float32)
     return tf.mul(alpha, tf.log(scale)) - log_gamma(alpha) + \
            tf.mul(-alpha-1, tf.log(x)) - tf.truediv(scale, x)