Home › Logarithms › Lesson 11

Information, Entropy and Logarithmic Scales

Lesson 11 of 13

Key idea of this section

H(p₁, …, pₙ) = −∑ pᵢ log₂ pᵢ bits,   0 ≤ H ≤ log₂ n
D(p ‖ q) = ∑ pᵢ ln(pᵢ/qᵢ) ≥ 0   (Gibbs)
level in dB = 10 log₁₀(P/P₀)

Why information is a logarithm

Suppose we want a measure I(N) of the information gained when one of N equally likely possibilities is revealed. Two natural requirements are that I is non-decreasing in N and that independent choices add: choosing one of M and, independently, one of N is choosing one of MN, so I(MN) = I(M) + I(N). Hartley (1928) and Shannon (1948) took I(N) = log N; the following theorem shows there is no other choice.

Theorem 11.1. Let f: ℕ → ℝ be non-decreasing with f(mn) = f(m) + f(n) for all m, n ≥ 1. Then f(n) = c ln n for some c ≥ 0.

Proof. f(1) = 2f(1) gives f(1) = 0. If f(2) = 0 then f(2ᵏ) = 0 for all k, and monotonicity forces f ≡ 0, which is the case c = 0. Otherwise f(m) ≥ f(2) > 0 for all m ≥ 2. Fix m, n ≥ 2 and k ≥ 1, and choose the integer j with mʲ ≤ nᵏ < mʲ⁺¹. Applying the monotone, additive f and the increasing, additive ln to these inequalities gives

j/k ≤ f(n)/f(m) ≤ (j + 1)/k   and   j/k ≤ ln n/ln m < (j + 1)/k.

So |f(n)/f(m) − ln n/ln m| ≤ 1/k for every k, hence f(n)/ln n = f(m)/ln m. This common value is the constant c. ∎

Erdős (1946) proved the stronger result in which additivity is required only for coprime m, n. The choice of c is the choice of unit: c = 1/ln 2 gives bits, c = 1 gives nats, and c = 1/ln 10 gives hartleys (also called bans or dits). Thus 1 nat = 1/ln 2 ≈ 1.4427 bits and 1 hartley = log₂ 10 ≈ 3.3219 bits.

Shannon entropy

For a probability distribution p = (p₁, …, pₙ), an outcome of probability pᵢ carries surprisal −log₂ pᵢ bits, and the entropy is the expected surprisal

H(p) = −∑ pᵢ log₂ pᵢ,   with the convention 0 log 0 = 0 (justified by x ln x → 0).

Shannon showed that H is, up to the unit, the only function that is continuous, increasing in n on uniform distributions, and satisfies the grouping rule H(p₁, …, pₙ) = H(p₁ + p₂, p₃, …, pₙ) + (p₁ + p₂)H(p₁/(p₁ + p₂), p₂/(p₁ + p₂)); the uniform case is Theorem 11.1. Examples: a fair coin has H = 1 bit; a coin with P(heads) = 0.9 has H ≈ 0.4690 bits; the distribution (1/2, 1/4, 1/8, 1/8) has H = 1/2 + 2/4 + 3/8 + 3/8 = 1.75 bits; a uniformly shuffled deck has log₂ 52! ≈ 225.58 bits.

Gibbs' inequality

Theorem 11.2. Let p, q be probability distributions on {1, …, n} with qᵢ > 0 whenever pᵢ > 0. Then the Kullback–Leibler divergence D(p ‖ q) = ∑ pᵢ ln(pᵢ/qᵢ) is non-negative, with equality if and only if p = q.

Proof. Sum over i with pᵢ > 0 and use ln x ≤ x − 1 (Proposition 1.6): −D(p ‖ q) = ∑ pᵢ ln(qᵢ/pᵢ) ≤ ∑ pᵢ(qᵢ/pᵢ − 1) = ∑pᵢ>0 qᵢ − 1 ≤ 0. Equality in Proposition 1.6 requires qᵢ = pᵢ for every i with pᵢ > 0, and then ∑pᵢ>0 qᵢ = 1 forces qᵢ = 0 elsewhere. ∎

Corollary 11.3. 0 ≤ H(p) ≤ log₂ n, with H = log₂ n exactly for the uniform distribution. Indeed log₂ n − H(p) = D(p ‖ u)/ln 2 for the uniform distribution u.

The source coding theorem

A prefix code assigns to symbol i a binary word of length ℓᵢ, no word being a prefix of another. Kraft's inequality says such a code exists if and only if ∑ 2−ℓᵢ ≤ 1.

Theorem 11.4 (Shannon, 1948). Every prefix code has expected length L = ∑ pᵢℓᵢ ≥ H(p), and there is a prefix code with L < H(p) + 1.

Proof. Let K = ∑ 2−ℓᵢ ≤ 1 and qᵢ = 2−ℓᵢ/K. Then L − H(p) = ∑ pᵢ log₂(pᵢ/2−ℓᵢ) = D(p ‖ q)/ln 2 − log₂ K ≥ 0. For the second statement take ℓᵢ = ⌈−log₂ pᵢ⌉; then ∑ 2−ℓᵢ ≤ ∑ pᵢ = 1, so a prefix code exists by Kraft, and ℓᵢ < −log₂ pᵢ + 1 gives L < H + 1. ∎

Coding blocks of k symbols reduces the overhead to 1/k bit per symbol, so the entropy is exactly the optimal compression rate. The same quantity, with natural logarithms and Boltzmann's constant, is the thermodynamic entropy S = kB ln W of a system with W equally likely microstates.

Logarithmic scales

A logarithmic scale reports log(X/X₀) for a reference value X₀. It is the right choice whenever ratios, not differences, are meaningful, and whenever the quantity ranges over many orders of magnitude.

decibel (power):       L = 10 log₁₀(P/P₀) dB;   doubling the power adds 10 log₁₀ 2 ≈ 3.0103 dB
decibel (amplitude):   L = 20 log₁₀(A/A₀) dB,   since power ∝ amplitude²
neper:                 ln(A/A₀) Np;   1 Np = 20/ln 10 dB ≈ 8.6859 dB
stellar magnitude:     m₁ − m₂ = −2.5 log₁₀(F₁/F₂)   (5 magnitudes = factor 100, Pogson 1856)
pH:                    pH = −log₁₀ a(H⁺)
moment magnitude:      Mw = (2/3)(log₁₀ M₀ − 9.1),   M₀ the seismic moment in N·m
musical cents:         1200 log₂(f₂/f₁);   a just fifth 3/2 is 701.955 cents

Because the moment magnitude has slope 2/3, one magnitude unit corresponds to a factor 101.5 ≈ 31.6 in seismic moment, and roughly in radiated energy. The decibel scale for sound pressure uses P₀ corresponding to 20 μPa; adding n incoherent sources of equal level adds 10 log₁₀ n dB, while two coherent sources in phase add 20 log₁₀ 2 ≈ 6.02 dB. The Weber–Fechner law in psychophysics, that perceived intensity grows like the logarithm of stimulus intensity, is the empirical reason that loudness, brightness and pitch are reported on logarithmic scales.

Exercise

  • (a)
    Compute the entropy in bits of the distribution (1/2, 1/4, 1/4), and D(p ‖ q) in bits for p = (1/2, 1/2), q = (1/4, 3/4).
  • (b)
    A signal has power 0.5 mW and the reference is 1 mW. Express its level in dBm, and find the power at 27 dBm.
  • (c)
    Prove that the cents value of an equal-tempered semitone is exactly 100, and that twelve just fifths exceed seven octaves by about 23.46 cents (the Pythagorean comma).
Show solution

Answers: (a) H = 1/2·1 + 1/4·2 + 1/4·2 = 1.5 bits. D = ½ log₂(0.5/0.25) + ½ log₂(0.5/0.75) = ½ − ½ log₂ 1.5 ≈ 0.5 − 0.2925 = 0.2075 bits. (b) 10 log₁₀ 0.5 ≈ −3.01 dBm. 27 dBm corresponds to 102.7 ≈ 501.2 mW. (c) A semitone is the ratio 21/12, and 1200 log₂ 21/12 = 100. Twelve fifths give 12 × 701.955 = 8423.46 cents, and seven octaves are 8400 cents, a difference of 23.46 cents; exactly, the comma is 3¹²/2¹⁹ ≈ 1.01364.

V.3.1