Content deleted Content added
m +iw fr |
Adding short description: "Lossless data compression algorithm" |
||
(15 intermediate revisions by 12 users not shown) | |||
Line 1:
{{Short description|Lossless data compression algorithm}}
'''Dynamic Markov compression''' ('''DMC
== Algorithm ==
Line 7 ⟶ 8:
=== Arithmetic coding ===
A bitwise arithmetic coder such as DMC has two components, a predictor and an arithmetic coder. The predictor accepts an ''n''-bit input string ''x'' = ''x''<sub>1</sub>''x''<sub>2</sub>...''x''<sub>''n''</sub> and assigns it a probability ''p''(''x''), expressed as a product of a series of predictions, ''p''(''x''<sub>1</sub>)''p''(''x''<sub>2</sub>'''|'''''x''<sub>1</sub>)''p''(''x''<sub>3</sub>'''|'''''x''<sub>1</sub>''x''<sub>2</sub>) ... ''p''(''x''<sub>''n''</sub>'''|''' ''x''<sub>1</sub>''x''<sub>2</sub>...''x''<sub>''n''–1</sub>). The arithmetic coder maintains two high precision binary numbers, ''p''<sub>low</sub> and ''p''<sub>high</sub>, representing the possible range for the total probability that the model would assign to all strings lexicographically less than ''x'', given the bits of ''x'' seen so far. The compressed code for ''x'' is ''p''<sub>''x''</sub>, the shortest bit string representing a number between ''p''<sub>low</sub> and ''p''<sub>high</sub>. It is always possible to find a number in this range no more than one bit longer than the [[Claude Shannon|Shannon]] limit, log<sub>2</sub> 1 '''/''' ''p''(''x''). One such number can be obtained from ''p''<sub>high</sub> by dropping all of the trailing bits after the first bit that differs from ''p''<sub>low</sub>.
Compression proceeds as follows. The initial range is set to ''p''<sub>low</sub> = 0, ''p''<sub>high</sub> = 1. For each bit, the predictor estimates ''p''<sub>0</sub> = ''p''(''x''<sub>''i''</sub> = 0'''|'''''x''<sub>1</sub>''x''<sub>2</sub>...''x''<sub>''i''–1</sub>) and ''p''<sub>1</sub> = 1 − ''p''<sub>0</sub>, the probability of a 0 or 1, respectively. The arithmetic coder then divides the current range, (''p''<sub>low</sub>, ''p''<sub>high</sub>) into two parts in proportion to ''p''<sub>0</sub> and ''p''<sub>1</sub>. Then the subrange corresponding to the next bit ''x''<sub>''i''</sub> becomes the new range.
For decompression, the predictor makes an identical series of predictions, given the bits decompressed so far. The arithmetic coder makes an identical series of range splits, then selects the range containing ''p''<sub>''x''</sub> and outputs the bit ''x''<sub>''i''</sub> corresponding to that subrange.
In practice, it is not necessary to keep ''p''<sub>low</sub> and ''p''<sub>high</sub> in memory to high precision. As the range narrows
=== DMC model ===
The DMC predictor is a table which maps (bitwise) contexts to a pair of counts, ''n''<sub>0</sub> and ''n''<sub>1</sub>, representing the number of zeros and ones previously observed in this context. Thus, it predicts that the next bit will be a 0 with probability ''p''<sub>0</sub> = ''n''<sub>0</sub> '''/''' ''n'' = ''n''<sub>0</sub> '''/''' (''n''<sub>0</sub> + ''n''<sub>1</sub>) and 1 with probability ''p''<sub>1</sub> = 1 − ''p''<sub>0</sub> = ''n''<sub>1</sub> '''/''' ''n''. In addition, each table entry has a pair of pointers to the contexts obtained by appending either a 0 or a 1 to the right of the current context (and possibly dropping bits on the left). Thus, it is never necessary to look up the current context in the table; it is sufficient to maintain a pointer to the current context and follow the links.
In the original DMC implementation, the initial table is the set of all contexts of length 8 to 15 bits that begin on a byte boundary. The initial state is any of the 8 bit contexts. The counts are floating point numbers initialized to a small nonzero constant such as 0.2. The counts are not initialized to zero in order to allow values to be coded even if they have not been seen before in the current context.
Line 86 ⟶ 87:
== External links ==
* [http://www.cs.uvic.ca/~nigelh/Publications/DMC.pdf Data Compression Using Dynamic Markov Modelling]
* Google Developers YouTube channel: [https://www.youtube.com/watch?v=05RFEGWNxts Compressor Head Episode 3 (Markov Chain Compression)] {{plays audio}}
{{Compression Methods}}
Line 92 ⟶ 94:
[[Category:Lossless compression algorithms]]
[[Category:Markov models]]
[[Category:Data compression]]
|