In [15]: a = np.array([0.5, 0.5, 0, 0, 0])
In [16]: b = np.array([1, 0, 0, 0, 0])
In [17]: entropy(a, b)
Out[17]: inf
In [18]: entropy(b, a)
Out[18]: 0.6931471805599453
从它们的documentation中,我期望两者都返回inf
,因为给出的等式是S = sum(pk * log(pk / qk), axis=0)
。第18行的非无限输出的原因是什么?在
entropy(b, a)
函数计算第一对:结果是
0.6931471805599453
。在对于
entropy(a, b)
,有一个被零除的情况,0.5/0
,这将导致无穷解。在其余的,
entropy()
假设0 * np.log(0/0)
等于0
。在纵观Kullback-Leibler散度的定义,它似乎是由于它是如何定义的。在
来自维基百科:
相关问题 更多 >
编程相关推荐