Decimal Module
The AE technique encodes the entire message, regardless of its length, into a single floating-point number.
In Python, the float data type is restricted to a limited number of decimal digits.
A Python float cannot accurately save a number beyond this number of decimal digits.
The exact number of digits is returned using the dig attribute in the str.
,
Decoding
The inputs for decoding are:.
1) The single value that encodes the message.
2) The frequency table.
It should be identical to the one used for encoding.
3) The number of symbols in the original message.
In our example, the value that encodes the message is 0.173.
The frequency table is [a=2, b=7, c=1].
The number of symbols in the message is.
3) The .
,
Encoding
Encoding in AE works by representing the cumulative probabilities of all symbols on a line that ranges from 0.0 to 1.0.
On that line, each symbol uses a sub-range.
Given any symbol C, it starts from the value Sand ends at the value calculated using the following equation: S+(P(C))*R Where:.
1) S: The cumulative sum of all previous probabilities. 2. .
,
Frequency Table
To encode (= compress) a message using AE, you need these inputs:.
1) The message you want to encode.
2) The frequency table of all possible symbols in the message.
The frequency table is usually calculated by analyzing different messages and concluding by the number of times each symbol is repeated.
For example: assume that the messages to be encod.
,
Overview of The Lossless Algorithm
In data compression, lossy algorithms compress data while losing some details.
They reduce the number of bits used to represent the message, even if that reduces the quality of reconstructed data.
Lossless algorithms reconstruct original data without any loss.
Because of this, they use a higher number of bits compared to lossy algorithms.
Arithmeti.
,
Python Implementation
We build the implementation of AE as a class named ArithmeticEncoding, within a module named pyae.py.
The constructor of this class accepts the frequency table, as in the next code.
The frequency table passed to this method is a dictionary where each item has a string key representing the symbol, and an integer value representing the frequency.
Her.
Data Compression and Archiving ¶ The modules described in this chapter support data compression with the zlib, gzip, bzip2 and lzma algorithms, and the creation of ZIP- and tar-format archives. See also Archiving operations provided by the shutil module.I use this to save memory in one place: import cPickle import zlib # Compress: compressed = zlib.compress (cPickle.dumps (obj)) # Get it back: obj = cPickle.loads (zlib.decompress (compressed)),In data compression, lossy algorithms compress data while losing some details