April 25, 2013

Adaptive Coding

For this week's class information theory and coding methods, we were given the task of thinking, implement and evaluate our own adaptive coding method.

An adaptive coding means that the program has no previous knowledge of the distribution of the symbols.

The method that I implement is very simple and dummy, that truth is that I don't understand very well how I have to do this. My method consists in given a file the program read it and takes the first 4 words, pass them to the encoder and for each letter of the words it creates a random code of 8 bits and looks in a table (dictionary) if it is not in this table is added, otherwise another code is created until it is not in the table. This is done until there is no words to encode, then the table and a counter of how many symbols are in the table, are added at the end of the file because it is needed to decompress it.

To decompress the file first reads all the bin file (compressed file) ant takes the last byte that is the counter n. With this counter the program reads the last n lines and makes the table. After this is just look for every byte of the compressed file in the table and get the letter that corresponds it.

This almost works because from the compressed file the program gets the original text, but without spaces, this is a thing that I have to correct.

Code.


Tests

 



As you can see in the images, using a short text in the source file the program doesn't give a compressed file with less kb.



In this one test can be appreciated that using longer file the compressed file is smaller than the original.

Size of the data obtained.

Time taken to decompressed

No comments:

Post a Comment