Difference between revisions of "Aufgaben:Exercise 2.3: About the LZ78 Compression"
(15 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | {{quiz-Header|Buchseite= | + | {{quiz-Header|Buchseite=Information_Theory/Compression_According_to_Lempel,_Ziv_and_Welch |
}} | }} | ||
− | [[File:P_ID2434__Inf_A_2_3.png|right|frame| | + | [[File:P_ID2434__Inf_A_2_3.png|right|frame|The LZ78–inventors]] |
− | + | In contrast to "Entropy Coding" according to Huffman or Shannon, where one must know the source statistics (as precisely as possible), such restrictions do not apply to the compression methods developed by [https://en.wikipedia.org/wiki/Abraham_Lempel Abraham Lempel] and [https://en.wikipedia.org/wiki/Jacob_Ziv Jacob Ziv] . This is called "Universal Source Coding". | |
− | + | In this exercise, we consider the variant first published in 1978 [LZ78]. The string <b>BARBARA–BAR</b> is to be encoded. | |
− | * | + | *The procedure "LZ78" works with a global dictionary, which is initially only filled with an empty character $(\varepsilon)$ under the index $I = 0$. This distinguishes "LZ78" from its predecessor "LZ77" (with local dictionary) and also from its successor "LZW" (dictionary is prefilled with the possible characters). |
− | * | + | *If a character or a word fragment (several characters) of the input string is found in the dictionary, the index $I_0$ of this entry is output together with the next input character $Z$ . In each step $i$ the output is therefore: $(I_0, \ Z)$. |
− | * | + | *Afterwards, the new string is entered into the dictionary under the next free index $I_{\rm new}$. |
− | * | + | *If one considers the dictionary as a field $W\big[\hspace{0.05cm}I\hspace{0.05cm}\big]$ with $I ≥ 0$, where each element contains a string of arbitrary length, then with the character variable $Z$: |
− | :$$W \big[\hspace{0.05cm}I_{\rm | + | :$$W \big[\hspace{0.05cm}I_{\rm new}\hspace{0.05cm}\big] = W\big[\hspace{0.05cm}I_0\hspace{0.05cm}\big] + Z \hspace{0.05cm}. $$ |
− | |||
− | |||
− | |||
− | |||
− | |||
+ | For clarification, a simple example: | ||
+ | *At a given time, the dictionary is filled up to index $I_{\rm act }= 20$. | ||
+ | *'''Handy''' is waiting to be encoded. In the dictionary, "<b>Ha</b>" is found under index $I = 11$ and the entry "<b>Han</b>" under index $I = 16$. | ||
+ | *Thus, the current code output is $(I_0, Z) = (16,$ <b>d</b>$)$ and the following is entered into the dictionary as a new phrase: | ||
+ | |||
+ | $W(21) = $ <b>Hand</b>. | ||
+ | *Now the string <b>y</b> is available for coding. If no suitable entry is found, $(0,$ <b>y</b>$)$ is output and a new entry is made in the dictionary: | ||
+ | $W(22) = \rm ε$ + <b>y</b> $=$ <b>y</b> . | ||
− | + | For subtask '''(6)''' you can assume the following: | |
− | * | + | * The decimal number $I$ (index) is represented in binary by three bits. |
− | * | + | * The character $Z ∈ \{$<b>A</b>, <b>B</b>, <b>R</b>, <b>–</b>$ \}$ is binary coded by two bits each. |
Line 29: | Line 32: | ||
− | + | Hints: | |
− | + | *The exercise belongs to the chapter [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch|Compression According to Lempel, Ziv and Welch]]. | |
− | * | + | *In particular, reference is made to the page [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch#The_Lempel-Ziv_variant_LZ78|The Lempel-Ziv Variant LZ78]]. |
− | * | + | *The original literature [LZ78] on this method is: <br> Ziv, J.; Lempel, A.: Compression of Individual Sequences via Variable-Rate Coding. In: IEEE Transactions on Information Theory, no. 5, vol. 24, 1978, p. 530–536. |
− | * | ||
− | * | + | *[[Aufgaben:2.3Z_Zur_LZ77-Codierung|Exercise 2.3Z]] and [[Aufgaben:Aufgabe_2.4:_Zum_LZW-Algorithmus|Exercise 2.4]] deal with other Lempel–Ziv methods in a similar way. |
− | === | + | ===Questions=== |
<quiz display=simple> | <quiz display=simple> | ||
− | { | + | {Which statements apply to the preassignment of the LZ78 dictionary? |
|type="()"} | |type="()"} | ||
− | + | + | + Only the index $I = 0$ with the space $(\varepsilon)$ is preassigned. |
− | - | + | - The indices $I = 0$ to $I = 3$ with the four characters "'''A'''", "'''B'''", '''R''' and "'''–'''" are preallocated. |
− | { | + | {What happens in the coding step $i = 1$? |
|type="[]"} | |type="[]"} | ||
− | + | + | + The coder output is: $(0,$ <b>B</b>$)$. |
− | + | + | + The dictionary entry is: $W(I = 1) =$ <b>B</b>. |
− | - | + | - The dictionary entry is: $W(I = 1) =$ <b>BA</b>. |
− | { | + | {Which statements are true for the coding steps $i = 2$ and $i = 3$? |
|type="[]"} | |type="[]"} | ||
− | + | + | + For $i = 2$ , the following is true: Output $(0,$ <b>A</b>$)$, entry $W(I = 2) =$ <b>A</b>. |
− | + | + | + For $i = 3$ , the following is true: Output $(0,$ <b>R</b>$)$, entry $W(I = 3) =$ <b>R</b>. |
− | { | + | {Which statements are true for the coding step $i = 4$? |
|type="[]"} | |type="[]"} | ||
− | - | + | - At step $i = 4$ <b>BAR</b> is coded together. |
− | + | + | + At step $i = 4$ <b>BA</b> is coded together. |
− | - | + | - The coder output is: $(2,$ <b>AR</b>$)$. |
− | + | + | + The coder output is: $(1,$ <b>A</b>$)$. |
− | { | + | {Complete the LZ78 coding. After which coding step $i_{\rm end}$ is "<b>BARBARA–BAR</b>" completely coded? |
|type="{}"} | |type="{}"} | ||
− | $i_{\rm | + | $i_{\rm end} \ = \ $ { 7 3% } |
− | { | + | {How many binary characters are needed to code "<b>BARBARA–BAR"</b> ? Follow the instructions on the information page. |
|type="{}"} | |type="{}"} | ||
− | $\text{ | + | $\text{without coding: }\ N \ = \ $ { 22 3% } $\ \rm bits$ |
− | $\text{ | + | $\text{with LZ78 coding: }\ N \ = \ $ { 35 3% } $\ \rm bits$ |
Line 82: | Line 84: | ||
</quiz> | </quiz> | ||
− | === | + | ===Solution=== |
{{ML-Kopf}} | {{ML-Kopf}} | ||
− | '''(1)''' | + | '''(1)''' <u>Statement 1</u> applies to the LZ78 algorithm: |
− | * | + | *In contrast, the preassignment according to statement 2 is true for the LZW algorithm, which was published in 1983 together with Terry Welch. |
+ | |||
+ | |||
+ | |||
+ | |||
+ | '''(2)''' $\rm ε$ denotes the empty character. | ||
+ | *Since $\rm ε$ + <b>B</b> = <b>B</b> ⇒ <u>statements 1 and 2</u> are correct. | ||
+ | *Statement 3 is again only true for LZW compression. | ||
+ | |||
+ | |||
+ | |||
+ | '''(3)''' Here <u>both statements</u> are true. | ||
− | |||
+ | '''(4)''' <u>Statements 2 and 4</u> are correct: | ||
+ | *In the dictionary, character <b>B</b> is found under index $I = 1$. | ||
+ | *The next character <b>A</b> of the input sequence is appended: <b>(1, A)</b>. | ||
+ | *Statement 3 cannot be correct because $Z$ can only be a character and not a character sequence. | ||
− | |||
− | '''( | + | [[File:EN_Inf_A_2_3f.png|right|frame|LZ78 coding of "<b>BARBARA–BAR</b>"]] |
− | * | + | '''(5)''' The entire coding process is summarised in the table on the right. One can see: |
− | * | + | * At each time $i$, the edited string is entered into the dictionary. |
− | + | * At time $\underline{i=7}$ the coding process is completed. | |
− | |||
− | |||
− | |||
− | |||
+ | '''(6)''' If we represent all indices with three bits and the four characters with two bits each, we get the following results: | ||
+ | * Without coding: $N = 11 \cdot 2 \hspace{0.15cm}\underline {= 22 \, \rm bits}$, | ||
+ | * with LZ78 coding: $N = 7 \cdot (3+2) \hspace{0.15cm}\underline {= 35 \, \rm bits}$. | ||
− | |||
− | |||
− | |||
− | + | You can see from this: | |
− | * | + | * Any LZ compression only makes sense with a larger file, even if one believes that a text like "<b>BARBARA–BAR</b>" accommodates the LZ78 algorithm. |
− | * | + | * With variable number of bits for the index according to Exercise 2.4, the result for this LZ78 example would be: |
− | :$$N = 1 \cdot 3 + 2 \cdot 4 + 4 \cdot 5 = 31 \,{\rm | + | :$$N = 1 \cdot 3 + 2 \cdot 4 + 4 \cdot 5 = 31 \,{\rm bits}\hspace{0.05cm}.$$ |
{{ML-Fuß}} | {{ML-Fuß}} | ||
Line 121: | Line 132: | ||
− | [[Category: | + | [[Category:Information Theory: Exercises|^2.2 Lempel-Ziv-Welch Compression^]] |
Latest revision as of 13:10, 10 August 2021
In contrast to "Entropy Coding" according to Huffman or Shannon, where one must know the source statistics (as precisely as possible), such restrictions do not apply to the compression methods developed by Abraham Lempel and Jacob Ziv . This is called "Universal Source Coding".
In this exercise, we consider the variant first published in 1978 [LZ78]. The string BARBARA–BAR is to be encoded.
- The procedure "LZ78" works with a global dictionary, which is initially only filled with an empty character $(\varepsilon)$ under the index $I = 0$. This distinguishes "LZ78" from its predecessor "LZ77" (with local dictionary) and also from its successor "LZW" (dictionary is prefilled with the possible characters).
- If a character or a word fragment (several characters) of the input string is found in the dictionary, the index $I_0$ of this entry is output together with the next input character $Z$ . In each step $i$ the output is therefore: $(I_0, \ Z)$.
- Afterwards, the new string is entered into the dictionary under the next free index $I_{\rm new}$.
- If one considers the dictionary as a field $W\big[\hspace{0.05cm}I\hspace{0.05cm}\big]$ with $I ≥ 0$, where each element contains a string of arbitrary length, then with the character variable $Z$:
- $$W \big[\hspace{0.05cm}I_{\rm new}\hspace{0.05cm}\big] = W\big[\hspace{0.05cm}I_0\hspace{0.05cm}\big] + Z \hspace{0.05cm}. $$
For clarification, a simple example:
- At a given time, the dictionary is filled up to index $I_{\rm act }= 20$.
- Handy is waiting to be encoded. In the dictionary, "Ha" is found under index $I = 11$ and the entry "Han" under index $I = 16$.
- Thus, the current code output is $(I_0, Z) = (16,$ d$)$ and the following is entered into the dictionary as a new phrase:
$W(21) = $ Hand.
- Now the string y is available for coding. If no suitable entry is found, $(0,$ y$)$ is output and a new entry is made in the dictionary:
$W(22) = \rm ε$ + y $=$ y .
For subtask (6) you can assume the following:
- The decimal number $I$ (index) is represented in binary by three bits.
- The character $Z ∈ \{$A, B, R, –$ \}$ is binary coded by two bits each.
Hints:
- The exercise belongs to the chapter Compression According to Lempel, Ziv and Welch.
- In particular, reference is made to the page The Lempel-Ziv Variant LZ78.
- The original literature [LZ78] on this method is:
Ziv, J.; Lempel, A.: Compression of Individual Sequences via Variable-Rate Coding. In: IEEE Transactions on Information Theory, no. 5, vol. 24, 1978, p. 530–536.
- Exercise 2.3Z and Exercise 2.4 deal with other Lempel–Ziv methods in a similar way.
Questions
Solution
- In contrast, the preassignment according to statement 2 is true for the LZW algorithm, which was published in 1983 together with Terry Welch.
(2) $\rm ε$ denotes the empty character.
- Since $\rm ε$ + B = B ⇒ statements 1 and 2 are correct.
- Statement 3 is again only true for LZW compression.
(3) Here both statements are true.
(4) Statements 2 and 4 are correct:
- In the dictionary, character B is found under index $I = 1$.
- The next character A of the input sequence is appended: (1, A).
- Statement 3 cannot be correct because $Z$ can only be a character and not a character sequence.
(5) The entire coding process is summarised in the table on the right. One can see:
- At each time $i$, the edited string is entered into the dictionary.
- At time $\underline{i=7}$ the coding process is completed.
(6) If we represent all indices with three bits and the four characters with two bits each, we get the following results:
- Without coding: $N = 11 \cdot 2 \hspace{0.15cm}\underline {= 22 \, \rm bits}$,
- with LZ78 coding: $N = 7 \cdot (3+2) \hspace{0.15cm}\underline {= 35 \, \rm bits}$.
You can see from this:
- Any LZ compression only makes sense with a larger file, even if one believes that a text like "BARBARA–BAR" accommodates the LZ78 algorithm.
- With variable number of bits for the index according to Exercise 2.4, the result for this LZ78 example would be:
- $$N = 1 \cdot 3 + 2 \cdot 4 + 4 \cdot 5 = 31 \,{\rm bits}\hspace{0.05cm}.$$