scipy.special.rel_entr#

scipy.special.rel_entr(x, y, out=None) = <ufunc 'rel_entr'>#

用於計算相對熵的逐元素函數。

\[\begin{split}\mathrm{rel\_entr}(x, y) = \begin{cases} x \log(x / y) & x > 0, y > 0 \\ 0 & x = 0, y \ge 0 \\ \infty & \text{otherwise} \end{cases}\end{split}\]
參數:
x, yarray_like

輸入陣列

outndarray, optional

函數結果的選用輸出陣列

回傳值:
純量或 ndarray

輸入的相對熵

註解

在 0.15.0 版本中新增。

此函數在 x 和 y 中是聯合凸函數。

此函數的起源在於凸優化;請參閱 [1]。給定兩個離散機率分佈 \(p_1, \ldots, p_n\)\(q_1, \ldots, q_n\),在資訊理論的背景下,相對熵的定義為

\[\sum_{i = 1}^n \mathrm{rel\_entr}(p_i, q_i).\]

若要計算後者,請使用 scipy.stats.entropy

詳細資訊請參閱 [2]

參考文獻

[1]

Boyd, Stephen 和 Lieven Vandenberghe. Convex optimization. Cambridge University Press, 2004. DOI:https://doi.org/10.1017/CBO9780511804441