当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.lgamma方法代码示例

本文整理汇总了Python中tensorflow.lgamma方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.lgamma方法的具体用法?Python tensorflow.lgamma怎么用?Python tensorflow.lgamma使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.lgamma方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _log_prob

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def _log_prob(self, given):
        logits, temperature = self.path_param(self.logits), \
                              self.path_param(self.temperature)
        log_given = tf.log(given)
        log_temperature = tf.log(temperature)
        n = tf.cast(self.n_categories, self.dtype)

        if self._check_numerics:
            log_given = tf.check_numerics(log_given, "log(given)")
            log_temperature = tf.check_numerics(
                log_temperature, "log(temperature)")

        temp = logits - temperature * log_given

        return tf.lgamma(n) + (n - 1) * log_temperature + \
            tf.reduce_sum(temp - log_given, axis=-1) - \
            n * tf.reduce_logsumexp(temp, axis=-1) 
开发者ID:thu-ml,项目名称:zhusuan,代码行数:19,代码来源:multivariate.py

示例2: _log_prob

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def _log_prob(self, given):
        # TODO: not right when given=0 or 1
        alpha, beta = self.alpha, self.beta
        log_given = tf.log(given)
        log_1_minus_given = tf.log(1 - given)
        lgamma_alpha, lgamma_beta = tf.lgamma(alpha), tf.lgamma(beta)
        lgamma_alpha_plus_beta = tf.lgamma(alpha + beta)

        if self._check_numerics:
            log_given = tf.check_numerics(log_given, "log(given)")
            log_1_minus_given = tf.check_numerics(
                log_1_minus_given, "log(1 - given)")
            lgamma_alpha = tf.check_numerics(lgamma_alpha, "lgamma(alpha)")
            lgamma_beta = tf.check_numerics(lgamma_beta, "lgamma(beta)")
            lgamma_alpha_plus_beta = tf.check_numerics(
                lgamma_alpha_plus_beta, "lgamma(alpha + beta)")

        return (alpha - 1) * log_given + (beta - 1) * log_1_minus_given - (
            lgamma_alpha + lgamma_beta - lgamma_alpha_plus_beta) 
开发者ID:thu-ml,项目名称:zhusuan,代码行数:21,代码来源:univariate.py

示例3: Poisson

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def Poisson(lambda_, name=None):
    k = tf.placeholder(config.int_dtype, name=name)

    # FIXME tf.lgamma only supports floats so cast before
    Distribution.logp = (
        tf.cast(k, config.dtype)*tf.log(lambda_) -
        lambda_ -
        tf.lgamma(tf.cast(k+1, config.dtype))
    )

    # TODO Distribution.integral = ...
    def integral(l, u):
        return tf.constant(1, dtype=config.dtype)
    Distribution.integral = integral

    return k 
开发者ID:tensorprob,项目名称:tensorprob,代码行数:18,代码来源:poisson.py

示例4: logp

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def logp(self, bin_counts):
    """Compute the log probability for the counts in the bin, under the model.

    Args:
      bin_counts: array-like integer counts

    Returns:
      The log-probability under the Poisson models for each element of
      bin_counts.
    """
    k = tf.to_float(bin_counts)
    # log poisson(k, r) = log(r^k * e^(-r) / k!) = k log(r) - r - log k!
    # log poisson(k, r=exp(x)) = k * x - exp(x) - lgamma(k + 1)
    return k * self.logr - tf.exp(self.logr) - tf.lgamma(k + 1) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:16,代码来源:distributions.py

示例5: log_combination

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def log_combination(n, ks):
    """
    Compute the log combination function.

    .. math::

        \\log \\binom{n}{k_1, k_2, \\dots} = \\log n! - \\sum_{i}\\log k_i!

    :param n: A N-D `float` Tensor. Can broadcast to match `tf.shape(ks)[:-1]`.
    :param ks: A (N + 1)-D `float` Tensor. Each slice `[i, j, ..., k, :]` is
        a vector of `[k_1, k_2, ...]`.

    :return: A N-D Tensor of type same as `n`.
    """
    return tf.lgamma(n + 1) - tf.reduce_sum(tf.lgamma(ks + 1), axis=-1) 
开发者ID:thu-ml,项目名称:zhusuan,代码行数:17,代码来源:utils.py

示例6: test_Lgamma

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def test_Lgamma(self):
        t = tf.lgamma(self.random(4, 3))
        self.check(t) 
开发者ID:riga,项目名称:tfdeploy,代码行数:5,代码来源:ops.py

示例7: beta_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def beta_fn(a,b):
    return tf.exp( tf.lgamma(a) + tf.lgamma(b) - tf.lgamma(a+b) ) 
开发者ID:enalisnick,项目名称:mixture_density_VAEs,代码行数:4,代码来源:gaussMMVAE_collapsed.py

示例8: testFloatBasic

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def testFloatBasic(self):
    x = np.arange(-3, 3).reshape(1, 3, 2).astype(np.float32)
    y = (x + .5).astype(np.float32)     # no zero
    z = (x + 15.5).astype(np.float32)   # all positive
    k = np.arange(-0.90, 0.90, 0.25).astype(np.float32) # between -1 and 1

    self._compareBoth(x, np.abs, tf.abs)
    self._compareBoth(x, np.abs, _ABS)
    self._compareBoth(x, np.negative, tf.neg)
    self._compareBoth(x, np.negative, _NEG)
    self._compareBoth(y, self._inv, tf.inv)
    self._compareBoth(x, np.square, tf.square)
    self._compareBoth(z, np.sqrt, tf.sqrt)
    self._compareBoth(z, self._rsqrt, tf.rsqrt)
    self._compareBoth(x, np.exp, tf.exp)
    self._compareBoth(z, np.log, tf.log)
    self._compareBoth(z, np.log1p, tf.log1p)
    self._compareBoth(x, np.tanh, tf.tanh)
    self._compareBoth(x, self._sigmoid, tf.sigmoid)
    self._compareBoth(y, np.sign, tf.sign)
    self._compareBoth(x, np.sin, tf.sin)
    self._compareBoth(x, np.cos, tf.cos)
    self._compareBoth(k, np.arcsin, tf.asin)
    self._compareBoth(k, np.arccos, tf.acos)
    self._compareBoth(x, np.arctan, tf.atan)
    self._compareBoth(x, np.tan, tf.tan)
    self._compareBoth(
        y,
        np.vectorize(self._replace_domain_error_with_inf(math.lgamma)),
        tf.lgamma)
    self._compareBoth(x, np.vectorize(math.erf), tf.erf)
    self._compareBoth(x, np.vectorize(math.erfc), tf.erfc)

    self._compareBothSparse(x, np.abs, tf.abs)
    self._compareBothSparse(x, np.negative, tf.neg)
    self._compareBothSparse(x, np.square, tf.square)
    self._compareBothSparse(z, np.sqrt, tf.sqrt, tol=1e-3)
    self._compareBothSparse(x, np.tanh, tf.tanh)
    self._compareBothSparse(y, np.sign, tf.sign)
    self._compareBothSparse(x, np.vectorize(math.erf), tf.erf) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:42,代码来源:cwise_ops_test.py

示例9: testFloatEmpty

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def testFloatEmpty(self):
    x = np.empty((2, 0, 5), dtype=np.float32)
    self._compareBoth(x, np.abs, tf.abs)
    self._compareBoth(x, np.abs, _ABS)
    self._compareBoth(x, np.negative, tf.neg)
    self._compareBoth(x, np.negative, _NEG)
    self._compareBoth(x, self._inv, tf.inv)
    self._compareBoth(x, np.square, tf.square)
    self._compareBoth(x, np.sqrt, tf.sqrt)
    self._compareBoth(x, self._rsqrt, tf.rsqrt)
    self._compareBoth(x, np.exp, tf.exp)
    self._compareBoth(x, np.log, tf.log)
    self._compareBoth(x, np.log1p, tf.log1p)
    self._compareBoth(x, np.tanh, tf.tanh)
    self._compareBoth(x, self._sigmoid, tf.sigmoid)
    self._compareBoth(x, np.sign, tf.sign)
    self._compareBoth(x, np.sin, tf.sin)
    self._compareBoth(x, np.cos, tf.cos)
    # Can't use vectorize below, so just use some arbitrary function
    self._compareBoth(x, np.sign, tf.lgamma)
    self._compareBoth(x, np.sign, tf.erf)
    self._compareBoth(x, np.sign, tf.erfc)
    self._compareBoth(x, np.tan, tf.tan)
    self._compareBoth(x, np.arcsin, tf.asin)
    self._compareBoth(x, np.arccos, tf.acos)
    self._compareBoth(x, np.arctan, tf.atan)

    self._compareBothSparse(x, np.abs, tf.abs)
    self._compareBothSparse(x, np.negative, tf.neg)
    self._compareBothSparse(x, np.square, tf.square)
    self._compareBothSparse(x, np.sqrt, tf.sqrt, tol=1e-3)
    self._compareBothSparse(x, np.tanh, tf.tanh)
    self._compareBothSparse(x, np.sign, tf.sign)
    self._compareBothSparse(x, np.sign, tf.erf) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:36,代码来源:cwise_ops_test.py

示例10: testDoubleBasic

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def testDoubleBasic(self):
    x = np.arange(-3, 3).reshape(1, 3, 2).astype(np.float64)
    y = (x + .5).astype(np.float64)    # no zero
    z = (x + 15.5).astype(np.float64)  # all positive
    k = np.arange(-0.90, 0.90, 0.35).reshape(1, 3, 2).astype(np.float64) # between -1 and 1
    self._compareBoth(x, np.abs, tf.abs)
    self._compareBoth(x, np.abs, _ABS)
    self._compareBoth(x, np.negative, tf.neg)
    self._compareBoth(x, np.negative, _NEG)
    self._compareBoth(y, self._inv, tf.inv)
    self._compareBoth(x, np.square, tf.square)
    self._compareBoth(z, np.sqrt, tf.sqrt)
    self._compareBoth(z, self._rsqrt, tf.rsqrt)
    self._compareBoth(x, np.exp, tf.exp)
    self._compareBoth(z, np.log, tf.log)
    self._compareBoth(z, np.log1p, tf.log1p)
    self._compareBoth(x, np.tanh, tf.tanh)
    self._compareBoth(x, self._sigmoid, tf.sigmoid)
    self._compareBoth(y, np.sign, tf.sign)
    self._compareBoth(x, np.sin, tf.sin)
    self._compareBoth(x, np.cos, tf.cos)
    self._compareBoth(
        y,
        np.vectorize(self._replace_domain_error_with_inf(math.lgamma)),
        tf.lgamma)
    self._compareBoth(x, np.vectorize(math.erf), tf.erf)
    self._compareBoth(x, np.vectorize(math.erfc), tf.erfc)
    self._compareBoth(x, np.arctan, tf.atan)
    self._compareBoth(k, np.arcsin, tf.asin)
    self._compareBoth(k, np.arccos, tf.acos)
    self._compareBoth(k, np.tan, tf.tan)

    self._compareBothSparse(x, np.abs, tf.abs)
    self._compareBothSparse(x, np.negative, tf.neg)
    self._compareBothSparse(x, np.square, tf.square)
    self._compareBothSparse(z, np.sqrt, tf.sqrt, tol=1e-3)
    self._compareBothSparse(x, np.tanh, tf.tanh)
    self._compareBothSparse(y, np.sign, tf.sign)
    self._compareBothSparse(x, np.vectorize(math.erf), tf.erf) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:41,代码来源:cwise_ops_test.py

示例11: testHalfBasic

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def testHalfBasic(self):
    x = np.arange(-3, 3).reshape(1, 3, 2).astype(np.float16)
    y = (x + .5).astype(np.float16)    # no zero
    z = (x + 15.5).astype(np.float16)  # all positive
    self._compareBoth(x, np.abs, tf.abs)
    self._compareBoth(x, np.abs, _ABS)
    self._compareBoth(x, np.negative, tf.neg)
    self._compareBoth(x, np.negative, _NEG)
    self._compareBoth(y, self._inv, tf.inv)
    self._compareBoth(x, np.square, tf.square)
    self._compareBoth(z, np.sqrt, tf.sqrt)
    self._compareBoth(z, self._rsqrt, tf.rsqrt)
    self._compareBoth(x, np.exp, tf.exp)
    self._compareBoth(z, np.log, tf.log)
    self._compareBoth(z, np.log1p, tf.log1p)
    self._compareBoth(x, np.tanh, tf.tanh)
    self._compareBoth(x, self._sigmoid, tf.sigmoid)
    self._compareBoth(y, np.sign, tf.sign)
    self._compareBoth(x, np.sin, tf.sin)
    self._compareBoth(x, np.cos, tf.cos)
    self._compareBoth(
        y,
        np.vectorize(self._replace_domain_error_with_inf(math.lgamma)),
        tf.lgamma)
    self._compareBoth(x, np.vectorize(math.erf), tf.erf)
    self._compareBoth(x, np.vectorize(math.erfc), tf.erfc)

    self._compareBothSparse(x, np.abs, tf.abs)
    self._compareBothSparse(x, np.negative, tf.neg)
    self._compareBothSparse(x, np.square, tf.square)
    self._compareBothSparse(z, np.sqrt, tf.sqrt, tol=1e-3)
    self._compareBothSparse(x, np.tanh, tf.tanh)
    self._compareBothSparse(y, np.sign, tf.sign)
    self._compareBothSparse(x, np.vectorize(math.erf), tf.erf, tol=1e-3) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:36,代码来源:cwise_ops_test.py

示例12: _beta_log_prob

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def _beta_log_prob(alpha, beta, value):
    with tf.Graph().as_default():
        with tf.Session() as sess:
            gamma_a, gamma_b, gamma_ab = sess.run((tf.lgamma(alpha), tf.lgamma(beta),
                                                   tf.lgamma(alpha + beta)))
    log_denom = gamma_a + gamma_b - gamma_ab
    log_num = np.log((value ** (alpha - 1)) * ((1 - value) ** (beta - 1)))
    return log_num - log_denom 
开发者ID:flyyufelix,项目名称:sonic_contest,代码行数:10,代码来源:test_dists.py

示例13: gammaln

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def gammaln(self, x):
        return tf.lgamma(x) 
开发者ID:sharadmv,项目名称:deepx,代码行数:4,代码来源:tensorflow.py

示例14: get_log_likelihood

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def get_log_likelihood(self, observation, mask_dim=None):
        x = observation
        mu, var, nu = self.current_distribution
        ln_gamma_quotient = tf.lgamma((1. + nu) / 2.) - tf.lgamma(nu / 2.)
        ln_nom = (-(1. + nu) / 2.) * tf.log1p(tf.square(x - mu) / ((nu - 2.) * var))
        ln_denom = 0.5 * tf.log((nu - 2.) * np.pi * var)
        log_pdf = ln_gamma_quotient + ln_nom - ln_denom
        if mask_dim is not None:
            return tf.reduce_sum(log_pdf * mask_dim, 1)
        else:
            return tf.reduce_sum(log_pdf, 1) 
开发者ID:IraKorshunova,项目名称:bruno,代码行数:13,代码来源:nn_extra_student.py

示例15: get_log_likelihood_under_prior

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lgamma [as 别名]
def get_log_likelihood_under_prior(self, observation, mask_dim=None):
        x = observation
        mu, var, nu = self.prior
        ln_gamma_quotient = tf.lgamma((1. + nu) / 2.) - tf.lgamma(nu / 2.)
        ln_nom = (-(1. + nu) / 2.) * tf.log1p((tf.square(x - mu) / ((nu - 2.) * var)))
        ln_denom = 0.5 * tf.log((nu - 2.) * np.pi * var)
        log_pdf = ln_gamma_quotient + ln_nom - ln_denom
        if mask_dim is not None:
            return tf.reduce_sum(log_pdf * mask_dim, 1)
        else:
            return tf.reduce_sum(log_pdf, 1) 
开发者ID:IraKorshunova,项目名称:bruno,代码行数:13,代码来源:nn_extra_student.py


注:本文中的tensorflow.lgamma方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。