Commit 04e80045 authored by Vladislav Perepelkin's avatar Vladislav Perepelkin
Browse files

Improved rules generator: zero probabilities are now cleaned out

parent b0b59fc4
......@@ -59,6 +59,8 @@ def init_rules():
def add_rule(s0, s1, p):
global rules
rules[s0][s1]=p
if p==0:
del rules[s0][s1]
init_rules()
......@@ -100,7 +102,10 @@ while i<len(lines):
# check normalization
for s0 in range(256):
sum_prob=reduce(lambda x, y: x+y, [rules[s0][s1] for s1 in rules[s0]])
sum_prob=0
if len(rules[s0])>0:
sum_prob=reduce(lambda x, y: x+y,
[rules[s0][s1] for s1 in rules[s0]])
if sum_prob!=1:
error("Normalization fails for state (" + str(s0) +\
"), sum prob is " + str(sum_prob))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment