Source Coding
Source Coding
Chirayu Athalye
Basic Concepts
Source Coding
Theorem
Source Coding
Techniques
Information and its Efficient Representation Rate Distortion
Function
References
Chirayu D. Athalye
2026
Source Coding
Let X be a discrete random variable with possible outcomes {x1 , . . . , xn }. The self information Basic Concepts
of the event X = xi is given by Self Information and Mutual
Information
Average Mutual Information
1 and Entropy
I (xi ) := log = − log P(xi ) ≥ 0.
P(xi ) Information Measures for
Continuous RVs
KL Divergence and JS
Remark: Divergence
Source Coding
1 The unit of self information depends on the base of log (Common Choices: 2 or e). Theorem
2 Depending upon whether the base is 2 or e, we have bits or nats as the unit. Source Coding
Techniques
Rate Distortion
Function
Example (Desired Additive Property of log(·) Measure)
References
Consider a binary source that generates equiprobable outputs {0, 1}.
The information content of each output from the source is
I (xi ) = − log2 (0.5) = 1 bit.
Suppose the source is memoryless (i.e., successive outputs are statistically independent).
There are 2m equiprobable m-bit blocks. The self information of an m-bit block is
I (xi ) = − log2 2−m = m bits.
Source Coding
Chirayu Athalye
Source Coding
Example (Desired Additive Property of log(·) Measure) Techniques
Consider a discrete memoryless source C that generates 2 bits simultaneously. Rate Distortion
Function
Source C consists of two independent binary sources A and B that generates equiprobable References
outputs {0, 1}.
Thus, outputs {00, 01, 10, 11} generated by source C are equiprobable. Notice that
I (cij ) = − log2 P(cij ) = − log2 P(ai ) P(bj ) = − log2 (0.25) = 2 bits.
Thus, the information content of the source C is sum of the information content of sources
A and B.
Source Coding
Chirayu Athalye
Mutual Information
Basic Concepts
Let X and Y be random variables with possible outcomes {x1 , . . . , xn } and {y1 , . . . , ym }. Self Information and Mutual
Information
Source Coding
Interpretation of I (xi ; yj ): Information provided (reduction in uncertainty) by the occurrence of Techniques
References
Remark
1 The mutual information I (xi ; yj ) can be positive, negative, or zero.
2 Since P(xi | yj ) P(yj ) = P(yj | xi ) P(xi ), we have I (xi ; yj ) = I (yj ; xi ).
3 If X and Y are statistically independent, then I (xi ; yj ) = 0.
4 If x and Y are fully dependent (i.e., P(xi | yj ) = 1), then I (xi ; yj ) = I (xi ).
Source Coding
Let random variables X and Y represent the input and output of a BSC. Basic Concepts
Self Information and Mutual
Information
Average Mutual Information
P(Y = 0|X = 0) = 1 − p, and Entropy
Information Measures for
P(Y = 0|X = 1) = p, Continuous RVs
KL Divergence and JS
P(Y = 1|X = 1) = 1 − p, Divergence
Source Coding
Techniques
Let P(X = 0) = P(X = 1) = 0.5. Using the total probability theorem, Rate Distortion
Function
Source Coding
Techniques
Rate Distortion
Function
References
Figure: Plot of mutual information I (x0 ; y0 ) = log2 2(1 − p) vs error probability p.
Source Coding
Let random variables X and Y represent the input and output of a binary channel. Basic Concepts
Self Information and Mutual
Information
Average Mutual Information
P(Y = 0 | X = 0) = 1 − p0 , and Entropy
Information Measures for
P(Y = 0 | X = 1) = p1 , Continuous RVs
KL Divergence and JS
P(Y = 1 | X = 1) = 1 − p1 , Divergence
Source Coding
Techniques
Let P(X = 0) = P(X = 1) = 0.5. Using the total probability theorem, Rate Distortion
Function
Source Coding
Techniques
How self information, mutual information, and conditional self information are related?
Rate Distortion
P(yj ) P(xi ) Function
By Bayes’ rule, = . Taking − log(·) of both sides, we get
P(yj | xi ) P(xi | yj ) References
Chirayu Athalye
Source Coding
Theorem
Remark: Source Coding
Techniques
1 I (X ; Y ) ≥ 0; equality holds iff X and Y are statistically independent.
Rate Distortion
2 Since I (xi ; yj ) = I (yj ; xi ), we have I (X ; Y ) = I (Y , X ). Function
References
Chirayu Athalye
Remark
Basic Concepts
1 The term entropy originates from statistical mechanics, where it quantifies the level of Self Information and Mutual
Source Coding
Consider a binary source X that emits 0 and 1 with Techniques
probabilities p and (1 − p), respectively. Rate Distortion
Function
Its entropy is given by
References
Remark: Entropy of a discrete source is maximum when symbols generated from the source are
equiprobable.
Source Coding
Chirayu Athalye
However, all letters don’t have the same probability. If we consider the normalized letter KL Divergence and JS
Divergence
Chirayu Athalye
Conditional Entropy (Average Conditional Self Information)
Basic Concepts
Let X and Y be random variables with possible outcomes {x1 , . . . , xn } and {y1 , . . . , ym }. Self Information and Mutual
Information
Average Mutual Information
The conditional entropy of X given Y is defined as and Entropy
Information Measures for
n X
X m n X
X m Continuous RVs
Source Coding
How Entropy, Average Mutual Information, and Conditional Entropy are related? Techniques
Rate Distortion
It follows from the definitions that Function
Remark:
1 Since I (X ; Y ) ≥ 0, we have H(X ) ≥ H(X | Y ); i.e., observation of Y can only decrease
the entropy.
2 H(X ) = H(X | Y ) iff X and Y are statistically independent.
3 I (X ; X ) = H(X ).
Source Coding
Let X and Y be discrete random variables with the joint PMF pX ,Y . Basic Concepts
Self Information and Mutual
The joint entropy of (X , Y ) is given by Information
Average Mutual Information
n X
X m and Entropy
H(X , Y ) := − pX ,Y (xi , yj ) log pX ,Y (xi , yj ) . Information Measures for
Continuous RVs
Source Coding
Theorem
Source Coding
Techniques
Chain Rule for Entropy
Rate Distortion
Function
H(X , Y ) = H(X ) + H(Y ) − I (X ; Y )
References
= H(X ) + H(Y | X )
= H(Y ) + H(X | Y ).
In general,
n
X
H(X1 , . . . , Xn ) = H(Xk | X1 , . . . , Xk−1 ).
k=1
Source Coding
Chirayu Athalye
Basic Concepts
Self Information and Mutual
Information
Average Mutual Information
and Entropy
Information Measures for
Continuous RVs
KL Divergence and JS
Divergence
Source Coding
Example Theorem
Source Coding
Techniques
Rate Distortion
Function
References
Source Coding
Information Measures for Continuous Random Variables (RVs)
Chirayu Athalye
Basic Concepts
Self Information and Mutual
Information
Average Mutual Information Average Mutual Information
and Entropy
Let X and Y be continuous RVs with the joint PDF fX ,Y . Information Measures for
Continuous RVs
KL Divergence and JS
The average mutual information between X and Y is given by Divergence
Z ∞ Z ∞ Source Coding
fX |Y (x | y)
Theorem
I (X ; Y ) := fX ,Y (x, y) log dxdy.
−∞ −∞ fX (x) Source Coding
Techniques
Rate Distortion
Remark Function
References
1 The definition of average mutual information can be extended to continuous RVs, but not
the physical interpretation.
2 Note that the information content of a continuous RV is infinite.
3 Thus, instead of entropy, we consider differential entropy for a continuous RV.
4 However, there is no physical interpretation attached to the differential entropy.
Source Coding
Differential Entropy Chirayu Athalye
Source Coding
Theorem
Conditional Differential Entropy Source Coding
Techniques
The conditional differential entropy of a continuous random variable X given Y is defined as Rate Distortion
Z ∞ Z ∞ Function
Remark
1 I (X ; Y ) = h(X ) − h(X | Y ) = h(Y ) − h(Y | X ).
n
X
2 Chain Rule for Differential Entropy: h(X1 , . . . , Xn ) = h(Xk | X1 , . . . , xk−1 ).
k=1
3 If X and Y are independent, then h(X + Y ) ≥ h(X ).
Source Coding
Relative Entropy (Kullback-Leibler (KL) Divergence) Chirayu Athalye
x∈X
q(x) Average Mutual Information
and Entropy
Remark
1 Gibbs’ Inequality: DKL (p k q) ≥ 0.
2 Gibbs inequality can be proved by applying Jensen’s inequality to − log(·).
3 Note that DKL (p k q) 6= DKL (q k p). Thus, KL divergence fails to induce a metric 1 .
4 Note that I (X , Y ) = DKL pX ,Y (x, y) k pX (x) pY (y) ≥ 0.
1
distance function
Source Coding
Chirayu Athalye
Basic Concepts
Self Information and Mutual
Information
Average Mutual Information
Jensen-Shannon Divergence and Entropy
Information Measures for
Jensen-Shannon divergence between two probability distributions p and q is given by Continuous RVs
KL Divergence and JS
Divergence
DKL (p k r ) + DKL (q k r ) p+q
JSD(p k q) = , where r= . Source Coding
2 2 Theorem
Source Coding
Techniques
Remark Rate Distortion
Function
1 If we use log2 (·), then 0 ≤ JSD(p k q) ≤ 1.
References
2 Square root of Jensen-Shannon divergence is a metric (Jensen-Shannon distance).
3 Similarity between distributions is greater when Jensen-Shannon distance is closer to 0.
Source Coding
Chirayu Athalye
Code and Prefix Code
Basic Concepts
1 A code is a set of codewords (sequence of bits assigned to symbols).
Source Coding
2 A prefix code is a code in which no codeword forms a prefix of any other codeword. Theorem
Code and Prefix Code
Kraft Inequality
Source Coding
1 In a prefix code, when a sequence of bits corresponding to a possible codeword is detected, Techniques
Chirayu Athalye
Basic Concepts
Source Coding
Theorem
Code and Prefix Code
Kraft Inequality
Source Coding Theorem
Source Coding
Techniques
References
Source Coding
1 An equivalent condition for the existence of a binary code with codewords of length Basic Concepts
`
Source Coding
X
n1 ≤ · · · ≤ n` that satisfy the prefix condition is 2−nk ≤ 1. Theorem
Code and Prefix Code
k=1
Kraft Inequality
2 An equivalent condition for the existence of an M-alphabet code with codewords of length Source Coding Theorem
`
X Source Coding
n1 ≤ · · · ≤ n` that satisfy the prefix condition is M −nk ≤ 1. Techniques
Rate Distortion
k=1 Function
References
References
Remark
1 For a prefix code, the minimum average length required to represent source symbols is equal to the
entropy of the source.
2 A source with higher entropy requires, on an average, more # of bits to represent source symbols
using a prefix code.
3 Efficient representation of symbols leads to compression of data.
4 Source coding theorem is primarily used for compression of data (speech, text, image, video, etc.)
H(X )
The efficiency of a prefix code is defined as η := ≤ 1.
R̄
Source Coding
Chirayu Athalye
Example
Suppose a source X generates symbols {x1 , . . . , x4 } with probabilities {0.5, 0.3, 0.1, 0.1}. Basic Concepts
Source Coding
4
X Theorem
Source Entropy: H(X ) = − pk log2 pk = 1.685 bits. Code and Prefix Code
Kraft Inequality
k=1 Source Coding Theorem
If we use the prefix code {0, 10, 110, 111} to represent {x1 , . . . , x4 }, then Source Coding
Techniques
4
X Rate Distortion
Function
Average Codeword Length: R̄ = nk pk = 1.7 bits.
References
k=1
Source Coding
1 It is a variable length prefix code that is optimal among all prefix codes. Theorem
2
2 It is a greedy algorithm . Source Coding
Techniques
Applications: Huffman Coding
Shannon-Fano-Elias Coding
Used in file compression (zip and Deflate), image compression (JPEG), audio compression (MP3 Arithmetic Coding
and AAC), video compression (MPEG and AVC), etc. Lempel-Ziv Algorithm
Run Length Coding
Suitable for micro-controllers and real-time systems due to low computational complexity and
Rate Distortion
simple decoding. Function
References
Basic Concepts
Rate Distortion
Function
7
X Symbol Probability Self Information Codeword References
H(X ) = − pk log2 pk
k=1
x1 p1 = 0.46 1.1203 1
= 1.9781 bits. x2 p2 = 0.30 1.7370 00
x3 p3 = 0.12 3.0589 010
7
X x4 p4 = 0.06 4.0589 0110
R̄ = nk pk = 1.99 bits
k=1
x5 p5 = 0.03 5.0589 01110
H(X ) x6 p6 = 0.02 5.6439 011110
η= R̄
= 0.9940.
x7 p7 = 0.01 6.6439 011111
Basic Concepts
Symbol Probability Self Information Codeword
Source Coding
x1 p1 = 0.4 1.3219 1 Theorem
k=1
5
X H(X )
R̄ = nk pk = 2.2 bits and η= R̄
= 0.972.
k=1
Remark
In case of a dyadic distribution, we have the following equality for each symbol:
Self Information = Huffman Codeword Length.
Source Coding
Coding in Blocks (Efficient Technique) Chirayu Athalye
By selecting a large enough block-size B, we can make R̄ arbitrarily close to H(X ). References
Example
Chirayu Athalye
Basic Concepts
Example (Contd..) Source Coding
Theorem
Let us group 2 symbols and apply the Huffman encoding algorithm.
Source Coding
Techniques
Symbol Pairs Probability Self Information Codeword Huffman Coding
Rate Distortion
x2 x2 0.1225 3.0291 011 Function
x1 x3 0.1 3.3219 111 References
x3 x1 0.1 3.3219 0000
x2 x3 0.0875 3.5146 0001
x3 x2 0.0875 3.5146 1100
x3 x3 0.0625 4 1101
R̄2
Note that R̄ = 2
= 1.588 bits and η = 0.9812 (improved efficiency).
Source Coding
Source Coding
Basic Idea for Encoding Techniques
Huffman Coding
Let X be a source that generates symbols {x1 , . . . , x` } with probabilities {p1 , . . . , p` }. Shannon-Fano-Elias Coding
Arithmetic Coding
Example
1 Lossless data compression technique that represents an entire message as a fraction in the Basic Concepts
interval [0, 1). Source Coding
Theorem
2 Unlike Huffman coding, it encodes the entire (finite-length) sequence at once.
Source Coding
3 Thus, it avoids inefficiencies of Huffman coding that assigns codewords symbol-by-symbol. Techniques
Huffman Coding
4 Arithmetic coding can achieve R̄ (average codeword length) closer to the entropy limit. Shannon-Fano-Elias Coding
Arithmetic Coding
Lempel-Ziv Algorithm
Rate Distortion
Encoding: Function
References
1 Start with an interval [0, 1).
2 In an iterative manner, subdivide the interval according to symbol probabilities.
3 Each symbol in the given sequence narrows the interval.
4 Any number within the final interval uniquely represents the given sequence.
Decoding:
1 Start with the same probability model.
2 Use the encoded number to determine which sub-interval it falls into.
3 Output that symbol. Narrow the interval and repeat.
Source Coding
Example Chirayu Athalye
Consider symbols {A, B, C } with probabilities {0.5, 0.25, 0.25}. Divide [0, 1) as
Basic Concepts
Rate Distortion
Function
References
Remark: A symbol with higher probability causes smaller reduction in the interval, and thus
contribute fewer bits
Source Coding
Chirayu Athalye
Basic Concepts
Lempel-Ziv Algorithm (Dictionary-Based Method)
Source Coding
Theorem
1 Lossless data compression algorithm that exploits patterns and repetitions in data-stream
Source Coding
without prior knowledge of symbol probabilities. Techniques
Huffman Coding
2 It builds an explicit dictionary of substrings (phrases) during encoding. Shannon-Fano-Elias Coding
Arithmetic Coding
3 Each new phrase is encoded as: (index of known prefix-string, next symbol). Lempel-Ziv Algorithm
Rate Distortion
5 It is a fast, practical, and adaptive method that learns patterns while encoding. Function
References
1 For a large size string, unlike the example above, we get a rich Lempel-Ziv (LZ) dictionary. As a
result, the Lempel-Ziv algorithm typically gives close to optimal compression.
2 Size of an LZ dictionary grows exponentially with the number of bits assigned for location.
1 A lossless data compression technique that compresses data by replacing consecutive Basic Concepts
repeated symbols (called a run) with a pair (run length, symbol). Source Coding
Theorem
2 It can compress any type of data; the compression ratio depends on the content of data. Source Coding
Techniques
3 Inefficient compared to other compression techniques; thus, often used in conjunction with Huffman Coding
References
Example
Consider a bit stream: 1111111111110000000000000001111111.
It can be represented as: (12, 1), (15, 0), (7, 1). Notice that the maximum number of
repetitions is 15, which can be represented with 4 bits.
Run Length Code: (1100, 1), (1111, 1), (0111, 1). Compression Ratio: 15 : 34 = 1 : 2.2667.
Fax machines use a combination of a run length code and Huffman code. Read about the
coding technique used in fax machines.
Source Coding
Chirayu Athalye
Basic Concepts
Source Coding
Theorem
Rate Distortion
R. Bose, Information Theory, Coding and Cryptography (3rd edition), Chennai, TN, India: McGraw Hill Function
Education, 2016. References
T.M. Cover and J.A. Thomas, Elements of Information Theory (2nd edition), Hoboken, NJ, USA:
Wiley-Interscience, 2006.
Readings
1 [Information Theory, Coding and Cryptography (Bose), Chapter 1].