AIToday
Qiita 機械学習Published: Nov 1, 2026, 13:00 JST

KLダイバージェンス: 0.368 vs 0.511, why order matters

Send on LINE
KLダイバージェンス: 0.368 vs 0.511, why order matters

3 Key Points

  1. What happened

    Aoki's explainer computes KL divergence between a 90/10 red-blue box (reality P) and a 50/50 belief (Q), getting about 0.368 in one direction and 0.511 in the reverse.

  2. Why it matters

    The gap shows KL divergence measures extra surprise from using the wrong distribution, not plain distance, so swapping which world is real changes the number.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, every morning.

Context & Analysis

This is the sixth installment of Aoki's series on the mathematics behind AI and neuroscience, and it picks up from the previous episode's treatment of entropy. Entropy described the uncertainty of the world itself; KL divergence adds a second perspective, the extra information cost of believing a distribution that differs from reality. The worked example makes the abstract formula tangible: with natural logarithms the units are nats, and the two directions differ because the average is taken over whichever distribution is treated as real.

The piece then links the formula to a boxed identity, cross entropy equals entropy plus KL divergence, and to three properties: the value is never negative, it is zero only when the distributions match, and it is generally asymmetric. That last property is why KL divergence is not a distance in the usual mathematical sense. A further note points out that if the believed distribution assigns zero probability to something that can happen, the divergence becomes infinite, a warning about overconfident models.

Aoki extends the idea to continuous distributions, where the sum becomes an integral, and then to three application areas. In statistics, minimizing KL divergence is equivalent to minimizing cross entropy, which connects to maximum likelihood estimation from an earlier episode. In generative AI, the VAE objective includes a KL term that keeps the learned latent distribution close to a prior. In neuroscience, Karl Friston's free energy principle uses KL divergence to describe how the brain compares predicted and actual sensory information, though it is not established that the brain literally computes KL divergence.

FAQ
Why do the two directions give different numbers?
Reality is 90% red but you believe 50/50, so being wrong about blue is only mildly surprising. If reality is 50/50 but you believe 90% red, each blue ball strongly breaks your expectation, raising the average.
What happens if I believe something is impossible that actually happens?
If P(x) is above zero but Q(x) is zero, KL divergence becomes infinite, because the model assigned zero probability to an event that occurs.
Where does KL divergence show up beyond this toy example?
It appears in maximum likelihood estimation, in the VAE generative model's training objective, and in neuroscience theories such as predictive coding and the free energy principle.
Qiita 機械学習Read Original Article
Send on LINE

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Next articleApple passes Nvidia at $5.03 trillion as chip stocks slide