From 7c5834de2011e1e14182ea6c316697c4f1946f4b Mon Sep 17 00:00:00 2001 From: Connor Date: Mon, 10 Sep 2018 13:30:55 -0700 Subject: [PATCH] --- ac_encode.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ac_encode.py b/ac_encode.py index 57aacd2..57d013f 100644 --- a/ac_encode.py +++ b/ac_encode.py @@ -30,7 +30,7 @@ def encode(string, c0=BETA0, c1=BETA1, adaptive=True): tot0 = 0 tot1 = 0 if not adaptive: - p0 = c0 * 1 / (c0 + c1) + p0 = c0 / (c0 + c1) ans = "" charstack = [0] # how many undecided characters remain to print @@ -38,7 +38,7 @@ def encode(string, c0=BETA0, c1=BETA1, adaptive=True): w = b - a if adaptive: cT = c0 + c1 - p0 = c0 * 1 / cT + p0 = c0 / cT boundary = a + int(p0 * w) # these warnings mean that some of the probabilities @@ -109,7 +109,7 @@ def encode(string, c0=BETA0, c1=BETA1, adaptive=True): return ans -def decode(string, N=10000, c0=BETA0, c1=BETA1, adaptive=True): +def decode(string, N, c0=BETA0, c1=BETA1, adaptive=True): # must supply N, the number of source characters remaining. assert c0 > 0 assert c1 > 0 @@ -120,7 +120,7 @@ def decode(string, N=10000, c0=BETA0, c1=BETA1, adaptive=True): tot1 = 0 model_needs_updating = True if not adaptive: - p0 = c0 * 1 / (c0 + c1) + p0 = c0 / (c0 + c1) ans = "" u = 0 @@ -145,12 +145,11 @@ def decode(string, N=10000, c0=BETA0, c1=BETA1, adaptive=True): # Then emulate the encoder's computations, # and tie (u,v) to tag along for the ride. while 1: # do-while - firsttime = 0 if model_needs_updating: w = b - a if adaptive: cT = c0 + c1 - p0 = c0 * 1 / cT + p0 = c0 / cT boundary = a + int(p0 * w) if boundary == a: boundary += 1