信息熵与KL散度
在1948年,香农(Shannon)在他著名的《通信的数学原理》论文中指出:“信息是用来消除随机不确定性的东西”,并提出了“信息熵”的概念(借用了热力学中熵的概念),来解决信息的度量问题。也就是量化信息(信息,泛指人类社会传播的一切内容,指音讯、消息、通信系统传输和处理的对象。)。
一个事件或一个系统,准确的说是一个随机变量,它有着一定的不确定性。要消除这个不确定性,就需要引入很多的信息,这些很多信息的度量就用“信息熵”表达。需要引入消除不确定性的信息量越多,则信息熵越高,反之则越低。
根据香农(Shannon)给出的信息熵公式,对于任意一个随机变量X,它的信息熵定义如下,单位为比特(bit):
H [ X ] = E x ∼ p ( x ) [ − log p ( x ) ] = − ∫ x ∈ X p ( x ) log p ( x ) d x = − ∑ x ∈ X p ( x ) log p ( x ) H[\mathbf X]=\mathbb{E}_{\mathbf x\sim p(\mathbf x)}[-\log p(\mathbf x)]=-\int_{\mathbf x\in\mathbf X}p(\mathbf x)\log p(\mathbf x)d\mathbf x=-\sum_{\mathbf x\in\mathbf X}p(\mathbf x)\log p(\mathbf x) H[X]=Ex∼p(x)[−logp(x)]=−∫x∈Xp(x)logp(x)dx=−x∈X∑p(x)logp(x)
条件熵
H [ Y ∣ X ] = ∑ x ∈ X E x ∼ p ( x ) [ H ( Y ∣ X = x ) ] = − ∑ x ∈ X p ( x ) ∑ y ∈ Y [ p ( y ∣ x ) log p ( y ∣ x ) ] = − ∑ x ∈ X ∑ y ∈ Y [ p ( x , y ) log p ( y ∣ x ) ] \begin{align} H[\mathbf Y|\mathbf X]&=\sum_{\mathbf x \in \mathbf X}\mathbb{E}_{\mathbf x\sim p(\mathbf x)}[H(\mathbf Y|\mathbf X = \mathbf x)]\notag\\ &=-\sum_{\mathbf x \in \mathbf X}p(\mathbf x)\sum_{\mathbf y \in \mathbf Y}[p(\mathbf y|\mathbf x)\log p(\mathbf y|\mathbf x)]\notag\\ &=-\sum_{\mathbf x \in \mathbf X}\sum_{\mathbf y \in \mathbf Y}[p(\mathbf x, \mathbf y)\log p(\mathbf y|\mathbf x)]\notag \end{align} H[Y∣X]=x∈X∑Ex∼p(x)[H(Y∣X=x)]=−x∈X∑p(x)y∈Y∑[p(y∣x)logp(y∣x)]=−x∈X∑y∈Y∑[p(x,y)logp(y∣x)]
KL 散度 Kullback-Leibler Divergence(相对熵)
KL散度用来衡量两个分布对于同一变量的差异情况。在概率学中,我们经常使用更简单的分布来近似观察数据或复杂分布。KL散度能帮助我们度量使用一种分布近似另一种分布时所损失的信息量。设p为观察得到的概率分布,q为另一分布来近似p,则p、q的K-L散度为:
D K L ( p ∥ q ) = E x ∼ p ( x ) [ log p ( x ) − log q ( x ) ] = ∫ p ( x ) ( log p ( x ) − log q ( x ) ) d x D_{KL}(p\|q)=\mathbb{E}_{\mathbf x\sim p(\mathbf x)}\Big[\log p(\mathbf x)-\log q(\mathbf x)\Big]=\int p(\mathbf x)\Big(\log p(\mathbf x)-\log q(\mathbf x) \Big)d\mathbf x DKL(p∥q)=Ex∼p(x)[logp(x)−logq(x)]=∫p(x)(logp(x)−logq(x))dx
D K L ( p ∥ q ) = ∑ i p ( x i ) ( log p ( x i ) − log q ( x i ) ) D_{KL}(p\|q)=\sum_ip(\mathbf x_i)\Big(\log p(\mathbf x_i)-\log q(\mathbf x_i) \Big) DKL(p∥q)=i∑p(xi)(logp(xi)−logq(xi))
显然,根据上述公式,K-L散度其实是统一随机变量x的原始分布p和近似分布q之间的对数差值的期望。如果继续用2为底的对数计算,则K-L散度值表示信息损失的二进制位数。K-L散度通常也被写为以下形式:
D K L ( p ∥ q ) = ∑ i p ( x i ) ⋅ log p ( x i ) q ( x i ) D_{KL}(p\|q)=\sum_ip(\mathbf x_i)\cdot\log \frac{p(\mathbf x_i)}{q(\mathbf x_i)} DKL(p∥q)=i∑p(xi)⋅logq(xi)p(xi)