An implementation of an Encoder and Decoder for the Luby Transform Fountain code. Useful for transmitting data over very lossy channels where retry-based transmission protocols struggle.
Project description
LT-code
=======
This is an implementation of a Luby Transform code in Python, consisting of two executables, one for each encoding and decoding files. These are thin wrappers around a core stream/file API.
See _D.J.C, MacKay, 'Information theory, inference, and learning algorithms. Cambridge University Press, 2003_ for reference on the algorithms.
## Encoding
The encoding algorithm follows the given spec, so no innovations there. A few optimizations are made however. First, the CDF of the degree distribution, M(d), is precomputed for all degrees d = 1, ..., K. This CDF is represented as an array mapping index d => M(d), so sampling from the degree distribution mu(d) becomes a linear search through the CDF array looking for the bucket our random number on \[0, 1) landed in. This random number is generated as specified using the linear congruential generator.
Second, the integer representation of all blocks is held in RAM for maximum speed in block sample generation. This is a limitation on the size of the file practically encoded on most computers, but this decision does not reach far into other parts of the design, and it can be easily addressed if necessary for better memory scalability.
```python
from sys import stdout
from lt import encode
# Stream a fountain of 1024B blocks to stdout
block_size = 1024
with open(filename, 'rb') as f:
for block in encode.encoder(f, block_size):
stdout.buffer.write(block)
```
## Decoding
The decoder reads the header, then the body, of each incoming block and conducts all possible steps in the belief propagation algorithm on a representation of the source node/check node graph that become possible given the new check node. This is done using an online algorithm, which computes the appropriate messages incrementally and passes them eagerly as the value of source nodes is resolved. Thus, the decoder will finish decoding once it has read only as many blocks is necessary in the stream to decode the file, and it seems to scale well as the file size, and block size increase.
```python
from sys import stdin
from lt import decode
# Block to fully decode transmission incoming on stdin
data = decode.decode(stdin.buffer)
# Feed the decoder as blocks come in
decoder = decode.LtDecoder()
for block in decode.read_blocks(some_stream):
decoder.consume_block(block)
if decoder.is_done():
break
# Write bytes payload to stream
decoder.stream_dump(some_out_stream)
# Get entire transmission as bytes
data = decoder.bytes_dump()
```
## Commandline Usage
To run the encoder, invoke the following from the shell
$ ./bin/encoder <file> <blocksize> <seed> [c] [delta]
To run the decoder, run the following
$ ./bin/decoder
=======
This is an implementation of a Luby Transform code in Python, consisting of two executables, one for each encoding and decoding files. These are thin wrappers around a core stream/file API.
See _D.J.C, MacKay, 'Information theory, inference, and learning algorithms. Cambridge University Press, 2003_ for reference on the algorithms.
## Encoding
The encoding algorithm follows the given spec, so no innovations there. A few optimizations are made however. First, the CDF of the degree distribution, M(d), is precomputed for all degrees d = 1, ..., K. This CDF is represented as an array mapping index d => M(d), so sampling from the degree distribution mu(d) becomes a linear search through the CDF array looking for the bucket our random number on \[0, 1) landed in. This random number is generated as specified using the linear congruential generator.
Second, the integer representation of all blocks is held in RAM for maximum speed in block sample generation. This is a limitation on the size of the file practically encoded on most computers, but this decision does not reach far into other parts of the design, and it can be easily addressed if necessary for better memory scalability.
```python
from sys import stdout
from lt import encode
# Stream a fountain of 1024B blocks to stdout
block_size = 1024
with open(filename, 'rb') as f:
for block in encode.encoder(f, block_size):
stdout.buffer.write(block)
```
## Decoding
The decoder reads the header, then the body, of each incoming block and conducts all possible steps in the belief propagation algorithm on a representation of the source node/check node graph that become possible given the new check node. This is done using an online algorithm, which computes the appropriate messages incrementally and passes them eagerly as the value of source nodes is resolved. Thus, the decoder will finish decoding once it has read only as many blocks is necessary in the stream to decode the file, and it seems to scale well as the file size, and block size increase.
```python
from sys import stdin
from lt import decode
# Block to fully decode transmission incoming on stdin
data = decode.decode(stdin.buffer)
# Feed the decoder as blocks come in
decoder = decode.LtDecoder()
for block in decode.read_blocks(some_stream):
decoder.consume_block(block)
if decoder.is_done():
break
# Write bytes payload to stream
decoder.stream_dump(some_out_stream)
# Get entire transmission as bytes
data = decoder.bytes_dump()
```
## Commandline Usage
To run the encoder, invoke the following from the shell
$ ./bin/encoder <file> <blocksize> <seed> [c] [delta]
To run the decoder, run the following
$ ./bin/decoder
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lt-code-0.3.3.tar.gz
(7.3 kB
view details)
Built Distribution
File details
Details for the file lt-code-0.3.3.tar.gz
.
File metadata
- Download URL: lt-code-0.3.3.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66ad2abe97b0374a549a3b445cd43703b569b7358f42f2eba96a46251d74c7f6 |
|
MD5 | 23efbb696d253f772951644c102e0126 |
|
BLAKE2b-256 | 9c266285f43fa1715c4167ff769aad445799489054bcce9628f2b1b9994e26cd |
File details
Details for the file lt-code-0.3.3.linux-x86_64.tar.gz
.
File metadata
- Download URL: lt-code-0.3.3.linux-x86_64.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03a8f569003f0700094e9ebd01546782fca2ed49054bc896e70464d5a5f32ebc |
|
MD5 | a4597d60d370892438c83f9bd140dbd9 |
|
BLAKE2b-256 | 5bc4e73d912b4964253b86ca5f872b329f575a24e0c04f74e66f65579c3e8ed7 |