<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>KL Divergence - Tag - Naifan Li's Blog</title><link>https://blog.omagiclee.com/tags/kl-divergence/</link><description>KL Divergence - Tag - Naifan Li's Blog</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sat, 14 Mar 2026 21:00:00 +0800</lastBuildDate><atom:link href="https://blog.omagiclee.com/tags/kl-divergence/" rel="self" type="application/rss+xml"/><item><title>信息量、熵、交叉熵与 KL 散度</title><link>https://blog.omagiclee.com/posts/basics/kl-divergence/</link><pubDate>Sat, 14 Mar 2026 21:00:00 +0800</pubDate><author>Naifan Li</author><guid>https://blog.omagiclee.com/posts/basics/kl-divergence/</guid><description><![CDATA[<h2 id="术语说明">术语说明</h2>
<table>
  <thead>
      <tr>
          <th>术语</th>
          <th>英文</th>
          <th>含义</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>真实分布</strong></td>
          <td>true distribution</td>
          <td>数据实际服从的概率分布，记为 $P$。在信息论中，它是「世界本来的样子」；在机器学习中，常对应真实标签分布或数据生成分布。</td>
      </tr>
      <tr>
          <td><strong>经验分布</strong></td>
          <td>empirical distribution</td>
          <td>由有限样本估计得到的分布，记为 $\hat{P}$。若样本 $x^{(1)}, \dots, x^{(n)}$ 中，$x$ 出现 $n_x$ 次，则 $\hat{P}(x) = n_x / n$。样本量越大，经验分布越接近真实分布。</td>
      </tr>
      <tr>
          <td><strong>模型分布</strong></td>
          <td>model distribution</td>
          <td>由模型参数决定的分布，记为 $Q$ 或 $q(x;\theta)$。训练的目标是让模型分布接近真实分布（或经验分布）。</td>
      </tr>
  </tbody>
</table>
<h2 id="信息量">信息量</h2>
<p><strong>核心问题</strong>：信息量为什么定义为 $i(x) = -\log_2 p(x)$？</p>
<p><strong>核心思想</strong>：信息是“消除不确定性”的程度。事件越可能发生，发生后带来的新信息越少；越不可能发生，发生后带来的新信息越多。</p>
<p>例如：</p>
<ul>
<li>“太阳今天升起来了”几乎不会让人惊讶，因此信息量很小</li>
<li>“你的彩票中了一个亿”极其罕见，因此信息量很大</li>
</ul>
<p>所以，信息量本质上应该是概率 $p$ 的某个函数 $I(p)$，并满足：</p>
<ol>
<li><strong>单调性</strong>：概率越小，信息量越大</li>
<li><strong>可加性</strong>：若两个事件独立，则联合事件的信息量应该等于两者之和</li>
<li><strong>非负性</strong>：信息量不应小于 $0$</li>
</ol>
<p>其中，第二条最关键。</p>
<p>若事件 $A$ 和 $B$ 独立，则：</p>
$$
P(A \cap B) = P(A)P(B)
$$<p>而“知道 $A$ 发生”带来一部分信息，“知道 $B$ 发生”再带来一部分信息，那么“知道 $A$ 和 $B$ 同时发生”带来的信息，应该等于两者之和。因此信息量函数应满足：</p>]]></description></item></channel></rss>