You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1) An optional parameter named save_stages is added to the constructor of the ArithmeticEncoding class. If True, then the intervals of each stage are saved in a list. Note that setting save_stages=True may cause memory overflow if the message is large
2) The decoded message returned by the decode() method is always a list.
3) The order of the returned values by the the encode() and decode() method changed.
4) Added an example in the example_image.py script to encode and decode an image.
Copy file name to clipboardExpand all lines: README.md
+33-15
Original file line number
Diff line number
Diff line change
@@ -24,14 +24,20 @@ import pyae
24
24
25
25
## Instantiate the `ArithmeticEncoding` Class
26
26
27
-
Create an instance of the `ArithmeticEncoding` class. Its constructor accepts the frequency table which is a dictionary mapping each possible character to its frequency. According to this frequency table, the messages to be encoded/decoded must have only the 3 characters **a**, **b**, and **c**.
27
+
Create an instance of the `ArithmeticEncoding` class. Its constructor accepts 2 arguments:
28
+
29
+
1.`frequency_table`: The frequency table as a dictionary where key is the symbol and value is the frequency.
30
+
2.`save_stages`: If `True`, then the intervals of each stage are saved in a list. Note that setting `save_stages=True` may cause memory overflow if the message is large
31
+
32
+
According to the following frequency table, the messages to be encoded/decoded must have only the 3 characters **a**, **b**, and **c**.
Encode the message using the `encode()` method. It accepts the message to be encoded and the probability table. It returns the encoder and the encoded message (single double value).
53
+
Encode the message using the `encode()` method. It accepts the message to be encoded and the probability table. It returns the encoded message (single double value) and the encoder stages.
48
54
49
55
```python
50
-
encoder, encoded_msg=AE.encode(msg=original_msg,
56
+
encoded_msg, encoder=AE.encode(msg=original_msg,
51
57
probability_table=AE.probability_table)
52
58
```
53
59
54
60
## Decode the Message
55
61
56
-
Decode the message using the `decode()` method. It accepts the encoded message, message length, and the probability table. It returns the decoder and the decoded message.
62
+
Decode the message using the `decode()` method. It accepts the encoded message, message length, and the probability table. It returns the decoded message and the decoder stages.
Note that the symbols in the decoded message are returned in a `list`. If the original message is a string, then consider converting the list into a string using `join()` function as follows.
71
+
72
+
```python
73
+
decoded_msg ="".join(decoded_msg)
74
+
```
75
+
64
76
# <u>IMPORTANT</u>: `double` Module
65
77
66
78
The floating-point numbers in Python are limited to a certain precision. Beyond it, Python cannot store any additional decimal numbers. This is why the project uses the double data type offered by the [`decimal` module](https://docs.python.org/2/library/decimal.html).
0 commit comments