Feb 2 homework

Looking at Huffman compression and entropies.

Jim Mahoney | 2017 | MIT License

In [1]:
% matplotlib inline
from numpy import *
from matplotlib.pyplot import plot
import matplotlib.pyplot as plt
import numpy as np

See the other files in this folder for an explanation of what's what here, and feb2_output.txt for what we're plotting.

In [2]:
from feb2 import *
(entropy, compression) = entropies_and_compressions()
sizes = range(1, 1+len(entropy['stream1.txt']))
In [3]:
entropy, compression
Out[3]:
({'stream1.txt': [0.8106971777397934,
   0.8106866496323406,
   0.8105876820849813,
   0.810163763444749,
   0.8098174674554679,
   0.8093110871952541,
   0.8078027109061537,
   0.8037416275687037],
  'stream2.txt': [0.9691337321122968,
   0.8269229982243773,
   0.7790671037944586,
   0.7581065427263635,
   0.7409758442536537,
   0.7312748241754409,
   0.7254915886338196,
   0.7195773903643955]},
 {'stream1.txt': [1.0,
   0.84356689453125,
   0.8220106207654275,
   0.817596435546875,
   0.8167251640470014,
   0.8155099798571691,
   0.8120059816278572,
   0.808013916015625],
  'stream2.txt': [1.0,
   0.93096923828125,
   0.8125190746505524,
   0.765228271484375,
   0.7488783763161909,
   0.7359152780321065,
   0.7298196356089968,
   0.72454833984375]})
In [16]:
def plotit(filename):
    plt.figure()
    plt.title(filename)
    plt.axis([0, 10, 0, 1.1])
    plot(sizes, entropy[filename], color='green', marker='o', linestyle='None', label='entropy')
    plot(sizes, compression[filename], color='red', marker='s', linestyle='None', label='compression')
    plt.legend()
    plt.show()
In [17]:
plotit('stream1.txt')
plotit('stream2.txt')
In [ ]: