13 L_init:
for( s=0; s<
N_STATES; s++ ) {
14 llike[0][s] =
init[s] + emission[s*N_TOKENS+obs[0]];
18 L_timestep:
for( t=1; t<
N_OBS; t++ ) {
19 L_curr_state:
for( curr=0; curr<
N_STATES; curr++ ) {
22 min_p = llike[t-1][prev] +
23 transition[prev*N_STATES+curr] +
24 emission[curr*N_TOKENS+obs[t]];
25 L_prev_state:
for( prev=1; prev<
N_STATES; prev++ ) {
26 p = llike[t-1][prev] +
27 transition[prev*N_STATES+curr] +
28 emission[curr*N_TOKENS+obs[t]];
33 llike[t][curr] = min_p;
39 min_p = llike[N_OBS-1][min_s];
41 p = llike[N_OBS-1][s];
47 path[N_OBS-1] = min_s;
50 L_backtrack:
for( t=N_OBS-2; t>=0; t-- ) {
52 min_p = llike[t][min_s] + transition[min_s*N_STATES+path[t+1]];
53 L_state:
for( s=1; s<
N_STATES; s++ ) {
54 p = llike[t][s] + transition[s*N_STATES+path[t+1]];
void init(int bucket[BUCKETSIZE])
int viterbi(tok_t obs[N_OBS], prob_t init[N_STATES], prob_t transition[N_STATES *N_STATES], prob_t emission[N_STATES *N_TOKENS], state_t path[N_OBS])