# Shannon's source coding theorem

## From Wikipedia, the free encyclopedia

Information theory |
---|

In information theory, **Shannon's source coding theorem** (or **noiseless coding theorem**) establishes the limits to possible data compression, and the operational meaning of the Shannon entropy.

Named after Claude Shannon, the **source coding theorem** shows that (in the limit, as the length of a stream of independent and identically-distributed random variable (i.i.d.) data tends to infinity) it is impossible to compress the data such that the code rate (average number of bits per symbol) is less than the Shannon entropy of the source, without it being virtually certain that information will be lost. However it is possible to get the code rate arbitrarily close to the Shannon entropy, with negligible probability of loss.

The **source coding theorem for symbol codes** places an upper and a lower bound on the minimal possible expected length of codewords as a function of the entropy of the input word (which is viewed as a random variable) and of the size of the target alphabet.

## Statements

*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 the concept behind data compression.

### Source coding theorem

In information theory, the **source coding theorem** (Shannon 1948)^{[1]} informally states that (MacKay 2003, pg. 81,^{[2]} Cover 2006, Chapter 5^{[3]}):

N i.i.d. random variables each with entropy

H(X) can be compressed into more thanN H(X) bits with negligible risk of information loss, asN→ ∞; but conversely, if they are compressed into fewer thanN H(X) bits it is virtually certain that information will be lost.

The 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 . Usually, the information that characterizes the source is inserted at the beginning of the transmitted message.

### Source coding theorem for symbol codes

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 denotes the expected value operator.

## Proof: Source coding theorem

Given X is an i.i.d. source, its time series *X*_{1}, ..., *X _{n}* 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,

*X*

^{1:n}, and maps it to

*n*(

*H*(

*X*) +

*ε*) binary bits such that the source symbols

*X*

^{1: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, can be made arbitrarily close to 1, and specifically, greater than (See
AEP for a proof).

The definition of typical sets implies that those sequences that lie in the typical set satisfy:

Note that:

- The probability of a sequence being drawn from
*A*^{ε}_{n}is greater than 1 −*ε*. - , which follows from the left hand side (lower bound) for .
- , which follows from upper bound for and the lower bound on the total probability of the whole set
*A*^{ε}_{n}.

Since 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 doesn't 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.

## Proof: Source coding theorem for symbol codes

For 1 ≤ *i* ≤ *n* let *s _{i}* denote the word length of each possible

*x*. Define , where C is chosen so that

_{i}*q*

_{1}+ ... +

*q*= 1. Then

_{n}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

## Extension to non-stationary independent sources

### Fixed Rate lossless source coding for discrete time non-stationary independent sources

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 . Thus, on an average, *H _{n}*(

*X*) +

*ε*bits suffice for encoding with probability greater than 1 −

*δ*, where ε and δ can be made arbitrarily small, by making n larger.

Text is available under the CC BY-SA 4.0 license; additional terms may apply.

Images, videos and audio are available under their respective licenses.