Let p=(12,14,14) and q=(13,13,13) on three outcomes. Compute H(p), the cross-entropy H(p,q), and both DKL(p∥q) and DKL(q∥p) in bits. What do the numbers show?

Probability and statistics, Information theory
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can evaluate entropy-type quantities by hand and know that KL is not symmetric.

Key idea

H(p)=−∑ipilog⁡2pi, H(p,q)=−∑ipilog⁡2qi, and DKL(p∥q)=∑ipilog⁡2piqi=H(p,q)−H(p).

Steps

  1. Entropy: H(p)=12⋅1+14⋅2+14⋅2=1.5 bits.
  2. Cross-entropy: qi=1/3 for every i, so H(p,q)=−∑pilog⁡213=log⁡23≈1.585 bits.
  3. KL from p to q: DKL(p∥q)=1.585−1.5=0.085 bits.
  4. KL the other way: DKL(q∥p)=13[log⁡21/31/2+2log⁡21/31/4]=13[−0.585+2(0.415)]≈0.082 bits.
  5. Read the results. Both KLs are positive, as they must be, and they are different (0.085 against 0.082), so KL is not symmetric. Also H(p,q)≥H(p): coding with the wrong distribution costs extra bits.

Common mistakes

How long your answer should be

Half a page, 3 minutes.

Last checked on 4 December 2026.

Read this

Previous in Probability and statistics: A non-negative random variable X (say, the response time of a server) has mean 50 and variance 25. Using Markov's and Chebyshev's inequalities, what bounds do you get for P(X≥80) and for P(∣X−50∣≥15), and why is one bound much tighter?
Next in Probability and statistics: Two binary variables X and Y have the joint distribution P(0,0)=P(1,1)=0.4 and P(0,1)=P(1,0)=0.1. What is the mutual information I(X;Y) in bits, and what would it be if X and Y were independent?