Difference between revisions of "Information Theory/Further Source Coding Methods"

From LNTwww
 
(48 intermediate revisions by 5 users not shown)
Line 2: Line 2:
 
{{Header
 
{{Header
 
|Untermenü=Source coding - Data compression
 
|Untermenü=Source coding - Data compression
|Vorherige Seite=Entropy coding according to Huffman
+
|Vorherige Seite=Entropy Coding According to Huffman
|Nächste Seite=Some preliminary remarks on two-dimensional random variables
+
|Nächste Seite=Some_Preliminary_Remarks_on_Two-Dimensional_Random_Variables
 
}}
 
}}
  
Line 9: Line 9:
 
==The Shannon-Fano algorithm==  
 
==The Shannon-Fano algorithm==  
 
<br>
 
<br>
The Huffman coding from 1952 is a special case of &bdquo;entropy coding&rdquo;.&nbsp; It attempts to represent the source symbol&nbsp; $q_μ$&nbsp; by a code symbol&nbsp; $c_μ$&nbsp; of length&nbsp; $L_μ$&nbsp;, aiming for the following construction rule:
+
The Huffman coding from 1952 is a special case of&nbsp; "entropy coding".&nbsp; It attempts to represent the source symbol&nbsp; $q_μ$&nbsp; by a code symbol&nbsp; $c_μ$&nbsp; of length&nbsp; $L_μ$,&nbsp; aiming for the following construction rule:
 
   
 
   
 
:$$L_{\mu} \approx  -{\rm log}_2\hspace{0.15cm}(p_{\mu})  
 
:$$L_{\mu} \approx  -{\rm log}_2\hspace{0.15cm}(p_{\mu})  
 
\hspace{0.05cm}.$$
 
\hspace{0.05cm}.$$
  
Since&nbsp; $L_μ$&nbsp;, in contrast to&nbsp; $-{\rm log}_2\hspace{0.15cm}(p_{\mu})$&nbsp;, is integer, this does not always succeed.
+
Since&nbsp; $-{\rm log}_2\hspace{0.15cm}(p_{\mu})$&nbsp; is in contrast to&nbsp; $L_μ$&nbsp; not always an integer, this does not succeed in any case.
  
Already three years before David A. Huffman,&nbsp; [https://en.wikipedia.org/wiki/Claude_Shannon Claude E. Shannon]&nbsp; and&nbsp; [https://en.wikipedia.org/wiki/Robert_Fano Robert Fano]&nbsp;gave a similar algorithm, namely:
+
Already three years before David A. Huffman,&nbsp; [https://en.wikipedia.org/wiki/Claude_Shannon $\text{Claude E. Shannon}$]&nbsp; and&nbsp; [https://en.wikipedia.org/wiki/Robert_Fano $\text{Robert Fano}$]&nbsp;gave a similar algorithm, namely:
:# &nbsp; Order the source symbols according to decreasing probabilities of occurrence (identical to Huffman).
+
:# &nbsp; Order the source symbols according to decreasing symbol probabilities (identical to Huffman).
 
:# &nbsp; Divide the sorted characters into two groups of equal probability.
 
:# &nbsp; Divide the sorted characters into two groups of equal probability.
 
:# &nbsp; The binary symbol&nbsp; '''1'''&nbsp; is assigned to the first group,&nbsp; '''0'''&nbsp; to the second (or vice versa).
 
:# &nbsp; The binary symbol&nbsp; '''1'''&nbsp; is assigned to the first group,&nbsp; '''0'''&nbsp; to the second (or vice versa).
Line 23: Line 23:
  
 
{{GraueBox|TEXT=
 
{{GraueBox|TEXT=
$\text{Example 1:}$&nbsp; As in the&nbsp; [[Information_Theory/Entropiecodierung_nach_Huffman#The_Huffman_algorithm|introductory example for the Huffman code]]&nbsp; im letzten Kapitel von&nbsp; $M = 6$&nbsp; Symbolen und folgenden Wahrscheinlichkeiten aus:
+
$\text{Example 1:}$&nbsp; As in the&nbsp; [[Information_Theory/Entropiecodierung_nach_Huffman#The_Huffman_algorithm|"introductory example for the Huffman algorithm"]]&nbsp; in the last chapter, we assume&nbsp; $M = 6$&nbsp; symbols and the following probabilities:
 
   
 
   
 
:$$p_{\rm A} = 0.30 \hspace{0.05cm},\hspace{0.2cm}p_{\rm B} = 0.24 \hspace{0.05cm},\hspace{0.2cm}p_{\rm C} = 0.20 \hspace{0.05cm},\hspace{0.2cm}
 
:$$p_{\rm A} = 0.30 \hspace{0.05cm},\hspace{0.2cm}p_{\rm B} = 0.24 \hspace{0.05cm},\hspace{0.2cm}p_{\rm C} = 0.20 \hspace{0.05cm},\hspace{0.2cm}
Line 29: Line 29:
 
\hspace{0.05cm}.$$
 
\hspace{0.05cm}.$$
  
Dann lautet der Shannon–Fano–Algorithmus:
+
Then the Shannon-Fano algorithm is:
:# &nbsp; $\rm AB$ &nbsp; → &nbsp; '''1'''x &nbsp;(Wahrscheinlichkeit 0.54), &nbsp; $\rm CDEF$ &nbsp; → &nbsp; '''0'''x &nbsp;(Wahrscheinlichkeit 0.46),
+
:# &nbsp; $\rm AB$ &nbsp; → &nbsp; '''1'''x &nbsp;(probability 0.54), &nbsp; $\rm CDEF$ &nbsp; → &nbsp; '''0'''x &nbsp;(probability 0.46),
:# &nbsp; $\underline{\rm A}$ &nbsp; → &nbsp; '''<u>11</u>''' &nbsp;(Wahrscheinlichkeit 0.30),  &nbsp;  $\underline{\rm B}$ &nbsp;  → &nbsp; '''<u>10</u>''' &nbsp;(Wahrscheinlichkeit 0.24),
+
:# &nbsp; $\underline{\rm A}$ &nbsp; → &nbsp; '''<u>11</u>''' &nbsp;(probability 0.30),  &nbsp;  $\underline{\rm B}$ &nbsp;  → &nbsp; '''<u>10</u>''' &nbsp;(probability 0.24),
:# &nbsp; $\underline{\rm C}$ &nbsp; → &nbsp; '''<u>01</u>''' &nbsp;(Wahrscheinlichkeit 0.20), &nbsp;  $\rm DEF$ → '''00'''x, &nbsp;(Wahrscheinlichkeit 0.26),
+
:# &nbsp; $\underline{\rm C}$ &nbsp; → &nbsp; '''<u>01</u>''' &nbsp;(probability 0.20), &nbsp;  $\rm DEF$ → '''00'''x, &nbsp;(probability 0.26),
:# &nbsp; $\underline{\rm D}$ &nbsp; → &nbsp;  '''<u>001</u>''' &nbsp;(Wahrscheinlichkeit 0.12),  &nbsp;  $\rm EF$ &nbsp; → &nbsp; '''000'''x &nbsp;(Wahrscheinlichkeit 0.14),
+
:# &nbsp; $\underline{\rm D}$ &nbsp; → &nbsp;  '''<u>001</u>''' &nbsp;(probability 0.12),  &nbsp;  $\rm EF$ &nbsp; → &nbsp; '''000'''x &nbsp;(probability 0.14),
:# &nbsp; $\underline{\rm E}$ &nbsp; → &nbsp; '''<u>0001</u>''' &nbsp;(Wahrscheinlichkeit 0.10), &nbsp;  $\underline{\rm F}$ &nbsp; → &nbsp; '''<u>0000</u>'''  &nbsp;(Wahrscheinlichkeit 0.04).
+
:# &nbsp; $\underline{\rm E}$ &nbsp; → &nbsp; '''<u>0001</u>''' &nbsp;(probability 0.10), &nbsp;  $\underline{\rm F}$ &nbsp; → &nbsp; '''<u>0000</u>'''  &nbsp;(probability 0.04).
  
''Anmerkungen'':  
+
''Notes'':  
*Ein „x” weist wieder darauf hin, dass in nachfolgenden Codierschritten noch Bit hinzugefügt werden müssen.
+
*An "x" again indicates that bits must still be added in subsequent coding steps.
*Es ergibt sich hier zwar eine andere Zuordnung als bei der&nbsp; [[Information_Theory/Entropiecodierung_nach_Huffman#Der_Huffman.E2.80.93Algorithmus|Huffman–Codierung]], aber genau die gleiche mittlere Codewortlänge:
+
*This results in a different assignment than with&nbsp; [[Information_Theory/Entropiecodierung_nach_Huffman#The_Huffman_algorithm|$\text{Huffman coding}$]], but exactly the same average code word length:
 
    
 
    
:$$L_{\rm M} = (0.30\hspace{-0.05cm}+\hspace{-0.05cm} 0.24\hspace{-0.05cm}+ \hspace{-0.05cm}0.20) \hspace{-0.05cm}\cdot\hspace{-0.05cm} 2 + 0.12\hspace{-0.05cm} \cdot \hspace{-0.05cm} 3 + (0.10\hspace{-0.05cm}+\hspace{-0.05cm}0.04) \hspace{-0.05cm}\cdot \hspace{-0.05cm}4 = 2.4\,{\rm bit/Quellensymbol}\hspace{0.05cm}.$$}}
+
:$$L_{\rm M} = (0.30\hspace{-0.05cm}+\hspace{-0.05cm} 0.24\hspace{-0.05cm}+ \hspace{-0.05cm}0.20) \hspace{-0.05cm}\cdot\hspace{-0.05cm} 2 + 0.12\hspace{-0.05cm} \cdot \hspace{-0.05cm} 3 + (0.10\hspace{-0.05cm}+\hspace{-0.05cm}0.04) \hspace{-0.05cm}\cdot \hspace{-0.05cm}4 = 2.4\,{\rm bit/source\hspace{0.15cm} symbol}\hspace{0.05cm}.$$}}
  
  
Mit den Wahrscheinlichkeiten entsprechend dem&nbsp; $\text{Beispiel 1}$&nbsp; führt der Shannon–Fano–Algorithmus zur gleichen mittleren Codewortlänge wie die Huffman–Codierung.&nbsp; Ebenso sind bei vielen&nbsp; (eigentlich:&nbsp; den meisten)&nbsp; anderen Wahrscheinlichkeitsprofilen Huffman und Shannon–Fano aus informationstheoretischer Sicht äquivalent.  
+
With the probabilities corresponding to&nbsp; $\text{Example 1}$,&nbsp; the Shannon-Fano algorithm leads to the same avarage code word length as Huffman coding.&nbsp; Similarly, for most other probability profiles, Huffman and Shannon-Fano are equivalent from an information-theoretic point of view.
  
Es gibt aber durchaus Fälle, bei denen sich beide Verfahren hinsichtlich der (mittleren) Codewortlänge unterscheiden, wie das folgende Beispiel zeigt.
+
However, there are definitely cases where the two methods differ in terms of (mean) code word length, as the following example shows.
  
 
{{GraueBox|TEXT=
 
{{GraueBox|TEXT=
$\text{Beispiel 2:}$&nbsp; Wir betrachten&nbsp; $M = 5$&nbsp; Symbole mit folgenden Wahrscheinlichkeiten:
+
$\text{Example 2:}$&nbsp; We consider&nbsp; $M = 5$&nbsp; symbols with the following probabilities:
 
 
 
:$$p_{\rm A} = 0.38 \hspace{0.05cm}, \hspace{0.2cm}p_{\rm B}= 0.18 \hspace{0.05cm}, \hspace{0.2cm}p_{\rm C}= 0.16 \hspace{0.05cm},\hspace{0.2cm}
 
:$$p_{\rm A} = 0.38 \hspace{0.05cm}, \hspace{0.2cm}p_{\rm B}= 0.18 \hspace{0.05cm}, \hspace{0.2cm}p_{\rm C}= 0.16 \hspace{0.05cm},\hspace{0.2cm}
 
p_{\rm D}= 0.15 \hspace{0.05cm}, \hspace{0.2cm}p_{\rm E}= 0.13 \hspace{0.3cm}  
 
p_{\rm D}= 0.15 \hspace{0.05cm}, \hspace{0.2cm}p_{\rm E}= 0.13 \hspace{0.3cm}  
\Rightarrow\hspace{0.3cm}  H = 2.19\,{\rm bit/Quellensymbol}
+
\Rightarrow\hspace{0.3cm}  H = 2.19\,{\rm bit/source\hspace{0.15cm} symbol}
 
\hspace{0.05cm}. $$
 
\hspace{0.05cm}. $$
  
[[File:P_ID2461__Inf_T_2_4_S1_ganz_neu.png|center|frame|Baumstrukturen nach Shannon–Fano bzw. Huffman]]
+
[[File:EN_Inf_T_2_4_S1_v2.png|right|frame|Tree structures according to Shannon-Fano and Huffman]]
  
Die Grafik zeigt die jeweiligen Codebäume für Shannon–Fano (links) bzw. Huffman (rechts).&nbsp; Die Ergebnisse lassen sich wie folgt zusammenfassen:
+
The diagram shows the respective code trees for Shannon-Fano (left) and Huffman (right).&nbsp; The results can be summarized as follows:
* Der Shannon–Fano–Algorithmus führt zum Code&nbsp; $\rm A$ &nbsp; → &nbsp; '''11''', &nbsp; $\rm B$ &nbsp; → &nbsp; '''10''', &nbsp; $\rm C$ &nbsp; → &nbsp; '''01''', &nbsp; $\rm D$ &nbsp; → &nbsp; '''001''', &nbsp; $\rm E$ &nbsp; → &nbsp; '''000'''&nbsp; und damit zur mittleren Codewortlänge
+
* The Shannon-Fano algorithm leads to the code
 +
:&nbsp; &nbsp; $\rm A$ &nbsp; → &nbsp; '''11''', &nbsp; $\rm B$ &nbsp; → &nbsp; '''10''', &nbsp; $\rm C$ &nbsp; → &nbsp; '''01''', &nbsp; $\rm D$ &nbsp; → &nbsp; '''001''', &nbsp; $\rm E$ &nbsp; → &nbsp; '''000'''&nbsp;  
 +
:and thus to the mean code word length
 
   
 
   
:$$L_{\rm M} = (0.38 + 0.18 + 0.16) \cdot 2 + (0.15 + 0.13) \cdot 3 = 2.28\,\,{\rm bit/Quellensymbol}\hspace{0.05cm}.$$
+
:$$L_{\rm M} = (0.38 + 0.18 + 0.16) \cdot 2 + (0.15 + 0.13) \cdot 3 $$
 +
:$$\Rightarrow\hspace{0.3cm} L_{\rm M}  = 2.28\,\,{\rm bit/source\hspace{0.15cm} symbol}\hspace{0.05cm}.$$
  
*Mit &bdquo;Huffman&rdquo; erhält man&nbsp; $\rm A$ &nbsp; → &nbsp; '''1''', &nbsp; $\rm B$ &nbsp; → &nbsp; '''001''', &nbsp; $\rm C$ &nbsp; → &nbsp; '''010''', &nbsp; $\rm D$ &nbsp; → &nbsp; '''001''', &nbsp; $\rm E$ &nbsp; → &nbsp; '''000'''&nbsp; und eine etwas kleinere mittlere Codewortlänge:
+
*Using "Huffman", we get&nbsp;  
 +
:&nbsp; &nbsp; $\rm A$ &nbsp; → &nbsp; '''1''', &nbsp; $\rm B$ &nbsp; → &nbsp; '''001''', &nbsp; $\rm C$ &nbsp; → &nbsp; '''010''', &nbsp; $\rm D$ &nbsp; → &nbsp; '''001''', &nbsp; $\rm E$ &nbsp; → &nbsp; '''000'''&nbsp;  
 +
:and a slightly smaller code word length:
 
   
 
   
:$$L_{\rm M} = 0.38 \cdot 1 + (1-0.38) \cdot 3 = 2.24\,\,{\rm bit/Quellensymbol}\hspace{0.05cm}. $$
+
:$$L_{\rm M} = 0.38 \cdot 1 + (1-0.38) \cdot 3 $$
 +
:$$\Rightarrow\hspace{0.3cm} L_{\rm M} = 2.24\,\,{\rm bit/source\hspace{0.15cm} symbol}\hspace{0.05cm}. $$
  
*Es gibt keinen Satz von Wahrscheinlichkeiten, bei denen &bdquo;Shannon–Fano&rdquo; ein besseres Ergebnis liefert als der Huffman–Algorithmus, der stets den bestmöglichen Entropiecodierer bereitstellt.
+
*There is no set of probabilities for which&nbsp; "Shannon–Fano"&nbsp; provides a better result than&nbsp; "Huffman",&nbsp; which always provides the best possible entropy encoder.
*Die Grafik zeigt zudem, dass die Algorithmen im Baumdiagramm in unterschiedlichen Richtungen vorgehen, nämlich einmal von der Wurzel zu den Einzelsymbolen&nbsp; (Shannon–Fano), zum anderen von den Einzelsymbolen zur Wurzel&nbsp; (Huffman).}}
+
*The graph also shows that the algorithms proceed in different directions in the tree diagram, namely once from the root to the individual symbols&nbsp; (Shannon–Fano), and secondly from the individual symbols to the root&nbsp; (Huffman).}}
  
  
==Arithmetische Codierung ==  
+
The (German language) interactive applet&nbsp; [[Applets:Huffman_Shannon_Fano|"Huffman- und Shannon-Fano-Codierung&nbsp; &rArr; &nbsp; $\text{SWF}$&nbsp;version"]]&nbsp; illustrates the procedure for two variants of entropy coding.
 +
 
 +
 
 +
 
 +
==Arithmetic coding ==  
 
<br>
 
<br>
Eine weitere Form der Entropiecodierung ist die arithmetische Codierung.&nbsp; Auch bei dieser müssen die Symbolwahrscheinlichkeiten&nbsp; $p_μ$&nbsp; bekannt sein.&nbsp; Für den Index gelte weiter&nbsp; $μ = 1$, ... ,&nbsp; $M$.
+
Another form of entropy coding is arithmetic coding.&nbsp; Here, too, the symbol probabilities&nbsp; $p_μ$&nbsp; must be known.&nbsp; For the index applies&nbsp; $μ = 1$, ... ,&nbsp; $M$.
Hier nun ein kurzer Abriss über die Vorgehensweise:
 
*Im Gegensatz zur Huffman– und zur Shannon–Fano–Codierung wird bei arithmetischer Codierung eine Symbolfolge der Länge&nbsp; $N$&nbsp; gemeinsam codiert.&nbsp; Wir schreiben abkürzend&nbsp; $Q = 〈\hspace{0.05cm} q_1, q_2$, ... , $q_N \hspace{0.05cm} 〉$.
 
*Jeder Symbolfolge&nbsp; $Q_i$&nbsp; wird ein reelles Zahlenintervall&nbsp; $I_i$&nbsp; zugewiesen, das durch den Beginn&nbsp; $B_i$&nbsp; und die Intervallbreite&nbsp; ${\it Δ}_i$&nbsp; gekennzeichnet ist.
 
*Der „Code” für die Folge&nbsp; $Q_i$&nbsp; ist die Binärdarstellung eines reellen Zahlenwertes aus diesem Intervall: &nbsp; $r_i ∈ I_i = \big [B_i, B_i + {\it Δ}_i\big)$.&nbsp; Diese Notation besagt, dass zwar&nbsp; $B_i$&nbsp; zum Intervall&nbsp; $I_i$&nbsp; gehört&nbsp; (eckige Klammer), aber &nbsp;$B_i + {\it Δ}_i$&nbsp; gerade nicht mehr&nbsp; (runde Klammer).
 
*Es gilt stets&nbsp; $0 ≤ r_i < 1$.&nbsp; Sinnvollerweise wählt man&nbsp; $r_i$&nbsp; aus dem Intervall&nbsp; $I_i$&nbsp; derart, dass der Wert mit möglichst wenigen Bit darstellbar ist.&nbsp; Es gibt aber stets eine Mindestbitanzahl, die von der Intervallbreite&nbsp; ${\it Δ}_i$&nbsp; abhängt.
 
  
 +
Here is a brief outline of the procedure:
 +
*In contrast to Huffman and Shannon-Fano coding, a symbol sequence of length&nbsp; $N$&nbsp; is coded together in arithmetic coding.&nbsp; We write abbreviated&nbsp; $Q = 〈\hspace{0.05cm} q_1, q_2$, ... , $q_N \hspace{0.05cm} 〉$.
 +
*Each symbol sequence&nbsp; $Q_i$&nbsp; is assigned a real number interval&nbsp; $I_i$&nbsp; which is identified by the beginning&nbsp; $B_i$&nbsp; and the interval width&nbsp; ${\it Δ}_i$&nbsp;.
 +
*The&nbsp; "code"&nbsp; for the sequence&nbsp; $Q_i$&nbsp; is the binary representation of a real number value from this interval: &nbsp; $r_i ∈ I_i = \big [B_i, B_i + {\it Δ}_i\big)$.&nbsp; This notation says that&nbsp; $B_i$&nbsp; belongs to the interval&nbsp; $I_i$&nbsp; &nbsp; (square bracket), but &nbsp;$B_i + {\it Δ}_i$&nbsp; just does not&nbsp; (round bracket).
 +
*It is always&nbsp; $0 ≤ r_i < 1$.&nbsp; It makes sense to select&nbsp; $r_i$&nbsp; from the interval&nbsp; $I_i$&nbsp; in such a way that the value can be represented with as few bits as possible.&nbsp; However, there is always a minimum number of bits, which depends on the interval width&nbsp; ${\it Δ}_i$.
  
Der Algorithmus zur Bestimmung der Intervallparameter&nbsp; $B_i$&nbsp; und&nbsp; ${\it Δ}_i$&nbsp; wird im späteren&nbsp; $\text{Beispiel 4}$&nbsp; erläutert, ebenso eine Decodiermöglichkeit.  
+
 
*Zunächst folgt noch ein kurzes Beispiel zur Auswahl der reellen Zahl&nbsp; $r_i$&nbsp; in Hinblick auf minimale Bitanzahl.  
+
The algorithm for determining the interval parameters&nbsp; $B_i$&nbsp; and&nbsp; ${\it Δ}_i$&nbsp; is explained later in&nbsp; $\text{Example 4}$&nbsp;, as is the decoding option.
*Genauere Informationen hierzu finden Sie bei der Beschreibung zur&nbsp; [[Aufgaben:Aufgabe_2.11Z:_Nochmals_Arithmetische_Codierung|Aufgabe 2.11Z]].
+
*First, there is a short example for the selection of the real number &nbsp; $r_i$&nbsp; with regard to the minimum number of bits.  
 +
*More detailed information on this can be found in the description of&nbsp; [[Aufgaben:Aufgabe_2.11Z:_Nochmals_Arithmetische_Codierung|"Exercise 2.11Z"]].
  
  
 
{{GraueBox|TEXT=
 
{{GraueBox|TEXT=
$\text{Beispiel 3:}$&nbsp; Für die beiden nachfolgend aufgeführten  Parametersätze des arithmetischen Codieralgorithmus ergeben sich folgende reelle Ergebnisse&nbsp; $r_i$&nbsp; und folgende Codes, die zum zugehörigen Intervall&nbsp; $I_i$&nbsp; gehören:
+
$\text{Example 3:}$&nbsp; For the two parameter sets of the arithmetic coding algorithm listed below, yields the following real results&nbsp; $r_i$&nbsp; and the following codes belong to the associated interval&nbsp; $I_i$&nbsp;:
 
* $B_i = 0.25, {\it Δ}_i = 0.10  \ ⇒  \ I_i = \big[0.25, 0.35\big)\text{:}$
 
* $B_i = 0.25, {\it Δ}_i = 0.10  \ ⇒  \ I_i = \big[0.25, 0.35\big)\text{:}$
  
Line 93: Line 103:
 
\hspace{0.05cm},$$  
 
\hspace{0.05cm},$$  
  
* $B_i = 0.65, {\it Δ}_i = 0.10 \ ⇒  \ I_i = \big[0.65, 0.75\big);$&nbsp; zu beachten: &nbsp; $0.75$&nbsp; gehört nicht zum Intervall:
+
* $B_i = 0.65, {\it Δ}_i = 0.10 \ ⇒  \ I_i = \big[0.65, 0.75\big);$&nbsp; note: &nbsp; $0.75$&nbsp; does not belong to the interval:
 
   
 
   
 
:$$r_i =  1 \cdot 2^{-1}  + 0 \cdot 2^{-2} + 1 \cdot 2^{-3} + 1 \cdot 2^{-4} = 0.6875 \hspace{0.3cm}\Rightarrow\hspace{0.3cm}
 
:$$r_i =  1 \cdot 2^{-1}  + 0 \cdot 2^{-2} + 1 \cdot 2^{-3} + 1 \cdot 2^{-4} = 0.6875 \hspace{0.3cm}\Rightarrow\hspace{0.3cm}
 
{\rm Code} \hspace{0.15cm} \boldsymbol{\rm 1011} \in I_i\hspace{0.05cm}. $$
 
{\rm Code} \hspace{0.15cm} \boldsymbol{\rm 1011} \in I_i\hspace{0.05cm}. $$
  
Um den sequentiellen Ablauf zu organisieren, wählt man allerdings die Bitanzahl konstant zu&nbsp; $N_{\rm Bit} = \big\lceil {\rm log}_2 \hspace{0.15cm}  ({1}/{\it \Delta_i})\big\rceil+1\hspace{0.05cm}. $  
+
However, to organize the sequential flow, one chooses the number of bits constant to&nbsp; $N_{\rm Bit} = \big\lceil {\rm log}_2 \hspace{0.15cm}  ({1}/{\it \Delta_i})\big\rceil+1\hspace{0.05cm}. $  
*Mit der Intervallbreite&nbsp; ${\it Δ}_i = 0.10$&nbsp; ergibt sich&nbsp; $N_{\rm Bit} = 5$.  
+
*With the interval width&nbsp; ${\it Δ}_i = 0.10$&nbsp; results&nbsp; $N_{\rm Bit} = 5$.  
*Die tatsächlichen arithmetischen Codes wären also &nbsp; '''01000''' &nbsp; bzw. &nbsp; '''10110'''.}}
+
*So the actual arithmetic codes would be &nbsp; '''01000''' &nbsp; and &nbsp; '''10110''' respectively.}}
  
  
 
{{GraueBox|TEXT=
 
{{GraueBox|TEXT=
$\text{Beispiel 4:}$&nbsp; Nun sei der Symbolumfang&nbsp; $M = 3$&nbsp; und die Symbole bezeichnen wir mit&nbsp; $\rm X$,&nbsp; $\rm Y$&nbsp; und&nbsp; $\rm Z$:
+
$\text{Example 4:}$&nbsp; Now let the symbol set size be&nbsp; $M = 3$&nbsp; and let the symbols be denoted by&nbsp; $\rm X$,&nbsp; $\rm Y$&nbsp; and&nbsp; $\rm Z$:
*Übertragen werden soll die Zeichenfolge&nbsp; $\rm XXYXZ$ &nbsp;  ⇒ &nbsp;  Länge der Quellensybolfolge: &nbsp; $N = 5$.
+
*The character sequence&nbsp; $\rm XXYXZ$ &nbsp;  ⇒ &nbsp;  length of the source symbol sequence: &nbsp; $N = 5$.
*Auszugehen ist von den Wahrscheinlichkeiten&nbsp; $p_{\rm X} = 0.6$,&nbsp; $p_{\rm Y} = 0.2$&nbsp; und&nbsp; $p_{\rm Z} = 0.2$.
+
*Assume the probabilities&nbsp; $p_{\rm X} = 0.6$,&nbsp; $p_{\rm Y} = 0.2$&nbsp; and&nbsp; $p_{\rm Z} = 0.2$.
  
[[File:Inf_T_2_4_S2_version2.png|center|frame|Zum arithmetischen Codieralgorithmus]]
+
[[File:EN_Inf_T_2_4_S2.png|right|frame|About the arithmetic coding algorithm]]
  
Die Grafik zeigt den Algorithmus zur Bestimmung der Intervallgrenzen.
 
*Man unterteilt zunächst den gesamten Wahrscheinlichkeitsbereich&nbsp; $($zwischen&nbsp; $0$&nbsp; und&nbsp; $1)$&nbsp; gemäß den Symbolwahrscheinlichkeiten&nbsp; $p_{\rm X}$,&nbsp; $p_{\rm Y}$&nbsp; und&nbsp; $p_{\rm Z}$&nbsp; in drei Bereiche mit den Grenzen&nbsp; $B_0$,&nbsp; $C_0$,&nbsp; $D_0$&nbsp; und&nbsp; $E_0$.
 
*Das erste zur Codierung anliegende Symbol ist&nbsp; $\rm X$.&nbsp; Deshalb wird im nächsten Schritt der Wahrscheinlichkeitsbereich von&nbsp; $B_1 = B_0 = 0$ &nbsp;bis&nbsp; $E_1 = C_0 = 0.6$&nbsp; wiederum im Verhältnis&nbsp; $0.6$&nbsp; :&nbsp; $0.2$&nbsp; :&nbsp; $0.2$&nbsp; aufgeteilt.
 
*Nach dem zweiten Symbol&nbsp; $\rm X$&nbsp; liegen die Bereichsgrenzen bei&nbsp; $B_2 = 0$,&nbsp; $C_2 = 0.216$,&nbsp; $D_2 = 0.288$ &nbsp;und&nbsp; $E_2 = 0.36$.&nbsp; Da nun das Symbol&nbsp; $\rm Y$&nbsp; ansteht, erfolgt die Unterteilung des Bereiches zwischen&nbsp; $0.216$ ... $0.288$.
 
*Nach dem fünften Symbol&nbsp; $\rm Z$&nbsp; liegt das Intervall&nbsp; $I_i$&nbsp; für die betrachtete Symbolfolge&nbsp; $Q_i = \rm XXYXZ$&nbsp; fest.&nbsp; Es muss nun eine reelle Zahl&nbsp; $r_i$&nbsp; gefunden werden, für die gilt: &nbsp; $0.25056 ≤ r_i < 0.2592$.
 
*Die einzige reelle Zahl im Intervall&nbsp; $I_i = \big[0.25056, 0.2592\big)$, die man mit sieben Bit darstellen kann, ist&nbsp; $r_i = 1 · 2^{–2} + 1 · 2^{–7} = 0.2578125$.&nbsp; Damit liegt die Coderausgabe fest: &nbsp;  '''0100001'''.}}
 
  
 +
The diagram on the right shows the algorithm for determining the interval boundaries.
 +
*First, the entire probability range&nbsp; $($between&nbsp; $0$&nbsp; and&nbsp; $1)$&nbsp; is divided according to the symbol probabilities&nbsp; $p_{\rm X}$,&nbsp; $p_{\rm Y}$&nbsp; and&nbsp; $p_{\rm Z}$&nbsp; into three areas with the boundaries&nbsp; $B_0$,&nbsp; $C_0$,&nbsp; $D_0$&nbsp; and&nbsp; $E_0$.
 +
*The first symbol present for coding is&nbsp; $\rm X$.&nbsp; Therefore, in the next step, the probability range from&nbsp; $B_1 = B_0 = 0$ &nbsp;to&nbsp; $E_1 = C_0 = 0.6$&nbsp; is again divided in the ratio&nbsp; $0.6$&nbsp; :&nbsp; $0.2$&nbsp; :&nbsp; $0.2$.
 +
*After the second symbol&nbsp; $\rm X$&nbsp;, the range limits are&nbsp; $B_2 = 0$,&nbsp; $C_2 = 0.216$,&nbsp; $D_2 = 0.288$ &nbsp;and&nbsp; $E_2 = 0.36$.&nbsp; Since the symbol&nbsp; $\rm Y$&nbsp; is now pending, the range is subdivided between&nbsp; $0.216$ ... $0.288$.
 +
*After the fifth symbol&nbsp; $\rm Z$&nbsp; , the interval&nbsp; $I_i$&nbsp; for the considered symbol sequence&nbsp; $Q_i = \rm XXYXZ$&nbsp; is fixed.&nbsp; A real number&nbsp; $r_i$&nbsp; must now be found for which the following applies:: &nbsp; $0.25056 ≤ r_i < 0.2592$.
 +
*The only real number in the interval&nbsp; $I_i = \big[0.25056, 0.2592\big)$, that can be represented with seven bits is&nbsp;
 +
:$$r_i = 1 · 2^{–2} + 1 · 2^{–7} = 0.2578125.$$
 +
*Thus the encoder output is fixed: &nbsp;  '''0100001'''.}}
  
Für diese&nbsp; $N = 5$&nbsp; Symbole werden also sieben Bit benötigt, genau so viele wie bei Huffman–Codierung mit der Zuordnung $\rm X$ &nbsp; → &nbsp; '''1''', $\rm Y$ &nbsp; → &nbsp; '''00''', $\rm Z$ &nbsp; → &nbsp; '''01'''.
 
*Die arithmetische Codierung ist allerdings dann dem Huffman–Code überlegen, wenn die tatsächlich bei Huffman verwendete Bitanzahl noch mehr von der optimalen Verteilung abweicht, zum Beispiel, wenn ein Zeichen extrem häufig vorkommt.
 
  
*Oft wird aber einfach nur die Intervallmitte im Beispiel&nbsp;  $0.25488$ – binär dargestellt: &nbsp;  '''0.01000010011''' .... Die Bitanzahl erhält man daraus wie folgt:
+
Seven bits are therefore needed for these&nbsp; $N = 5$&nbsp; symbols, exactly as many as with Huffman coding with the assignment $\rm X$ &nbsp; → &nbsp; '''1''', $\rm Y$ &nbsp; → &nbsp; '''00''', &nbsp; $\rm Z$ &nbsp; → &nbsp; '''01'''.
 +
*However, arithmetic coding is superior to Huffman coding when the actual number of bits used in Huffman deviates even more from the optimal distribution, for example, when a character occurs extremely frequently.
 +
*Often, however, only the middle of the interval in the example&nbsp;  $0.25488$ – is represented in binary: &nbsp;  '''0.01000010011''' .... The number of bits is obtained as follows:
 
   
 
   
 
:$${\it Δ}_5 = 0.2592 - 0.25056 = 0.00864 \hspace{0.3cm}\Rightarrow \hspace{0.3cm}N_{\rm Bit} = \left\lceil  {\rm log}_2 \hspace{0.15cm} \frac{1}{0.00864} \right\rceil + 1\hspace{0.15cm} =
 
:$${\it Δ}_5 = 0.2592 - 0.25056 = 0.00864 \hspace{0.3cm}\Rightarrow \hspace{0.3cm}N_{\rm Bit} = \left\lceil  {\rm log}_2 \hspace{0.15cm} \frac{1}{0.00864} \right\rceil + 1\hspace{0.15cm} =
Line 127: Line 139:
 
\hspace{0.05cm}.$$
 
\hspace{0.05cm}.$$
  
*Damit lautet der arithmetische Code für dieses Beispiel mit&nbsp;  $N = 5$&nbsp;  Eingangszeichen: &nbsp;  '''01000010'''.
+
*Thus the arithmetic code for this example with&nbsp;  $N = 5$&nbsp;  input characters is: &nbsp;  '''01000010'''.
  
*Der Decodiervorgang lässt sich ebenfalls anhand der obigen Grafik erklären. Die ankommende Bitsequenz '''0100001''' wird zu $r = 0.2578125$ gewandelt.  
+
*The decoding process can also be explained using the above graphic. The incoming bit sequence&nbsp; '''0100001'''&nbsp; is converted to&nbsp; $r = 0.2578125$ .  
*Dieser liegt im ersten und zweiten Schritt jeweils im ersten Bereich &nbsp;  ⇒ &nbsp; Symbol $\rm X$, im dritten Schritt in zweiten Bereich &nbsp;  ⇒ &nbsp; Symbol $\rm Y$, usw.
+
*This lies in the first and second step respectively in the first area &nbsp;  ⇒ &nbsp; symbol $\rm X$, in the third step in the second area &nbsp;  ⇒ &nbsp; symbol $\rm Y$,&nbsp; and so on.
  
  
Weitere Informationen zur Arithmetischen Codierung finden Sie in&nbsp;  [https://en.wikipedia.org/wiki/Arithmetic_coding WIKIPEDIA]&nbsp;  und in&nbsp;  [BCK02]<ref> Bodden, E.; Clasen, M.; Kneis, J.: ''Algebraische Kodierung''. Proseminar, Lehrstuhl für Informatik IV, RWTH Aachen, 2002.</ref>.
+
Further information on arithmetic coding can be found in&nbsp;  [https://en.wikipedia.org/wiki/Arithmetic_coding $\text{WIKIPEDIA}$]&nbsp;  and in&nbsp;  [BCK02]<ref> Bodden, E.; Clasen, M.; Kneis, J.:&nbsp; Algebraische Kodierung.&nbsp; Algebraic Coding.  Proseminar, Chair of Computer Science IV, RWTH Aachen University, 2002.</ref>.
 
   
 
   
  
==Lauflängencodierung – Run–Length Coding ==  
+
==Run–Length coding ==  
 
<br>
 
<br>
Wir betrachten eine Binärquelle&nbsp; $(M = 2)$&nbsp; mit dem Symbolvorrat&nbsp; $\{$ $\rm A$,&nbsp; $\rm B$ $\}$,&nbsp; wobei ein Symbol sehr viel häufiger auftritt als das andere.&nbsp; Beispielsweise sei&nbsp; $p_{\rm A} \gg p_{\rm B}$.
+
We consider a binary source&nbsp; $(M = 2)$&nbsp; with the symbol set&nbsp; $\{$ $\rm A$,&nbsp; $\rm B$ $\}$,&nbsp; where one symbol occurs much more frequently than the other.&nbsp; For example, let&nbsp; $p_{\rm A} \gg p_{\rm B}$.
  
*Eine Entropiecodierung macht hier nur dann Sinn, wenn man diese auf&nbsp; $k$–Tupel anwendet.  
+
*Entropy coding only makes sense here when applied to&nbsp; $k$–tuples.  
*Eine zweite Möglichkeit bietet die&nbsp; '''Lauflängencodierung'''&nbsp; (englisch:&nbsp; ''Run–Length Coding'', RLC), die das seltenere Zeichen&nbsp; $\rm B$&nbsp; als Trennzeichen betrachtet und die Längen&nbsp; $L_i$&nbsp; der einzelnen Substrings &nbsp; $\rm AA\text{...}A$&nbsp; als Ergebnis liefert.
+
*A second possibility is&nbsp; &raquo;'''Run-length Coding'''&laquo;&nbsp; $\rm  (RLC)$, <br>which considers the rarer character&nbsp; $\rm B$&nbsp; as a separator and returns the lengths&nbsp; $L_i$&nbsp; of the individual sub-strings&nbsp; $\rm AA\text{...}A$&nbsp; as a result.
  
  
 +
[[File:P_ID2470__Inf_T_2_4_S4_neu.png|right|frame|To illustrate the run-length coding]]
 
{{GraueBox|TEXT=
 
{{GraueBox|TEXT=
$\text{Beispiel 5:}$&nbsp; Die Grafik zeigt eine beispielhafte Folge mit den Wahrscheinlichkeiten&nbsp; $p_{\rm A} = 0.9$&nbsp; und&nbsp; $p_{\rm B} = 0.1$ &nbsp; &rArr; &nbsp;  Quellenentropie $H = 0.469$ bit/Quellensymbol.  
+
$\text{Example 5:}$&nbsp; The graphic shows an example sequence
 +
*with the probabilities&nbsp; $p_{\rm A} = 0.9$&nbsp; and&nbsp; $p_{\rm B} = 0.1$ &nbsp; <br>&rArr; &nbsp;  source entropy $H = 0.469$ bit/source symbol.  
  
Die Beispielfolge der Länge&nbsp; $N = 100$&nbsp; beinhaltet genau zehnmal das Symbol&nbsp; $\rm B$&nbsp; und neunzigmal das Symbol&nbsp; $\rm A$, das heißt, die relativen Häufigkeiten stimmen hier exakt mit den Wahrscheinlichkeiten überein.
 
  
[[File:P_ID2470__Inf_T_2_4_S4_neu.png|center|frame|Zur Verdeutlichung der Lauflängencodierung]]
+
The example sequence of length&nbsp; $N = 100$&nbsp; contains the symbol&nbsp; $\rm B$&nbsp; exactly ten times and the symbol&nbsp; $\rm A$ ninety times, i.e. the relative frequencies here correspond exactly to the probabilities.
 
+
<br clear=all>
Man erkennt an diesem Beispiel:
+
You can see from this example:
*Die Lauflängencodierung dieser Folge ergibt in Dezimalschreibweise die Folge&nbsp; $ \langle \hspace{0.05cm}6, \ 14,  \ 26, \ 11, \ 4, \ 10, \ 3,\  9,\  1,\  16 \hspace{0.05cm} \rangle $.
+
*The run-length coding of this sequence results in the sequence&nbsp; $ \langle \hspace{0.05cm}6, \ 14,  \ 26, \ 11, \ 4, \ 10, \ 3,\  9,\  1,\  16 \hspace{0.05cm} \rangle $.
*Stellt man die Längen&nbsp; $L_1$, ... , $L_{10}$&nbsp; mit jeweils fünf Bit dar, so benötigt man so&nbsp; $5 · 10 = 50$&nbsp; Bit.  
+
*If one represents the lengths&nbsp; $L_1$, ... , $L_{10}$&nbsp; with five bits each, one thus requires&nbsp; $5 · 10 = 50$&nbsp; bits.  
*Die RLC&ndash;Datenkomprimierung ist also nicht viel schlechter als der theoretische Grenzwert, der sich entsprechend der Quellenentropie zu&nbsp; $H · N ≈ 47$&nbsp;  Bit ergibt.
+
*The RLC data compression is thus not much worse than the theoretical limit that results according to the source entropy to&nbsp; $H · N ≈ 47$&nbsp;  bits.
*Die direkte Anwendung einer Entropiecodierung  hätte hier keine Datenkomprimierung zur Folge; man benötigt weiterhin vielmehr weiterhin&nbsp; $100$&nbsp; Bit.  
+
*The direct application of entropy coding would not result in any data compression here; rather, one continues to need&nbsp; $100$&nbsp; bits.  
*Auch bei der Bildung von Dreiertupeln würde man mit Huffman noch&nbsp; $54$&nbsp; Bit benötigen, also mehr als mit Run–Length Coding.}}
+
*Even with the formation of triples,&nbsp; $54$&nbsp; bits would still be needed with Huffman, i.e. more than with run-length coding.}}
  
  
Das Beispiel zeigt aber auch zwei Probleme der Lauflängencodierung auf:
+
However, the example also shows two problems of run-length coding:
*Die Längen&nbsp; $L_i$&nbsp; der Substrings sind nicht begrenzt.&nbsp; Hier muss man besondere Maßnahmen treffen, wenn eine Länge&nbsp; $L_i$&nbsp; größer ist als&nbsp; $2^5 = 32$&nbsp; $($gültig für&nbsp; $N_{\rm Bit} = 5)$, zum Beispiel die Variante&nbsp; ''Run–Length Limited Coding''&nbsp; (RLLC). Siehe auch&nbsp; [Meck09]<ref>Mecking, M.: Information Theory. ''Vorlesungsmanuskript, Lehrstuhl für Nachrichtentechnik'', Technische Universität München, 2009.</ref>&nbsp; und&nbsp; [[Aufgaben:Aufgabe_2.13:_Burrows-Wheeler-Rücktransformation|Aufgabe 2.13]].
+
*The lengths&nbsp; $L_i$&nbsp; of the substrings are not limited.&nbsp; Special measures must be taken here if a length&nbsp; $L_i$&nbsp; is greater than&nbsp; $2^5 = 32$&nbsp; $($valid for&nbsp; $N_{\rm Bit} = 5)$, <br>for example the variant&nbsp; &raquo;'''Run–Length Limited Coding'''&laquo;&nbsp; $\rm (RLLC)$.&nbsp; See also&nbsp; [Meck09]<ref>Mecking, M.: Information Theory.&nbsp; Lecture manuscript, Chair of Communications Engineering, Technical University of Munich, 2009.</ref>&nbsp; and&nbsp; [[Aufgaben:Aufgabe_2.13:_Burrows-Wheeler-Rücktransformation|"Exercise 2.13"]].
*Endet die Folge nicht mit&nbsp; $\rm B$&nbsp; – was bei kleiner Wahrscheinlichkeit&nbsp; $p_{\rm B}$&nbsp; eher der Normalfall ist, so muss man auch für das Dateiende eine Sonderbehandlung vorsehen.
+
*If the sequence does not end with&nbsp; $\rm B$&nbsp; – which is rather the normal case with small probability&nbsp; $p_{\rm B}$&nbsp; one must also provide special treatment for the end of the file.
 
 
 
 
  
==Burrows–Wheeler–Transformation== 
+
==Burrows–Wheeler transformation== 
 
<br>
 
<br>
Zum Abschluss dieses Quellencodier–Kapitels behandeln wir noch kurz den 1994 von&nbsp; [https://en.wikipedia.org/wiki/Michael_Burrows Michael Burrows]&nbsp; und&nbsp; [https://en.wikipedia.org/wiki/David_Wheeler_(computer_scientist) David J. Wheeler]&nbsp; veröffentlichten Algorithmus&nbsp; [BW94]<ref>Burrows, M.; Wheeler, D.J.: ''A Block-sorting Lossless Data Compression Algorithm.'' Technical Report. Digital Equipment Corporation Communications, Palo Alto, 1994.</ref>,
+
To conclude this source coding chapter, we briefly discuss the algorithm published in 1994 by&nbsp; [https://en.wikipedia.org/wiki/Michael_Burrows $\text{Michael Burrows}$]&nbsp; and&nbsp; [https://en.wikipedia.org/wiki/David_Wheeler_(computer_scientist) $\text{David J. Wheeler}$]&nbsp; [BW94]<ref>Burrows, M.; Wheeler, D.J.:&nbsp; A Block-sorting Lossless Data Compression Algorithm.&nbsp; Technical Report. Digital Equipment Corp. Communications, Palo Alto, 1994.</ref>,
*der zwar alleine keinerlei Komprimierungspotenzial besitzt,
+
[[File:EN_Inf_T_2_4_S3_vers2.png|frame|Example of the BWT (forward transformation)]]
*aber die Komprimierungsfähigkeit anderer Verfahren stark verbessert.
 
  
[[File:P_ID2475__Inf_T_2_4_S3_neu.png|frame|Beispiel zur BWT (Hintransformation)]]
+
*which, although it has no compression potential on its own,
 +
*but it greatly improves the compression capability of other methods.
  
<br>Die Burrows–Wheeler–Transformation bewerkstelligt eine blockweise Sortierung von Daten, die in der Grafik am Beispiel des Textes&nbsp; $\text{ANNAS_ANANAS}$&nbsp; der Länge&nbsp; $N = 12$&nbsp; verdeutlicht wird:
 
  
*Zunächst wird aus dem String der Länge&nbsp; $N$&nbsp; eine&nbsp; $N×N$–Matrix erzeugt, wobei sich jede Zeile aus der Vorgängerzeile durch zyklische Linksverschiebung ergibt.
+
<br>The Burrows–Wheeler Transformation accomplishes a blockwise sorting of data, which is illustrated in the diagram using the example of the text&nbsp; $\text{ANNAS_ANANAS}$&nbsp; (meaning:&nbsp; Anna's pineapple)&nbsp; of length&nbsp; $N = 12$:
*Danach wird die BWT–Matrix lexikografisch sortiert.&nbsp; Das Ergebnis der Transformation ist die letzte Spalte &nbsp;  ⇒  &nbsp; $\text{L–Spalte}$. Im Beispiel ergibt sich&nbsp;  $\text{_NSNNAANAAAS}$.
+
 
*Des Weiteren muss auch der Primärindex&nbsp; $I$&nbsp; weitergegeben werden. Dieser gibt die Zeile der sortierten BWT–Matrix an, die den Originaltext enthält (in der Grafik rot markiert).
+
*First, an&nbsp; $N×N$ matrix is generated from the string of length&nbsp; $N$&nbsp; with each row resulting from the preceding row by cyclic left shift.
*Zur Bestimmung von L–Spalte und Primärindex sind natürlich keine Matrixoperationen erforderlich.&nbsp; Vielmehr findet man das BWT–Ergebnis mit Zeigertechnik sehr schnell.
+
*Then the BWT matrix is sorted lexicographically.&nbsp; The result of the transformation is the last  column&nbsp;  ⇒  &nbsp; $\text{L–column}$.&nbsp; In the example, this results in&nbsp;  $\text{_NSNNAANAAAS}$.
 +
*Furthermore, the primary index&nbsp; $I$&nbsp; must also be passed on. This value indicates the row of the sorted BWT matrix that contains the original text&nbsp; (marked red in the graphic).
 +
*Of course, no matrix operations are necessary to determine the&nbsp; $\text{L–column}$&nbsp; and the primary index.&nbsp; Rather, the BWT result can be found very quickly with pointer technology.
 
<br clear=all>
 
<br clear=all>
 
{{BlaueBox|TEXT=
 
{{BlaueBox|TEXT=
$\text{Außerdem ist zum BWT–Verfahren anzumerken:}$&nbsp;  
+
$\text{Furthermore, it should be noted about the BWT procedure:}$&nbsp;  
  
*Ohne Zusatzmaßnahme &nbsp;  ⇒  &nbsp;  eine nachgeschaltete „echte Kompression” führt die BWT zu keiner Datenkomprimierung. &nbsp;  
+
*Without an additional measure &nbsp;  ⇒  &nbsp;  a downstream "real compression" the BWT does not lead to any data compression. &nbsp;  
*Vielmehr ergibt sich sogar eine geringfügige Erhöhung der Datenmenge, da außer den&nbsp; $N$&nbsp; Zeichen nun auch der Primärindex&nbsp; $I$&nbsp; übermittelt werden muss.
+
*Rather, there is even a slight increase in the amount of data, since in addition to the&nbsp; $N$&nbsp; characters, the primary index&nbsp; $I$&nbsp; now also be transmitted.
*Bei längeren Texten ist dieser Effekt aber vernachlässigbar.&nbsp; Geht man von 8 Bit–ASCII–Zeichen (jeweils ein Byte) und der Blocklänge&nbsp; $N = 256$&nbsp; aus, so erhöht sich die Byte–Anzahl pro Block nur von&nbsp; $256$&nbsp; auf&nbsp; $257$, also lediglich um&nbsp; $0.4\%$.}}
+
*For longer texts,&nbsp; however,&nbsp; this effect is negligible.&nbsp; Assuming 8 bit–ASCII–characters&nbsp; (one byte each)&nbsp; and the block length&nbsp; $N = 256$&nbsp; the number of bytes per block only increases from&nbsp; $256$&nbsp; to&nbsp; $257$, i.e. by only&nbsp; $0.4\%$.}}
  
  
Wir verweisen auf die ausführlichen Beschreibungen zur BWT in&nbsp; [Abel04]<ref>Abel, J.: ''Grundlagen des Burrows-Wheeler-Kompressionsalgorithmus''. In: Informatik Forschung & Entwicklung, no. 2, vol. 18, S. 80-87, Jan.  2004 </ref>.
+
We refer to the detailed descriptions of BWT in&nbsp; [Abel04]<ref>Abel, J.:&nbsp; Grundlagen des Burrows-Wheeler-Kompressionsalgorithmus.&nbsp; In: Informatik Forschung & Entwicklung, no. 2, vol. 18, S. 80-87, Jan.  2004 </ref>.
+
 
Abschließend soll noch dargestellt werden, wie der Ursprungstext aus der&nbsp; $\text{L–Spalte}$ der BWT–Matrix rekonstruiert werden kann.
+
[[File:EN_Inf_T_2_4_S3b.png|frame|Example for BWT (reverse transformation)]]
* Dazu benötigt man noch den Primärindex $I$, sowie die erste Spalte der BWT–Matrix.  
+
 
*Diese&nbsp; $\text{F–Spalte}$ (von „First”) muss nicht übertragen werden, sondern ergibt sich aus der&nbsp; $\text{L–Spalte}$ (von „Last”) sehr einfach durch lexikografische Sortierung.
+
Finally, we will show how the original text can be reconstructed from the&nbsp; $\text{L}$–column&nbsp;  (from&nbsp; "Last")&nbsp; of the BWT matrix.
 +
* For this, one still needs the primary index $I$, as well as the first column of the BWT matrix.
 +
*This&nbsp; $\text{F}$–column&nbsp; (from&nbsp; "First")&nbsp; does not have to be transferred, but results from the&nbsp; $\text{L}$–column very simply through lexicographic sorting.
  
[[File:P_ID2476__Inf_T_2_4_S3b_neu.png|frame|Beispiel zur BWT (Rücktransformation)]]
 
  
<br>Die Grafik zeigt die Vorgehensweise für das betrachtete Beispiel:
+
The graphic shows the  reconstruction procedure for the example under consideration:
*Man beginnt in der Zeile mit dem Primärindex&nbsp; $I$.&nbsp; Als erstes Zeichen wird das rot markierte&nbsp; $\rm A$&nbsp; in der&nbsp; $\text{F–Spalte}$&nbsp; ausgegeben.&nbsp; Dieser Schritt ist in der Grafik mit einer gelben (1) gekennzeichnet.
+
*One starts in the line with the primary index&nbsp; $I$.&nbsp; The first character to be output is the&nbsp; $\rm A$&nbsp; marked in red in the&nbsp; $\text{F}$–column.&nbsp; This step is marked in the graphic with a yellow (1).
*Dieses&nbsp; $\rm A$&nbsp; ist das dritte&nbsp; $\rm A$–Zeichen in der&nbsp; $\text{F–Spalte}$.&nbsp; Man sucht nun das dritte&nbsp; $\rm A$&nbsp; in der&nbsp; $\text{L–Spalte}$, findet dieses in der mit&nbsp; '''(2)'''&nbsp; markierten Zeile und gibt das zugehörige&nbsp; '''N'''&nbsp; der&nbsp; $\text{F–Spalte}$&nbsp; aus.
+
*This&nbsp; $\rm A$&nbsp; is the third&nbsp; $\rm A$ character in the&nbsp; $\text{F}$–column.&nbsp; Now look for the third&nbsp; $\rm A$&nbsp; in the&nbsp; $\text{L}$–column,&nbsp; find it in the line marked with&nbsp; '''(2)'''&nbsp; and output the corresponding&nbsp; '''N'''&nbsp; of the&nbsp; $\text{F}$–column.
*Das letzte&nbsp; '''N'''&nbsp; der&nbsp; $\text{L–Spalte}$&nbsp; findet man in der  Zeile&nbsp; '''(3)'''.&nbsp; Ausgegeben wird das Zeichen der F–Spalte in der gleichen Zeile, also wieder ein&nbsp; '''N'''.
+
*The last&nbsp; '''N'''&nbsp; of the&nbsp; $\text{L}$–column is found in line&nbsp; '''(3)'''.&nbsp; The character of the F column is output in the same line, i.e. an&nbsp; '''N''' again.
  
  
Nach&nbsp;  $N = 12$&nbsp;  Decodierschritten ist die Rekonstruktion abgeschlossen.  
+
After&nbsp;  $N = 12$&nbsp;  decoding steps, the reconstruction is completed.  
 
<br clear=all>
 
<br clear=all>
 
{{BlaueBox|TEXT=
 
{{BlaueBox|TEXT=
$\text{Fazit:}$&nbsp;  
+
$\text{Conclusion:}$&nbsp;  
*Dieses Beispiel hat gezeigt, dass die&nbsp; ''Burrows–Wheeler–Transformation''&nbsp; nichts anderes ist als ein Sortieralgorithmus für Texte.&nbsp; Das Besondere daran ist, dass die Sortierung eindeutig umkehrbar ist.
+
*This example has shown that the&nbsp; Burrows–Wheeler transformation&nbsp;is nothing more than a sorting algorithm for texts.&nbsp; What is special about it is that the sorting is uniquely reversible.
 
   
 
   
*Diese Eigenschaft und zusätzlich seine innere Struktur sind die Grundlage dafür, dass man das BWT–Ergebnis mittels bekannter und effizienter Verfahren wie&nbsp; [[Information_Theory/Entropiecodierung_nach_Huffman|Huffman]]&nbsp; (eine Form der Entropiecodierung) und&nbsp; [[Information_Theory/Weitere_Quellencodierverfahren#Laufl.C3.A4ngencodierung_.E2.80.93_Run.E2.80.93Length_Coding|Run–Length Coding ]]&nbsp; komprimieren kann.}}
+
*This property and additionally its inner structure are the basis for compressing the BWT result by means of known and efficient methods such as&nbsp; [[Information_Theory/Entropiecodierung_nach_Huffman|$\text{Huffman}$]]&nbsp; (a form of entropy coding) and&nbsp; [[Information_Theory/Further_Source_Coding_Methods#Run.E2.80.93Length_coding|$\text{run–length coding}$]].}}
  
  
==Anwendungsszenario für die Burrows–Wheeler–Transformation==   
+
==Application scenario for the Burrows-Wheeler transformation==   
 
<br>
 
<br>
Als Beispiel für die Einbettung der&nbsp; [[Information_Theory/Weitere_Quellencodierverfahren#Burrows.E2.80.93Wheeler.E2.80.93Transformation|Burrows–Wheeler–Transformation]]&nbsp; (BWT) in eine Kette von Quellencodierverfahren wählen wir eine in&nbsp; [Abel03]<ref>Abel, J.: ''Verlustlose Datenkompression auf Grundlage der Burrows-Wheeler-Transformation''. In: PIK - Praxis der Informationsverarbeitung und Kommunikation, no. 3, vol. 26, S. 140-144, Sept.  2003.</ref>&nbsp; vorgeschlagene Struktur.&nbsp; Wir verwenden dabei das gleiche Textbeispiel&nbsp; $\text{ANNAS_ANANAS}$&nbsp; wie auf der letzten Seite.&nbsp; Die entsprechenden Strings nach den einzelnen Blöcken sind in der Grafik ebenfalls angegeben.
+
As an example for embedding the&nbsp; [[Information_Theory/Further_Source_Coding_Methods#Burrows.E2.80.93Wheeler_transformation|$\text{Burrows–Wheeler Transformation}$]]&nbsp; (BWT) into a chain of source coding methods, we choose a structure proposed in&nbsp; [Abel03]<ref>Abel, J.:&nbsp; Verlustlose Datenkompression auf Grundlage der Burrows-Wheeler-Transformation.&nbsp; <br>In: PIK - Praxis der Informationsverarbeitung und Kommunikation, no. 3, vol. 26, pp. 140-144, Sept.  2003.</ref>.&nbsp; We use the same text example&nbsp; $\text{ANNAS_ANANAS}$&nbsp; as in the last section.&nbsp; The corresponding strings after each block are also given in the graphic.
  
[[File:P_ID2477__Inf_T_2_4_S5_neu.png|center|frame|Schema für die Burrows–Wheeler–Datenkompression]]
+
[[File:EN_Inf_T_2_4_S5_v2.png|center|frame|Scheme for Burrows-Wheeler data compression]]
  
*Das&nbsp; '''BWT'''&ndash;Ergebnis lautet: &nbsp;  &nbsp; $\text{_NSNNAANAAAS}$.&nbsp; An der Textlänge&nbsp; $N = 12$&nbsp; hat die BWT nichts verändert, doch gibt es jetzt vier Zeichen, die identisch mit ihren Vorgängerzeichen sind&nbsp; (in der Grafik rot hervorgehoben).&nbsp; Im Originaltext war dies nur einmal der Fall.
+
*The&nbsp; $\rm BWT$&nbsp; result is: &nbsp;  &nbsp; $\text{_NSNNAANAAAS}$.&nbsp; BWT has not changed anything about the text length&nbsp; $N = 12$&nbsp; but there are now four characters that are identical to their predecessors&nbsp; (highlighted in red in the graphic).&nbsp; In the original text, this was only the case once.
*Im nächsten Block&nbsp; '''MTF'''&nbsp; (''Move–To–Front'') wird aus jedem Eingangszeichen aus der Menge&nbsp; $\{$ $\rm A$,&nbsp; $\rm N$,&nbsp; $\rm S$,&nbsp; '''_'''$\}$&nbsp; ein Index&nbsp; $I ∈ \{0, 1, 2, 3\}$.&nbsp; Es handelt sich hierbei aber nicht um ein einfaches Mapping, sondern um einen Algorithmus, der in der&nbsp; [[Aufgabe_2.13Z:_Kombination_BWT_und_''Move-to-Front''|Aufgabe 1.13Z]]&nbsp; angegeben ist.
+
*In the next block&nbsp; $\rm MTF$&nbsp; ("Move–To–Front") , each input character from the set&nbsp; $\{$ $\rm A$,&nbsp; $\rm N$,&nbsp; $\rm S$,&nbsp; '''_'''$\}$&nbsp; becomes an index&nbsp; $I ∈ \{0, 1, 2, 3\}$.&nbsp; However,&nbsp; this is not a simple mapping, but an algorithm given in&nbsp; [[Exercise_2.13Z:_Combination_of_BWT_and_MTF|"Exercise 1.13Z"]].
*Für unser Beispiel lautet die MTF–Ausgangsfolge&nbsp; $323303011002$, ebenfalls mit der Länge&nbsp; $N = 12$.&nbsp; Die vier Nullen in der MTF–Folge (in der Grafik ebenfalls mit roter Schrift) geben an, dass an diesen Stellen das BWT–Zeichen jeweils gleich ist wie sein Vorgänger.
+
*For our example, the MTF output sequence is&nbsp; $323303011002$, also with length&nbsp; $N = 12$.&nbsp; The four zeros in the MTF sequence&nbsp; (also in red font in the diagram)&nbsp; indicate that at each of these positions the BWT character is the same as its predecessor.
*Bei großen ASCII–Dateien kann die Häufigkeit der&nbsp; $0$&nbsp; durchaus mehr als&nbsp; $50\%$&nbsp; betragen, während die anderen&nbsp; $255$&nbsp; Indizes nur selten auftreten.&nbsp; Zur Komprimierung einer solchen Textstruktur eignet sich eine Lauflängencodierung (englisch:&nbsp; ''Run–Length Coding'', RLC) hervorragend.
+
*In large ASCII files, the frequency of the&nbsp; $0$&nbsp; may well be more than&nbsp; $50\%$,&nbsp; while the other&nbsp; $255$&nbsp; indices occur only rarely.&nbsp; Run-length coding&nbsp; $\rm (RCL)$&nbsp; is an excellent way to compress such a text structure.
*Der Block&nbsp; '''RLC0'''&nbsp; in obiger Codierungskette bezeichnet eine spezielle&nbsp; [[Information_Theory/Weitere_Quellencodierverfahren#Laufl.C3.A4ngencodierung_.E2.80.93_Run.E2.80.93Length_Coding|Lauflängencodierung]]&nbsp; für Nullen.&nbsp; Die graue Schattierung der Nullen soll andeuten, dass hier eine lange Nullsequenz durch eine spezifische Bitfolge&nbsp; (kürzer als die Nullsequenz)&nbsp; maskiert wurde.
+
*The block&nbsp; $\rm RCL0$&nbsp; in the above coding chain denotes a special&nbsp; [[Information_Theory/Further_Source_Coding_Methods#Run.E2.80.93Length_coding|$\text{run-length coding}$]]&nbsp; for zeros.&nbsp; The gray shading of the zeros indicates that a long zero sequence has been masked by a specific bit sequence &nbsp; (shorter than the zero sequence).
*Der Entropiecodierer&nbsp; $($'''EC''', zum Beispiel &bdquo;Huffman&rdquo;$)$&nbsp; sorgt für eine weitere Komprimierung.&nbsp; ''BWT''&nbsp; und&nbsp; ''MTF''&nbsp; haben in der Codierungskette nur die Aufgabe, durch eine Zeichenvorverarbeitung die Effizienz von&nbsp; ''RLC0''&nbsp; und&nbsp; ''EC''&nbsp; zu steigern. Die Ausgangsdatei ist wieder binär.
+
*The entropy encoder&nbsp; $\rm (EC$, for example "Huffman"$)$&nbsp; provides further compression.&nbsp; BWT&nbsp; and&nbsp; MTF&nbsp; only have the task in the coding chain of increasing the efficiency of&nbsp; "RLC0"&nbsp; and&nbsp; "EC"&nbsp; through character preprocessing.&nbsp; The output file is again binary.
  
  
==Aufgaben zum Kapitel ==  
+
==Exercises for the chapter ==  
 
<br>
 
<br>
[[Aufgaben:2.10 Shannon-Fano-Codierung|Aufgabe 2.10: Shannon-Fano-Codierung]]
+
[[Aufgaben:Exercise_2.10:_Shannon-Fano_Coding|Exercise 2.10: Shannon-Fano Coding]]
  
[[Aufgaben:2.11 Arithmetische Codierung|Aufgabe 2.11: Arithmetische Codierung]]
+
[[Aufgaben:Exercise_2.11:_Arithmetic_Coding|Exercise 2.11: Arithmetic Coding]]
  
[[Aufgaben:Aufgabe_2.11Z:_Nochmals_Arithmetische_Codierung|Aufgabe 2.11Z: Nochmals Arithmetische Codierung]]
+
[[Aufgaben:Exercise_2.11Z:_Arithmetic_Coding_once_again|Exercise 2.11Z: Arithmetic Coding once again]]
  
[[Aufgabe_2.12:_Run–Length_Coding_und_RLLC|Aufgabe 2.12: Run–Length Coding & RLLC]]
+
[[Exercise_2.12:_Run–Length_Coding_and_Run–Length_Limited_Coding|Exercise 2.12: Run–Length Coding and Run–Length Limited Coding]]
  
[[Aufgaben:Aufgabe_2.13:_Burrows-Wheeler-Rücktransformation|Aufgabe 2.13: Burrows-Wheeler-Rücktransformation]]
+
[[Aufgaben:Exercise_2.13:_Inverse_Burrows-Wheeler_Transformation|Exercise 2.13: Inverse Burrows-Wheeler Transformation]]
  
[[Aufgabe_2.13Z:_Kombination_BWT_und_''Move-to-Front''|Aufgabe 2.13Z: Kombination BWT & &bdquo;Move-to-Front&rdquo;]]
+
[[Exercise_2.13Z:_Combination_of_BWT_and_MTF|Exercise 2.13Z: Combination of BWT and MTF]]
  
==Quellenverzeichnis==
+
==References==
 
<references />
 
<references />
  
  
 
{{Display}}
 
{{Display}}

Latest revision as of 19:11, 20 February 2023


The Shannon-Fano algorithm


The Huffman coding from 1952 is a special case of  "entropy coding".  It attempts to represent the source symbol  $q_μ$  by a code symbol  $c_μ$  of length  $L_μ$,  aiming for the following construction rule:

$$L_{\mu} \approx -{\rm log}_2\hspace{0.15cm}(p_{\mu}) \hspace{0.05cm}.$$

Since  $-{\rm log}_2\hspace{0.15cm}(p_{\mu})$  is in contrast to  $L_μ$  not always an integer, this does not succeed in any case.

Already three years before David A. Huffman,  $\text{Claude E. Shannon}$  and  $\text{Robert Fano}$ gave a similar algorithm, namely:

  1.   Order the source symbols according to decreasing symbol probabilities (identical to Huffman).
  2.   Divide the sorted characters into two groups of equal probability.
  3.   The binary symbol  1  is assigned to the first group,  0  to the second (or vice versa).
  4.   If there is more than one character in a group, the algorithm is to be applied recursively to this group.

$\text{Example 1:}$  As in the  "introductory example for the Huffman algorithm"  in the last chapter, we assume  $M = 6$  symbols and the following probabilities:

$$p_{\rm A} = 0.30 \hspace{0.05cm},\hspace{0.2cm}p_{\rm B} = 0.24 \hspace{0.05cm},\hspace{0.2cm}p_{\rm C} = 0.20 \hspace{0.05cm},\hspace{0.2cm} p_{\rm D} = 0.12 \hspace{0.05cm},\hspace{0.2cm}p_{\rm E} = 0.10 \hspace{0.05cm},\hspace{0.2cm}p_{\rm F} = 0.04 \hspace{0.05cm}.$$

Then the Shannon-Fano algorithm is:

  1.   $\rm AB$   →   1x  (probability 0.54),   $\rm CDEF$   →   0x  (probability 0.46),
  2.   $\underline{\rm A}$   →   11  (probability 0.30),   $\underline{\rm B}$   →   10  (probability 0.24),
  3.   $\underline{\rm C}$   →   01  (probability 0.20),   $\rm DEF$ → 00x,  (probability 0.26),
  4.   $\underline{\rm D}$   →   001  (probability 0.12),   $\rm EF$   →   000x  (probability 0.14),
  5.   $\underline{\rm E}$   →   0001  (probability 0.10),   $\underline{\rm F}$   →   0000  (probability 0.04).

Notes:

  • An "x" again indicates that bits must still be added in subsequent coding steps.
  • This results in a different assignment than with  $\text{Huffman coding}$, but exactly the same average code word length:
$$L_{\rm M} = (0.30\hspace{-0.05cm}+\hspace{-0.05cm} 0.24\hspace{-0.05cm}+ \hspace{-0.05cm}0.20) \hspace{-0.05cm}\cdot\hspace{-0.05cm} 2 + 0.12\hspace{-0.05cm} \cdot \hspace{-0.05cm} 3 + (0.10\hspace{-0.05cm}+\hspace{-0.05cm}0.04) \hspace{-0.05cm}\cdot \hspace{-0.05cm}4 = 2.4\,{\rm bit/source\hspace{0.15cm} symbol}\hspace{0.05cm}.$$


With the probabilities corresponding to  $\text{Example 1}$,  the Shannon-Fano algorithm leads to the same avarage code word length as Huffman coding.  Similarly, for most other probability profiles, Huffman and Shannon-Fano are equivalent from an information-theoretic point of view.

However, there are definitely cases where the two methods differ in terms of (mean) code word length, as the following example shows.

$\text{Example 2:}$  We consider  $M = 5$  symbols with the following probabilities:

$$p_{\rm A} = 0.38 \hspace{0.05cm}, \hspace{0.2cm}p_{\rm B}= 0.18 \hspace{0.05cm}, \hspace{0.2cm}p_{\rm C}= 0.16 \hspace{0.05cm},\hspace{0.2cm} p_{\rm D}= 0.15 \hspace{0.05cm}, \hspace{0.2cm}p_{\rm E}= 0.13 \hspace{0.3cm} \Rightarrow\hspace{0.3cm} H = 2.19\,{\rm bit/source\hspace{0.15cm} symbol} \hspace{0.05cm}. $$
Tree structures according to Shannon-Fano and Huffman

The diagram shows the respective code trees for Shannon-Fano (left) and Huffman (right).  The results can be summarized as follows:

  • The Shannon-Fano algorithm leads to the code
    $\rm A$   →   11,   $\rm B$   →   10,   $\rm C$   →   01,   $\rm D$   →   001,   $\rm E$   →   000 
and thus to the mean code word length
$$L_{\rm M} = (0.38 + 0.18 + 0.16) \cdot 2 + (0.15 + 0.13) \cdot 3 $$
$$\Rightarrow\hspace{0.3cm} L_{\rm M} = 2.28\,\,{\rm bit/source\hspace{0.15cm} symbol}\hspace{0.05cm}.$$
  • Using "Huffman", we get 
    $\rm A$   →   1,   $\rm B$   →   001,   $\rm C$   →   010,   $\rm D$   →   001,   $\rm E$   →   000 
and a slightly smaller code word length:
$$L_{\rm M} = 0.38 \cdot 1 + (1-0.38) \cdot 3 $$
$$\Rightarrow\hspace{0.3cm} L_{\rm M} = 2.24\,\,{\rm bit/source\hspace{0.15cm} symbol}\hspace{0.05cm}. $$
  • There is no set of probabilities for which  "Shannon–Fano"  provides a better result than  "Huffman",  which always provides the best possible entropy encoder.
  • The graph also shows that the algorithms proceed in different directions in the tree diagram, namely once from the root to the individual symbols  (Shannon–Fano), and secondly from the individual symbols to the root  (Huffman).


The (German language) interactive applet  "Huffman- und Shannon-Fano-Codierung  ⇒   $\text{SWF}$ version"  illustrates the procedure for two variants of entropy coding.


Arithmetic coding


Another form of entropy coding is arithmetic coding.  Here, too, the symbol probabilities  $p_μ$  must be known.  For the index applies  $μ = 1$, ... ,  $M$.

Here is a brief outline of the procedure:

  • In contrast to Huffman and Shannon-Fano coding, a symbol sequence of length  $N$  is coded together in arithmetic coding.  We write abbreviated  $Q = 〈\hspace{0.05cm} q_1, q_2$, ... , $q_N \hspace{0.05cm} 〉$.
  • Each symbol sequence  $Q_i$  is assigned a real number interval  $I_i$  which is identified by the beginning  $B_i$  and the interval width  ${\it Δ}_i$ .
  • The  "code"  for the sequence  $Q_i$  is the binary representation of a real number value from this interval:   $r_i ∈ I_i = \big [B_i, B_i + {\it Δ}_i\big)$.  This notation says that  $B_i$  belongs to the interval  $I_i$    (square bracket), but  $B_i + {\it Δ}_i$  just does not  (round bracket).
  • It is always  $0 ≤ r_i < 1$.  It makes sense to select  $r_i$  from the interval  $I_i$  in such a way that the value can be represented with as few bits as possible.  However, there is always a minimum number of bits, which depends on the interval width  ${\it Δ}_i$.


The algorithm for determining the interval parameters  $B_i$  and  ${\it Δ}_i$  is explained later in  $\text{Example 4}$ , as is the decoding option.

  • First, there is a short example for the selection of the real number   $r_i$  with regard to the minimum number of bits.
  • More detailed information on this can be found in the description of  "Exercise 2.11Z".


$\text{Example 3:}$  For the two parameter sets of the arithmetic coding algorithm listed below, yields the following real results  $r_i$  and the following codes belong to the associated interval  $I_i$ :

  • $B_i = 0.25, {\it Δ}_i = 0.10 \ ⇒ \ I_i = \big[0.25, 0.35\big)\text{:}$
$$r_i = 0 \cdot 2^{-1} + 1 \cdot 2^{-2} = 0.25 \hspace{0.3cm}\Rightarrow\hspace{0.3cm} {\rm Code} \hspace{0.15cm} \boldsymbol{\rm 01} \in I_i \hspace{0.05cm},$$
  • $B_i = 0.65, {\it Δ}_i = 0.10 \ ⇒ \ I_i = \big[0.65, 0.75\big);$  note:   $0.75$  does not belong to the interval:
$$r_i = 1 \cdot 2^{-1} + 0 \cdot 2^{-2} + 1 \cdot 2^{-3} + 1 \cdot 2^{-4} = 0.6875 \hspace{0.3cm}\Rightarrow\hspace{0.3cm} {\rm Code} \hspace{0.15cm} \boldsymbol{\rm 1011} \in I_i\hspace{0.05cm}. $$

However, to organize the sequential flow, one chooses the number of bits constant to  $N_{\rm Bit} = \big\lceil {\rm log}_2 \hspace{0.15cm} ({1}/{\it \Delta_i})\big\rceil+1\hspace{0.05cm}. $

  • With the interval width  ${\it Δ}_i = 0.10$  results  $N_{\rm Bit} = 5$.
  • So the actual arithmetic codes would be   01000   and   10110 respectively.


$\text{Example 4:}$  Now let the symbol set size be  $M = 3$  and let the symbols be denoted by  $\rm X$,  $\rm Y$  and  $\rm Z$:

  • The character sequence  $\rm XXYXZ$   ⇒   length of the source symbol sequence:   $N = 5$.
  • Assume the probabilities  $p_{\rm X} = 0.6$,  $p_{\rm Y} = 0.2$  and  $p_{\rm Z} = 0.2$.
About the arithmetic coding algorithm


The diagram on the right shows the algorithm for determining the interval boundaries.

  • First, the entire probability range  $($between  $0$  and  $1)$  is divided according to the symbol probabilities  $p_{\rm X}$,  $p_{\rm Y}$  and  $p_{\rm Z}$  into three areas with the boundaries  $B_0$,  $C_0$,  $D_0$  and  $E_0$.
  • The first symbol present for coding is  $\rm X$.  Therefore, in the next step, the probability range from  $B_1 = B_0 = 0$  to  $E_1 = C_0 = 0.6$  is again divided in the ratio  $0.6$  :  $0.2$  :  $0.2$.
  • After the second symbol  $\rm X$ , the range limits are  $B_2 = 0$,  $C_2 = 0.216$,  $D_2 = 0.288$  and  $E_2 = 0.36$.  Since the symbol  $\rm Y$  is now pending, the range is subdivided between  $0.216$ ... $0.288$.
  • After the fifth symbol  $\rm Z$  , the interval  $I_i$  for the considered symbol sequence  $Q_i = \rm XXYXZ$  is fixed.  A real number  $r_i$  must now be found for which the following applies::   $0.25056 ≤ r_i < 0.2592$.
  • The only real number in the interval  $I_i = \big[0.25056, 0.2592\big)$, that can be represented with seven bits is 
$$r_i = 1 · 2^{–2} + 1 · 2^{–7} = 0.2578125.$$
  • Thus the encoder output is fixed:   0100001.


Seven bits are therefore needed for these  $N = 5$  symbols, exactly as many as with Huffman coding with the assignment $\rm X$   →   1, $\rm Y$   →   00,   $\rm Z$   →   01.

  • However, arithmetic coding is superior to Huffman coding when the actual number of bits used in Huffman deviates even more from the optimal distribution, for example, when a character occurs extremely frequently.
  • Often, however, only the middle of the interval – in the example  $0.25488$ – is represented in binary:   0.01000010011 .... The number of bits is obtained as follows:
$${\it Δ}_5 = 0.2592 - 0.25056 = 0.00864 \hspace{0.3cm}\Rightarrow \hspace{0.3cm}N_{\rm Bit} = \left\lceil {\rm log}_2 \hspace{0.15cm} \frac{1}{0.00864} \right\rceil + 1\hspace{0.15cm} = \left\lceil {\rm log}_2 \hspace{0.15cm} 115.7 \right\rceil + 1 = 8 \hspace{0.05cm}.$$
  • Thus the arithmetic code for this example with  $N = 5$  input characters is:   01000010.
  • The decoding process can also be explained using the above graphic. The incoming bit sequence  0100001  is converted to  $r = 0.2578125$ .
  • This lies in the first and second step respectively in the first area   ⇒   symbol $\rm X$, in the third step in the second area   ⇒   symbol $\rm Y$,  and so on.


Further information on arithmetic coding can be found in  $\text{WIKIPEDIA}$  and in  [BCK02][1].


Run–Length coding


We consider a binary source  $(M = 2)$  with the symbol set  $\{$ $\rm A$,  $\rm B$ $\}$,  where one symbol occurs much more frequently than the other.  For example, let  $p_{\rm A} \gg p_{\rm B}$.

  • Entropy coding only makes sense here when applied to  $k$–tuples.
  • A second possibility is  »Run-length Coding«  $\rm (RLC)$,
    which considers the rarer character  $\rm B$  as a separator and returns the lengths  $L_i$  of the individual sub-strings  $\rm AA\text{...}A$  as a result.


To illustrate the run-length coding

$\text{Example 5:}$  The graphic shows an example sequence

  • with the probabilities  $p_{\rm A} = 0.9$  and  $p_{\rm B} = 0.1$  
    ⇒   source entropy $H = 0.469$ bit/source symbol.


The example sequence of length  $N = 100$  contains the symbol  $\rm B$  exactly ten times and the symbol  $\rm A$ ninety times, i.e. the relative frequencies here correspond exactly to the probabilities.
You can see from this example:

  • The run-length coding of this sequence results in the sequence  $ \langle \hspace{0.05cm}6, \ 14, \ 26, \ 11, \ 4, \ 10, \ 3,\ 9,\ 1,\ 16 \hspace{0.05cm} \rangle $.
  • If one represents the lengths  $L_1$, ... , $L_{10}$  with five bits each, one thus requires  $5 · 10 = 50$  bits.
  • The RLC data compression is thus not much worse than the theoretical limit that results according to the source entropy to  $H · N ≈ 47$  bits.
  • The direct application of entropy coding would not result in any data compression here; rather, one continues to need  $100$  bits.
  • Even with the formation of triples,  $54$  bits would still be needed with Huffman, i.e. more than with run-length coding.


However, the example also shows two problems of run-length coding:

  • The lengths  $L_i$  of the substrings are not limited.  Special measures must be taken here if a length  $L_i$  is greater than  $2^5 = 32$  $($valid for  $N_{\rm Bit} = 5)$,
    for example the variant  »Run–Length Limited Coding«  $\rm (RLLC)$.  See also  [Meck09][2]  and  "Exercise 2.13".
  • If the sequence does not end with  $\rm B$  – which is rather the normal case with small probability  $p_{\rm B}$  one must also provide special treatment for the end of the file.


Burrows–Wheeler transformation


To conclude this source coding chapter, we briefly discuss the algorithm published in 1994 by  $\text{Michael Burrows}$  and  $\text{David J. Wheeler}$  [BW94][3],

Example of the BWT (forward transformation)
  • which, although it has no compression potential on its own,
  • but it greatly improves the compression capability of other methods.



The Burrows–Wheeler Transformation accomplishes a blockwise sorting of data, which is illustrated in the diagram using the example of the text  $\text{ANNAS_ANANAS}$  (meaning:  Anna's pineapple)  of length  $N = 12$:

  • First, an  $N×N$ matrix is generated from the string of length  $N$  with each row resulting from the preceding row by cyclic left shift.
  • Then the BWT matrix is sorted lexicographically.  The result of the transformation is the last column  ⇒   $\text{L–column}$.  In the example, this results in  $\text{_NSNNAANAAAS}$.
  • Furthermore, the primary index  $I$  must also be passed on. This value indicates the row of the sorted BWT matrix that contains the original text  (marked red in the graphic).
  • Of course, no matrix operations are necessary to determine the  $\text{L–column}$  and the primary index.  Rather, the BWT result can be found very quickly with pointer technology.


$\text{Furthermore, it should be noted about the BWT procedure:}$ 

  • Without an additional measure   ⇒   a downstream "real compression" – the BWT does not lead to any data compression.  
  • Rather, there is even a slight increase in the amount of data, since in addition to the  $N$  characters, the primary index  $I$  now also be transmitted.
  • For longer texts,  however,  this effect is negligible.  Assuming 8 bit–ASCII–characters  (one byte each)  and the block length  $N = 256$  the number of bytes per block only increases from  $256$  to  $257$, i.e. by only  $0.4\%$.


We refer to the detailed descriptions of BWT in  [Abel04][4].

Example for BWT (reverse transformation)

Finally, we will show how the original text can be reconstructed from the  $\text{L}$–column  (from  "Last")  of the BWT matrix.

  • For this, one still needs the primary index $I$, as well as the first column of the BWT matrix.
  • This  $\text{F}$–column  (from  "First")  does not have to be transferred, but results from the  $\text{L}$–column very simply through lexicographic sorting.


The graphic shows the reconstruction procedure for the example under consideration:

  • One starts in the line with the primary index  $I$.  The first character to be output is the  $\rm A$  marked in red in the  $\text{F}$–column.  This step is marked in the graphic with a yellow (1).
  • This  $\rm A$  is the third  $\rm A$ character in the  $\text{F}$–column.  Now look for the third  $\rm A$  in the  $\text{L}$–column,  find it in the line marked with  (2)  and output the corresponding  N  of the  $\text{F}$–column.
  • The last  N  of the  $\text{L}$–column is found in line  (3).  The character of the F column is output in the same line, i.e. an  N again.


After  $N = 12$  decoding steps, the reconstruction is completed.

$\text{Conclusion:}$ 

  • This example has shown that the  Burrows–Wheeler transformation is nothing more than a sorting algorithm for texts.  What is special about it is that the sorting is uniquely reversible.
  • This property and additionally its inner structure are the basis for compressing the BWT result by means of known and efficient methods such as  $\text{Huffman}$  (a form of entropy coding) and  $\text{run–length coding}$.


Application scenario for the Burrows-Wheeler transformation


As an example for embedding the  $\text{Burrows–Wheeler Transformation}$  (BWT) into a chain of source coding methods, we choose a structure proposed in  [Abel03][5].  We use the same text example  $\text{ANNAS_ANANAS}$  as in the last section.  The corresponding strings after each block are also given in the graphic.

Scheme for Burrows-Wheeler data compression
  • The  $\rm BWT$  result is:     $\text{_NSNNAANAAAS}$.  BWT has not changed anything about the text length  $N = 12$  but there are now four characters that are identical to their predecessors  (highlighted in red in the graphic).  In the original text, this was only the case once.
  • In the next block  $\rm MTF$  ("Move–To–Front") , each input character from the set  $\{$ $\rm A$,  $\rm N$,  $\rm S$,  _$\}$  becomes an index  $I ∈ \{0, 1, 2, 3\}$.  However,  this is not a simple mapping, but an algorithm given in  "Exercise 1.13Z".
  • For our example, the MTF output sequence is  $323303011002$, also with length  $N = 12$.  The four zeros in the MTF sequence  (also in red font in the diagram)  indicate that at each of these positions the BWT character is the same as its predecessor.
  • In large ASCII files, the frequency of the  $0$  may well be more than  $50\%$,  while the other  $255$  indices occur only rarely.  Run-length coding  $\rm (RCL)$  is an excellent way to compress such a text structure.
  • The block  $\rm RCL0$  in the above coding chain denotes a special  $\text{run-length coding}$  for zeros.  The gray shading of the zeros indicates that a long zero sequence has been masked by a specific bit sequence   (shorter than the zero sequence).
  • The entropy encoder  $\rm (EC$, for example "Huffman"$)$  provides further compression.  BWT  and  MTF  only have the task in the coding chain of increasing the efficiency of  "RLC0"  and  "EC"  through character preprocessing.  The output file is again binary.


Exercises for the chapter


Exercise 2.10: Shannon-Fano Coding

Exercise 2.11: Arithmetic Coding

Exercise 2.11Z: Arithmetic Coding once again

Exercise 2.12: Run–Length Coding and Run–Length Limited Coding

Exercise 2.13: Inverse Burrows-Wheeler Transformation

Exercise 2.13Z: Combination of BWT and MTF

References

  1. Bodden, E.; Clasen, M.; Kneis, J.:  Algebraische Kodierung.  Algebraic Coding. Proseminar, Chair of Computer Science IV, RWTH Aachen University, 2002.
  2. Mecking, M.: Information Theory.  Lecture manuscript, Chair of Communications Engineering, Technical University of Munich, 2009.
  3. Burrows, M.; Wheeler, D.J.:  A Block-sorting Lossless Data Compression Algorithm.  Technical Report. Digital Equipment Corp. Communications, Palo Alto, 1994.
  4. Abel, J.:  Grundlagen des Burrows-Wheeler-Kompressionsalgorithmus.  In: Informatik Forschung & Entwicklung, no. 2, vol. 18, S. 80-87, Jan. 2004
  5. Abel, J.:  Verlustlose Datenkompression auf Grundlage der Burrows-Wheeler-Transformation. 
    In: PIK - Praxis der Informationsverarbeitung und Kommunikation, no. 3, vol. 26, pp. 140-144, Sept. 2003.