fix the bug of issue#137

pull/129/merge
fxsjy 11 years ago
parent cc708de40c
commit 9d4ac26f16

@ -1,5 +1,6 @@
import operator
MIN_FLOAT=-3.14e100
MIN_INF=float("-inf")
def get_top_states(t_state_v,K=4):
items = t_state_v.items()
@ -27,7 +28,7 @@ def viterbi(obs, states, start_p, trans_p, emit_p):
if len(obs_states)==0: obs_states = all_states
for y in obs_states:
(prob,state ) = max([(V[t-1][y0] + trans_p[y0].get(y,MIN_FLOAT) + emit_p[y].get(obs[t],MIN_FLOAT) ,y0) for y0 in prev_states])
(prob,state ) = max([(V[t-1][y0] + trans_p[y0].get(y,MIN_INF) + emit_p[y].get(obs[t],MIN_FLOAT) ,y0) for y0 in prev_states])
V[t][y] =prob
mem_path[t][y] = state

Loading…
Cancel
Save