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


Python random_ops.random_gamma方法代码示例

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


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

示例1: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    n_draws = math_ops.cast(self.total_count, dtype=dtypes.int32)
    k = self.event_shape_tensor()[0]
    unnormalized_logits = array_ops.reshape(
        math_ops.log(random_ops.random_gamma(
            shape=[n],
            alpha=self.concentration,
            dtype=self.dtype,
            seed=seed)),
        shape=[-1, k])
    draws = random_ops.multinomial(
        logits=unnormalized_logits,
        num_samples=n_draws,
        seed=distribution_util.gen_new_seed(seed, salt="dirichlet_multinomial"))
    x = math_ops.reduce_sum(array_ops.one_hot(draws, depth=k), -2)
    final_shape = array_ops.concat([[n], self.batch_shape_tensor(), [k]], 0)
    return array_ops.reshape(x, final_shape) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:19,代码来源:dirichlet_multinomial.py

示例2: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    expanded_concentration1 = array_ops.ones_like(
        self.total_concentration, dtype=self.dtype) * self.concentration1
    expanded_concentration0 = array_ops.ones_like(
        self.total_concentration, dtype=self.dtype) * self.concentration0
    gamma1_sample = random_ops.random_gamma(
        shape=[n],
        alpha=expanded_concentration1,
        dtype=self.dtype,
        seed=seed)
    gamma2_sample = random_ops.random_gamma(
        shape=[n],
        alpha=expanded_concentration0,
        dtype=self.dtype,
        seed=distribution_util.gen_new_seed(seed, "beta"))
    beta_sample = gamma1_sample / (gamma1_sample + gamma2_sample)
    return beta_sample 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:19,代码来源:beta.py

示例3: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    # The sampling method comes from the fact that if:
    #   X ~ Normal(0, 1)
    #   Z ~ Chi2(df)
    #   Y = X / sqrt(Z / df)
    # then:
    #   Y ~ StudentT(df).
    shape = array_ops.concat([[n], self.batch_shape_tensor()], 0)
    normal_sample = random_ops.random_normal(shape, dtype=self.dtype, seed=seed)
    df = self.df * array_ops.ones(self.batch_shape_tensor(), dtype=self.dtype)
    gamma_sample = random_ops.random_gamma(
        [n],
        0.5 * df,
        beta=0.5,
        dtype=self.dtype,
        seed=distribution_util.gen_new_seed(seed, salt="student_t"))
    samples = normal_sample * math_ops.rsqrt(gamma_sample / df)
    return samples * self.scale + self.loc  # Abs(scale) not wanted. 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:20,代码来源:student_t.py

示例4: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    # Here we use the fact that if:
    # lam ~ Gamma(concentration=total_count, rate=(1-probs)/probs)
    # then X ~ Poisson(lam) is Negative Binomially distributed.
    rate = random_ops.random_gamma(
        shape=[n],
        alpha=self.total_count,
        beta=math_ops.exp(-self.logits),
        dtype=self.dtype,
        seed=seed)

    return random_ops.random_poisson(
        rate,
        shape=[],
        dtype=self.dtype,
        seed=distribution_util.gen_new_seed(seed, "negative_binom")) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:18,代码来源:negative_binomial.py

示例5: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    # The sampling method comes from the fact that if:
    #   X ~ Normal(0, 1)
    #   Z ~ Chi2(df)
    #   Y = X / sqrt(Z / df)
    # then:
    #   Y ~ StudentT(df).
    shape = array_ops.concat([[n], self.batch_shape()], 0)
    normal_sample = random_ops.random_normal(shape, dtype=self.dtype, seed=seed)
    df = self.df * array_ops.ones(self.batch_shape(), dtype=self.dtype)
    gamma_sample = random_ops.random_gamma(
        [n],
        0.5 * df,
        beta=0.5,
        dtype=self.dtype,
        seed=distribution_util.gen_new_seed(seed, salt="student_t"))
    samples = normal_sample / math_ops.sqrt(gamma_sample / df)
    return samples * self.sigma + self.mu  # Abs(sigma) not wanted. 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:20,代码来源:student_t.py

示例6: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    n_draws = math_ops.cast(self.total_count, dtype=dtypes.int32)
    k = self.event_shape_tensor()[0]
    unnormalized_logits = array_ops.reshape(
        math_ops.log(random_ops.random_gamma(
            shape=[n],
            alpha=self.concentration,
            dtype=self.dtype,
            seed=seed)),
        shape=[-1, k])
    draws = random_ops.multinomial(
        logits=unnormalized_logits,
        num_samples=n_draws,
        seed=distribution_util.gen_new_seed(seed, salt="dirichlet_multinomial"))
    x = math_ops.reduce_sum(array_ops.one_hot(draws, depth=k), -2)
    final_shape = array_ops.concat([[n], self.batch_shape_tensor(), [k]], 0)
    x = array_ops.reshape(x, final_shape)
    return math_ops.cast(x, self.dtype) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:20,代码来源:dirichlet_multinomial.py

示例7: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    return random_ops.random_gamma(
        shape=[n],
        alpha=self.concentration,
        beta=self.rate,
        dtype=self.dtype,
        seed=seed) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:gamma.py

示例8: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    gamma_sample = random_ops.random_gamma(
        shape=[n],
        alpha=self.concentration,
        dtype=self.dtype,
        seed=seed)
    return gamma_sample / math_ops.reduce_sum(gamma_sample, -1, keep_dims=True) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:dirichlet.py

示例9: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    """See the documentation for tf.random_gamma for more details."""
    return random_ops.random_gamma([n],
                                   self.alpha,
                                   beta=self.beta,
                                   dtype=self.dtype,
                                   seed=seed) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:9,代码来源:gamma.py

示例10: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    """See the documentation for tf.random_gamma for more details."""
    return 1. / random_ops.random_gamma([n], self.alpha, beta=self.beta,
                                        dtype=self.dtype, seed=seed) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:6,代码来源:inverse_gamma.py

示例11: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    n_draws = math_ops.cast(self.n, dtype=dtypes.int32)
    if self.n.get_shape().ndims is not None:
      if self.n.get_shape().ndims != 0:
        raise NotImplementedError(
            "Sample only supported for scalar number of draws.")
    elif self.validate_args:
      is_scalar = check_ops.assert_rank(
          n_draws, 0,
          message="Sample only supported for scalar number of draws.")
      n_draws = control_flow_ops.with_dependencies([is_scalar], n_draws)
    k = self.event_shape()[0]
    unnormalized_logits = array_ops.reshape(
        math_ops.log(random_ops.random_gamma(
            shape=[n],
            alpha=self.alpha,
            dtype=self.dtype,
            seed=seed)),
        shape=[-1, k])
    draws = random_ops.multinomial(
        logits=unnormalized_logits,
        num_samples=n_draws,
        seed=distribution_util.gen_new_seed(seed, salt="dirichlet_multinomial"))
    x = math_ops.reduce_sum(array_ops.one_hot(draws, depth=k),
                            reduction_indices=-2)
    final_shape = array_ops.concat([[n], self.batch_shape(), [k]], 0)
    return array_ops.reshape(x, final_shape) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:29,代码来源:dirichlet_multinomial.py

示例12: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    a = array_ops.ones_like(self.a_b_sum, dtype=self.dtype) * self.a
    b = array_ops.ones_like(self.a_b_sum, dtype=self.dtype) * self.b
    gamma1_sample = random_ops.random_gamma(
        [n,], a, dtype=self.dtype, seed=seed)
    gamma2_sample = random_ops.random_gamma(
        [n,], b, dtype=self.dtype,
        seed=distribution_util.gen_new_seed(seed, "beta"))
    beta_sample = gamma1_sample / (gamma1_sample + gamma2_sample)
    return beta_sample 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:12,代码来源:beta.py

示例13: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    # The sampling method comes from the well known fact that if X ~ Normal(0,
    # 1), and Z ~ Chi2(df), then X / sqrt(Z / df) ~ StudentT(df).
    shape = array_ops.concat(0, ([n], self.batch_shape()))
    normal_sample = random_ops.random_normal(
        shape, dtype=self.dtype, seed=seed)
    half = constant_op.constant(0.5, self.dtype)
    df = self.df * array_ops.ones(self.batch_shape(), dtype=self.dtype)
    gamma_sample = random_ops.random_gamma(
        [n,], half * df, beta=half, dtype=self.dtype,
        seed=distribution_util.gen_new_seed(seed, salt="student_t"))
    samples = normal_sample / math_ops.sqrt(gamma_sample / df)
    return samples * self.sigma + self.mu 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:15,代码来源:student_t.py

示例14: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed=None):
    gamma_sample = random_ops.random_gamma(
        [n,], self.alpha, dtype=self.dtype, seed=seed)
    return gamma_sample / math_ops.reduce_sum(
        gamma_sample, reduction_indices=[-1], keep_dims=True) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:7,代码来源:dirichlet.py

示例15: _sample_n

# 需要导入模块: from tensorflow.python.ops import random_ops [as 别名]
# 或者: from tensorflow.python.ops.random_ops import random_gamma [as 别名]
def _sample_n(self, n, seed):
    batch_shape = self.batch_shape_tensor()
    event_shape = self.event_shape_tensor()
    batch_ndims = array_ops.shape(batch_shape)[0]

    ndims = batch_ndims + 3  # sample_ndims=1, event_ndims=2
    shape = array_ops.concat([[n], batch_shape, event_shape], 0)

    # Complexity: O(nbk**2)
    x = random_ops.random_normal(shape=shape,
                                 mean=0.,
                                 stddev=1.,
                                 dtype=self.dtype,
                                 seed=seed)

    # Complexity: O(nbk)
    # This parametrization is equivalent to Chi2, i.e.,
    # ChiSquared(k) == Gamma(alpha=k/2, beta=1/2)
    g = random_ops.random_gamma(shape=[n],
                                alpha=self._multi_gamma_sequence(
                                    0.5 * self.df, self.dimension),
                                beta=0.5,
                                dtype=self.dtype,
                                seed=distribution_util.gen_new_seed(
                                    seed, "wishart"))

    # Complexity: O(nbk**2)
    x = array_ops.matrix_band_part(x, -1, 0)  # Tri-lower.

    # Complexity: O(nbk)
    x = array_ops.matrix_set_diag(x, math_ops.sqrt(g))

    # Make batch-op ready.
    # Complexity: O(nbk**2)
    perm = array_ops.concat([math_ops.range(1, ndims), [0]], 0)
    x = array_ops.transpose(x, perm)
    shape = array_ops.concat([batch_shape, [event_shape[0]], [-1]], 0)
    x = array_ops.reshape(x, shape)

    # Complexity: O(nbM) where M is the complexity of the operator solving a
    # vector system. E.g., for OperatorPDDiag, each matmul is O(k**2), so
    # this complexity is O(nbk**2). For OperatorPDCholesky, each matmul is
    # O(k^3) so this step has complexity O(nbk^3).
    x = self.scale_operator_pd.sqrt_matmul(x)

    # Undo make batch-op ready.
    # Complexity: O(nbk**2)
    shape = array_ops.concat([batch_shape, event_shape, [n]], 0)
    x = array_ops.reshape(x, shape)
    perm = array_ops.concat([[ndims - 1], math_ops.range(0, ndims - 1)], 0)
    x = array_ops.transpose(x, perm)

    if not self.cholesky_input_output_matrices:
      # Complexity: O(nbk^3)
      x = math_ops.matmul(x, x, adjoint_b=True)

    return x 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:59,代码来源:wishart.py


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