【问题标题】:Tensorflow Implement Multivariate Student T diagonal distributionTensorflow 实现多元学生 T 对角分布
【发布时间】:2018-11-27 23:28:58
【问题描述】:

我正在实现对角多元学生 t 分布(所以 logP(x1,x2,x3,..xD) = logP(x1) + logP(x2)+ ....+ logP(xD) )这样它可以用作 TensorFlow 中双射器的基础分布

import tensorflow_probability as tfp
tfd = tfp.distributions

D = 2 # number of dimension
df = 5. # degree of freedom

# construct D univariate student t distribution

base_dist = tfd.StudentT(loc=tf.constant([0.] * D,dtype=DTYPE),
                         scale = tf.constant([1.] * D,dtype=DTYPE),
                         df = tf.constant([df],dtype=DTYPE))

Q = tfd.TransformedDistribution(distribution=base_dist,bijector=Chain)
# where Chain is a tfb.Chain() object that a sequence of bisector numbers

我更改了tfd.StudentT.log_prob(),使其在最后一个轴上求和。它以 shape[batch_size,dim] 作为输入,并以 shape[batch_size,] 返回 pdf

但是,当我打电话给Q.log_prob(x);我收到错误ValueError: event_ndims (0) must be larger than min_event_ndims (1)

我不确定如何修复此错误;有人可以帮我吗?

【问题讨论】:

    标签: python tensorflow tensorflow-probability


    【解决方案1】:

    TensorFlow Probability 提供了一种通过 tfd.Independent 元分布从标量分布创建向量值分布的方法。这将自动在log_prob 中执行您想要的求和。

    如果您真的想自己实现,您遇到的问题听起来像是您没有覆盖 event_shapeevent_shape_tensor 方法(以及 batch_shapebatch_shape_tensor)。

    最后,通常当人们谈论多元学生 t 分布时,他们指的是here 所描述的椭圆分布,这与将一维 Student-t 分布和然后对它们进行线性变换。最近,TFP 添加了此分布here 的椭圆变体的实现。它需要一个仿射变换作为输入,您可以使用它来设置分布的位置/相关结构。

    【讨论】:

      猜你喜欢
      • 2015-06-30
      • 2021-04-08
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2016-04-09
      • 1970-01-01
      • 2016-11-28
      • 1970-01-01
      相关资源
      最近更新 更多