Study Vault Search notes, aliases and full text
Graph
ConceptDBISAI-written · not yet proofread

Entropy

Also Shannon Entropy

The entropy H(X) = −∑ p_i log₂ p_i of a discrete random variable X is its average information content in bits per symbol and the lower bound on the expected code length of any prefix-free encoding of X.

Know these firstRandom Variable

Formula#

  • Two values with probabilities p,1−pp, 1 - p: H(p)=−plog⁡2p−(1−p)log⁡2(1−p)H(p) = -p \log_2 p - (1 - p) \log_2 (1 - p).
  • Uniform distribution over nn symbols: H=−n⋅1nlog⁡21n=log⁡2nH = -n \cdot \frac{1}{n} \log_2 \frac{1}{n} = \log_2 n.

Properties#

  • log⁡2(1/pi)\log_2(1/p_i) is the information content of symbol xix_i: rare symbols carry more information. H(X)H(X) is its expected value.
  • Lower bound for compression: every prefix-free code for XX has expected code length ∑ipiLi≥H(X)\sum_i p_i L_i \geq H(X), and Shannon’s source coding theorem gives one with <H(X)+1< H(X) + 1 (Entropy-Optimal Code).
  • 0≤H(X)≤log⁡2n0 \leq H(X) \leq \log_2 n, with H(X)=0H(X) = 0 iff one pi=1p_i = 1.
ProofProof with Lagrange multipliers
  1. Maximize H=−∑ipilog⁡2piH = -\sum_i p_i \log_2 p_i subject to ∑ipi−1=0\sum_i p_i - 1 = 0. Lagrangian: L=−∑i=1npilog⁡2pi+λ(∑i=1npi−1)\mathcal{L} = -\sum_{i=1}^{n} p_i \log_2 p_i + \lambda \left(\sum_{i=1}^{n} p_i - 1\right)
  2. With log⁡2p=ln⁡pln⁡2\log_2 p = \frac{\ln p}{\ln 2} and (pln⁡p)′=1+ln⁡p(p \ln p)' = 1 + \ln p: ∂L∂pi=−log⁡2pi−1ln⁡2+λ=0  ⟺  log⁡2pi=λ−1ln⁡2.\frac{\partial \mathcal{L}}{\partial p_i} = -\log_2 p_i - \frac{1}{\ln 2} + \lambda = 0 \iff \log_2 p_i = \lambda - \frac{1}{\ln 2}. The right-hand side is the same for all ii, so all pip_i are equal.
  3. ∂L∂λ=∑ipi−1=0\frac{\partial \mathcal{L}}{\partial \lambda} = \sum_i p_i - 1 = 0, so pi=1/np_i = 1/n.
  4. Maximum, not minimum: ∂2H∂pi2=−1piln⁡2<0\frac{\partial^2 H}{\partial p_i^2} = -\frac{1}{p_i \ln 2} < 0 and the mixed second derivatives vanish, so HH is concave. (The exam allows assuming this; WS 16/17 Task 6.3 asks for the second derivative.)
  5. H(1/n,…,1/n)=log⁡2nH(1/n, \ldots, 1/n) = \log_2 n. ■\blacksquare

Two values (DBIS Exam WS1516 (not published), Task 6.3): H′(p)=1ln⁡2(−(1+ln⁡p)+(1+ln⁡(1−p)))=1ln⁡2ln⁡1−pp=0  ⟺  p=12H'(p) = \frac{1}{\ln 2}\left(-(1 + \ln p) + (1 + \ln(1-p))\right) = \frac{1}{\ln 2} \ln\frac{1-p}{p} = 0 \iff p = \frac{1}{2}, and H′′(p)=−1ln⁡2⋅p(1−p)<0H''(p) = -\frac{1}{\ln 2 \cdot p(1-p)} < 0, so p=1/2p = 1/2 is the maximum, H(1/2)=1H(1/2) = 1 bit.

Example#

Sequence A,B,A,A,B,C,A,DA, B, A, A, B, C, A, D with relative frequencies Pr⁡(A)=12\Pr(A) = \frac{1}{2}, Pr⁡(B)=14\Pr(B) = \frac{1}{4}, Pr⁡(C)=Pr⁡(D)=18\Pr(C) = \Pr(D) = \frac{1}{8} (DBIS Exam WS1920 (not published), Task 2.1):

H=12⋅1+14⋅2+2⋅18⋅3=0.5+0.5+0.75=1.75 bits per symbol.H = \tfrac{1}{2} \cdot 1 + \tfrac{1}{4} \cdot 2 + 2 \cdot \tfrac{1}{8} \cdot 3 = 0.5 + 0.5 + 0.75 = 1.75 \text{ bits per symbol.}

Uniform over 1,…,81, \ldots, 8: H=log⁡28=3H = \log_2 8 = 3 bits (DBIS Exam WS1819 (not published), Task 2.1).

Sources#

  • DBIS Exam WS2223 (not published) Task 1.3 (maximum entropy via Lagrange), DBIS Exam WS1617 (not published) Task 6.3, DBIS Exam WS1516 (not published) Task 6.3 (two values)
  • DBIS Exam WS1819 (not published) Task 2.1, DBIS Exam WS1920 (not published) Task 2.1, DBIS Exam WS2122 (not published) Task 2.3 (entropy of concrete distributions)
  • Not lectured in WS 25/26.

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only