I hereby claim:
- I am mreid on github.
- I am mreid (https://keybase.io/mreid) on keybase.
- I have a public key whose fingerprint is 0290 8892 E023 A876 460B D320 2B84 F83F 283D 58D8
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
# Example Huffman coding implementation | |
# Distributions are represented as dictionaries of { 'symbol': probability } | |
# Codes are dictionaries too: { 'symbol': 'codeword' } | |
def huffman(p): | |
'''Return a Huffman code for an ensemble with distribution p.''' | |
assert(sum(p.values()) == 1.0) # Ensure probabilities sum to 1 | |
# Base case of only two symbols, assign 0 or 1 arbitrarily | |
if(len(p) == 2): |
# Example implementation of simple arithmetic coding in Python (2.7+). | |
# | |
# USAGE | |
# | |
# python -i arithmetic.py | |
# >>> m = {'a': 1, 'b': 1, 'c': 1} | |
# >>> model = dirichlet(m) | |
# >>> encode(model, "aabbaacc") | |
# '00011110011110010' | |
# |