本文整理汇总了Python中tensorflow.random_gamma方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.random_gamma方法的具体用法?Python tensorflow.random_gamma怎么用?Python tensorflow.random_gamma使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.random_gamma方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testShape
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_gamma [as 别名]
def testShape(self):
# Fully known shape.
rnd = tf.random_gamma([150], 2.0)
self.assertEqual([150], rnd.get_shape().as_list())
rnd = tf.random_gamma([150], 2.0, beta=[3.0, 4.0])
self.assertEqual([150, 2], rnd.get_shape().as_list())
rnd = tf.random_gamma([150], tf.ones([1, 2, 3]))
self.assertEqual([150, 1, 2, 3], rnd.get_shape().as_list())
rnd = tf.random_gamma([20, 30], tf.ones([1, 2, 3]))
self.assertEqual([20, 30, 1, 2, 3], rnd.get_shape().as_list())
rnd = tf.random_gamma([123], tf.placeholder(tf.float32, shape=(2,)))
self.assertEqual([123, 2], rnd.get_shape().as_list())
# Partially known shape.
rnd = tf.random_gamma(tf.placeholder(tf.int32, shape=(1,)), tf.ones([7, 3]))
self.assertEqual([None, 7, 3], rnd.get_shape().as_list())
rnd = tf.random_gamma(tf.placeholder(tf.int32, shape=(3,)), tf.ones([9, 6]))
self.assertEqual([None, None, None, 9, 6], rnd.get_shape().as_list())
# Unknown shape.
rnd = tf.random_gamma(tf.placeholder(tf.int32), tf.placeholder(tf.float32))
self.assertIs(None, rnd.get_shape().ndims)
rnd = tf.random_gamma([50], tf.placeholder(tf.float32))
self.assertIs(None, rnd.get_shape().ndims)
示例2: _sample
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_gamma [as 别名]
def _sample(self, n_samples):
samples = tf.random_gamma([n_samples], self.alpha,
beta=1, dtype=self.dtype)
return samples / tf.reduce_sum(samples, -1, keepdims=True)
示例3: _sample
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_gamma [as 别名]
def _sample(self, n_samples):
return tf.random_gamma([n_samples], self.alpha,
beta=self.beta, dtype=self.dtype)
示例4: _Sampler
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_gamma [as 别名]
def _Sampler(self, num, alpha, beta, dtype, use_gpu, seed=None):
def func():
with self.test_session(use_gpu=use_gpu, graph=tf.Graph()) as sess:
rng = tf.random_gamma([num], alpha, beta=beta, dtype=dtype, seed=seed)
ret = np.empty([10, num])
for i in xrange(10):
ret[i, :] = sess.run(rng)
return ret
return func
示例5: testNoCSE
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_gamma [as 别名]
def testNoCSE(self):
"""CSE = constant subexpression eliminator.
SetIsStateful() should prevent two identical random ops from getting
merged.
"""
for dtype in tf.float16, tf.float32, tf.float64:
for use_gpu in [False, True]:
with self.test_session(use_gpu=use_gpu):
rnd1 = tf.random_gamma([24], 2.0, dtype=dtype)
rnd2 = tf.random_gamma([24], 2.0, dtype=dtype)
diff = rnd2 - rnd1
self.assertGreater(np.linalg.norm(diff.eval()), 0.1)
示例6: _get_histogram_var_by_type
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_gamma [as 别名]
def _get_histogram_var_by_type(self,
histogram_type,
shape,
name=None,
**kwargs):
with tf.name_scope(name, "get_hist_{}".format(histogram_type)):
if histogram_type == "normal":
# Make a normal distribution, with a shifting mean
mean = tf.Variable(kwargs['mean'])
stddev = tf.Variable(kwargs['stddev'])
return tf.random_normal(
shape=shape, mean=mean, stddev=stddev), [mean, stddev]
elif histogram_type == "gamma":
# Add a gamma distribution
alpha = tf.Variable(kwargs['alpha'])
return tf.random_gamma(shape=shape, alpha=alpha), [alpha]
elif histogram_type == "poisson":
lam = tf.Variable(kwargs['lam'])
return tf.random_poisson(shape=shape, lam=lam), [lam]
elif histogram_type == "uniform":
# Add a uniform distribution
maxval = tf.Variable(kwargs['maxval'])
return tf.random_uniform(shape=shape, maxval=maxval), [maxval]
raise Exception('histogram type error %s' % histogram_type,
'builtin type', self._histogram_distribute_list)
示例7: random_gamma
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_gamma [as 别名]
def random_gamma(self, shape, alpha, beta=None):
return tf.random_gamma(shape, alpha, beta=beta)
pass
示例8: _sample
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_gamma [as 别名]
def _sample(self, alpha, beta):
gammas = tf.random_gamma(shape=self.shape, alpha=alpha, beta=beta)
return gammas
示例9: sample_pi
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_gamma [as 别名]
def sample_pi(self, alpha, beta):
Gam = tf.random_gamma([1], alpha=alpha, beta=beta, name="Gam", seed=None)[0]
return self.G_inv(Gam, alpha, beta)
# shape augmentation
示例10: random_exponential
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_gamma [as 别名]
def random_exponential(shape, rate=1.0, dtype=tf.float32, seed=None):
"""
Helper function to sample from the exponential distribution, which is not
included in core TensorFlow.
"""
return tf.random_gamma(shape, alpha=1, beta=1. / rate, dtype=dtype, seed=seed)