Source coding is a mapping from (a sequence of) symbols from an information source to a sequence of alphabet symbols (usually bits) such that the source symbols can be exactly recovered from the binary bits (lossless source coding) or recovered within some distortion (lossy source coding). This is one approach to data compression.
In information theory, the source coding theorem (Shannon 1948)2 informally states that (MacKay 2003, pg. 81,3 Cover 2006, Chapter 54):
N i.i.d. random variables each with entropy H(X) can be compressed into more than N H(X) bits with negligible risk of information loss, as N → ∞; but conversely, if they are compressed into fewer than N H(X) bits it is virtually certain that information will be lost.
The N H ( X ) {\displaystyle NH(X)} coded sequence represents the compressed message in a biunivocal way, under the assumption that the decoder knows the source. From a practical point of view, this hypothesis is not always true. Consequently, when the entropy encoding is applied the transmitted message is N H ( X ) + ( i n f . s o u r c e ) {\displaystyle NH(X)+(inf.source)} . Usually, the information that characterizes the source is inserted at the beginning of the transmitted message.
Let Σ1, Σ2 denote two finite alphabets and let Σ∗1 and Σ∗2 denote the set of all finite words from those alphabets (respectively).
Suppose that X is a random variable taking values in Σ1 and let f be a uniquely decodable code from Σ∗1 to Σ∗2 where |Σ2| = a. Let S denote the random variable given by the length of codeword f (X).
If f is optimal in the sense that it has the minimal expected word length for X, then (Shannon 1948):
Where E {\displaystyle \mathbb {E} } denotes the expected value operator.
Given X is an i.i.d. source, its time series X1, ..., Xn is i.i.d. with entropy H(X) in the discrete-valued case and differential entropy in the continuous-valued case. The Source coding theorem states that for any ε > 0, i.e. for any rate H(X) + ε larger than the entropy of the source, there is large enough n and an encoder that takes n i.i.d. repetition of the source, X1:n, and maps it to n(H(X) + ε) binary bits such that the source symbols X1:n are recoverable from the binary bits with probability of at least 1 − ε.
Proof of Achievability. Fix some ε > 0, and let
The typical set, Aεn, is defined as follows:
The asymptotic equipartition property (AEP) shows that for large enough n, the probability that a sequence generated by the source lies in the typical set, Aεn, as defined approaches one. In particular, for sufficiently large n, P ( ( X 1 , X 2 , ⋯ , X n ) ∈ A n ε ) {\displaystyle P((X_{1},X_{2},\cdots ,X_{n})\in A_{n}^{\varepsilon })} can be made arbitrarily close to 1, and specifically, greater than 1 − ε {\displaystyle 1-\varepsilon } (See AEP for a proof).
The definition of typical sets implies that those sequences that lie in the typical set satisfy:
Since | A n ε | ≤ 2 n ( H ( X ) + ε ) , n ( H ( X ) + ε ) {\displaystyle \left|A_{n}^{\varepsilon }\right|\leq 2^{n(H(X)+\varepsilon )},n(H(X)+\varepsilon )} bits are enough to point to any string in this set.
The encoding algorithm: the encoder checks if the input sequence lies within the typical set; if yes, it outputs the index of the input sequence within the typical set; if not, the encoder outputs an arbitrary n(H(X) + ε) digit number. As long as the input sequence lies within the typical set (with probability at least 1 − ε), the encoder does not make any error. So, the probability of error of the encoder is bounded above by ε.
Proof of converse: the converse is proved by showing that any set of size smaller than Aεn (in the sense of exponent) would cover a set of probability bounded away from 1.
For 1 ≤ i ≤ n let si denote the word length of each possible xi. Define q i = a − s i / C {\displaystyle q_{i}=a^{-s_{i}}/C} , where C is chosen so that q1 + ... + qn = 1. Then
where the second line follows from Gibbs' inequality and the fifth line follows from Kraft's inequality:
so log C ≤ 0.
For the second inequality we may set
so that
and so
and
and so by Kraft's inequality there exists a prefix-free code having those word lengths. Thus the minimal S satisfies
Define typical set Aεn as:
Then, for given δ > 0, for n large enough, Pr(Aεn) > 1 − δ. Now we just encode the sequences in the typical set, and usual methods in source coding show that the cardinality of this set is smaller than 2 n ( H n ¯ ( X ) + ε ) {\displaystyle 2^{n({\overline {H_{n}}}(X)+\varepsilon )}} . Thus, on an average, Hn(X) + ε bits suffice for encoding with probability greater than 1 − δ, where ε and δ can be made arbitrarily small, by making n larger.
Shen, A. and Uspensky, V.A. and Vereshchagin, N. (2017). "Chapter 7.3. : Complexity and entropy". Kolmogorov Complexity and Algorithmic Randomness. American Mathematical Society. p. 226. ISBN 9781470431822.{{cite book}}: CS1 maint: multiple names: authors list (link) 9781470431822 ↩
C.E. Shannon, "A Mathematical Theory of Communication Archived 2009-02-16 at the Wayback Machine", Bell System Technical Journal, vol. 27, pp. 379–423, 623-656, July, October, 1948 /wiki/C.E._Shannon ↩
David J. C. MacKay. Information Theory, Inference, and Learning Algorithms Cambridge: Cambridge University Press, 2003. ISBN 0-521-64298-1 http://www.inference.phy.cam.ac.uk/mackay/itila/book.html ↩
Cover, Thomas M. (2006). "Chapter 5: Data Compression". Elements of Information Theory. John Wiley & Sons. pp. 103–142. ISBN 0-471-24195-4. 0-471-24195-4 ↩