fbpx
Wikipedia

Asymmetric numeral systems

Asymmetric numeral systems (ANS)[1][2] is a family of entropy encoding methods introduced by Jarosław (Jarek) Duda[3] from Jagiellonian University, used in data compression since 2014[4] due to improved performance compared to previous methods.[5] ANS combines the compression ratio of arithmetic coding (which uses a nearly accurate probability distribution), with a processing cost similar to that of Huffman coding. In the tabled ANS (tANS) variant, this is achieved by constructing a finite-state machine to operate on a large alphabet without using multiplication.

Among others, ANS is used in the Facebook Zstandard compressor[6][7] (also used e.g. in Linux kernel,[8] Google Chrome browser,[9] Android[10] operating system, was published as RFC 8478 for MIME[11] and HTTP[12]), Apple LZFSE compressor,[13] Google Draco 3D compressor[14] (used e.g. in Pixar Universal Scene Description format[15]) and PIK image compressor,[16] CRAM DNA compressor[17] from SAMtools utilities,[18] NVIDIA nvCOMP high speed compression library,[19] Dropbox DivANS compressor,[20] Microsoft DirectStorage BCPack texture compressor,[21] and JPEG XL[22] image compressor.

The basic idea is to encode information into a single natural number . In the standard binary number system, we can add a bit of information to by appending at the end of , which gives us . For an entropy coder, this is optimal if . ANS generalizes this process for arbitrary sets of symbols with an accompanying probability distribution . In ANS, if the information from is appended to to result in , then . Equivalently, , where is the number of bits of information stored in the number , and is the number of bits contained in the symbol .

For the encoding rule, the set of natural numbers is split into disjoint subsets corresponding to different symbols – like into even and odd numbers, but with densities corresponding to the probability distribution of the symbols to encode. Then to add information from symbol into the information already stored in the current number , we go to number being the position of the -th appearance from the -th subset.

There are alternative ways to apply it in practice – direct mathematical formulas for encoding and decoding steps (uABS and rANS variants), or one can put the entire behavior into a table (tANS variant). Renormalization is used to prevent going to infinity – transferring accumulated bits to or from the bitstream.

Entropy coding edit

Suppose a sequence of 1,000 zeros and ones would be encoded, which would take 1000 bits to store directly. However, if it is somehow known that it only contains 1 zero and 999 ones, it would be sufficient to encode the zero's position, which requires only   bits here instead of the original 1000 bits.

Generally, such length   sequences containing   zeros and   ones, for some probability  , are called combinations. Using Stirling's approximation we get their asymptotic number being

 

called Shannon entropy.

Hence, to choose one such sequence we need approximately   bits. It is still   bits if  , however, it can also be much smaller. For example, we need only   bits for  .

An entropy coder allows the encoding of a sequence of symbols using approximately the Shannon entropy bits per symbol. For example, ANS could be directly used to enumerate combinations: assign a different natural number to every sequence of symbols having fixed proportions in a nearly optimal way.

In contrast to encoding combinations, this probability distribution usually varies in data compressors. For this purpose, Shannon entropy can be seen as a weighted average: a symbol of probability   contains   bits of information. ANS encodes information into a single natural number  , interpreted as containing   bits of information. Adding information from a symbol of probability   increases this informational content to  . Hence, the new number containing both information should be  .

Motivating examples edit

Consider a source with 3 letters A, B, C, with probability 1/2, 1/4, 1/4. It is simple to construct the optimal prefix code in binary: A = 0, B = 10, C = 11. Then, a message is encoded as ABC -> 01011.

We see that an equivalent method for performing the encoding is as follows:

  • Start with number 1, and perform an operation on the number for each input letter.
  • A = multiply by 2; B = multiply by 4, add 2; C = multiply by 4, add 3.
  • Express the number in binary, then remove the first digit 1.

Consider a more general source with k letters, with rational probabilities  . Then performing arithmetic coding on the source requires only exact arithmetic with integers.

In general, ANS is an approximation of arithmetic coding that approximates the real probabilities   by rational numbers   with a small denominator  .

Basic concepts of ANS edit

 
Comparison of the concept of arithmetic coding (left) and ANS (right). Both can be seen as generalizations of standard numeral systems, optimal for uniform probability distribution of digits, into optimized for some chosen probability distribution. Arithmetic or range coding corresponds to adding new information in the most significant position, while ANS generalizes adding information in the least significant position. Its coding rule is "x goes to x-th appearance of subset of natural numbers corresponding to currently encoded symbol". In the presented example, sequence (01111) is encoded into a natural number 18, which is smaller than 47 obtained by using standard binary system, due to better agreement with frequencies of sequence to encode. The advantage of ANS is storing information in a single natural number, in contrast to two defining a range.

Imagine there is some information stored in a natural number  , for example as bit sequence of its binary expansion. To add information from a binary variable  , we can use coding function  , which shifts all bits one position up, and place the new bit in the least significant position. Now decoding function   allows one to retrieve the previous   and this added bit:  . We can start with   initial state, then use the   function on the successive bits of a finite bit sequence to obtain a final   number storing this entire sequence. Then using   function multiple times until   allows one to retrieve the bit sequence in reversed order.

The above procedure is optimal for the uniform (symmetric) probability distribution of symbols  . ANS generalize it to make it optimal for any chosen (asymmetric) probability distribution of symbols:  . While   in the above example was choosing between even and odd  , in ANS this even/odd division of natural numbers is replaced with division into subsets having densities corresponding to the assumed probability distribution  : up to position  , there are approximately   occurrences of symbol  .

The coding function   returns the  -th appearance from such subset corresponding to symbol  . The density assumption is equivalent to condition  . Assuming that a natural number   contains   bits of information,  . Hence the symbol of probability   is encoded as containing   bits of information as it is required from entropy coders.

Variants edit

Uniform binary variant (uABS) edit

Let us start with the binary alphabet and a probability distribution  ,  . Up to position   we want approximately   analogues of odd numbers (for  ). We can choose this number of appearances as  , getting  . This variant is called uABS and leads to the following decoding and encoding functions:[23]

Decoding:

s = ceil((x+1)*p) - ceil(x*p) // 0 if fract(x*p) < 1-p, else 1 if s = 0 then new_x = x - ceil(x*p) // D(x) = (new_x, 0), this is the same as new_x = floor(x*(1-p)) if s = 1 then new_x = ceil(x*p) // D(x) = (new_x, 1) 

Encoding:

if s = 0 then new_x = ceil((x+1)/(1-p)) - 1 // C(x,0) = new_x if s = 1 then new_x = floor(x/p) // C(x,1) = new_x 

For   it amounts to the standard binary system (with 0 and 1 inverted), for a different   it becomes optimal for this given probability distribution. For example, for   these formulas lead to a table for small values of  :

  0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  0 1 2 3 4 5 6 7 8 9 10 11 12 13
  0 1 2 3 4 5 6

The symbol   corresponds to a subset of natural numbers with density  , which in this case are positions  . As  , these positions increase by 3 or 4. Because   here, the pattern of symbols repeats every 10 positions.

The coding   can be found by taking the row corresponding to a given symbol  , and choosing the given   in this row. Then the top row provides  . For example,   from the middle to the top row.

Imagine we would like to encode the sequence '0100' starting from  . First   takes us to  , then   to  , then   to  , then   to  . By using the decoding function   on this final  , we can retrieve the symbol sequence. Using the table for this purpose,   in the first row determines the column, then the non-empty row and the written value determine the corresponding   and  .

Range variants (rANS) and streaming edit

The range variant also uses arithmetic formulas, but allows operation on a large alphabet. Intuitively, it divides the set of natural numbers into size   ranges, and split each of them in identical way into subranges of proportions given by the assumed probability distribution.

We start with quantization of probability distribution to   denominator, where n is chosen (usually 8-12 bits):   for some natural   numbers (sizes of subranges).

Denote  , and a cumulative distribution function:

 

Note here that the CDF[s] function is not a true CDF in that the current symbol's probability is not included in the expression's value. Instead, the CDF[s] represents the total probability of all previous symbols. Example: Instead of the normal definition of CDF[0] = f[0], it is evaluated as CDF[0] = 0, since there are no previous symbols.

For   denote function (usually tabled)

symbol(y) = s such that CDF[s] <= y < CDF[s+1] 

Now coding function is:

C(x,s) = (floor(x / f[s]) << n) + (x % f[s]) + CDF[s] 

Decoding: s = symbol(x & mask)

D(x) = (f[s] * (x >> n) + (x & mask ) - CDF[s], s) 

This way we can encode a sequence of symbols into a large natural number x. To avoid using large number arithmetic, in practice stream variants are used: which enforce   by renormalization: sending the least significant bits of x to or from the bitstream (usually L and b are powers of 2).

In rANS variant x is for example 32 bit. For 16 bit renormalization,  , decoder refills the least significant bits from the bitstream when needed:

if(x < (1 << 16)) x = (x << 16) + read16bits() 

Tabled variant (tANS) edit

 
Simple example of 4 state ANS automaton for Pr(a) = 3/4, Pr(b) = 1/4 probability distribution. Symbol b contains −lg(1/4) = 2 bits of information and so it always produces two bits. In contrast, symbol a contains −lg(3/4) ~ 0.415 bits of information, hence sometimes it produces one bit (from state 6 and 7), sometimes 0 bits (from state 4 and 5), only increasing the state, which acts as buffer containing fractional number of bits: lg(x). The number of states in practice is for example 2048, for 256 size alphabet (to directly encode bytes).

tANS variant puts the entire behavior (including renormalization) for   into a table which yields a finite-state machine avoiding the need of multiplication.

Finally, the step of the decoding loop can be written as:

t = decodingTable(x);  x = t.newX + readBits(t.nbBits); //state transition writeSymbol(t.symbol); //decoded symbol 

The step of the encoding loop:

s = ReadSymbol(); nbBits = (x + ns[s]) >> r; // # of bits for renormalization writeBits(x, nbBits); // send the least significant bits to bitstream x = encodingTable[start[s] + (x >> nbBits)]; 

A specific tANS coding is determined by assigning a symbol to every   position, their number of appearances should be proportional to the assumed probabilities. For example, one could choose "abdacdac" assignment for Pr(a)=3/8, Pr(b)=1/8, Pr(c)=2/8, Pr(d)=2/8 probability distribution. If symbols are assigned in ranges of lengths being powers of 2, we would get Huffman coding. For example, a->0, b->100, c->101, d->11 prefix code would be obtained for tANS with "aaaabcdd" symbol assignment.

 
Example of generation of tANS tables for m = 3 size alphabet and L = 16 states, then applying them for stream decoding. First we approximate probabilities using fraction with denominator being the number of states. Then we spread these symbols in nearly uniform way, optionally the details may depend on cryptographic key for simultaneous encryption. Then we enumerate the appearances starting with value being their amount for a given symbol. Then we refill the youngests bits from the stream to return to the assumed range for x (renormalization).

Remarks edit

As for Huffman coding, modifying the probability distribution of tANS is relatively costly, hence it is mainly used in static situations, usually with some Lempel–Ziv scheme (e.g. ZSTD, LZFSE). In this case, the file is divided into blocks - for each of them symbol frequencies are independently counted, then after approximation (quantization) written in the block header and used as static probability distribution for tANS.

In contrast, rANS is usually used as a faster replacement for range coding (e.g. CRAM, LZNA, Draco,[14]). It requires multiplication, but is more memory efficient and is appropriate for dynamically adapting probability distributions.

Encoding and decoding of ANS are performed in opposite directions, making it a stack for symbols. This inconvenience is usually resolved by encoding in backward direction, after which decoding can be done forward. For context-dependence, like Markov model, the encoder needs to use context from the perspective of later decoding. For adaptivity, the encoder should first go forward to find probabilities which will be used (predicted) by decoder and store them in a buffer, then encode in backward direction using the buffered probabilities.

The final state of encoding is required to start decoding, hence it needs to be stored in the compressed file. This cost can be compensated by storing some information in the initial state of encoder. For example, instead of starting with "10000" state, start with "1****" state, where "*" are some additional stored bits, which can be retrieved at the end of the decoding. Alternatively, this state can be used as a checksum by starting encoding with a fixed state, and testing if the final state of decoding is the expected one.

Patent controversy edit

The author of the novel ANS algorithm and its variants tANS and rANS specifically intended his work to be available freely in the public domain, for altruistic reasons. He has not sought to profit from them and took steps to ensure they would not become a "legal minefield", or restricted by, or profited from by others. In 2015, Google published a US and then worldwide patent for "Mixed boolean-token ans coefficient coding".[24] At the time, Professor Duda had been asked by Google to help it with video compression, so was intimately aware of this domain, having the original author assisting them.

Duda was not pleased by (accidentally) discovering Google's patent intentions, given he had been clear he wanted it as public domain, and had assisted Google specifically on that basis. Duda subsequently filed a third-party application[25] to the US Patent office seeking a rejection. The USPTO rejected its application in 2018, and Google subsequently abandoned the patent.[26]

In June 2019 Microsoft lodged a patent application called "Features of range asymmetric number system encoding and decoding".[27] The USPTO issued a final rejection of the application on October 27, 2020. Yet on March 2, 2021, Microsoft gave a USPTO explanatory filing stating "The Applicant respectfully disagrees with the rejections.",[28] seeking to overturn the final rejection under the "After Final Consideration Pilot 2.0" program.[29] After reconsideration, the USPTO granted the application on January 25, 2022.[30]

See also edit

References edit

  1. ^ J. Duda, K. Tahboub, N. J. Gadil, E. J. Delp, The use of asymmetric numeral systems as an accurate replacement for Huffman coding, Picture Coding Symposium, 2015.
  2. ^ J. Duda, Asymmetric numeral systems: entropy coding combining speed of Huffman coding with compression rate of arithmetic coding, arXiv:1311.2540, 2013.
  3. ^ "Dr Jarosław Duda (Jarek Duda)". Institute of Theoretical Physics. Jagiellonian University in Krakow. Retrieved 2021-08-02.
  4. ^ Duda, Jarek (October 6, 2019). "List of compressors using ANS, implementations and other materials". Retrieved October 6, 2019.
  5. ^ "Google Accused of Trying to Patent Public Domain Technology". Bleeping Computer. September 11, 2017.
  6. ^ Smaller and faster data compression with Zstandard, Facebook, August 2016.
  7. ^ 5 ways Facebook improved compression at scale with Zstandard, Facebook, December 2018.
  8. ^ Zstd Compression For Btrfs & Squashfs Set For Linux 4.14, Already Used Within Facebook, Phoronix, September 2017.
  9. ^ New in Chrome 123 (Content-Encoding), Google, March 2024.
  10. ^ . Archived from the original on 2020-08-26. Retrieved 2019-05-29.
  11. ^ Zstandard Compression and The application/zstd Media Type (email standard).
  12. ^ Hypertext Transfer Protocol (HTTP) Parameters, IANA.
  13. ^ Apple Open-Sources its New Compression Algorithm LZFSE, InfoQ, July 2016.
  14. ^ a b Google Draco 3D compression library.
  15. ^ Google and Pixar add Draco Compression to Universal Scene Description (USD) Format .
  16. ^ Google PIK: new lossy image format for the internet.
  17. ^ CRAM format specification (version 3.0).
  18. ^ Chen W, Elliott LT (2021). "Compression for population genetic data through finite-state entropy". J Bioinform Comput Biol. 19 (5): 2150026. doi:10.1142/S0219720021500268. PMID 34590992.
  19. ^ High Speed Data Compression Using NVIDIA GPUs.
  20. ^ Building better compression together with DivANS.
  21. ^ Microsoft DirectStorage overview.
  22. ^ Rhatushnyak, Alexander; Wassenberg, Jan; Sneyers, Jon; Alakuijala, Jyrki; Vandevenne, Lode; Versari, Luca; Obryk, Robert; Szabadka, Zoltan; Kliuchnikov, Evgenii; Comsa, Iulia-Maria; Potempa, Krzysztof; Bruse, Martin; Firsching, Moritz; Khasanova, Renata; Ruud van Asseldonk; Boukortt, Sami; Gomez, Sebastian; Fischbacher, Thomas (2019). "Committee Draft of JPEG XL Image Coding System". arXiv:1908.03565 [eess.IV].
  23. ^ Data Compression Explained, Matt Mahoney
  24. ^ "Mixed boolean-token ans coefficient coding". Retrieved 14 June 2021.
  25. ^ "Protest to Google" (PDF). Institute of Theoretical Physics. Jagiellonian University in Krakow Poland. Professor Jarosław Duda.
  26. ^ "After Patent Office Rejection, It is Time For Google To Abandon Its Attempt to Patent Use of Public Domain Algorithm". EFF. 30 August 2018.
  27. ^ "Features of range asymmetric number system encoding and decoding". Retrieved 14 June 2021.
  28. ^ "Third time's a harm? Microsoft tries to get twice-rejected compression patent past skeptical examiners". The Register. Retrieved 14 June 2021.
  29. ^ "After Final Consideration Pilot 2.0". United States Patent and Trademark Office. Retrieved 14 June 2021.
  30. ^ "Features of range asymmetric number system encoding and decoding". Retrieved 16 February 2022.

External links edit

  • High throughput hardware architectures for asymmetric numeral systems entropy coding S. M. Najmabadi, Z. Wang, Y. Baroud, S. Simon, ISPA 2015
  • New Generation Entropy coders Finite state entropy (FSE) implementation of tANS by Yann Collet
  • rygorous/ryg_rans Implementation of rANS by Fabian Giesen
  • jkbonfield/rans_static Fast implementation of rANS and aritmetic coding by James K. Bonfield
  • facebook/zstd Facebook Zstandard compressor by Yann Collet (author of LZ4)
  • LZFSE LZFSE compressor (LZ+FSE) of Apple Inc.
  • CRAM 3.0 DNA compressor (order 1 rANS) (part of SAMtools) by European Bioinformatics Institute
  • [1] implementation for Google VP10
  • [2] implementation for Google WebP
  • [3] Google Draco 3D compression library
  • aom_dsp - aom - Git at Google implementation of Alliance for Open Media
  • Data Compression Using Asymmetric Numeral Systems - Wolfram Demonstrations Project Wolfram Demonstrations Project
  • GST: GPU-decodable Supercompressed Textures GST: GPU-decodable Supercompressed Textures
  • Understanding compression book by A. Haecky, C. McAnlis

asymmetric, numeral, systems, this, article, includes, list, general, references, lacks, sufficient, corresponding, inline, citations, please, help, improve, this, article, introducing, more, precise, citations, 2017, learn, when, remove, this, message, family. This article includes a list of general references but it lacks sufficient corresponding inline citations Please help to improve this article by introducing more precise citations May 2017 Learn how and when to remove this message Asymmetric numeral systems ANS 1 2 is a family of entropy encoding methods introduced by Jaroslaw Jarek Duda 3 from Jagiellonian University used in data compression since 2014 4 due to improved performance compared to previous methods 5 ANS combines the compression ratio of arithmetic coding which uses a nearly accurate probability distribution with a processing cost similar to that of Huffman coding In the tabled ANS tANS variant this is achieved by constructing a finite state machine to operate on a large alphabet without using multiplication Among others ANS is used in the Facebook Zstandard compressor 6 7 also used e g in Linux kernel 8 Google Chrome browser 9 Android 10 operating system was published as RFC 8478 for MIME 11 and HTTP 12 Apple LZFSE compressor 13 Google Draco 3D compressor 14 used e g in Pixar Universal Scene Description format 15 and PIK image compressor 16 CRAM DNA compressor 17 from SAMtools utilities 18 NVIDIA nvCOMP high speed compression library 19 Dropbox DivANS compressor 20 Microsoft DirectStorage BCPack texture compressor 21 and JPEG XL 22 image compressor The basic idea is to encode information into a single natural number x displaystyle x In the standard binary number system we can add a bit s 0 1 displaystyle s in 0 1 of information to x displaystyle x by appending s displaystyle s at the end of x displaystyle x which gives us x 2 x s displaystyle x 2x s For an entropy coder this is optimal if Pr 0 Pr 1 1 2 displaystyle Pr 0 Pr 1 1 2 ANS generalizes this process for arbitrary sets of symbols s S displaystyle s in S with an accompanying probability distribution p s s S displaystyle p s s in S In ANS if the information from s displaystyle s is appended to x displaystyle x to result in x displaystyle x then x x p s 1 displaystyle x approx x cdot p s 1 Equivalently log 2 x log 2 x log 2 1 p s displaystyle log 2 x approx log 2 x log 2 1 p s where log 2 x displaystyle log 2 x is the number of bits of information stored in the number x displaystyle x and log 2 1 p s displaystyle log 2 1 p s is the number of bits contained in the symbol s displaystyle s For the encoding rule the set of natural numbers is split into disjoint subsets corresponding to different symbols like into even and odd numbers but with densities corresponding to the probability distribution of the symbols to encode Then to add information from symbol s displaystyle s into the information already stored in the current number x displaystyle x we go to number x C x s x p displaystyle x C x s approx x p being the position of the x displaystyle x th appearance from the s displaystyle s th subset There are alternative ways to apply it in practice direct mathematical formulas for encoding and decoding steps uABS and rANS variants or one can put the entire behavior into a table tANS variant Renormalization is used to prevent x displaystyle x going to infinity transferring accumulated bits to or from the bitstream Contents 1 Entropy coding 1 1 Motivating examples 2 Basic concepts of ANS 3 Variants 3 1 Uniform binary variant uABS 3 2 Range variants rANS and streaming 3 3 Tabled variant tANS 4 Remarks 5 Patent controversy 6 See also 7 References 8 External linksEntropy coding editSuppose a sequence of 1 000 zeros and ones would be encoded which would take 1000 bits to store directly However if it is somehow known that it only contains 1 zero and 999 ones it would be sufficient to encode the zero s position which requires only log 2 1000 10 displaystyle lceil log 2 1000 rceil approx 10 nbsp bits here instead of the original 1000 bits Generally such length n displaystyle n nbsp sequences containing p n displaystyle pn nbsp zeros and 1 p n displaystyle 1 p n nbsp ones for some probability p 0 1 displaystyle p in 0 1 nbsp are called combinations Using Stirling s approximation we get their asymptotic number being n p n 2 n h p for large n and h p p log 2 p 1 p log 2 1 p displaystyle n choose pn approx 2 nh p text for large n text and h p p log 2 p 1 p log 2 1 p nbsp called Shannon entropy Hence to choose one such sequence we need approximately n h p displaystyle nh p nbsp bits It is still n displaystyle n nbsp bits if p 1 2 displaystyle p 1 2 nbsp however it can also be much smaller For example we need only n 2 displaystyle approx n 2 nbsp bits for p 0 11 displaystyle p 0 11 nbsp An entropy coder allows the encoding of a sequence of symbols using approximately the Shannon entropy bits per symbol For example ANS could be directly used to enumerate combinations assign a different natural number to every sequence of symbols having fixed proportions in a nearly optimal way In contrast to encoding combinations this probability distribution usually varies in data compressors For this purpose Shannon entropy can be seen as a weighted average a symbol of probability p displaystyle p nbsp contains log 2 1 p displaystyle log 2 1 p nbsp bits of information ANS encodes information into a single natural number x displaystyle x nbsp interpreted as containing log 2 x displaystyle log 2 x nbsp bits of information Adding information from a symbol of probability p displaystyle p nbsp increases this informational content to log 2 x log 2 1 p log 2 x p displaystyle log 2 x log 2 1 p log 2 x p nbsp Hence the new number containing both information should be x x p displaystyle x approx x p nbsp Motivating examples edit Consider a source with 3 letters A B C with probability 1 2 1 4 1 4 It is simple to construct the optimal prefix code in binary A 0 B 10 C 11 Then a message is encoded as ABC gt 01011 We see that an equivalent method for performing the encoding is as follows Start with number 1 and perform an operation on the number for each input letter A multiply by 2 B multiply by 4 add 2 C multiply by 4 add 3 Express the number in binary then remove the first digit 1 Consider a more general source with k letters with rational probabilities n 1 N n k N displaystyle n 1 N n k N nbsp Then performing arithmetic coding on the source requires only exact arithmetic with integers In general ANS is an approximation of arithmetic coding that approximates the real probabilities r 1 r k displaystyle r 1 r k nbsp by rational numbers n 1 N n k N displaystyle n 1 N n k N nbsp with a small denominator N displaystyle N nbsp Basic concepts of ANS edit nbsp Comparison of the concept of arithmetic coding left and ANS right Both can be seen as generalizations of standard numeral systems optimal for uniform probability distribution of digits into optimized for some chosen probability distribution Arithmetic or range coding corresponds to adding new information in the most significant position while ANS generalizes adding information in the least significant position Its coding rule is x goes to x th appearance of subset of natural numbers corresponding to currently encoded symbol In the presented example sequence 01111 is encoded into a natural number 18 which is smaller than 47 obtained by using standard binary system due to better agreement with frequencies of sequence to encode The advantage of ANS is storing information in a single natural number in contrast to two defining a range Imagine there is some information stored in a natural number x displaystyle x nbsp for example as bit sequence of its binary expansion To add information from a binary variable s displaystyle s nbsp we can use coding function x C x s 2 x s displaystyle x C x s 2x s nbsp which shifts all bits one position up and place the new bit in the least significant position Now decoding function D x x 2 m o d x 2 displaystyle D x lfloor x 2 rfloor mathrm mod x 2 nbsp allows one to retrieve the previous x displaystyle x nbsp and this added bit D C x s x s C D x x displaystyle D C x s x s C D x x nbsp We can start with x 1 displaystyle x 1 nbsp initial state then use the C displaystyle C nbsp function on the successive bits of a finite bit sequence to obtain a final x displaystyle x nbsp number storing this entire sequence Then using D displaystyle D nbsp function multiple times until x 1 displaystyle x 1 nbsp allows one to retrieve the bit sequence in reversed order The above procedure is optimal for the uniform symmetric probability distribution of symbols Pr 0 Pr 1 1 2 displaystyle Pr 0 Pr 1 1 2 nbsp ANS generalize it to make it optimal for any chosen asymmetric probability distribution of symbols Pr s p s displaystyle Pr s p s nbsp While s displaystyle s nbsp in the above example was choosing between even and odd C x s displaystyle C x s nbsp in ANS this even odd division of natural numbers is replaced with division into subsets having densities corresponding to the assumed probability distribution p s s displaystyle p s s nbsp up to position x displaystyle x nbsp there are approximately x p s displaystyle xp s nbsp occurrences of symbol s displaystyle s nbsp The coding function C x s displaystyle C x s nbsp returns the x displaystyle x nbsp th appearance from such subset corresponding to symbol s displaystyle s nbsp The density assumption is equivalent to condition x C x s x p s displaystyle x C x s approx x p s nbsp Assuming that a natural number x displaystyle x nbsp contains log 2 x displaystyle log 2 x nbsp bits of information log 2 C x s log 2 x log 2 1 p s displaystyle log 2 C x s approx log 2 x log 2 1 p s nbsp Hence the symbol of probability p s displaystyle p s nbsp is encoded as containing log 2 1 p s displaystyle approx log 2 1 p s nbsp bits of information as it is required from entropy coders Variants editUniform binary variant uABS edit Let us start with the binary alphabet and a probability distribution Pr 1 p displaystyle Pr 1 p nbsp Pr 0 1 p displaystyle Pr 0 1 p nbsp Up to position x displaystyle x nbsp we want approximately p x displaystyle p cdot x nbsp analogues of odd numbers for s 1 displaystyle s 1 nbsp We can choose this number of appearances as x p displaystyle lceil x cdot p rceil nbsp getting s x 1 p x p displaystyle s lceil x 1 cdot p rceil lceil x cdot p rceil nbsp This variant is called uABS and leads to the following decoding and encoding functions 23 Decoding s ceil x 1 p ceil x p 0 if fract x p lt 1 p else 1 if s 0 then new x x ceil x p D x new x 0 this is the same as new x floor x 1 p if s 1 then new x ceil x p D x new x 1 Encoding if s 0 then new x ceil x 1 1 p 1 C x 0 new x if s 1 then new x floor x p C x 1 new x For p 1 2 displaystyle p 1 2 nbsp it amounts to the standard binary system with 0 and 1 inverted for a different p displaystyle p nbsp it becomes optimal for this given probability distribution For example for p 0 3 displaystyle p 0 3 nbsp these formulas lead to a table for small values of x displaystyle x nbsp C x s displaystyle C x s nbsp 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 s 0 displaystyle s 0 nbsp 0 1 2 3 4 5 6 7 8 9 10 11 12 13 s 1 displaystyle s 1 nbsp 0 1 2 3 4 5 6 The symbol s 1 displaystyle s 1 nbsp corresponds to a subset of natural numbers with density p 0 3 displaystyle p 0 3 nbsp which in this case are positions 0 3 6 10 13 16 20 23 26 displaystyle 0 3 6 10 13 16 20 23 26 ldots nbsp As 1 4 lt 0 3 lt 1 3 displaystyle 1 4 lt 0 3 lt 1 3 nbsp these positions increase by 3 or 4 Because p 3 10 displaystyle p 3 10 nbsp here the pattern of symbols repeats every 10 positions The coding C x s displaystyle C x s nbsp can be found by taking the row corresponding to a given symbol s displaystyle s nbsp and choosing the given x displaystyle x nbsp in this row Then the top row provides C x s displaystyle C x s nbsp For example C 7 0 11 displaystyle C 7 0 11 nbsp from the middle to the top row Imagine we would like to encode the sequence 0100 starting from x 1 displaystyle x 1 nbsp First s 0 displaystyle s 0 nbsp takes us to x 2 displaystyle x 2 nbsp then s 1 displaystyle s 1 nbsp to x 6 displaystyle x 6 nbsp then s 0 displaystyle s 0 nbsp to x 9 displaystyle x 9 nbsp then s 0 displaystyle s 0 nbsp to x 14 displaystyle x 14 nbsp By using the decoding function D x displaystyle D x nbsp on this final x displaystyle x nbsp we can retrieve the symbol sequence Using the table for this purpose x displaystyle x nbsp in the first row determines the column then the non empty row and the written value determine the corresponding s displaystyle s nbsp and x displaystyle x nbsp Range variants rANS and streaming edit The range variant also uses arithmetic formulas but allows operation on a large alphabet Intuitively it divides the set of natural numbers into size 2 n displaystyle 2 n nbsp ranges and split each of them in identical way into subranges of proportions given by the assumed probability distribution We start with quantization of probability distribution to 2 n displaystyle 2 n nbsp denominator where n is chosen usually 8 12 bits p s f s 2 n displaystyle p s approx f s 2 n nbsp for some natural f s displaystyle f s nbsp numbers sizes of subranges Denote mask 2 n 1 displaystyle text mask 2 n 1 nbsp and a cumulative distribution function CDF s i lt s f i f 0 f s 1 displaystyle operatorname CDF s sum i lt s f i f 0 cdots f s 1 nbsp Note here that the span class n CDF span span class p span span class n s span span class p span function is not a true CDF in that the current symbol s probability is not included in the expression s value Instead the span class n CDF span span class p span span class n s span span class p span represents the total probability of all previous symbols Example Instead of the normal definition of span class n CDF span span class p span span class mi 0 span span class p span span class w span span class o span span class w span span class n f span span class p span span class mi 0 span span class p span it is evaluated as span class n CDF span span class p span span class mi 0 span span class p span span class w span span class o span span class w span span class mi 0 span since there are no previous symbols For y 0 2 n 1 displaystyle y in 0 2 n 1 nbsp denote function usually tabled symbol y s such that CDF s lt y lt CDF s 1 Now coding function is C x s floor x f s lt lt n x f s CDF s Decoding span class n s span span class w span span class o span span class w span span class n symbol span span class p span span class n x span span class w span span class o amp span span class w span span class n mask span span class p span D x f s x gt gt n x amp mask CDF s s This way we can encode a sequence of symbols into a large natural number x To avoid using large number arithmetic in practice stream variants are used which enforce x L b L 1 displaystyle x in L b cdot L 1 nbsp by renormalization sending the least significant bits of x to or from the bitstream usually L and b are powers of 2 In rANS variant x is for example 32 bit For 16 bit renormalization x 2 16 2 32 1 displaystyle x in 2 16 2 32 1 nbsp decoder refills the least significant bits from the bitstream when needed if x lt 1 lt lt 16 x x lt lt 16 read16bits Tabled variant tANS edit nbsp Simple example of 4 state ANS automaton for Pr a 3 4 Pr b 1 4 probability distribution Symbol b contains lg 1 4 2 bits of information and so it always produces two bits In contrast symbol a contains lg 3 4 0 415 bits of information hence sometimes it produces one bit from state 6 and 7 sometimes 0 bits from state 4 and 5 only increasing the state which acts as buffer containing fractional number of bits lg x The number of states in practice is for example 2048 for 256 size alphabet to directly encode bytes tANS variant puts the entire behavior including renormalization for x L 2 L 1 displaystyle x in L 2L 1 nbsp into a table which yields a finite state machine avoiding the need of multiplication Finally the step of the decoding loop can be written as t decodingTable x x t newX readBits t nbBits state transition writeSymbol t symbol decoded symbol The step of the encoding loop s ReadSymbol nbBits x ns s gt gt r of bits for renormalization writeBits x nbBits send the least significant bits to bitstream x encodingTable start s x gt gt nbBits A specific tANS coding is determined by assigning a symbol to every L 2 L 1 displaystyle L 2L 1 nbsp position their number of appearances should be proportional to the assumed probabilities For example one could choose abdacdac assignment for Pr a 3 8 Pr b 1 8 Pr c 2 8 Pr d 2 8 probability distribution If symbols are assigned in ranges of lengths being powers of 2 we would get Huffman coding For example a gt 0 b gt 100 c gt 101 d gt 11 prefix code would be obtained for tANS with aaaabcdd symbol assignment nbsp Example of generation of tANS tables for m 3 size alphabet and L 16 states then applying them for stream decoding First we approximate probabilities using fraction with denominator being the number of states Then we spread these symbols in nearly uniform way optionally the details may depend on cryptographic key for simultaneous encryption Then we enumerate the appearances starting with value being their amount for a given symbol Then we refill the youngests bits from the stream to return to the assumed range for x renormalization Remarks editAs for Huffman coding modifying the probability distribution of tANS is relatively costly hence it is mainly used in static situations usually with some Lempel Ziv scheme e g ZSTD LZFSE In this case the file is divided into blocks for each of them symbol frequencies are independently counted then after approximation quantization written in the block header and used as static probability distribution for tANS In contrast rANS is usually used as a faster replacement for range coding e g CRAM LZNA Draco 14 It requires multiplication but is more memory efficient and is appropriate for dynamically adapting probability distributions Encoding and decoding of ANS are performed in opposite directions making it a stack for symbols This inconvenience is usually resolved by encoding in backward direction after which decoding can be done forward For context dependence like Markov model the encoder needs to use context from the perspective of later decoding For adaptivity the encoder should first go forward to find probabilities which will be used predicted by decoder and store them in a buffer then encode in backward direction using the buffered probabilities The final state of encoding is required to start decoding hence it needs to be stored in the compressed file This cost can be compensated by storing some information in the initial state of encoder For example instead of starting with 10000 state start with 1 state where are some additional stored bits which can be retrieved at the end of the decoding Alternatively this state can be used as a checksum by starting encoding with a fixed state and testing if the final state of decoding is the expected one Patent controversy editThe author of the novel ANS algorithm and its variants tANS and rANS specifically intended his work to be available freely in the public domain for altruistic reasons He has not sought to profit from them and took steps to ensure they would not become a legal minefield or restricted by or profited from by others In 2015 Google published a US and then worldwide patent for Mixed boolean token ans coefficient coding 24 At the time Professor Duda had been asked by Google to help it with video compression so was intimately aware of this domain having the original author assisting them Duda was not pleased by accidentally discovering Google s patent intentions given he had been clear he wanted it as public domain and had assisted Google specifically on that basis Duda subsequently filed a third party application 25 to the US Patent office seeking a rejection The USPTO rejected its application in 2018 and Google subsequently abandoned the patent 26 In June 2019 Microsoft lodged a patent application called Features of range asymmetric number system encoding and decoding 27 The USPTO issued a final rejection of the application on October 27 2020 Yet on March 2 2021 Microsoft gave a USPTO explanatory filing stating The Applicant respectfully disagrees with the rejections 28 seeking to overturn the final rejection under the After Final Consideration Pilot 2 0 program 29 After reconsideration the USPTO granted the application on January 25 2022 30 See also editEntropy encoding Huffman coding Arithmetic coding Range encoding Zstandard Facebook compressor LZFSE Apple compressorReferences edit J Duda K Tahboub N J Gadil E J Delp The use of asymmetric numeral systems as an accurate replacement for Huffman coding Picture Coding Symposium 2015 J Duda Asymmetric numeral systems entropy coding combining speed of Huffman coding with compression rate of arithmetic coding arXiv 1311 2540 2013 Dr Jaroslaw Duda Jarek Duda Institute of Theoretical Physics Jagiellonian University in Krakow Retrieved 2021 08 02 Duda Jarek October 6 2019 List of compressors using ANS implementations and other materials Retrieved October 6 2019 Google Accused of Trying to Patent Public Domain Technology Bleeping Computer September 11 2017 Smaller and faster data compression with Zstandard Facebook August 2016 5 ways Facebook improved compression at scale with Zstandard Facebook December 2018 Zstd Compression For Btrfs amp Squashfs Set For Linux 4 14 Already Used Within Facebook Phoronix September 2017 New in Chrome 123 Content Encoding Google March 2024 Zstd in Android P release Archived from the original on 2020 08 26 Retrieved 2019 05 29 Zstandard Compression and The application zstd Media Type email standard Hypertext Transfer Protocol HTTP Parameters IANA Apple Open Sources its New Compression Algorithm LZFSE InfoQ July 2016 a b Google Draco 3D compression library Google and Pixar add Draco Compression to Universal Scene Description USD Format Google PIK new lossy image format for the internet CRAM format specification version 3 0 Chen W Elliott LT 2021 Compression for population genetic data through finite state entropy J Bioinform Comput Biol 19 5 2150026 doi 10 1142 S0219720021500268 PMID 34590992 High Speed Data Compression Using NVIDIA GPUs Building better compression together with DivANS Microsoft DirectStorage overview Rhatushnyak Alexander Wassenberg Jan Sneyers Jon Alakuijala Jyrki Vandevenne Lode Versari Luca Obryk Robert Szabadka Zoltan Kliuchnikov Evgenii Comsa Iulia Maria Potempa Krzysztof Bruse Martin Firsching Moritz Khasanova Renata Ruud van Asseldonk Boukortt Sami Gomez Sebastian Fischbacher Thomas 2019 Committee Draft of JPEG XL Image Coding System arXiv 1908 03565 eess IV Data Compression Explained Matt Mahoney Mixed boolean token ans coefficient coding Retrieved 14 June 2021 Protest to Google PDF Institute of Theoretical Physics Jagiellonian University in Krakow Poland Professor Jaroslaw Duda After Patent Office Rejection It is Time For Google To Abandon Its Attempt to Patent Use of Public Domain Algorithm EFF 30 August 2018 Features of range asymmetric number system encoding and decoding Retrieved 14 June 2021 Third time s a harm Microsoft tries to get twice rejected compression patent past skeptical examiners The Register Retrieved 14 June 2021 After Final Consideration Pilot 2 0 United States Patent and Trademark Office Retrieved 14 June 2021 Features of range asymmetric number system encoding and decoding Retrieved 16 February 2022 External links editHigh throughput hardware architectures for asymmetric numeral systems entropy coding S M Najmabadi Z Wang Y Baroud S Simon ISPA 2015 New Generation Entropy coders Finite state entropy FSE implementation of tANS by Yann Collet rygorous ryg rans Implementation of rANS by Fabian Giesen jkbonfield rans static Fast implementation of rANS and aritmetic coding by James K Bonfield facebook zstd Facebook Zstandard compressor by Yann Collet author of LZ4 LZFSE LZFSE compressor LZ FSE of Apple Inc CRAM 3 0 DNA compressor order 1 rANS part of SAMtools by European Bioinformatics Institute 1 implementation for Google VP10 2 implementation for Google WebP 3 Google Draco 3D compression library aom dsp aom Git at Google implementation of Alliance for Open Media Data Compression Using Asymmetric Numeral Systems Wolfram Demonstrations Project Wolfram Demonstrations Project GST GPU decodable Supercompressed Textures GST GPU decodable Supercompressed Textures Understanding compression book by A Haecky C McAnlis Retrieved from https en wikipedia org w index php title Asymmetric numeral systems amp oldid 1215829186, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.