This commit is contained in:
parent
248a9c0305
commit
dfe69c396f
1 changed files with 2 additions and 9 deletions
|
@ -27,8 +27,6 @@ def encode(string, c0=BETA0, c1=BETA1, adaptive=True):
|
||||||
|
|
||||||
b = ONE
|
b = ONE
|
||||||
a = 0
|
a = 0
|
||||||
tot0 = 0
|
|
||||||
tot1 = 0
|
|
||||||
if not adaptive:
|
if not adaptive:
|
||||||
p0 = c0 / (c0 + c1)
|
p0 = c0 / (c0 + c1)
|
||||||
ans = ""
|
ans = ""
|
||||||
|
@ -54,12 +52,10 @@ def encode(string, c0=BETA0, c1=BETA1, adaptive=True):
|
||||||
|
|
||||||
if c == '1':
|
if c == '1':
|
||||||
a = boundary
|
a = boundary
|
||||||
tot1 += 1
|
|
||||||
if adaptive:
|
if adaptive:
|
||||||
c1 += 1
|
c1 += 1
|
||||||
elif c == '0':
|
elif c == '0':
|
||||||
b = boundary
|
b = boundary
|
||||||
tot0 += 1
|
|
||||||
if adaptive:
|
if adaptive:
|
||||||
c0 += 1
|
c0 += 1
|
||||||
# ignore other characters
|
# ignore other characters
|
||||||
|
@ -116,8 +112,6 @@ def decode(string, N, c0=BETA0, c1=BETA1, adaptive=True):
|
||||||
|
|
||||||
b = ONE
|
b = ONE
|
||||||
a = 0
|
a = 0
|
||||||
tot0 = 0
|
|
||||||
tot1 = 0
|
|
||||||
model_needs_updating = True
|
model_needs_updating = True
|
||||||
if not adaptive:
|
if not adaptive:
|
||||||
p0 = c0 / (c0 + c1)
|
p0 = c0 / (c0 + c1)
|
||||||
|
@ -129,6 +123,7 @@ def decode(string, N, c0=BETA0, c1=BETA1, adaptive=True):
|
||||||
if N <= 0:
|
if N <= 0:
|
||||||
break # out of the string-reading loop
|
break # out of the string-reading loop
|
||||||
assert N > 0
|
assert N > 0
|
||||||
|
|
||||||
# (u,v) is the current "encoded alphabet" binary interval,
|
# (u,v) is the current "encoded alphabet" binary interval,
|
||||||
# and halfway is its midpoint.
|
# and halfway is its midpoint.
|
||||||
# (a,b) is the current "source alphabet" interval,
|
# (a,b) is the current "source alphabet" interval,
|
||||||
|
@ -161,7 +156,6 @@ def decode(string, N, c0=BETA0, c1=BETA1, adaptive=True):
|
||||||
|
|
||||||
if boundary <= u:
|
if boundary <= u:
|
||||||
ans += "1"
|
ans += "1"
|
||||||
tot1 += 1
|
|
||||||
if adaptive:
|
if adaptive:
|
||||||
c1 += 1
|
c1 += 1
|
||||||
a = boundary
|
a = boundary
|
||||||
|
@ -169,7 +163,6 @@ def decode(string, N, c0=BETA0, c1=BETA1, adaptive=True):
|
||||||
N -= 1
|
N -= 1
|
||||||
elif boundary >= v:
|
elif boundary >= v:
|
||||||
ans += "0"
|
ans += "0"
|
||||||
tot0 += 1
|
|
||||||
if adaptive:
|
if adaptive:
|
||||||
c0 += 1
|
c0 += 1
|
||||||
b = boundary
|
b = boundary
|
||||||
|
|
Loading…
Reference in a new issue