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

From LNTwww
 
(93 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 
   
 
   
 
{{Header
 
{{Header
|Untermenü=Quellencodierung – Datenkomprimierung
+
|Untermenü=Source coding - Data compression
|Vorherige Seite=Entropiecodierung nach Huffman
+
|Vorherige Seite=Entropy Coding According to Huffman
|Nächste Seite=Einige Vorbemerkungen zu zweidimensionalen Zufallsgrößen
+
|Nächste Seite=Some_Preliminary_Remarks_on_Two-Dimensional_Random_Variables
 
}}
 
}}
  
  
==Der Shannon–Fano–Algorithmus==  
+
==The Shannon-Fano algorithm==  
 
+
<br>
Die Huffman–Codierung aus dem Jahr 1952 ist ein Sonderfall der '''Entropiecodierung'''. Dabei wird versucht, das Quellensymbol $q_μ$ durch ein Codesymbol $c_μ$ der Länge $L_μ$ darzustellen, wobei folgende Konstruktionsvorschrift angestrebt wird:
+
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}({1}/{p_{\mu}})  
+
:$$L_{\mu} \approx  -{\rm log}_2\hspace{0.15cm}(p_{\mu})  
 
\hspace{0.05cm}.$$
 
\hspace{0.05cm}.$$
  
Da $L_μ$ im Gegensatz zu log2(1/ $p_μ$) ganzzahlig ist, gelingt dies nicht immer.
+
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.
Bereits drei Jahre vor David A. Huffman haben [https://de.wikipedia.org/wiki/Claude_Shannon Claude E. Shannon] und [https://de.wikipedia.org/wiki/Robert_Fano Robert Fano] einen ähnlichen Algorithmus angegeben, nämlich:
 
#Man ordne die Quellensymbole nach fallenden Auftrittswahrscheinlichkeiten (identisch mit Huffman).
 
#Man teile die sortierten Zeichen in zwei möglichst gleichwahrscheinliche Gruppen.
 
#Der ersten Gruppe wird das Binärsymbol '''1''' zugeordnet, der zweiten die '''0''' (oder umgekehrt).
 
#Sind in einer Gruppe mehr als ein Zeichen, so ist auf diese der Algorithmus rekursiv anzuwenden.
 
  
 +
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 symbol probabilities (identical to Huffman).
 +
:# &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; If there is more than one character in a group, the algorithm is to be applied recursively to this group.
  
{{Beispiel}}
+
{{GraueBox|TEXT=
Wir gehen wie im Einführungsbeispiel für den Huffman–Algorithmus zu Beginn von Kapitel 2.3 von $M$ = 6 Symbolen und den 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}
 
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  
 
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}.$$
 
\hspace{0.05cm}.$$
  
Dann lautet der Shannon–Fano–Algorithmus:
+
Then the Shannon-Fano algorithm is:
# '''AB → 1'''x (Wahrscheinlichkeit 0.54), '''CDEF → 0'''x (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),
# '''<u>A → 11</u>''',   '''<u>B ⇒ 10</u>''',
+
:# &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),
# '''<u>C → 01</u>''', (Wahrscheinlichkeit 0.20),   '''DEF → 00'''x, (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),
# '''<u>D → D</u>''', (Wahrscheinlichkeit 0.12),   '''EF → 000'''x (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),
# '''<u>E → 0001</u>''',   '''<u>F → 0000</u>'''.
+
:# &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).
  
 
+
''Notes'':  
''Anmerkung'': Ein „x” weist wieder darauf hin, dass in nachfolgenden Codierschritten noch Bits 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 [[Informationstheorie/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}.$$}}
  
{{end}}
 
  
 +
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.
  
 +
However, there are definitely cases where the two methods differ in terms of (mean) code word length, as the following example shows.
  
Mit den Wahrscheinlichkeiten entsprechend dem Beispiel 1 (im letztem Abschnitt) der Shannon–Fano–Algorithmus zur gleichen mittleren Codewortlänge wie die Huffman–Codierung. Ebenso sind bei vielen (eigentlich: den meisten) anderen Wahrscheinlichkeitsprofilen Huffman und Shannon–Fano aus informationstheoretischer Sicht äquivalent. Es gibt aber durchaus Fälle, bei denen sich beide Verfahren hinsichtlich der (mittleren) Codewortlänge unterscheiden, wie das folgende Beispiel zeigt.
+
{{GraueBox|TEXT=
 +
$\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 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}. $$
  
 +
[[File:EN_Inf_T_2_4_S1_v2.png|right|frame|Tree structures according to Shannon-Fano and Huffman]]
  
{{Beispiel}}
+
The diagram shows the respective code trees for Shannon-Fano (left) and Huffman (right).&nbsp; The results can be summarized as follows:
Wir betrachten $M$ = 5 Symbole mit folgenden Wahrscheinlichkeiten:
+
* 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;
$$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}
+
:and thus to the mean code word length
p_{\rm D}= 0.15 \hspace{0.05cm}, \hspace{0.2cm}p_{\rm E}= 0.13$$
+
 +
:$$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}.$$
  
$$\Rightarrow\hspace{0.3cm} H = 2.19\,{\rm bit/Quellensymbol}
+
*Using "Huffman", we get&nbsp;
\hspace{0.05cm}. $$
+
:&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  $$
 +
:$$\Rightarrow\hspace{0.3cm} L_{\rm M} = 2.24\,\,{\rm bit/source\hspace{0.15cm} symbol}\hspace{0.05cm}. $$
  
[[File:P_ID2461__Inf_T_2_4_S1_ganz_neu.png|Baumstrukturen nach Shannon–Fano bzw. Huffman]]
+
*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.
 +
*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).}}
  
Die Grafik zeigt die jeweiligen Codebäume für Shannon–Fano (links) bzw. Huffman (rechts). Die Ergebnisse lassen sich wie folgt zusammenfassen:
 
* Der '''Shannon–Fano–Algorithmus''' führt zum Code '''A → 11''', '''B → 10''', '''C → 01''', '''D → 001''', '''E → 000''' und damit zur mittleren Codewortlänge
 
 
$$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}.$$
 
  
*Mit dem '''Huffman–Algorithmus''' erhält man '''A → 1''', '''B → 001''', '''C → 010''', '''D → 001''' sowie '''E → 000''' und eine etwas kleinere mittlere Codewortlänge:
+
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.
 
$$L_{\rm M} = 0.38 \cdot 1 + (1-0.38) \cdot 3 = 2.24\,\,{\rm bit/Quellensymbol}\hspace{0.05cm}. $$
 
  
*Es gibt keinen Satz von Wahrscheinlichkeiten, bei denen Shannon–Fano ein besseres Ergebnis liefert als der Huffman–Algorithmus, der den bestmöglichen Entropiecodierer bereitstellt.
 
*Die Grafik zeigt zudem, dass die Algorithmen im Baumdiagramm in unterschiedlichen Richtungen vorgehen, nämlich einmal von der Wurzel zu den Einzelsymbolen (Shannon–Fano), zum anderen von den Einzelsymbolen zur Wurzel (Huffman).
 
  
{{end}}
 
  
 +
==Arithmetic coding ==
 +
<br>
 +
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$.
  
==Arithmetische Codierung ==
+
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$.
  
Eine weitere Form der Entropiecodierung ist die arithmetische Codierung. Auch bei dieser müssen die Symbolwahrscheinlichkeiten $p_μ$ bekannt sein. Für den Index gelte weiter $μ$ = 1, ... , $M$.
 
Hier nun ein kurzer Abriss über die Vorgehensweise:
 
*Im Gegensatz zur Huffman– und Shannon–Fano–Codierung wird bei arithmetischer Codierung eine Symbolfolge der Länge N gemeinsam codiert. Wir schreiben abkürzend $Q = 〈q_1, q_2, ... , q_N〉$.
 
*Jeder solchen Symbolfolge $Q_i$ wird ein reelles Zahlenintervall $I_i$ zugewiesen, das durch den Beginn $B_i$ und die Intervallbreite $Δ_i$ gekennzeichnet ist.
 
*Der „Code” für die gesamte Folge $Q_i$ ist die Binärdarstellung eines reellen Zahlenwertes aus diesem Intervall: $r_i ∈ I_i = [B_i, B_i + Δ_i)$. Diese Notation besagt, dass zwar $B_i$ zum Intervall $I_i$ gehört (eckige Klammer), aber $B_i + Δ_i$ gerade nicht mehr (runde Klammer).
 
*Es gilt stets 0 ≤ $r_i$ < 1. Sinnvollerweise wählt man $r_i$ aus dem Intervall $I_i$ derart, dass der Wert mit möglichst wenigen Bits darstellbar ist. Es gibt aber eine Mindestbitanzahl, die von der Intervallbreite $Δ_i$ abhängt.
 
  
 +
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.
 +
*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"]].
  
Der Algorithmus zur Bestimmung der Intervallparameter $B_i$ und $Δ_i$ wird auf der nächsten Seite an einem Beispiel erläutert, ebenso eine Decodiermöglichkeit. Zunächst folgt ein kurzes Beispiel zur Auswahl der reellen Zahl $r_i$ in Hinblick auf minimale Bitanzahl. Genauere Informationen hierzu finden Sie zum Beispiel in <ref> Bodden, E.; Clasen, M.; Kneis, J.: ''Algebraische Kodierung''. Proseminar, Lehrstuhl für Informatik IV, RWTH Aachen, 2002.</ref> und bei der Beschreibung zur Aufgabe A1.12.
 
  
{{Beispiel}}
+
{{GraueBox|TEXT=
Für folgende Parameter des arithmetischen Codieralgorithmus ergeben sich folgende reelle Ergebnisse $r_i$ und folgende Codes, die zum zugehörigen Intervall $I_i$ 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, Δ_i = 0.10  ⇒  I_i = [0.25, 0.35):$
+
* $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}
+
:$$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  
+
{\rm Code} \hspace{0.15cm} \boldsymbol{\rm 01} \in I_i  
 
\hspace{0.05cm},$$  
 
\hspace{0.05cm},$$  
  
* $B_i = 0.65, Δ_i = 0.10 ⇒  I_i = [0.65, 0.75);$ zu beachten: 0.75 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}
 
{\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
 
 
   
 
   
$$N_{\rm Bit} = \left\lceil {\rm log}_2 \hspace{0.15cm} ({1}/{\it \Delta_i})\right\rceil+1\hspace{0.05cm}. $$
+
:$$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}. $$
  
Mit der Intervallbreite $Δ_i$ = 0.10 ergibt sich $N_{\rm Bit}$ = 5. Die tatsächlichen arithmetischen Codes wären also '''01000''' bzw. '''10110'''.
+
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}. $  
 +
*With the interval width&nbsp; ${\it Δ}_i = 0.10$&nbsp; results&nbsp; $N_{\rm Bit} = 5$.  
 +
*So the actual arithmetic codes would be &nbsp; '''01000''' &nbsp; and &nbsp; '''10110''' respectively.}}
  
{{end}}
 
  
 +
{{GraueBox|TEXT=
 +
$\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$:
 +
*The character sequence&nbsp; $\rm XXYXZ$ &nbsp;  ⇒ &nbsp;  length of the source symbol sequence: &nbsp; $N = 5$.
 +
*Assume the probabilities&nbsp; $p_{\rm X} = 0.6$,&nbsp; $p_{\rm Y} = 0.2$&nbsp; and&nbsp; $p_{\rm Z} = 0.2$.
  
Die Aussagen der letzten Seite sollen nun an einem weiteren Beispiel verdeutlicht werden. Im Folgenden sei der Symbolumfang $M$ = 3. Um Verwechslungen zu vermeiden, nennen wir die Symbole '''X''', '''Y''' und '''Z''':
+
[[File:EN_Inf_T_2_4_S2.png|right|frame|About the arithmetic coding algorithm]]
*Übertragen werden soll die Zeichenfolge '''XXYXZ'''  ⇒  Folgenlänge $N$ = 5.
 
*Auszugehen ist von den Wahrscheinlichkeiten $p_X$ = 0.6, $p_Y$ = 0.2, $p_Z$ = 0.2.
 
  
[[File:P_ID2467__Inf_T_2_4_S2_neu.png|Zum arithmetischen Codieralgorithmus]]
 
  
Die Grafik zeigt den Algorithmus zur Bestimmung der Intervallgrenzen.
+
The diagram on the right shows the algorithm for determining the interval boundaries.
*Man teilt zunächst den gesamten Wahrscheinlichkeitsbereich (zwischen 0 und 1) gemäß den Symbolwahrscheinlichkeiten $p_X$, $p_Y$ und $p_Z$ in drei Bereiche mit den Grenzen $B_0$, $C_0$, $D_0$ und $E_0$.
+
*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$.
*Das erste Symbol ist '''X'''. Deshalb wird im nächsten Schritt der Wahrscheinlichkeitsbereich von $B_1$ = $B_0$ = 0 bis $E_1$ = $C_0$ = 0.6 wiederum im Verhältnis 0.6 : 0.2 : 0.2 aufgeteilt.
+
*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$.
*Nach dem zweiten Symbol '''X''' liegen die Bereichsgrenzen bei $B_2$ = 0, $C_2$ = 0.216, $D_2$ = 0.288 und $E_2$ = 0.36. Da nun das Symbol '''Y''' ansteht, erfolgt die Unterteilung des Bereiches 0.216 ... 0.288.
+
*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$.
*Nach dem fünften Symbol '''Z''' liegt das Intervall $I_i$ für die betrachtete Symbolfolge $Q_i$ = '''XXYXZ''' fest. Es muss nun eine reelle Zahl $r_i$ gefunden werden, für die gilt: 0.25056 ≤ $r_i$ < 0.2592.
+
*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$.
*Die einzige reelle Zahl im Intervall $I_i$ = [0.25056, 0.2592), die man mit 7 Bit darstellen kann, ist $r_i = 1 · 2^{–2} + 1 · 2^{–7} = 0.2578125$. Damit liegt die Coderausgabe fest: '''0100001'''.
+
*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 $N$ = 5 Symbole werden also 7 Bit benötigt, genau so viele wie bei Huffman–Codierung mit der Zuordnung '''X → 1''', '''Y → 00''', '''Z → 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.
+
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'''.  
Oft wird aber die Intervallmitte im Beispiel 0.25488 – binär dargestellt: 0.01000010011 .... Die Bitanzahl erhält man daraus mit $Δ_5$ = 0.2592 - 0.25056 = 0.00864 wie folgt:
+
*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:
 
   
 
   
$$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} =
 
\left\lceil  {\rm log}_2 \hspace{0.15cm} 115.7 \right\rceil + 1 = 8
 
\left\lceil  {\rm log}_2 \hspace{0.15cm} 115.7 \right\rceil + 1 = 8
 
\hspace{0.05cm}.$$
 
\hspace{0.05cm}.$$
  
Damit lautet der arithmetische Code für dieses Beispiel mit $N$ = 5 Eingangszeichen: '''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. Dieser liegt im ersten und zweiten Schritt jeweils im ersten Bereich Symbol '''X''', im dritten Schritt in zweiten Bereich Symbol '''Y''', usw.
+
 
Weitere Informationen zu diesem Thema finden Sie in [https://de.wikipedia.org/wiki/Arithmetisches_Kodieren WIKIPEDIA ]sowie in <ref>Bodden, E.; Clasen, M.; Kneis, J.: ''Algebraische Kodierung''.  
+
*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$ .  
Proseminar, Lehrstuhl für Informatik IV, RWTH Aachen, 2002.</ref>.
+
*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.
 +
 
 +
 
 +
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>
 +
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}$.
 +
 
 +
*Entropy coding only makes sense here when applied to&nbsp; $k$–tuples.
 +
*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=
 +
$\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.
  
Wir betrachten eine Binärquelle $(M = 2)$ mit dem Symbolvorrat {'''A''', '''B'''}, wobei ein Symbol sehr viel häufiger auftritt als das andere. Beispielsweise sei $p_A$ sehr viel größer als $p_B$.
 
  
Eine Entropiecodierung macht hier nur dann Sinn, wenn man diese auf k–Tupel anwendet. Eine zweite Möglichkeit bietet die '''Lauflängencodierung''' (englisch: ''Run–Length Coding'', RLC), die das seltenere Zeichen '''B''' als Trennzeichen betrachtet und die Längen $L_i$ der einzelnen Substrings als Ergebnis liefert.
+
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>
 +
You can see from this example:
 +
*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 $.
 +
*If one represents the lengths&nbsp; $L_1$, ... , $L_{10}$&nbsp; with five bits each, one thus requires&nbsp; $5 · 10 = 50$&nbsp; bits.
 +
*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.
 +
*The direct application of entropy coding would not result in any data compression here; rather, one continues to need&nbsp; $100$&nbsp; bits.
 +
*Even with the formation of triples,&nbsp; $54$&nbsp; bits would still be needed with Huffman, i.e. more than with run-length coding.}}
  
  
{{Beispiel}}
+
However, the example also shows two problems of run-length coding:
Die Grafik zeigt eine beispielhafte Binärfolge mit den Wahrscheinlichkeiten $p_A$ = 0.9 und $p_B$ = 0.1, woraus sich die Quellenentropie $H$ = 0.469 bit/Quellensymbol ergibt. Die Beispielfolge der Länge $N$ = 100 beinhaltet genau zehnmal das Symbol '''B''' und neunzigmal das Symbol '''A''', das heißt, die relativen Häufigkeiten stimmen exakt mit den Wahrscheinlichkeiten überein.
+
*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"]].
 +
*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.
 +
  
[[File:P_ID2470__Inf_T_2_4_S4_neu.png|Zur Verdeutlichung der Lauflängencodierung]]
+
==Burrows–Wheeler transformation== 
 +
<br>
 +
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>,
 +
[[File:EN_Inf_T_2_4_S3_vers2.png|frame|Example of the BWT (forward transformation)]]
  
Man erkennt an diesem Beispiel:
+
*which, although it has no compression potential on its own,
*Die Binärfolge hat die Länge $N$ = 100. Die Lauflängencodierung dieser Folge ergibt in Dezimalschreibweise die Folge 6, 14, 26, 11, 4, 10, 3, 9, 1, 16.
+
*but it greatly improves the compression capability of other methods.
*Stellt man die Längen $L_1$, ... , $L_{10}$ mit jeweils 5 Bit dar, so benötigt man 5 · 10 = 50 Bit. Die Datenkomprimierung ist nicht viel schlechter als der theoretische Grenzwert, der sich durch die Quellenentropie $H$ ergibt ($H · N$ ≈ 47 Bit).
 
*Die direkte Anwendung einer Entropiecodierung – zum Beispiel nach Huffman – hätte hier keine Datenkomprimierung zur Folge; man benötigt weiterhin 100 Bit. Auch bei der Bildung von Dreiertupeln würde man mit Huffman noch mehr Bit benötigen als durch RLC, nämlich 54 Bit.
 
  
{{end}}
 
  
Das Beispiel zeigt aber auch zwei Probleme der Lauflängencodierung:
+
<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$:
*Die Längen $L_i$ der Substrings sind nicht begrenzt. Hier muss man besondere Maßnahmen treffen, wenn eine Länge $L_i$ größer ist als $2^5 = 32$ (falls $N_{Bit}$ = 5), zum Beispiel die Variante ''Run–Length Limited Coding'' (RLLC). Siehe auch <ref>Mecking, M.: Information Theory. ''Vorlesungsmanuskript, Lehrstuhl für Nachrichtentechnik'', Technische Universität München, 2009.</ref> und [[Aufgaben:2.13_Run–Length_Coding_und_RLLC|Aufgabe A2.13]].
+
 
*Endet die Folge nicht mit einem '''B''' – was bei kleiner Wahrscheinlichkeit $p_B$ eher der Normalfall ist, so muss auch für das Dateiende eine Sonderbehandlung vorgesehen werden.
+
*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.
+
*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>
 +
{{BlaueBox|TEXT=
 +
$\text{Furthermore, it should be noted about the BWT procedure:}$&nbsp;
 +
 
 +
*Without an additional measure  &nbsp;  ⇒  &nbsp;  a downstream "real compression" – the BWT does not lead to any data compression. &nbsp;
 +
*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.
 +
*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\%$.}}
  
==Burrows–Wheeler–Transformation== 
 
  
Zum Abschluss dieses Quellencodier–Kapitels behandeln wir noch kurz den 1994 von Michael Burrows und [https://de.wikipedia.org/wiki/David_Wheeler David J. Wheeler] veröffentlichten Algorithmus <ref>Burrows, M.; Wheeler, D.J.: ''A Block-sorting Lossless Data Compression Algorithm.'' Technical Report. Digital Equipment Corporation Communications, Palo Alto, 1994.</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>.
*der zwar alleine keinerlei Komprimierungspotenzial besitzt,
 
*aber die Komprimierungsfähigkeit anderer Verfahren stark verbessert.
 
  
Die Burrows–Wheeler–Transformation bewerkstelligt eine blockweise Sortierung von Daten, die in der folgenden Grafik am Beispiel des Textes '''ANNAS_ANANAS''' der Länge $N$ = 12 verdeutlicht werden:
+
[[File:EN_Inf_T_2_4_S3b.png|frame|Example for BWT (reverse transformation)]]
  
[[File:P_ID2475__Inf_T_2_4_S3_neu.png|Beispiel zur BWT (Hintransformation)]]
+
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.
  
*Zunächst wird aus dem String der Länge $N$ eine $N×N$–Matrix erzeugt, wobei sich jede Zeile aus der Vorgängerzeile durch zyklische Linksverschiebung ergibt.
 
*Danach wird die BWT–Matrix lexikografisch sortiert. Das Ergebnis der Transformation ist die letzte Spalte  ⇒  L–Spalte. Im Beispiel ergibt sich der String _'''NSNNAANAAAS'''.
 
*Des Weiteren muss auch der Primärindex I weitergegeben werden. Dieser gibt die Zeile der sortierten BWT–Matrix an, die den Originaltext enthält (in der Grafik rot markiert).
 
  
Zur Bestimmung von L–Spalte und Primärindex $I$ sind natürlich keine Matrixoperationen erforderlich. Vielmehr findet man das BWT–Ergebnis mit Zeigertechnik sehr schnell.
+
The graphic shows the  reconstruction procedure for the example under consideration:
Außerdem ist zum BWT–Verfahren noch anzumerken:
+
*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).
*Ohne Zusatzmaßnahme  ⇒  eine nachgeschaltete „echte Kompression” – führt die BWT zu keiner Datenkomprimierung: Vielmehr ergibt sich sogar eine geringfügige Erhöhung der Datenmenge, da außer den $N$ Zeichen nun auch der Primärindex $I$ übermittelt werden muss.
+
*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.
*Bei längeren Texten ist dieser Effekt aber vernachlässigbar. Geht man von 8 Bit–ASCII–Zeichen (jeweils ein Byte) und der Blocklänge $N$ = 256 aus, so erhöht sich die Byte–Anzahl pro Block nur von 256 auf 257, also lediglich um 0.4%.
+
*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.
  
Wir verweisen auf die ausführlichen Beschreibungen zur BWT in <ref>Abel, J.: ''Grundlagen des Burrows-Wheeler-Kompressionsalgorithmus''. PDF–Internetdokument</ref>.
 
  
 +
After&nbsp;  $N = 12$&nbsp;  decoding steps, the reconstruction is completed.
 +
<br clear=all>
 +
{{BlaueBox|TEXT=
 +
$\text{Conclusion:}$&nbsp;
 +
*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.
 
   
 
   
Abschließend soll noch dargestellt werden, wie der Ursprungstext aus der L–Spalte der BWT–Matrix rekonstruiert werden kann. Dazu benötigt man noch den Primärindex $I$, sowie die erste Spalte der BWT–Matrix. Diese F–Spalte (von „First”) muss nicht übertragen werden, sondern ergibt sich aus der L–Spalte sehr einfach durch lexikografische Sortierung.
+
*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}$]].}}
  
[[File: P_ID2476__Inf_T_2_4_S3b_neu.png|Beispiel zur BWT (Rücktransformation)]]
 
  
Die Grafik zeigt die Vorgehensweise für das betrachtete Beispiel:
+
==Application scenario for the Burrows-Wheeler transformation== 
*Man beginnt in der Zeile mit dem Primärindex $I$. Als erstes Zeichen wird das rot markierte '''A''' in der F–Spalte ausgegeben. Dieser Schritt ist in der Grafik mit einer gelben (1) gekennzeichnet.
+
<br>
*Dieses '''A''' ist das dritte '''A'''–Zeichen in der F–Spalte. Man sucht nun das dritte '''A''' in der L–Spalte, findet dieses in der mit (2) markierten Zeile und gibt das zugehörige '''N''' der F–Spalte aus.
+
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.
*Das letzte '''N''' der L–Spalte findet man in der mit (3) gekennzeichneten Zeile. Ausgegeben wird das Zeichen der F–Spalte in der gleichen Zeile, also wieder ein '''N''':
 
  
Nach $N$ = 12 Decodierschritten ist die Rekonstruktion abgeschlossen. Dieses Beispiel hat gezeigt, dass die BWT nichts anderes ist als ein Sortieralgorithmus für Texte.
+
[[File:EN_Inf_T_2_4_S5_v2.png|center|frame|Scheme for Burrows-Wheeler data compression]]
Das Besondere daran ist, dass die Sortierung eindeutig umkehrbar ist. Diese Eigenschaft und zusätzlich seine innere Struktur sind die Grundlage dafür, dass man das BWT–Ergebnis mittels bekannter und effizienter Verfahren wie Huffman (eine Form der Entropiecodierung) und [[Informationstheorie/Weitere_Quellencodierverfahren#Laufl.C3.A4ngencodierung_.E2.80.93_Run.E2.80.93Length_Coding|RLC ]](''Run–Length Coding'') komprimieren kann.
 
  
 +
*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.
 +
*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"]].
 +
*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.
 +
*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.
 +
*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).
 +
*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.
  
==Anwendungsszenario für BWT== 
 
  
Als Beispiel für die Einbettung der [[Informationstheorie/Weitere_Quellencodierverfahren#Burrows.E2.80.93Wheeler.E2.80.93Transformation|Burrows–Wheeler–Transformation]] (BWT) in eine Kette von Quellencodierverfahren wählen wir eine in <ref>Abel, J.: ''Verlustlose Datenkompression auf Grundlage der Burrows-Wheeler-Transformation.''
+
==Exercises for the chapter  ==
PDF–Internetdokument</ref> vorgeschlagene Struktur:
+
<br>
 +
[[Aufgaben:Exercise_2.10:_Shannon-Fano_Coding|Exercise 2.10: Shannon-Fano Coding]]
  
[[File:P_ID2477__Inf_T_2_4_S5_neu.png|Schema für die Burrows–Wheeler–Datenkompression]]
+
[[Aufgaben:Exercise_2.11:_Arithmetic_Coding|Exercise 2.11: Arithmetic Coding]]
  
Wir verwenden dabei das gleiche Textbeispiel '''ANNAS_ANANAS''' wie auf der letzten Seite. Die entsprechenden Strings nach den einzelnen Blöcken sind in der Grafik ebenfalls angegeben.
+
[[Aufgaben:Exercise_2.11Z:_Arithmetic_Coding_once_again|Exercise 2.11Z: Arithmetic Coding once again]]
*Das Ergebnis der '''BWT''' lautet: '''_NSNNAANAAAS'''. An der Textlänge $N$ = 12 hat die BWT nichts verändert, doch gibt es jetzt vier Zeichen, die identisch mit ihren Vorgängerzeichen sind (in der Grafik rot hervorgehoben). Im Originaltext war dies nur einmal der Fall.
 
*Im nächsten Block '''MTF''' (''Move–To–Front'') wird aus jedem Eingangszeichen aus der Menge {'''A, N, S, _'''} ein Index $I$ ∈ {'''0, 1, 2, 3'''}. Es handelt sich hierbei aber nicht um ein einfaches Mapping, sondern um einen Algorithmus, der in [[Aufgaben:2.14Z_Kombination_BWT_%26_MTF|Aufgabe Z1.14]] angegeben ist.
 
*Für unser Beispiel lautet die MTF–Ausgangsfolge '''323303011002''', ebenfalls mit der Länge $N$ = 12. 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.
 
*Bei großen ASCII–Dateien kann die Häufigkeit der '''0''' durchaus >50% betragen, während die anderen 255 Indizes nur selten auftreten. Zur Komprimierung einer solchen Textstruktur eignet sich eine Lauflängencodierung (englisch: ''Run–Length Coding'', RLC) hervorragend.
 
*Der Block '''RLC0''' in obiger Codierungskette bezeichnet eine spezielle [[Informationstheorie/Weitere_Quellencodierverfahren#Laufl.C3.A4ngencodierung_.E2.80.93_Run.E2.80.93Length_Coding|Lauflängencodierung]] für Nullen. Die graue Schattierung der Nullen soll andeuten, dass hier eine lange Nullsequenz durch eine spezifische Bitfolge (kürzer als die Nullsequenz) maskiert wurde.
 
*Der Entropiecodierer ( '''EC''', z.B. Huffman ) sorgt für eine weitere Komprimierung. BWT und MTF haben in der Codierungskette nur die Aufgabe, durch eine Zeichenvorverarbeitung die Effizienz von RLC0 und EC zu steigern. Die Ausgangsdatei ist wieder binär.
 
  
 +
[[Exercise_2.12:_Run–Length_Coding_and_Run–Length_Limited_Coding|Exercise 2.12: Run–Length Coding and Run–Length Limited Coding]]
  
==Quellenverzeichnis==
+
[[Aufgaben:Exercise_2.13:_Inverse_Burrows-Wheeler_Transformation|Exercise 2.13: Inverse Burrows-Wheeler Transformation]]
 +
 
 +
[[Exercise_2.13Z:_Combination_of_BWT_and_MTF|Exercise 2.13Z: Combination of BWT and MTF]]
 +
 
 +
==References==
 
<references />
 
<references />
 
==Aufgaben zu Kapitel 2.4 ==
 
  
  
 
{{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.