Forward–backward algorithm: Difference between revisions

Content deleted Content added
Addbot (talk | contribs)
m Bot: Migrating 5 interwiki links, now provided by Wikidata on d:q4909 (Report Errors)
Line 332:
# Initialize base fwd cases
prev_f_sum = a_0[st]
else:
prev_f_sum = sum(f_prev[k]*a[k][st] for k in states)
 
f_curr[st] = e[st][x_i] * prev_f_sum
 
fwd.append(f_curr)
f_prev = f_curr
Line 345 ⟶ 341:
b_prev = {}
# Run bkw
for i, x_i_plus in enumerate(reversed(x[1:]+(None,))):
b_curr = {}
for st in states:
if i == 0:
# Initialize base bkw cases
b_curr[st] = a[st][end_st]
else:
b_curr[st] = sum(a[st][l]*e[l][x_i_plus]*b_prev[l] for l in states)
 
bkw.insert(0,b_curr)
b_prev = b_curr
 
p_bkw = sum(a_0[l] * e[l][x[0]] * b_curr[l] for l in states)