python计算矩阵的散度_如何使用numpy.histogram计算概率,然后将其用于计算KL散度?...

在Python中,当使用numpy.histogram设置density=True时,返回的是概率密度函数。要计算概率,需要定义范围并累加该范围内PDF的值。文章提供了计算互信息和KL散度的代码示例,其中涉及概率密度的平滑处理和边缘概率的计算。对于最佳结果,建议使用经验法则来估计带宽。
摘要由CSDN通过智能技术生成

In the following code, the density=True returns probability density function at each bin. Now if have to calculate P(x), can I say that hist is showing probabilities? For example if the first bin's mean value is 0.5 can I say that at x=0.5 probability is hist[0] ? I have to use KL divergence which uses P(x).

x = np.array([0,0,0,0,0,3,3,2,2,2,1,1,1,1,])

hist,bin_edges= np.histogram(x,bins=10,density=True)

解决方案

When you set density=True, NumPy returns a probability density function (lets say p). Theoretically speaking, p(0.5) = 0 because the probability is defined as the area under the PDF curve. You can read more details about it here. So, if you want to the compute probability you will have to define desired range and sum up all PDF values in this range.

For the KL, I can share my solution for the mutual information computatio

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值