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

Entropy-Optimal Code

A code is entropy-optimal for a distribution p if its expected code length equals the entropy H(p), which holds exactly when every codeword length is L_i = log₂(1/p_i); by Shannon's source coding theorem a prefix-free code with expected length below H + 1 always exists.

Know these firstEntropyPrefix-Free Code

Formula#

H(X)≤Lˉ<H(X)+1for the best prefix-free code (Shannon’s source coding theorem)H(X) \leq \bar L < H(X) + 1 \quad \text{for the best prefix-free code (Shannon's source coding theorem)}

The theorem’s code uses lengths Li=⌈log⁡2(1/pi)⌉L_i = \lceil \log_2(1/p_i) \rceil, with expected length ∑ipi⌈log⁡2(1/pi)⌉\sum_i p_i \lceil \log_2 (1/p_i) \rceil.

Properties#

  • Lower bound. Among codes with ∑i2−Li=1\sum_i 2^{-L_i} = 1 (Kraft equality, see Prefix-Free Code), Lˉ≥H(X)\bar L \geq H(X). Proof (DBIS Exam WS1920 (not published), Task 2.2): minimize ∑ipiLi\sum_i p_i L_i subject to ∑i2−Li=1\sum_i 2^{-L_i} = 1 with the Lagrangian ∑ipiLi+λ(∑i2−Li−1)\sum_i p_i L_i + \lambda(\sum_i 2^{-L_i} - 1). Setting ∂/∂Li=pi−λln⁡2⋅2−Li=0\partial/\partial L_i = p_i - \lambda \ln 2 \cdot 2^{-L_i} = 0 gives pi=λln⁡2⋅2−Lip_i = \lambda \ln 2 \cdot 2^{-L_i}. Summing over ii gives 1=λln⁡21 = \lambda \ln 2, so pi=2−Lip_i = 2^{-L_i}, i.e. Li=log⁡2(1/pi)L_i = \log_2(1/p_i), and then ∑ipiLi≥∑ipilog⁡2(1/pi)=H(X)\sum_i p_i L_i \geq \sum_i p_i \log_2(1/p_i) = H(X) (the exam allows assuming there are no saddle points).
  • Exactly H(X)H(X) iff every pip_i is a negative power of 2 (12,14,18,…\tfrac12, \tfrac14, \tfrac18, \dots), because only then ⌈log⁡2(1/pi)⌉=log⁡2(1/pi)\lceil \log_2(1/p_i) \rceil = \log_2(1/p_i), i.e. no rounding (DBIS Exam WS1819 (not published), Task 2.2).
  • Standard proof technique that a given code is entropy-optimal for some distribution: set pi=2−Lip_i = 2^{-L_i}, check ∑ipi=1\sum_i p_i = 1, and compute Lˉ=H(X)\bar L = H(X).
  • Uniform distribution over n=2mn = 2^m symbols: the fixed-length mm-bit code is entropy-optimal.

Example#

Code a=000a = 000, b=001b = 001, c=01c = 01, d=10d = 10, e=11e = 11 (DBIS Exam WS2122 (not published), Task 2.3): choose pi=2−Lip_i = 2^{-L_i}, i.e. pa=pb=18p_a = p_b = \tfrac18, pc=pd=pe=14p_c = p_d = p_e = \tfrac14 (sum 28+34=1\tfrac28 + \tfrac34 = 1). Then Lˉ=2⋅18⋅3+3⋅14⋅2=94=H(X)\bar L = 2 \cdot \tfrac18 \cdot 3 + 3 \cdot \tfrac14 \cdot 2 = \tfrac94 = H(X).

Sources#

  • DBIS Exam WS1314 (not published) Task 1.4, DBIS Exam WS1516 (not published) Task 2.4, DBIS Exam WS1718 (not published) Tasks 2.3–2.4, DBIS Exam WS1819 (not published) Tasks 2.1–2.2, DBIS Exam WS1920 (not published) Tasks 2.1–2.2, DBIS Exam WS2122 (not published) Task 2.3
  • Not lectured in WS 25/26.

Search

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