【问题标题】:Why do I get a NaN when computing the KL divergence between two OneHotCategorical distributions?为什么在计算两个 OneHotCategorical 分布之间的 KL 散度时会得到 NaN?
【发布时间】:2020-01-14 15:21:55
【问题描述】:

我尝试使用以下代码计算两个 OneHotCategorical 分布之间的 KL-Divergence:

posterior = tfd.OneHotCategorical(probs=[0., 0., 0., 0., 0., 0., 0., 1.])
prior     = tfd.OneHotCategorical(probs=[0., 0., 0., 0., 0., 0., 0., 1.])

结果:

print(posterior.kl_divergence(prior))
tf.Tensor(nan, shape=(), dtype=float32)

这是一个错误还是想要的结果?我对其进行了一点测试,错误是指计算 KL 散度,其中出现 0. 值的问题(对数和除法)。在这种情况下,我认为 KL 散度应该设置为 0.0。 问候 张量流版本:2.1.0-rc1 TensorFlow 概率版本:0.8.0

【问题讨论】:

  • 这可能是由于计算log(0)。因此,如果您需要修复,只需在它为零时添加一个小 epsilon。
  • 是的,这也是我的解决方法。无论如何,这是一个错误,应该得到修复,因为不可能的事件(概率 = 0。)也应该在概率分布中考虑。

标签: tensorflow tensorflow-probability


【解决方案1】:

你能在http://github.com/tensorflow/probability 上举报吗?我们在那里跟踪问题。

【讨论】:

    猜你喜欢
    • 2021-04-12
    • 1970-01-01
    • 2019-12-12
    • 2018-09-27
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多