Data Compression Techniques

Similar documents
Data Compression Techniques

ASYMMETRIC NUMERAL SYSTEMS: ADDING FRACTIONAL BITS TO HUFFMAN CODER

Chapter 2 Date Compression: Source Coding. 2.1 An Introduction to Source Coding 2.2 Optimal Source Codes 2.3 Huffman Code

CSEP 590 Data Compression Autumn Arithmetic Coding

Bandwidth: Communicate large complex & highly detailed 3D models through lowbandwidth connection (e.g. VRML over the Internet)

SIGNAL COMPRESSION Lecture Shannon-Fano-Elias Codes and Arithmetic Coding

Chapter 3 Source Coding. 3.1 An Introduction to Source Coding 3.2 Optimal Source Codes 3.3 Shannon-Fano Code 3.4 Huffman Code

Entropy as a measure of surprise

Lecture 16. Error-free variable length schemes (contd.): Shannon-Fano-Elias code, Huffman code

Run-length & Entropy Coding. Redundancy Removal. Sampling. Quantization. Perform inverse operations at the receiver EEE

Basic Principles of Lossless Coding. Universal Lossless coding. Lempel-Ziv Coding. 2. Exploit dependences between successive symbols.

Multimedia Communications. Mathematical Preliminaries for Lossless Compression

Motivation for Arithmetic Coding

3F1 Information Theory, Lecture 3

Lecture 4 : Adaptive source coding algorithms

Shannon-Fano-Elias coding

EE376A: Homework #3 Due by 11:59pm Saturday, February 10th, 2018

1 Introduction to information theory

Generalized Kraft Inequality and Arithmetic Coding

3F1 Information Theory, Lecture 3

Lecture 1 : Data Compression and Entropy

Data Compression Techniques (Spring 2012) Model Solutions for Exercise 2

UNIT I INFORMATION THEORY. I k log 2

SIGNAL COMPRESSION Lecture 7. Variable to Fix Encoding

Lecture 12: November 6, 2017

Summary of Last Lectures

Source Coding Techniques

Source Coding. Master Universitario en Ingeniería de Telecomunicación. I. Santamaría Universidad de Cantabria

Chapter 2: Source coding

Chapter 5: Data Compression

ECE Advanced Communication Theory, Spring 2009 Homework #1 (INCOMPLETE)

EECS 229A Spring 2007 * * (a) By stationarity and the chain rule for entropy, we have

An instantaneous code (prefix code, tree code) with the codeword lengths l 1,..., l N exists if and only if. 2 l i. i=1

Exercise 1. = P(y a 1)P(a 1 )

10-704: Information Processing and Learning Fall Lecture 9: Sept 28

Sample solutions to Homework 4, Information-Theoretic Modeling (Fall 2014)

CSCI 2570 Introduction to Nanocomputing

Coding for Discrete Source

U Logo Use Guidelines

Fibonacci Coding for Lossless Data Compression A Review

Exercises with solutions (Set B)

Information Theory. Week 4 Compressing streams. Iain Murray,

Huffman Coding. C.M. Liu Perceptual Lab, College of Computer Science National Chiao-Tung University

Uncertainity, Information, and Entropy

10-704: Information Processing and Learning Fall Lecture 10: Oct 3

Lecture 2: Introduction to Audio, Video & Image Coding Techniques (I) -- Fundaments

SUPPLEMENTARY INFORMATION

Lecture 1: September 25, A quick reminder about random variables and convexity

17.1 Binary Codes Normal numbers we use are in base 10, which are called decimal numbers. Each digit can be 10 possible numbers: 0, 1, 2, 9.

COMM901 Source Coding and Compression. Quiz 1

Information Theory and Coding Techniques

Information and Entropy

Lec 05 Arithmetic Coding

Lecture 2: Introduction to Audio, Video & Image Coding Techniques (I) -- Fundaments. Tutorial 1. Acknowledgement and References for lectures 1 to 5

Data Compression Techniques

EE5585 Data Compression January 29, Lecture 3. x X x X. 2 l(x) 1 (1)

PROBABILITY AND INFORMATION THEORY. Dr. Gjergji Kasneci Introduction to Information Retrieval WS

Chapter 2 Source Models and Entropy. Any information-generating process can be viewed as. computer program in executed form: binary 0

Lecture 6: Kraft-McMillan Inequality and Huffman Coding

A Mathematical Theory of Communication

DCSP-3: Minimal Length Coding. Jianfeng Feng

Information Theory and Statistics Lecture 2: Source coding

CS4800: Algorithms & Data Jonathan Ullman

Entropy Coding. Connectivity coding. Entropy coding. Definitions. Lossles coder. Input: a set of symbols Output: bitstream. Idea

EE376A - Information Theory Midterm, Tuesday February 10th. Please start answering each question on a new page of the answer booklet.

Homework Set #2 Data Compression, Huffman code and AEP

Chapter 3. Regular grammars

Module 2 LOSSLESS IMAGE COMPRESSION SYSTEMS. Version 2 ECE IIT, Kharagpur

Lecture 3 : Algorithms for source coding. September 30, 2016

4F5: Advanced Communications and Coding Handout 2: The Typical Set, Compression, Mutual Information

And for polynomials with coefficients in F 2 = Z/2 Euclidean algorithm for gcd s Concept of equality mod M(x) Extended Euclid for inverses mod M(x)

Kolmogorov complexity

MODULAR ARITHMETIC I

Using an innovative coding algorithm for data encryption

4. Quantization and Data Compression. ECE 302 Spring 2012 Purdue University, School of ECE Prof. Ilya Pollak

EE5585 Data Compression May 2, Lecture 27

EE5139R: Problem Set 4 Assigned: 31/08/16, Due: 07/09/16

Autumn Coping with NP-completeness (Conclusion) Introduction to Data Compression

Outline. Computer Science 418. Number of Keys in the Sum. More on Perfect Secrecy, One-Time Pad, Entropy. Mike Jacobson. Week 3

A Universal Turing Machine

ELEC 515 Information Theory. Distortionless Source Coding

Lecture 3. Mathematical methods in communication I. REMINDER. A. Convex Set. A set R is a convex set iff, x 1,x 2 R, θ, 0 θ 1, θx 1 + θx 2 R, (1)

Information redundancy

Coding of memoryless sources 1/35

Communications II Lecture 9: Error Correction Coding. Professor Kin K. Leung EEE and Computing Departments Imperial College London Copyright reserved

Variable-to-Variable Codes with Small Redundancy Rates

CSEP 590 Data Compression Autumn Dictionary Coding LZW, LZ77

Error Detection and Correction: Hamming Code; Reed-Muller Code

Chapter 4. Data Transmission and Channel Capacity. Po-Ning Chen, Professor. Department of Communications Engineering. National Chiao Tung University

Error Correction Review

EE376A - Information Theory Final, Monday March 14th 2016 Solutions. Please start answering each question on a new page of the answer booklet.

Communications Theory and Engineering

( c ) E p s t e i n, C a r t e r a n d B o l l i n g e r C h a p t e r 1 7 : I n f o r m a t i o n S c i e n c e P a g e 1

Deterministic Finite Automaton (DFA)

Compression and Coding

Introduction to information theory and coding

Induction and Recursion

CS 361 Meeting 26 11/10/17

Multimedia. Multimedia Data Compression (Lossless Compression Algorithms)

lossless, optimal compressor

Transcription:

Data Compression Techniques Part 1: Entropy Coding Lecture 4: Asymmetric Numeral Systems Juha Kärkkäinen 08.11.2017 1 / 19

Asymmetric Numeral Systems Asymmetric numeral systems (ANS) is a recent entropy coding technique that combines the advantages of Huffman and arithmetic coding: Similarly to arithmetic coding, ANS gets very close to the entropy. Similarly to Huffman coding, ANS can be implemented to run much faster than arithmetic coding. The basic ANS coding procedure is: source string integer code string The mapping from integers to code strings is simple: Represent the integer in binary using (only) as many bits as needed. Remove the leading bit, which is always 1. The opposite direction is equally simple: Add 1 to to the front of the bit string and interpret as an integer. The missing piece is the mapping from source strings to integers. 2 / 19

The source string to integer mapping is based on the following observations: An integer x corresponds to a code string of length log x and thus should correspond to a source string of probability about 2 log x 1/x to get close to entropy. The code string with probability 0.5 for each bit has the right probability as a string. Thus the code string to integer mapping is the right kind of mapping. We want to generalize the mapping to handle larger alphabets and arbitrary probabilities. 3 / 19

Let us define the code string to integer mapping using arithmetic operations without relying directly on the binary representation of integers. Let x be an integer encoding some binary string B. The encoding function C(x, s) adds the bit s {0, 1} to the end of the string and returns the new integer: C(x, s) = 2x + s Starting with x = 1, which encodes the empty string, we can construct the encoding for any string by repeated application of the encoding function. The decoding function D(x) is the reverse mapping that extracts a bit from the end and returns the new integer and the extracted bit: D(x) = ( x/2, x mod 2) The bits are extracted until x becomes 1. 4 / 19

The encoding and decoding functions can be described using the following ANS coding table. C(x, s) 0 1 2 3 4 5 6 7 8 9... s = 0 0 1 2 3 4 x s = 1 0 1 2 3 4 Using the table, the functions can be computed as follows: To compute C(x, s), find x on the row corresponding to s and return the value on the first row in that column. To compute D(x), find x on the first row and return the value below it as well as the bit on the row containing that value. Example C(3, 1) = 7 and D(7) = (3, 1). 5 / 19

By modifying the table, we can represent inequal probabilities. For example, the probabilities P(0) = 1/4 and P(1) = 3/4 could be represented with the following table. C(x, s) 0 1 2 3 4 5 6 7 8 9 10 11 12 13... s = 0 0 1 2 3 x s = 1 0 1 2 3 4 5 6 7 8 9 Example Using the above table, the bitstring 0111 is encoded by the integer 13: 1 0 4 1 6 1 9 1 13 and the integer 12 decodes into the bitstring 110 (in reverse order): 12 0 3 1 2 1 1 The generalization to larger alphabets can be accomplished by adding more rows, one for each symbol. 6 / 19

Each symbol row in the coding table contains 0, 1, 2,.... Thus the code table can be described by specifying for each column, which symbol row contains a value in that column. Let E : N Σ be such mapping. In other words, E(x) is the last symbol encoded by the integer x, or equivalently the first symbol extracted during decoding, i.e., D(x) = (, E(x)). We can also consider E to be the (infinite) string E(0)E(1)E(2)..., which we call the ANS coding sequence. For example, the coding table on the preceding slide corresponds to the string 011101110111... = (0111). Example For Σ = {a, b, c} with the probabilities P(a) = 0.2, P(b) = 0.5 and P(c) = 0.3, we could choose E = (aabbbbbccc) as the ANS coding sequence and obtain the following coding table. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19... a 0 1 2 3 b 0 1 2 3 4 5 6 7 8 9 c 0 1 2 3 4 5 7 / 19

Define the following operations on the sequence E: p-rank E (x) = the number of occurrences of E(x) in E[0..x 1] select E (x, s) = the position of (x + 1) th occurrence of s in E Example x 0 1 2 3 4 5 6 7 8 9 10 11 12... E(x) a a b b b b b c c c a a b... p-rank E (x) 0 1 0 1 2 3 4 0 1 2 2 3 5... select E (x, b) 2 3 4 5 6 12 13 14 15 16 22 23 24... Then the encoding and decoding functions can be defined for any coding sequence as follows: C(x, s) = select E (x, s) D(x) = (p-rank E (x), E(x)) 8 / 19

A good coding sequence E for a probability distribution P over an alphabet Σ should satisfy, for all x N and s Σ, C(x, s) = select E (x, s) x/p(s) Then a string S Σ is encoded with an integer of value about 1/P(S) and the code string has a length of about log(1/p(s)). There are many possible ANS coding schemes. We will look at the two standard examples uabs and rans, and then some implementation techniques leading to a practical variant called tans. 9 / 19

uabs (uniform Asymmetric Binary Systems) Let Σ = {0, 1} with P(1) = p and P(0) = 1 p. Define the code sequence by E(x) = (x + 1)p xp Then the encoding function is C(x, s) = { x+1 1 p 1 if s = 0 x p if s = 1 and the decoding function for is { (x xp, E(x)) if E(x) = 0 D(x) = ( xp, E(x)) if E(x) = 1 There is also a variant using instead of. Example (p = 0.3) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... 0 0 1 2 3 4 5 6 7 8 9 10 11 12 1 0 1 2 3 4 5 10 / 19

rans (range ANS) Let Σ = {s 1, s 2,..., r σ }. Choose an integer L and integers f i, i [1..σ], so that f i /L P(s i ) and i [1..σ] f i = L. In other words, we will approximate the probabilities with rational numbers f i /L. Then set See slide 7 for an example. E = (s f i 1 sf 2 2... sfσ σ ) Setting F i = j [1..i 1] f j, the encoding function is The decoding function is C(x, s i ) = x/f i L + x mod f i + F i D(x) = ( x/l f i + x mod L F i, s i ) for i s.t. s i = E(x) In practice, L should be a power of two to speed up decoding. 11 / 19

Renormalization To avoid dealing with very large integers, we need occasionally to renormalize similarly to arithmetic coding. This is done with the decoding function. During encoding, we use the standard code string decoding function D(x) = ( x/2, x mod 2) and output the resulting bit. During decoding, we use the source string decoding function and output the resulting source symbols. With arithmetic coding renormalization does not change the eventual output. However, since the decoding function extracts bits in the reverse order, the extrated bits/symbols are from the middle of the sequence, not from the beginning as in arithmetic coding. This is not a problem, though, as long as the encoder decoder symmetry is maintained: Whenever the encoder reads source symbols and encodes them into the integer, the decoder extracts source symbols from the integer and writes them to output. Whenever the encoder renormalizes and outputs code bits, the decoder reads code bits and encodes them to the integer. 12 / 19

Let R be a suitable integer: For uabs, p = P(1) should be a multiple of 1/R. For rans, R should be a multiple of L. The decoding procedure under renormalization is: If x R, extract and output a source symbol. If x < R, read a code bit and encode it to the integer. Let C s be the source encoding function and D c the code decoding function. The encoding procedure under renormalization is as follows when s is the next source symbol to be encoded. If D c (C s (x, s)) R, extract and output a code bit (renormalize). If D c (C s (x, s)) < R, encode s to the integer. The symmetry between encoder and decoder is maintained because: The encoding rules ensure that x never grows too big. Thus, if the encoder renormalizes computing y = D c (x), then y < R so that the decoder does the inverse given integer y. The conditions on R ensure that, if the encoder computes y = C s (x, s), then y R so that the decoder does the inverse given integer y. 13 / 19

Example For rans with L = 8 let E = (abbbbbcc), i.e, P(a) 1/8, P(b) 5/8 and P(c) 2/8. The coding table is 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 a 0 1 b 0 1 2 3 4 5 6 7 8 9 c 0 1 2 3 We use renormalization with R = 8. The string cab is encoded as follows. The encoding starts with x = 2 allowing immediate encoding of the first symbol and ends with extracting code bits until x is 1. 2 c 14 0 7 1 3 1 1 a 8 b 12 0 6 0 3 1 1 Inputs are above and outputs below the arrows. The decoder starts with x = 1, works in reverse order, and ends after outputting n = 3 symbols. 1 1 3 0 6 0 6 b 8 a 1 1 3 1 7 0 14 c 2 14 / 19

tans (table ANS) rans with renormalization has the property that the integer x is always in the range [R..2R 1] right after encoding a source symbol during encoding and right before decoding a source symbol during decoding. The values of x in the range can be thought of as states of computation. The state transitions are then: Encoding: zero or more renormalization steps followed by a source symbol encoding. Decoding: source symbol extraction followed by zero or more code bit encodings. The idea of tans is to store all possible transitions into a table, and then do encoding and decoding with table lookups. 15 / 19

Example Let E = (abbbbbcc) and L = R = 8 (see slide 14). The tans encoding table is: 8 9 10 11 12 13 14 15 a 8 000 8 100 8 010 8 110 8 001 8 101 8 011 8 111 b 12 13 0 9 1 9 0 10 1 10 0 11 1 11 c 00 14 10 14 01 14 11 14 00 15 10 15 01 15 11 15 The string cab is encoded as follows. The first symbol is read just to set the initial state without output. c 14 a 011 8 b 12 001 The last bits of output identify the final state 12. The full output is 011001, the same as on slide 14. 16 / 19

Example (continued) Decoding table 8 9 10 11 b 1b 2b 3 a 8 + 4b 1 + 2b 2 + b 3 b 1 b 10 + b 1 b 1 b 12 + b 1 b 1 b 14 + b 1 Decoding starts with reading log R = 3 bits to establish the initial state as 8 + 4b 1 + 2b 2 + b 3. Then decoding proceeds according to the table. The last transition reads no bits. 100 12 8 110 14 b a c 12 b 8 13 b 9 14 15 b 1b 2 c 8 + 2b 1 + b 2 b 1b 2 c 12 + 2b 1 + b 2 17 / 19

Large Code Alphabet ANS can also be modified for larger code alphabet Γ = [0..γ 1]. The coding function is then and the decoding function is C(x, s) = γx + s D(x) = ( x/γ, x mod γ) With tans the set of states becomes [R..γR 1]. A larger code alphabet can speed up coding by avoiding dealing with individual bits. In particular, γ = 2 8 allows byte level processing. 18 / 19

Summary: Entropy Coding Huffman coding, arithmetic coding and ANS coding address the same problem: encoding data using as few bits as possible given a probability distribution over the data. Such methods are often called entropy coding. ANS offering fast coding and close to entropy compression is the state of the art in entropy coding. Some codes such as Elias γ code are not explicitly constructed from a probability distribution. However, since the codeword lengths can be interpreted as probabilities, there is an underlying implicit probability distribution (see also Exercise 2.3). Entropy coding assumes that the probability distribution of each symbol is independent of other symbols. When this is not the case, such as with natural language text, other techniques are needed. However, even then entropy coding is usually applied in the last stage of compression to produce the actual bits. 19 / 19