scipy.special.kl_div#
- scipy.special.kl_div(x, y, out=None) = <ufunc 'kl_div'>#
用于计算 Kullback-Leibler 散度的逐元素函数。
\[\begin{split}\mathrm{kl\_div}(x, y) = \begin{cases} x \log(x / y) - x + y & x > 0, y > 0 \\ y & x = 0, y \ge 0 \\ \infty & \text{otherwise} \end{cases}\end{split}\]- 参数:
- x, y类数组对象
实数参数
- outndarray, 可选
用于存放函数结果的可选输出数组
- 返回:
- 标量或 ndarray
Kullback-Liebler 散度的值。
另请参阅
备注
在版本 0.15.0 中添加。
此函数是非负的,并且在 x 和 y 中是联合凸的。
此函数源于凸优化;详情请参阅 [1]。这就是为什么此函数包含额外的 \(-x + y\) 项,这可能与 Kullback-Leibler 散度的预期不同。有关不含额外项的函数版本,请参阅
rel_entr
。参考文献
[1]Boyd, Stephen and Lieven Vandenberghe. 凸优化. Cambridge University Press, 2004. DOI:https://doi.org/10.1017/CBO9780511804441