【问题标题】:CDF of a multivariate Normal in TensorflowTensorflow中多元正态的CDF
【发布时间】:2018-06-22 12:57:27
【问题描述】:

我想使用 tensorflow 评估多元正态分布的 cdf。到目前为止我尝试过的:

import tensorflow as tf
ds = tf.contrib.distributions

# Initialize a single 3-variate Gaussian.
mu = [0., 0., 0.]
cov = [[ 0.36,  0.12,  0.06],
       [ 0.12,  0.29, -0.13],
       [ 0.06, -0.13,  0.26]]
mvn = ds.MultivariateNormalFullCovariance(
    loc=mu,
    covariance_matrix=cov)
value = tf.constant([0., 0., 0.])


with tf.Session() as sess:
    print mvn.cdf(value).eval()

这会产生错误:

NotImplementedError: cdf is not implemented when overriding event_shape

我不明白为什么要覆盖 event_shape,因为 event_shape 和 value 的形状是相同的。我做错了什么?

【问题讨论】:

    标签: python tensorflow cdf


    【解决方案1】:

    你没有做错任何事。未针对多元正态实施 CDF。 (我同意错误消息令人困惑。错误消息是由负责实现cdfTransformedDistribution 抛出的。)

    如果您可以容忍蒙特卡洛近似,我建议您执行以下操作:

    def approx_multivariate_cdf(dist, bound, num_samples=int(100e3), seed=None):
      s = dist.sample(num_samples, seed=seed)
      in_box = tf.cast(tf.reduce_all(s <= bound, axis=-1), dist.dtype)
      return tf.reduce_mean(in_box, axis=0)
    

    (经过一番思考,我相信有人可以做得比这更好。)

    这里可能还描述了一个更聪明的解决方案:https://arxiv.org/abs/1603.04166

    【讨论】:

      猜你喜欢
      • 2017-03-20
      • 2012-12-20
      • 2015-08-14
      • 2012-06-21
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      • 2020-02-12
      • 1970-01-01
      相关资源
      最近更新 更多