python - 连续 pdf 的 KL 散度

标签 python scipy statsmodels pymc

假设我有两个 pdf 文件,例如:

from scipy import stats
pdf_y = stats.beta(5, 9).pdf
pdf_x = stats.beta(9, 5).pdf

我想计算他们的 KL divergence 。在我重新发明轮子之前,PyData 生态系统中是否有任何内置函数可以做到这一点?

最佳答案

KL 散度可在 scipy.stats.entropy 中找到。来自文档字符串

stats.entropy(pk, qk=None, base=None) 

Calculate the entropy of a distribution for given probability values.           

If only probabilities `pk` are given, the entropy is calculated as              
``S = -sum(pk * log(pk), axis=0)``.                                             

If `qk` is not None, then compute a relative entropy (also known as             
Kullback-Leibler divergence or Kullback-Leibler distance)                       
``S = sum(pk * log(pk / qk), axis=0)``.  

关于python - 连续 pdf 的 KL 散度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22097409/

相关文章:

python - 将边界应用于 Scipy 优化曲线拟合

python - 列表和元组的行为不同

machine-learning - python 机器学习 弃用警告

python - 来自 statsmodels.tsa.statespace 的 sarimax 的 AttributeError

python - 按字段分组的 Django 查询对象

python - 如何在 Python 中从 AWS 中的 lambda 函数返回二进制数据?

python - Django Model Mixins : inherit from models. 模型还是来自对象?

python - 无法向 Gmail 验证 Google 服务帐户的身份

python - 在没有真实索引的情况下 reshape Pandas 数据框

python - python中的季节性分解