コード例 #1
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 lgamma(0.5 * (df + 1.0)) - lgamma(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))
コード例 #2
0
ファイル: distributions.py プロジェクト: ScartleRoy/edward
 def logpdf(self, x, df, loc=0, scale=1):
     x = tf.cast(x, dtype=tf.float32)
     df = tf.cast(df, dtype=tf.float32)
     loc = tf.cast(loc, dtype=tf.float32)
     scale = tf.cast(scale, dtype=tf.float32)
     z = (x - loc) / scale
     return lgamma(0.5 * (df + 1.0)) - lgamma(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))
コード例 #3
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 lgamma(n + 1.0) - \
                tf.reduce_sum(lgamma(x + 1.0)) + \
                tf.reduce_sum(tf.mul(x, tf.log(p)))
     else:
         return lgamma(n + 1.0) - \
                tf.reduce_sum(lgamma(x + 1.0), 1) + \
                tf.reduce_sum(tf.mul(x, tf.log(p)), 1)
コード例 #4
0
ファイル: distributions.py プロジェクト: ScartleRoy/edward
 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(x, dtype=tf.float32)
     n = tf.cast(n, dtype=tf.float32)
     p = tf.cast(p, dtype=tf.float32)
     if len(get_dims(x)) == 1:
         return lgamma(n + 1.0) - \
                tf.reduce_sum(lgamma(x + 1.0)) + \
                tf.reduce_sum(tf.mul(x, tf.log(p)))
     else:
         return lgamma(n + 1.0) - \
                tf.reduce_sum(lgamma(x + 1.0), 1) + \
                tf.reduce_sum(tf.mul(x, tf.log(p)), 1)
コード例 #5
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 lgamma(n + 1.0) - lgamma(x + 1.0) - lgamma(n - x + 1.0) + \
            tf.mul(x, tf.log(p)) + tf.mul(n - x, tf.log(1.0-p))
コード例 #6
0
ファイル: distributions.py プロジェクト: dcjones/edward
 def entropy(self, a, scale=1):
     a = tf.cast(a, dtype=tf.float32)
     scale = tf.cast(scale, dtype=tf.float32)
     return a + tf.log(scale*tf.exp(lgamma(a))) - \
            (1.0 + a) * digamma(a)
コード例 #7
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 - lgamma(x + 1.0)
コード例 #8
0
ファイル: distributions.py プロジェクト: codeaudit/edward
 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) - lgamma(a)
コード例 #9
0
ファイル: distributions.py プロジェクト: ScartleRoy/edward
 def logpmf(self, x, mu):
     x = tf.cast(x, dtype=tf.float32)
     mu = tf.cast(mu, dtype=tf.float32)
     return x * tf.log(mu) - mu - lgamma(x + 1.0)
コード例 #10
0
ファイル: distributions.py プロジェクト: ScartleRoy/edward
 def logpdf(self, x, a, scale=1):
     x = tf.cast(x, dtype=tf.float32)
     a = tf.cast(a, dtype=tf.float32)
     scale = tf.cast(scale, dtype=tf.float32)
     return tf.mul(a, tf.log(scale)) - lgamma(a) + \
            tf.mul(-a-1, tf.log(x)) - tf.truediv(scale, x)
コード例 #11
0
ファイル: distributions.py プロジェクト: crack521/edward
 def entropy(self, a, scale=1):
     a = tf.cast(a, dtype=tf.float32)
     scale = tf.cast(scale, dtype=tf.float32)
     return a + tf.log(scale*tf.exp(lgamma(a))) - \
            (1.0 + a) * digamma(a)
コード例 #12
0
ファイル: distributions.py プロジェクト: yluo42/edward
 def logpmf(self, x, mu):
     x = tf.cast(x, dtype=tf.float32)
     mu = tf.cast(mu, dtype=tf.float32)
     return x * tf.log(mu) - mu - lgamma(x + 1.0)
コード例 #13
0
ファイル: distributions.py プロジェクト: yluo42/edward
 def logpdf(self, x, a, scale=1):
     x = tf.cast(x, dtype=tf.float32)
     a = tf.cast(a, dtype=tf.float32)
     scale = tf.cast(scale, dtype=tf.float32)
     return tf.mul(a, tf.log(scale)) - lgamma(a) + \
            tf.mul(-a-1, tf.log(x)) - tf.truediv(scale, x)
コード例 #14
0
ファイル: distributions.py プロジェクト: yluo42/edward
 def logpdf(self, x, a, scale=1):
     x = tf.cast(x, dtype=tf.float32)
     a = tf.cast(a, dtype=tf.float32)
     scale = tf.cast(scale, dtype=tf.float32)
     return (a -
             1.0) * tf.log(x) - x / scale - a * tf.log(scale) - lgamma(a)
コード例 #15
0
ファイル: distributions.py プロジェクト: codeaudit/edward
 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 lgamma(n + 1.0) - lgamma(x + 1.0) - lgamma(n - x + 1.0) + \
            tf.mul(x, tf.log(p)) + tf.mul(n - x, tf.log(1.0-p))
コード例 #16
0
ファイル: distributions.py プロジェクト: codeaudit/edward
 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 - lgamma(x + 1.0)
コード例 #17
0
ファイル: distributions.py プロジェクト: codeaudit/edward
 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)) - lgamma(alpha) + \
            tf.mul(-alpha-1, tf.log(x)) - tf.truediv(scale, x)
コード例 #18
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)) - lgamma(0.5*df)
コード例 #19
0
ファイル: distributions.py プロジェクト: crack521/edward
 def entropy(self, a, scale=1):
     a = tf.cast(a, dtype=tf.float32)
     scale = tf.cast(scale, dtype=tf.float32)
     return a + tf.log(scale) + lgamma(a) + \
            tf.mul(1.0 - a, digamma(a))
コード例 #20
0
ファイル: distributions.py プロジェクト: yluo42/edward
 def logpmf(self, x, n, p):
     x = tf.cast(x, dtype=tf.float32)
     n = tf.cast(n, dtype=tf.float32)
     p = tf.cast(p, dtype=tf.float32)
     return lgamma(n + 1.0) - lgamma(x + 1.0) - lgamma(n - x + 1.0) + \
            tf.mul(x, tf.log(p)) + tf.mul(n - x, tf.log(1.0-p))
コード例 #21
0
ファイル: distributions.py プロジェクト: ScartleRoy/edward
 def logpdf(self, x, a, scale=1):
     x = tf.cast(x, dtype=tf.float32)
     a = tf.cast(a, dtype=tf.float32)
     scale = tf.cast(scale, dtype=tf.float32)
     return (a - 1.0) * tf.log(x) - x/scale - a * tf.log(scale) - lgamma(a)
コード例 #22
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) - lgamma(a)
コード例 #23
0
ファイル: distributions.py プロジェクト: ScartleRoy/edward
 def logpmf(self, x, n, p):
     x = tf.cast(x, dtype=tf.float32)
     n = tf.cast(n, dtype=tf.float32)
     p = tf.cast(p, dtype=tf.float32)
     return lgamma(n + 1.0) - lgamma(x + 1.0) - lgamma(n - x + 1.0) + \
            tf.mul(x, tf.log(p)) + tf.mul(n - x, tf.log(1.0-p))
コード例 #24
0
ファイル: distributions.py プロジェクト: dcjones/edward
 def entropy(self, a, scale=1):
     a = tf.cast(a, dtype=tf.float32)
     scale = tf.cast(scale, dtype=tf.float32)
     return a + tf.log(scale) + lgamma(a) + \
            tf.mul(1.0 - a, digamma(a))
コード例 #25
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)) - lgamma(alpha) + \
            tf.mul(-alpha-1, tf.log(x)) - tf.truediv(scale, x)
コード例 #26
0
ファイル: test_lgamma.py プロジェクト: 313-Ventures/edward
def _test(x):
    xtf = tf.constant(x)
    val_true = special.gammaln(x)
    _assert_eq(lgamma(xtf), val_true)
コード例 #27
0
ファイル: distributions.py プロジェクト: ScartleRoy/edward
 def logpdf(self, x, df):
     x = tf.cast(x, dtype=tf.float32)
     df = tf.cast(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)) - lgamma(0.5*df)
コード例 #28
0
def _test(x):
    xtf = tf.constant(x)
    val_true = special.gammaln(x)
    _assert_eq(lgamma(xtf), val_true)