SlideShare a Scribd company logo
1 of 23
Download to read offline
Module 4
                      Arithmetic Coding
                             Prof. Hung-Ta Pai




Module 4, Data Compression       LISA, NTPU      1
Reals in Binary
          Any real number x in the interval [0, 1) can be
          represented in binary as .b1b2... where bi is a bit




Module 4, Data Compression       LISA, NTPU                 2
First Conversion
                 L:=0; R:=1; i :=1;
                 while x > L *
                     if x < (L+R)/2 then bi := 0; R := (L+R)/2;
                     if x ≥ (L+R)/2 then bi := 1; L := (L+R)/2;
                     i := i + 1;
                 end{while}
                 bi := 0 for all j ≥ i;


                  * Invariant: x is always in the interval [L, R)

Module 4, Data Compression          LISA, NTPU                      3
Basic Ideas
          Represent each string x of length n by a unique
          interval [L, R) in [0, 1)
          The width of the interval [L, R) represents the
          probability of x occurring
          The interval [L, R) can itself be represented by
          any number, called a tag, within the half open
          interval
          The k significant bits of the tag .t1t2t3.... is the
          code of x
               That is, .t1t2t3...tk000... is in the interval [L, R)

Module 4, Data Compression            LISA, NTPU                       4
Example
                             1. Tag must be in the half open interval
                             2. Tag can be chosen to be (L+R)/2
                             3. Code is the significant bits of the tag




Module 4, Data Compression         LISA, NTPU                        5
Better Tag




Module 4, Data Compression     LISA, NTPU   6
Example of Codes
          P(a) = 1/3, P(b) = 2/3




Module 4, Data Compression        LISA, NTPU    7
Code Generation from Tag
        If binary tag is .t1t2t3... = (L+R)/2 in [L, R), then
        we want to choose k to form the code t1t2 ...tk
        Short code: choose k to be as small as possible
        so that L ≤ . t1t2 ...tk000... < R
        Guaranteed code:
           Choose k = ⎡log2(1/(R-L))⎤ + 1
           L ≤ . t1t2 ...tkb1b2b3... < R for any bits b1b2b3...
           For fixed length strings provides a good prefix code
           Example: [.000000000..., .000010010...), tag
           = .000001001...
                   Short code: 0
                   Guaranteed code: 000001
Module 4, Data Compression           LISA, NTPU                   8
Guaranteed Code Example
          P(a) = 1/3, P(b) = 2/3




                             Guaranteed code -> Prefix code
Module 4, Data Compression   LISA, NTPU                       9
Coding Algorithm
          P(a1), P(a2), ..., P(am)
          C(ai) = P(a1) + P(a2) + ... +P(ai-1)
          Encode x1x2...xn
                    Initialize L := 0; and R:=1;
                    For i = 1 to n do
                        W := R - L;
                        L := L + W * C(xi);
                        R := L + W * P(xi);
                    end;
                    t := (L+R)/2; choose code for the tag
Module 4, Data Compression          LISA, NTPU              10
Coding Example
          P(a) = 1/4, P(b) = 1/2, P(c) = 1/4
          C(a) = 0, C(b) =1/4, C(c) = 3/4
          abca




Module 4, Data Compression       LISA, NTPU    11
Coding Excercise
          P(a) = 1/4, P(b) = 1/2, P(c) = 1/4
          C(a) = 0, C(b) =1/4, C(c) = 3/4
          bbbb




Module 4, Data Compression        LISA, NTPU    12
Decoding (1/3)
          Assume the length is known to be 3
          0001 which converts to the tag .0001000




Module 4, Data Compression       LISA, NTPU         13
Decoding (2/3)
          Assume the length is known to be 3
          0001 which converts to the tag .0001000




Module 4, Data Compression       LISA, NTPU         14
Decoding (3/3)
          Assume the length is known to be 3
          0001 which converts to the tag .0001000




Module 4, Data Compression       LISA, NTPU         15
Decoding Algorithm
          P(a1), P(a2), ..., P(am)
          C(ai) = P(a1) + P(a2) + ... +P(ai-1)
          Decode b1b2...bm, number of symbols is n
     Initialize L := 0; and R:=1;
     t := b1b2...bm000...
     for i = 1 to n do
         W := R - L;
         find j such that L + W * C(aj) ≤ t < L + W * (C(aj)+P(aj));
         output aj;
         L := L + W * C(aj); R = L + W * P(aj);
Module 4, Data Compression         LISA, NTPU                      16
Decoding Example
          P(a) = 1/4, P(b) = 1/2, P(c) = 1/4
          C(a) = 0, C(b) =1/4, C(c) = 3/4
          00101




Module 4, Data Compression        LISA, NTPU    17
Decoding Issues
          There are two ways for the decoder to know
          when to stop decoding
               Transmit the length of the string
               Transmit a unique end of string symbol




Module 4, Data Compression       LISA, NTPU             18
Practical Arithmetic Coding
          Scaling:
               By scaling we can keep L and R in a reasonable
               range of values so that W = R–L does not underflow
               The code can be produced progressively, not at the
               end
               Complicates decoding some
          Integer arithmetic coding avoids floating point
          altogether



Module 4, Data Compression       LISA, NTPU                    19
Adaptation
          Simple solution – Equally Probable Model
               Initially all symbols have frequency 1
               After symbol x is coded, increment its frequency by 1
               Use the new model for coding the next symbol
               Example in alphabet a, b, c, d




Module 4, Data Compression        LISA, NTPU                      20
Zero Frequency Problem
          How do we weight symbols that have not
          occurred yet?
               Equal weight? Not so good with many symbols
               Escape symbol, but what should its weight be?
               When a new symbol is encountered send the <esc>,
               followed by the symbol in the equally probable model
               (both encoded arithmetically)




Module 4, Data Compression        LISA, NTPU                     21
End of File Problem
          Similar to Zero Frequency Problem
          Reasonable solution:
               Add EOF to the post-ESC equally-probable model
          When done compressing:
               First send ESC
               Then send EOF
          What’s the cost of this approach?




Module 4, Data Compression         LISA, NTPU                   22
Arithmetic vs. Huffman
          Both compress very well
          For m symbol grouping
               Huffman is within 1/m of entropy
               Arithmetic is within 2/m of entropy
          Context
               Huffman needs a tree for every context
               Arithmetic needs a small table of frequencies for
               every context
          Adaptation
               Huffman has an elaborate adaptive algorithm
               Arithmetic has a simple adaptive mechanism

Module 4, Data Compression         LISA, NTPU                      23

More Related Content

What's hot

carry look ahead adder
carry look ahead addercarry look ahead adder
carry look ahead adderASHISH MANI
 
Carry look ahead adder
Carry look ahead adderCarry look ahead adder
Carry look ahead adderdragonpradeep
 
Register transfer language & its micro operations
Register transfer language & its micro operationsRegister transfer language & its micro operations
Register transfer language & its micro operationsLakshya Sharma
 
Image trnsformations
Image trnsformationsImage trnsformations
Image trnsformationsJohn Williams
 
Digital Signal Processing[ECEG-3171]-Ch1_L07
Digital Signal Processing[ECEG-3171]-Ch1_L07Digital Signal Processing[ECEG-3171]-Ch1_L07
Digital Signal Processing[ECEG-3171]-Ch1_L07Rediet Moges
 
Linear Block Codes
Linear Block CodesLinear Block Codes
Linear Block CodesNilaNila16
 
LZ77 and LZ78 Compression Algorithms
LZ77 and LZ78 Compression AlgorithmsLZ77 and LZ78 Compression Algorithms
LZ77 and LZ78 Compression AlgorithmsMustafa GÖKÇE
 
Pulse modulation
Pulse modulationPulse modulation
Pulse modulationstk_gpg
 
Error detection & correction codes
Error detection & correction codesError detection & correction codes
Error detection & correction codesRevathi Subramaniam
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisRamakant Soni
 
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE ShivangiSingh241
 

What's hot (20)

Huffman ppt
Huffman ppt Huffman ppt
Huffman ppt
 
carry look ahead adder
carry look ahead addercarry look ahead adder
carry look ahead adder
 
Shannon Fano
Shannon FanoShannon Fano
Shannon Fano
 
Basics of coding theory
Basics of coding theoryBasics of coding theory
Basics of coding theory
 
Huffman Coding
Huffman CodingHuffman Coding
Huffman Coding
 
Unit 3 Arithmetic Coding
Unit 3 Arithmetic CodingUnit 3 Arithmetic Coding
Unit 3 Arithmetic Coding
 
Convolutional codes
Convolutional codesConvolutional codes
Convolutional codes
 
Carry look ahead adder
Carry look ahead adderCarry look ahead adder
Carry look ahead adder
 
Register transfer language & its micro operations
Register transfer language & its micro operationsRegister transfer language & its micro operations
Register transfer language & its micro operations
 
Huffman Coding
Huffman CodingHuffman Coding
Huffman Coding
 
Image trnsformations
Image trnsformationsImage trnsformations
Image trnsformations
 
Digital Signal Processing[ECEG-3171]-Ch1_L07
Digital Signal Processing[ECEG-3171]-Ch1_L07Digital Signal Processing[ECEG-3171]-Ch1_L07
Digital Signal Processing[ECEG-3171]-Ch1_L07
 
Linear Block Codes
Linear Block CodesLinear Block Codes
Linear Block Codes
 
LZ77 and LZ78 Compression Algorithms
LZ77 and LZ78 Compression AlgorithmsLZ77 and LZ78 Compression Algorithms
LZ77 and LZ78 Compression Algorithms
 
Fft
FftFft
Fft
 
Pulse modulation
Pulse modulationPulse modulation
Pulse modulation
 
Error detection & correction codes
Error detection & correction codesError detection & correction codes
Error detection & correction codes
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysis
 
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE
 
Hamming codes
Hamming codesHamming codes
Hamming codes
 

Similar to Module 4 Arithmetic Coding

High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)Enrique Monzo Solves
 
basicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptxbasicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptxupendrabhatt13
 
The performance of turbo codes for wireless communication systems
The performance of turbo codes for wireless communication systemsThe performance of turbo codes for wireless communication systems
The performance of turbo codes for wireless communication systemschakravarthy Gopi
 
system software 16 marks
system software 16 markssystem software 16 marks
system software 16 marksvvcetit
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxPJS KUMAR
 
Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法Kai Katsumata
 
Matlab 3
Matlab 3Matlab 3
Matlab 3asguna
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generatorsanchi29
 
CHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐ
CHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐCHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐ
CHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐlykhnh386525
 
SURF 2012 Final Report(1)
SURF 2012 Final Report(1)SURF 2012 Final Report(1)
SURF 2012 Final Report(1)Eric Zhang
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework HelpC++ Homework Help
 
Fast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka StreamsFast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka StreamsHostedbyConfluent
 
Pilot induced cyclostationarity based method for dvb system identification
Pilot induced cyclostationarity based method for dvb system identificationPilot induced cyclostationarity based method for dvb system identification
Pilot induced cyclostationarity based method for dvb system identificationiaemedu
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 

Similar to Module 4 Arithmetic Coding (20)

High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
 
Er24902905
Er24902905Er24902905
Er24902905
 
basicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptxbasicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptx
 
The performance of turbo codes for wireless communication systems
The performance of turbo codes for wireless communication systemsThe performance of turbo codes for wireless communication systems
The performance of turbo codes for wireless communication systems
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
system software 16 marks
system software 16 markssystem software 16 marks
system software 16 marks
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptx
 
Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法
 
Matlab 3
Matlab 3Matlab 3
Matlab 3
 
Lec5 Compression
Lec5 CompressionLec5 Compression
Lec5 Compression
 
internal assement 3
internal assement 3internal assement 3
internal assement 3
 
Ch9b
Ch9bCh9b
Ch9b
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Modulation techniques matlab_code
Modulation techniques matlab_codeModulation techniques matlab_code
Modulation techniques matlab_code
 
CHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐ
CHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐCHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐ
CHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐ
 
SURF 2012 Final Report(1)
SURF 2012 Final Report(1)SURF 2012 Final Report(1)
SURF 2012 Final Report(1)
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
 
Fast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka StreamsFast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka Streams
 
Pilot induced cyclostationarity based method for dvb system identification
Pilot induced cyclostationarity based method for dvb system identificationPilot induced cyclostationarity based method for dvb system identification
Pilot induced cyclostationarity based method for dvb system identification
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 

More from anithabalaprabhu (20)

Ch 04 Arithmetic Coding ( P P T)
Ch 04  Arithmetic  Coding ( P P T)Ch 04  Arithmetic  Coding ( P P T)
Ch 04 Arithmetic Coding ( P P T)
 
Compression
CompressionCompression
Compression
 
Datacompression1
Datacompression1Datacompression1
Datacompression1
 
Speech Compression
Speech CompressionSpeech Compression
Speech Compression
 
Z24 4 Speech Compression
Z24   4   Speech CompressionZ24   4   Speech Compression
Z24 4 Speech Compression
 
Dictor
DictorDictor
Dictor
 
Dictionary Based Compression
Dictionary Based CompressionDictionary Based Compression
Dictionary Based Compression
 
Ch 04 Arithmetic Coding (Ppt)
Ch 04 Arithmetic Coding (Ppt)Ch 04 Arithmetic Coding (Ppt)
Ch 04 Arithmetic Coding (Ppt)
 
Compression Ii
Compression IiCompression Ii
Compression Ii
 
Lassy
LassyLassy
Lassy
 
Compression Ii
Compression IiCompression Ii
Compression Ii
 
Lossy
LossyLossy
Lossy
 
Planning
PlanningPlanning
Planning
 
Lossless
LosslessLossless
Lossless
 
Losseless
LosselessLosseless
Losseless
 
Lec32
Lec32Lec32
Lec32
 
Huffman Student
Huffman StudentHuffman Student
Huffman Student
 
Huffman Encoding Pr
Huffman Encoding PrHuffman Encoding Pr
Huffman Encoding Pr
 
Huffman1
Huffman1Huffman1
Huffman1
 
Huffman
HuffmanHuffman
Huffman
 

Recently uploaded

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Recently uploaded (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Module 4 Arithmetic Coding

  • 1. Module 4 Arithmetic Coding Prof. Hung-Ta Pai Module 4, Data Compression LISA, NTPU 1
  • 2. Reals in Binary Any real number x in the interval [0, 1) can be represented in binary as .b1b2... where bi is a bit Module 4, Data Compression LISA, NTPU 2
  • 3. First Conversion L:=0; R:=1; i :=1; while x > L * if x < (L+R)/2 then bi := 0; R := (L+R)/2; if x ≥ (L+R)/2 then bi := 1; L := (L+R)/2; i := i + 1; end{while} bi := 0 for all j ≥ i; * Invariant: x is always in the interval [L, R) Module 4, Data Compression LISA, NTPU 3
  • 4. Basic Ideas Represent each string x of length n by a unique interval [L, R) in [0, 1) The width of the interval [L, R) represents the probability of x occurring The interval [L, R) can itself be represented by any number, called a tag, within the half open interval The k significant bits of the tag .t1t2t3.... is the code of x That is, .t1t2t3...tk000... is in the interval [L, R) Module 4, Data Compression LISA, NTPU 4
  • 5. Example 1. Tag must be in the half open interval 2. Tag can be chosen to be (L+R)/2 3. Code is the significant bits of the tag Module 4, Data Compression LISA, NTPU 5
  • 6. Better Tag Module 4, Data Compression LISA, NTPU 6
  • 7. Example of Codes P(a) = 1/3, P(b) = 2/3 Module 4, Data Compression LISA, NTPU 7
  • 8. Code Generation from Tag If binary tag is .t1t2t3... = (L+R)/2 in [L, R), then we want to choose k to form the code t1t2 ...tk Short code: choose k to be as small as possible so that L ≤ . t1t2 ...tk000... < R Guaranteed code: Choose k = ⎡log2(1/(R-L))⎤ + 1 L ≤ . t1t2 ...tkb1b2b3... < R for any bits b1b2b3... For fixed length strings provides a good prefix code Example: [.000000000..., .000010010...), tag = .000001001... Short code: 0 Guaranteed code: 000001 Module 4, Data Compression LISA, NTPU 8
  • 9. Guaranteed Code Example P(a) = 1/3, P(b) = 2/3 Guaranteed code -> Prefix code Module 4, Data Compression LISA, NTPU 9
  • 10. Coding Algorithm P(a1), P(a2), ..., P(am) C(ai) = P(a1) + P(a2) + ... +P(ai-1) Encode x1x2...xn Initialize L := 0; and R:=1; For i = 1 to n do W := R - L; L := L + W * C(xi); R := L + W * P(xi); end; t := (L+R)/2; choose code for the tag Module 4, Data Compression LISA, NTPU 10
  • 11. Coding Example P(a) = 1/4, P(b) = 1/2, P(c) = 1/4 C(a) = 0, C(b) =1/4, C(c) = 3/4 abca Module 4, Data Compression LISA, NTPU 11
  • 12. Coding Excercise P(a) = 1/4, P(b) = 1/2, P(c) = 1/4 C(a) = 0, C(b) =1/4, C(c) = 3/4 bbbb Module 4, Data Compression LISA, NTPU 12
  • 13. Decoding (1/3) Assume the length is known to be 3 0001 which converts to the tag .0001000 Module 4, Data Compression LISA, NTPU 13
  • 14. Decoding (2/3) Assume the length is known to be 3 0001 which converts to the tag .0001000 Module 4, Data Compression LISA, NTPU 14
  • 15. Decoding (3/3) Assume the length is known to be 3 0001 which converts to the tag .0001000 Module 4, Data Compression LISA, NTPU 15
  • 16. Decoding Algorithm P(a1), P(a2), ..., P(am) C(ai) = P(a1) + P(a2) + ... +P(ai-1) Decode b1b2...bm, number of symbols is n Initialize L := 0; and R:=1; t := b1b2...bm000... for i = 1 to n do W := R - L; find j such that L + W * C(aj) ≤ t < L + W * (C(aj)+P(aj)); output aj; L := L + W * C(aj); R = L + W * P(aj); Module 4, Data Compression LISA, NTPU 16
  • 17. Decoding Example P(a) = 1/4, P(b) = 1/2, P(c) = 1/4 C(a) = 0, C(b) =1/4, C(c) = 3/4 00101 Module 4, Data Compression LISA, NTPU 17
  • 18. Decoding Issues There are two ways for the decoder to know when to stop decoding Transmit the length of the string Transmit a unique end of string symbol Module 4, Data Compression LISA, NTPU 18
  • 19. Practical Arithmetic Coding Scaling: By scaling we can keep L and R in a reasonable range of values so that W = R–L does not underflow The code can be produced progressively, not at the end Complicates decoding some Integer arithmetic coding avoids floating point altogether Module 4, Data Compression LISA, NTPU 19
  • 20. Adaptation Simple solution – Equally Probable Model Initially all symbols have frequency 1 After symbol x is coded, increment its frequency by 1 Use the new model for coding the next symbol Example in alphabet a, b, c, d Module 4, Data Compression LISA, NTPU 20
  • 21. Zero Frequency Problem How do we weight symbols that have not occurred yet? Equal weight? Not so good with many symbols Escape symbol, but what should its weight be? When a new symbol is encountered send the <esc>, followed by the symbol in the equally probable model (both encoded arithmetically) Module 4, Data Compression LISA, NTPU 21
  • 22. End of File Problem Similar to Zero Frequency Problem Reasonable solution: Add EOF to the post-ESC equally-probable model When done compressing: First send ESC Then send EOF What’s the cost of this approach? Module 4, Data Compression LISA, NTPU 22
  • 23. Arithmetic vs. Huffman Both compress very well For m symbol grouping Huffman is within 1/m of entropy Arithmetic is within 2/m of entropy Context Huffman needs a tree for every context Arithmetic needs a small table of frequencies for every context Adaptation Huffman has an elaborate adaptive algorithm Arithmetic has a simple adaptive mechanism Module 4, Data Compression LISA, NTPU 23