Shannon coding

From HandWiki
Revision as of 22:08, 6 February 2024 by StanislovAI (talk | contribs) (fix)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Short description: Lossless data compression technique

In the field of data compression, Shannon coding, named after its creator, Claude Shannon, is a lossless data compression technique for constructing a prefix code based on a set of symbols and their probabilities (estimated or measured). It is suboptimal in the sense that it does not achieve the lowest possible expected code word length like Huffman coding does, and never better than but sometimes equal to the Shannon–Fano coding (Fano's method).

The method was the first of its type, the technique was used to prove Shannon's noiseless coding theorem in his 1948 article "A Mathematical Theory of Communication",[1] and is therefore a centerpiece of the information age.

Shannon–Fano coding methods gave rise to the field of information theory and without its contributions, the world would not have any of the many successors; for example Huffman coding, or arithmetic coding. Much of our day-to-day lives are significantly influenced by digital data and this would not be possible without Shannon-Fano coding and the ongoing evolution of its methods.[2][page needed]

In Shannon coding, the symbols are arranged in order from most probable to least probable, and assigned codewords by taking the first [math]\displaystyle{ l_i = \left\lceil -\log_2 p_i \right\rceil }[/math] bits from the binary expansions of the cumulative probabilities [math]\displaystyle{ \sum\limits_{k=1}^{i-1} p_k. }[/math] Here [math]\displaystyle{ \lceil x \rceil }[/math] denotes the ceiling function (which rounds [math]\displaystyle{ x }[/math] up to the next integer value).

Example

In the table below is an example of creating a code scheme for symbols a1 to a6. The value of li gives the number of bits used to represent the symbol ai. The last column is the bit code of each symbol.

i pi li [math]\displaystyle{ \sum_{n=0}^{i-1} p_n }[/math] Previous value in binary Codeword for ai
1 0.36 2 0.0 0.0000 00
2 0.18 3 0.36 0.0101... 010
3 0.18 3 0.54 0.1000... 100
4 0.12 4 0.72 0.1011... 1011
5 0.09 4 0.84 0.1101... 1101
6 0.07 4 0.93 0.1110... 1110

References

Shannon, Claude Elwood. "A Mathematical Theory of Communication." ACM SIGMOBILE mobile computing and communications review 5.1 (2001): 3-55.