Content deleted Content added
Undid revision 171198157 by Tomas kessler (talk) |
Adding short description: "Lossless data compression algorithm" |
||
(23 intermediate revisions by 19 users not shown) | |||
Line 1:
{{Short description|Lossless data compression algorithm}}
'''Dynamic Markov
== Algorithm ==
Line 5 ⟶ 6:
DMC predicts and codes one bit at a time. It differs from [[prediction by partial matching|PPM]] in that it codes bits rather than bytes, and from [[context mixing]] algorithms such as [[PAQ]] in that there is only one context per prediction. The predicted bit is then coded using [[arithmetic coding]].
=== Arithmetic
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
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> =
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
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>
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.
Modeling is the same for compression and decompression. For each bit, ''p''<sub>0</sub> and ''p''<sub>1</sub> are computed, bit ''x''<sub>''i''</sub> is coded or decoded, the model is updated by adding 1 to the count corresponding to ''x''<sub>''i''</sub>, and the next context is found by traversing the link corresponding to ''x''<sub>''i''</sub>.
=== Adding
DMC as described above is equivalent to an order-1 context model. However, it is normal to add longer contexts to improve compression. If the current context is A, and the next context B would drop bits on the left, then DMC may add (clone) a new context C from B. C represents the same context as A after appending one bit on the right as with B, but without dropping any bits on the left. The link from A will thus be moved from B to point to C. B and C will both make the same prediction, and both will point to the same pair of next states. The total count, ''n'' = ''n''<sub>0</sub>
For example, suppose that state A represents the context 11111. On input bit 0, it transitions to state B representing context 110, obtained by dropping 3 bits on the left. In context A, there have been 4 zero bits and some number of one bits. In context B, there have been 3 zeros and 7 ones (''n
{| class="wikitable"
|-
! State
! ''n''<sub>0</sub>
! ''n''<sub>1</sub>
! next<sub>0</sub>
! next<sub>1</sub>
Line 50 ⟶ 51:
|}
C is cloned from B. It represents context 111110. Both B and C predict ''p''<sub>1</sub> = 0.7, and both go to the same next states, E and F. The count for C is ''n'' = 4, equal to ''n''<sub>0</sub> for A. This leaves ''n'' = 6 for B.
{| class="wikitable"
|-
! State
! ''n''<sub>0</sub>
! ''n''<sub>1</sub>
! next<sub>0</sub>
! next<sub>1</sub>
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}}
[[Category:Lossless compression algorithms]]
[[Category:Markov models]]
[[Category:Data compression]]
|