Skip to content

Conversation

@NKNaN
Copy link
Contributor

@NKNaN NKNaN commented May 12, 2024

之前 kl 散度的推导有误,建议先不实现 kl 散度。

@paddle-bot
Copy link

paddle-bot bot commented May 12, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请检查PR提交格式和内容是否完备,具体请参考示例模版
Your PR has been submitted. Thanks for your contribution!
Please check its format and content. For this, you can refer to Template and Demo.

t 分布的 cdf 与 icdf 主要是在统计学的假设检验问题中有重要价值, 而在机器学习的概率模型领域下,使用最为广泛的主要还是分布的 pdf 与 logpdf。另一方面由于 t 分布的 cdf 和 icdf 的实现相对复杂, 对 pdf 的积分函数与其积分函数的逆函数的实现需要借助 [incomplete beta function](https://dlmf.nist.gov/8.17) 和 inverse incomplete beta function,这两个在 paddle 中尚未实现,所以考虑暂时先不实现 cdf 与 icdf。

此外, kl 散度的解析函数较难推导出, 以下过程参考[A Novel Kullback-Leilber Divergence Minimization-Based Adaptive Student's t-Filter](https://www.researchgate.net/publication/335580775_A_Novel_Kullback-Leilber_Divergence_Minimization-Based_Adaptive_Student's_t-Filter)

Copy link

@xuxinyi389 xuxinyi389 May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/distributions/student_t.py#L780-L1079 tf中也并没有为t分布实现kl逻辑。而是在https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/distributions/distribution.py#L1730-L1761 中调用return kullback_leibler.kl_divergence(self, other, allow_nan_stats=self.allow_nan_stats)实现,你可以看看padldle 中的paddle.distribution.kl_divergence(p, q) https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/distribution/kl_divergence_cn.html 是否能满足要求,因此也不需要单独为t分布实现kl。 刚才看了 下RFC对于一些符号的解释并没有在第一时间解释,比如Gamma函数的在此处第一次出现但是没有立刻解释,可以调整一下。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
tf 中的 kullback_leibler.kl_divergence(self, other, allow_nan_stats=self.allow_nan_stats) 根据他的文档注释应该意思是如果该分布没有直接实现kl_divergence,就去找父类有没有实现。padldle 中的 paddle.distribution.kl_divergence(p, q) 也是类似的逻辑。所以应该还是没办法实现t分布的kl。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

符号解释已调整

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,没有问题。kl本次开发不涉及。

D_{KL} & = \log \Gamma(\frac{\nu_1+1}{2}) - \log \Gamma(\frac{\nu_2+1}{2}) + \frac{1}{2}\log\frac{\nu_2}{\nu_1} + \log\frac{\sigma_2}{\sigma_1} - \log\Gamma(\frac{\nu_1}{2}) + \log\Gamma(\frac{\nu_2}{2}) \\
& - \frac{\nu_1+1}{2} [\psi(\frac{1+\nu_1}{2}) - \psi(\frac{\nu_1}{2})] \\
& + \frac{\nu_2+1}{2} \mathbb{E}\_{f1(x)}\[\log[1 +(\frac{x-\mu_2}{\sigma_2})^2 / \nu_2]\]
\end{aligned} $$

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该指明哪一项无法解析,看你的推导应该是最后一项无法解析,应该是只能利用不等式推出上确界,可以在RFC中补充下,更方便大家理解。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

@xuxinyi389
Copy link

LGTM

@luotao1 luotao1 merged commit 3d0e160 into PaddlePaddle:master May 14, 2024
@NKNaN NKNaN deleted the h6revise branch August 27, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants