【问题标题】:What is the Tensorflow equivalent of numpy.random.multivariate_normal?numpy.random.multivariate_normal 的 Tensorflow 等价物是什么?
【发布时间】:2017-10-18 14:32:12
【问题描述】:

我想在给定均值和协方差矩阵的情况下抽取随机样本。在 numpy 中,我可以使用 numpy.random.multivariate_normal 函数来做到这一点。什么是 TensorFlow 等价物?

在我的例子中,数据是二维的。因此,均值至少是维度张量 (batch_size, 1) 中的一个,并且均值列表的长度为 2。

【问题讨论】:

    标签: numpy tensorflow


    【解决方案1】:

    我认为您正在寻找tf.contrib.distributions.MultivariateNormalDiag,如TensorFlow Official Documentation 所示。

    【讨论】:

    • 没有。在这种情况下,我必须通过观察来评估 pdf,我想要的是随机抽取一些给定均值和协方差的样本。查看 numpy 函数
    【解决方案2】:

    要获得随机样本,您可以使用tf.distributions.Normal 类的方法sample。它需要标准偏差而不是协方差矩阵。例如二维:

    mean = [1.0, 2.0]
    std = [0.5, 0.7]
    dist = tf.distributions.Normal(mean, std)
    dist.sample()
    

    【讨论】:

      猜你喜欢
      • 2017-01-14
      • 2019-11-11
      • 2019-03-24
      • 1970-01-01
      • 2017-06-05
      • 1970-01-01
      • 2022-06-22
      • 2021-12-15
      • 2020-12-28
      相关资源
      最近更新 更多