tf.random.normal和tf.distributions.Normal有什么不同?或者tf.distributions.Multinomial和tf.random.multinomial之间的区别,或者任何类似的东西?
是否将tf.distributions.Normal用作tf.random.normal的后端
发布于 2019-06-03 08:02:52
我最近查看了tf distributions的新网站tf probability。这是我的理解:
它们是不一样的。tf.distributions.Normal将为您提供一个分布对象,您可以从中进行采样(这将与计算tf.random.normal函数调用返回的张量以获得相同的平均值和loc值相同)。但是,分布还允许您评估您提供的样本的概率,以及访问分布的所有方面。
例如,您可以执行以下操作:
>>> import tensorflow as tf
>>> dist = tf.distributions.Normal(loc=0., scale=1.)
>>> dist.log_prob(tf.random.normal(shape=(3,3)))
<tf.Tensor: id=58, shape=(3, 3), dtype=float32, numpy=
array([[-0.9486696 , -0.95645994, -1.1610177 ],
[-1.244764 , -1.416851 , -1.1236244 ],
[-0.9292835 , -0.98901427, -0.9705758 ]], dtype=float32)>https://stackoverflow.com/questions/56419668
复制相似问题