Difference between revisions of "Aufgaben:Exercise 2.3Z: About the LZ77 Coding"

From LNTwww
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  
{{quiz-Header|Buchseite=Informationstheorie/Komprimierung nach Lempel, Ziv und Welch
+
{{quiz-Header|Buchseite=Information_Theory/Compression_According_to_Lempel,_Ziv_and_Welch
 
}}
 
}}
  
 
[[File:P_ID2436__Inf_Z_2_3.png|right|frame|Sliding–Window with&nbsp; $G = 4$&nbsp; and&nbsp; $G = 5$<br>(valid for "LZ77")]]
 
[[File:P_ID2436__Inf_Z_2_3.png|right|frame|Sliding–Window with&nbsp; $G = 4$&nbsp; and&nbsp; $G = 5$<br>(valid for "LZ77")]]
In&nbsp; [[Aufgaben:2.3_Zur_LZ78-Komprimierung|Exercise 2.3]],&nbsp; you were supposed to compress&nbsp; "<b>BARBARA&ndash;BAR</b>"&nbsp; (string of length&nbsp; $11$, four different characters)&nbsp; using the LZ78 algorithm.&nbsp;  
+
In&nbsp; [[Aufgaben:Exercise_2.3:_About_the_LZ78_Compression|Exercise 2.3]],&nbsp; you were supposed to compress&nbsp; "<b>BARBARA&ndash;BAR</b>"&nbsp; (string of length&nbsp; $11$, four different characters)&nbsp; using the LZ78 algorithm.&nbsp;  
  
 
In this exercise we use the same text to demonstrate LZ77 compression.&nbsp; To note:
 
In this exercise we use the same text to demonstrate LZ77 compression.&nbsp; To note:
Line 33: Line 33:
  
  
''Hints:''
+
Hints:
 
*The task belongs to the chapter&nbsp; [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch|Compression according to Lempel, Ziv and Welch]].
 
*The task belongs to the chapter&nbsp; [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch|Compression according to Lempel, Ziv and Welch]].
 
*In particular, reference is made to the page&nbsp; [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch#LZ77_-_the_basic_form_of_the_Lempel-Ziv_algorithms|LZ77 &ndash; the basic form of the Lempel-Ziv algorithms]]&nbsp;.
 
*In particular, reference is made to the page&nbsp; [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch#LZ77_-_the_basic_form_of_the_Lempel-Ziv_algorithms|LZ77 &ndash; the basic form of the Lempel-Ziv algorithms]]&nbsp;.
 
*The original literature&nbsp; [LZ77]&nbsp; on this method is: <br> &nbsp; &nbsp; &nbsp; Ziv, J.; Lempel, A.:&nbsp; A Universal Algorithm for Sequential Data Compression.&nbsp; In: IEEE Transactions on Information Theory, no. 3, vol. 23, 1977, p. 337–343.
 
*The original literature&nbsp; [LZ77]&nbsp; on this method is: <br> &nbsp; &nbsp; &nbsp; Ziv, J.; Lempel, A.:&nbsp; A Universal Algorithm for Sequential Data Compression.&nbsp; In: IEEE Transactions on Information Theory, no. 3, vol. 23, 1977, p. 337–343.
 
   
 
   
*&nbsp; [[Aufgaben:2.3_Zur_LZ78-Komprimierung|Exercise 2.3]]&nbsp; and&nbsp; [[Aufgaben:Aufgabe_2.4:_Zum_LZW-Algorithmus|Exercise 2.4]]&nbsp; deal with other Lempel&ndash;Ziv methods in a similar way.
+
*&nbsp; [[Aufgaben:Exercise_2.3:_About_the_LZ78_Compression|Exercise 2.3]]&nbsp; and&nbsp; [[Aufgaben:Exercise_2.4:_About_the_LZW_algorithm|Exercise 2.4]]&nbsp; deal with other Lempel&ndash;Ziv methods in a similar way.
 
    
 
    
  
Line 54: Line 54:
 
{Which statement is true for the same buffer size&nbsp; $G = 4$&nbsp; at step&nbsp; $i = 5$?
 
{Which statement is true for the same buffer size&nbsp; $G = 4$&nbsp; at step&nbsp; $i = 5$?
 
|type="[]"}
 
|type="[]"}
+ The search buffer contains&nbsp; <b>BARA</b>.
+
+ The search buffer contains&nbsp; "<b>BARA</b>".
+ The preview buffer says&nbsp; <b>&ndash;BAR</b>.
+
+ The preview buffer says&nbsp; "<b>&ndash;BAR</b>".
 
- The output is&nbsp; $(0, 0,$ <b>A</b>$)$.
 
- The output is&nbsp; $(0, 0,$ <b>A</b>$)$.
  
  
{After which step&nbsp; $i_{\rm Ende}$&nbsp; is the coding with&nbsp; $G = 4$&nbsp; finished?
+
{After which step&nbsp; $i_{\rm end}$&nbsp; is the coding with&nbsp; $G = 4$&nbsp; finished?
 
|type="{}"}
 
|type="{}"}
$i_{\rm Ende} \ = \ $ { 9 }  
+
$i_{\rm end} \ = \ $ { 9 }  
  
  
{Now let&nbsp; $G = 5$.&nbsp; After which step&nbsp; $i_{\rm Ende}$&nbsp; is the coding finished?
+
{Now let&nbsp; $G = 5$.&nbsp; After which step&nbsp; $i_{\rm end}$&nbsp; is the coding finished?
 
|type="{}"}
 
|type="{}"}
$i_{\rm Ende} \ = \ $ { 6 }  
+
$i_{\rm end} \ = \ $ { 6 }  
  
  
Line 80: Line 80:
 
===Solution===
 
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
[[File:P_ID2438__Inf_Z_2_3c.png|right|frame|Beispiel zum LZ77–Algorithmus mit&nbsp; $G = 4$]]
+
[[File:P_ID2438__Inf_Z_2_3c.png|right|frame|Example of the LZ77 algorithm with&nbsp; $G = 4$]]
'''(1)'''&nbsp; Richtig ist der <u>Lösungsvorschlag 3</u>.  
+
'''(1)'''&nbsp;<u>Solution suggestion 3</u> is correct.  
*Im Vorschaupuffer steht zum betrachteten Zeitpunkt&nbsp; $i = 4$&nbsp; die Zeichenfolge&nbsp; <b>BARA</b>.  
+
*The preview buffer contains the character string&nbsp; "<b>BARA</b>" at the time&nbsp; $i = 4$&nbsp;.
*Im Suchpuffer steht in den letzten drei Stellen&nbsp; <b>BAR</b>:
+
*The search buffer contains&nbsp; "<b>BAR</b>" in the last three digits:
 
:$$P = 2\hspace{0.05cm},\hspace{0.2cm}L = 3\hspace{0.05cm},\hspace{0.2cm}Z = \boldsymbol{\rm A}\hspace{0.05cm}.$$
 
:$$P = 2\hspace{0.05cm},\hspace{0.2cm}L = 3\hspace{0.05cm},\hspace{0.2cm}Z = \boldsymbol{\rm A}\hspace{0.05cm}.$$
  
  
  
'''(2)'''&nbsp; Richtig sind die <u>beiden ersten Lösungsvorschläge</u>:  
+
'''(2)'''&nbsp;<u>The first two solutions</u> are correct:  
*Der Bindestrich findet sich zum Zeitpunkt&nbsp; $i = 5$&nbsp; nicht im Suchpuffer.  
+
*The hyphen is not found in the search buffer at time&nbsp; $i = 5$.  
*Ausgegeben wird&nbsp; $(0, 0,$ <b>&ndash;</b>$)$.
+
*The output is&nbsp; $(0, 0,$ <b>&ndash;</b>$)$.
  
  
  
'''(3)'''&nbsp; Die obere Grafik zeigt das&nbsp; <i>Sliding&ndash;Window</i>&nbsp; und die Coderausgabe zu den Zeiten&nbsp; $i>5$.  
+
'''(3)'''&nbsp; The upper graphic shows the&nbsp; "Sliding Window"&nbsp; and the coder output at times&nbsp; $i>5$.  
*Nach&nbsp; $i = 9$&nbsp; Codierschritten ist der Codiervorgang unter Berücksichtigung von&nbsp; <b>eof</b>&nbsp; beendet &nbsp; &rArr; &nbsp; $\underline{i_{\rm Ende} = 9}$.
+
*After&nbsp; $i = 9$&nbsp; coding steps the coding process is finished considering&nbsp; <b>eof</b>&nbsp; &nbsp; &rArr; &nbsp; $\underline{i_{\rm end} = 9}$.
  
  
  
[[File:P_ID2439__Inf_Z_2_3d.png|right|frame|Beispiel zum LZ77–Algorithmus mit&nbsp; $G = 5$]]
+
[[File:P_ID2439__Inf_Z_2_3d.png|right|frame|Example of the LZ77 algorithm with&nbsp; $G = 5$]]
'''(4)'''&nbsp; Bei größerer Puffergröße&nbsp; $(G = 5$&nbsp; anstelle von&nbsp; $G = 4)$&nbsp; ist die Codierung schon nach dem 6. Codierschritt  abgeschlossen &nbsp; &rArr; &nbsp; $\underline{i_{\rm Ende} = 6}$.
+
'''(4)'''&nbsp; With a larger buffer size&nbsp; $(G = 5$&nbsp; instead of&nbsp; $G = 4)$&nbsp; the coding is already completed after the 6th coding step &nbsp; &rArr; &nbsp; $\underline{i_{\rm end} = 6}$.
*Ein Vergleich der beiden Grafiken zeigt, dass sich für&nbsp; $G = 5$&nbsp; gegenüber&nbsp; $G = 4$&nbsp; bis einschließlich&nbsp; $i = 5$&nbsp; nichts ändert.  
+
*A comparison of the two graphs shows that nothing changes for&nbsp; $G = 5$&nbsp; compared to&nbsp; $G = 4$&nbsp; up to and including&nbsp; $i = 5$&nbsp;.  
*Aufgrund des größeren Puffers lässt sich aber nun&nbsp; <b>BAR</b>&nbsp; gemeinsam mit&nbsp; <b>eof</b>&nbsp; (end-of-file) in einem einzigen Schritt codieren, während mit&nbsp; $G = 4$&nbsp; hierfür vier Schritte notwendig waren.
+
*Due to the larger buffer, however,&nbsp; "<b>BAR</b>"&nbsp; can now be coded together with&nbsp; "<b>eof</b>"&nbsp; (end-of-file) in a single step, whereas with&nbsp; $G = 4$&nbsp; four steps were necessary for this.
 
<br clear=all>
 
<br clear=all>
'''(5)'''&nbsp; Richtig ist nur die  <u>Aussage 1</u>.  
+
'''(5)'''&nbsp;Only <u>statement 1</u> is correct.  
*Ein Nachteil von LZ77 ist das lokale Wörterbuch.&nbsp; Eigentlich schon bekannte Phrasen können nicht für die Datenkomprimierung verwendet werden, wenn sie mehr als&nbsp; $G$&nbsp; Zeichen vorher im Text aufgetreten sind.&nbsp; Dagegen sind bei LZ78 alle Phrasen im globalen Wörterbuch abgelegt.  
+
*A disadvantage of LZ77 is the local dictionary.&nbsp; Phrases that are actually already known cannot be used for data compression if they occurred more than&nbsp; $G$&nbsp; characters earlier in the text.&nbsp; In contrast, with LZ78 all phrases are stored in the global dictionary.  
*Richtig ist zwar, dass bei LZ78 nur Pärchen&nbsp; $(I, \ Z)$&nbsp; übertragen werden müssen, während bei LZ77 jeder Codierschritt durch ein Triple&nbsp; $(P, \ L, \ Z)$&nbsp; gekennzeichnet ist.&nbsp; Das bedeutet aber noch nicht, dass pro Codierschritt auch weniger Bit übertragen werden müssen.
+
*It is true that with LZ78 only pairs&nbsp; $(I, \ Z)$&nbsp; have to be transmitted, whereas with LZ77 each coding step is identified by a triple&nbsp; $(P, \ L, \ Z)$&nbsp;.&nbsp; However, this does not mean that fewer bits have to be transmitted per coding step.
*Betrachten wir beispielhaft die Puffergröße&nbsp; $G = 8$.&nbsp; Bei LZ77 muss man dann&nbsp; $P$&nbsp; mit drei Bit und&nbsp; $L$&nbsp; mit vier Bit dargestellen.&nbsp; Beachten Sie bitte, dass die gefundene Übereinstimmung zwischen Vorschaupuffer und Suchpuffer auch im Vorschaupuffer enden darf.
+
*Consider, for example, the buffer size&nbsp; $G = 8$.&nbsp; With LZ77, one must then represent&nbsp; $P$&nbsp; with three bits and&nbsp; $L$&nbsp; with four bits.&nbsp; Please note that the match found between the preview buffer and the search buffer may also end in the preview buffer.
*Das neue Zeichen&nbsp; $Z$&nbsp; benötigt bei LZ78 genau die gleiche Bitanzahl wie bei LZ77 (nämlich zwei Bit), wenn man wie hier vom Symbolumfang&nbsp; $M = 4$&nbsp; ausgeht.  
+
*The new character&nbsp; $Z$&nbsp; requires exactly the same number of bits in LZ78 as in LZ77 (namely two bits), if one assumes the symbol set size&nbsp; $M = 4$&nbsp; as here.  
*Die Aussage 2 wäre nur dann richtig, wenn&nbsp; $N_{\rm I}$&nbsp; kleiner wäre als&nbsp; $N_{\rm P}+ N_{\rm L}$, beispielsweise&nbsp; $N_{\rm I} = 6$. Das würde aber bedeuten, dass man die Wörterbuchgröße auf&nbsp; $I = 2^6 = 64$&nbsp; begrenzen müsste.&nbsp; Dies reicht für große Dateien nicht aus.
+
*Statement 2 would only be correct if&nbsp; $N_{\rm I}$&nbsp; were smaller than&nbsp; $N_{\rm P}+ N_{\rm L}$, for example&nbsp; $N_{\rm I} = 6$.&nbsp; But this would mean that one would have to limit the dictionary size to&nbsp; $I = 2^6 = 64$&nbsp;.&nbsp; This is not sufficient for large files.
*Unsere Überschlagsrechnung basiert allerdings auf einer einheitlichen Bitanzahl für den Index&nbsp; $I$.&nbsp; Mit variabler Bitanzahl für den Index kann man etliche Bit einsparen, indem man&nbsp; $I$&nbsp; nur mit so vielen Bit überträgt, wie es für den Codierschritt&nbsp; $i$&nbsp; erforderlich ist.  
+
*Our rough calculation, however, is based on a uniform number of bits for the index&nbsp; $I$.&nbsp; With a variable number of bits for the index, you can save quite a few bits by transmitting&nbsp; $I$&nbsp; only with as many bits as are necessary for the coding step&nbsp; $i$&nbsp;.  
*Prinzipiell ändert das aber nichts an der Beschränkung der Wörterbuchgröße, was bei großen Dateien stets zu Problemen führen wird.
+
*In principle, however, this does not change the limitation of the dictionary size, which will always lead to problems with large files.
 
{{ML-Fuß}}
 
{{ML-Fuß}}
  
  
  
[[Category:Information Theory: Exercises|^2.2 Verfahren von Lempel, Ziv, Welch^]]
+
[[Category:Information Theory: Exercises|^2.2 Lempel-Ziv-Welch Compression^]]

Latest revision as of 13:10, 10 August 2021

Sliding–Window with  $G = 4$  and  $G = 5$
(valid for "LZ77")

In  Exercise 2.3,  you were supposed to compress  "BARBARA–BAR"  (string of length  $11$, four different characters)  using the LZ78 algorithm. 

In this exercise we use the same text to demonstrate LZ77 compression.  To note:

  • While the successor  "LZ78"  successively builds a global dictionary,  "LZ77"  uses a local dictionary.
  • The LZ77 method works with a  "Sliding Window"  that is gradually shifted over the input text.
  • This  "sliding window"  is divided into the  "preview buffer"  (highlighted in blue in the graphic)  and the  "search buffer"  (highlighted in red).  Both buffers have a size of  $G$  memory locations each.
  • Each coding step  $i$  is characterised by a triple  $(P,\ L,\ Z)$.  Here,  $P$  and  $L$  are integers and  $Z$  is a character.  Transmitted are the binary representations of  $P$,  $L$  and  $Z$.
  • After transmission, the  sliding window  is shifted one or more positions to the right and the next coding step  $i + 1$ begins.


The upper diagram shows the initial allocation with the buffer size  $G = 4$  at the times  $i = 1$  as well as  $i = 4$.

  • At time  $i = 1$ , the search buffer is empty, so the coder output is  $(0, 0,$ B$)$ .
  • After the shift by one position, the search buffer contains a  B, but no string that begins with  A.  The second number triple is therefore  $(0, 0,$ A$)$.
  • The output for  $i = 3$  is  $(0, 0,$ R$)$, since there is no string beginning with  R  in the search buffer even now.


The snapshot at time  $i = 4$  is also shown in the graphic.  The search is now for the character string in the search buffer that best matches the preview text  BARA .  A number triple  $(P,\ L,\ Z)$, is transmitted again, but now with the following meaning:

  • $P$  indicates the position in the (red) search buffer where the match starts.  The  $P$  values of the individual memory locations can be seen in the graphic.
  • $L$  denotes the number of characters in the search buffer that, starting at  $P$,  match the current string in the preview buffer.
  • Finally $Z$  denotes the first character in the preview buffer that differs from the matching string found in the search buffer.


The larger the LZ77 parameter  $G$ , the easier it is to find the longest possible match.  In subtask  (4)  you will notice that the LZ77 encoding with  $G = 5$  gives a better result than the one with  $G = 4$.

  • However, because of the later binary representation of  $P$,  one will always choose  $G$  as a power of two, so that  $G$  can be represented with  $\log_2 \ P$  bits  $(G = 8$   ⇒   three-digit binary number  $P)$.
  • This means that a  "Sliding Window"  with  $G = 5$  has rather little practical relevance.



Hints:


Questions

1

What is the LZ77 output with  $G = 4$  at step  $i = 4$?

$(0, 0,$ B$)$,
$(2, 1,$ A$)$,
$(2, 3,$ A$)$.

2

Which statement is true for the same buffer size  $G = 4$  at step  $i = 5$?

The search buffer contains  "BARA".
The preview buffer says  "–BAR".
The output is  $(0, 0,$ A$)$.

3

After which step  $i_{\rm end}$  is the coding with  $G = 4$  finished?

$i_{\rm end} \ = \ $

4

Now let  $G = 5$.  After which step  $i_{\rm end}$  is the coding finished?

$i_{\rm end} \ = \ $

5

What advantages does LZ78 have over LZ77 for "very large" files?

One finds more often already stored phrases in the dictionary.
Fewer bits have to be transferred per coding step.


Solution

Example of the LZ77 algorithm with  $G = 4$

(1) Solution suggestion 3 is correct.

  • The preview buffer contains the character string  "BARA" at the time  $i = 4$ .
  • The search buffer contains  "BAR" in the last three digits:
$$P = 2\hspace{0.05cm},\hspace{0.2cm}L = 3\hspace{0.05cm},\hspace{0.2cm}Z = \boldsymbol{\rm A}\hspace{0.05cm}.$$


(2) The first two solutions are correct:

  • The hyphen is not found in the search buffer at time  $i = 5$.
  • The output is  $(0, 0,$ $)$.


(3)  The upper graphic shows the  "Sliding Window"  and the coder output at times  $i>5$.

  • After  $i = 9$  coding steps the coding process is finished considering  eof    ⇒   $\underline{i_{\rm end} = 9}$.


Example of the LZ77 algorithm with  $G = 5$

(4)  With a larger buffer size  $(G = 5$  instead of  $G = 4)$  the coding is already completed after the 6th coding step   ⇒   $\underline{i_{\rm end} = 6}$.

  • A comparison of the two graphs shows that nothing changes for  $G = 5$  compared to  $G = 4$  up to and including  $i = 5$ .
  • Due to the larger buffer, however,  "BAR"  can now be coded together with  "eof"  (end-of-file) in a single step, whereas with  $G = 4$  four steps were necessary for this.


(5) Only statement 1 is correct.

  • A disadvantage of LZ77 is the local dictionary.  Phrases that are actually already known cannot be used for data compression if they occurred more than  $G$  characters earlier in the text.  In contrast, with LZ78 all phrases are stored in the global dictionary.
  • It is true that with LZ78 only pairs  $(I, \ Z)$  have to be transmitted, whereas with LZ77 each coding step is identified by a triple  $(P, \ L, \ Z)$ .  However, this does not mean that fewer bits have to be transmitted per coding step.
  • Consider, for example, the buffer size  $G = 8$.  With LZ77, one must then represent  $P$  with three bits and  $L$  with four bits.  Please note that the match found between the preview buffer and the search buffer may also end in the preview buffer.
  • The new character  $Z$  requires exactly the same number of bits in LZ78 as in LZ77 (namely two bits), if one assumes the symbol set size  $M = 4$  as here.
  • Statement 2 would only be correct if  $N_{\rm I}$  were smaller than  $N_{\rm P}+ N_{\rm L}$, for example  $N_{\rm I} = 6$.  But this would mean that one would have to limit the dictionary size to  $I = 2^6 = 64$ .  This is not sufficient for large files.
  • Our rough calculation, however, is based on a uniform number of bits for the index  $I$.  With a variable number of bits for the index, you can save quite a few bits by transmitting  $I$  only with as many bits as are necessary for the coding step  $i$ .
  • In principle, however, this does not change the limitation of the dictionary size, which will always lead to problems with large files.