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))
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))
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)
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)
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))
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)
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)
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)
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)
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)
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)
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)
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)
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)
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))
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)
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)
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)
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))
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))
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)
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)
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))
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))
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)
def _test(x): xtf = tf.constant(x) val_true = special.gammaln(x) _assert_eq(lgamma(xtf), val_true)
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)
def _test(x): xtf = tf.constant(x) val_true = special.gammaln(x) _assert_eq(lgamma(xtf), val_true)