void hmm_dump(hmm_t * hmm, FILE * fp) { int32 i; if (hmm_is_mpx(hmm)) { fprintf(fp, "MPX "); for (i = 0; i < hmm_n_emit_state(hmm); i++) fprintf(fp, " %11d", hmm_senid(hmm, i)); fprintf(fp, " ( "); for (i = 0; i < hmm_n_emit_state(hmm); i++) fprintf(fp, "%d ", hmm_ssid(hmm, i)); fprintf(fp, ")\n"); } else { fprintf(fp, "SSID "); for (i = 0; i < hmm_n_emit_state(hmm); i++) fprintf(fp, " %11d", hmm_senid(hmm, i)); fprintf(fp, " (%d)\n", hmm_ssid(hmm, 0)); } if (hmm->ctx->senscore) { fprintf(fp, "SENSCR"); for (i = 0; i < hmm_n_emit_state(hmm); i++) fprintf(fp, " %11d", hmm_senscr(hmm, i)); fprintf(fp, "\n"); } fprintf(fp, "SCORES %11d", hmm_in_score(hmm)); for (i = 1; i < hmm_n_emit_state(hmm); i++) fprintf(fp, " %11d", hmm_score(hmm, i)); fprintf(fp, " %11d", hmm_out_score(hmm)); fprintf(fp, "\n"); fprintf(fp, "HISTID %11d", hmm_in_history(hmm)); for (i = 1; i < hmm_n_emit_state(hmm); i++) fprintf(fp, " %11d", hmm_history(hmm, i)); fprintf(fp, " %11d", hmm_out_history(hmm)); fprintf(fp, "\n"); if (hmm_in_score(hmm) > 0) fprintf(fp, "ALERT!! The input score %d is large than 0. Probably wrap around.\n", hmm_in_score(hmm)); if (hmm_out_score(hmm) > 0) fprintf(fp, "ALERT!! The output score %d is large than 0. Probably wrap around\n.", hmm_out_score(hmm)); fflush(fp); }
int srch_FLAT_FWD_select_active_gmm(void *srch) { kbcore_t *kbc; s3wid_t w; whmm_t *h; int32 st; s3pid_t p; s3senid_t *senp; ascr_t *ascr; srch_FLAT_FWD_graph_t *fwg; srch_t *s; mdef_t *mdef; dict_t *dict; s = (srch_t *) srch; fwg = (srch_FLAT_FWD_graph_t *) s->grh->graph_struct; ascr = s->ascr; kbc = s->kbc; mdef = kbcore_mdef(kbc); dict = kbcore_dict(kbc); ascr_clear_sen_active(ascr); /* Flag active senones */ for (w = 0; w < dict->n_word; w++) { for (h = fwg->whmm[w]; h; h = h->next) { if (hmm_is_mpx(h)) { for (st = 0; st < hmm_n_emit_state(h); ++st) { p = hmm_mpx_ssid(h, st); if (p == -1) break; /* All subsequent ones are also inactive */ senp = mdef->sseq[p]; ascr->sen_active[senp[st]] = 1; } } else { p = hmm_nonmpx_ssid(h); senp = mdef->sseq[p]; for (st = 0; st < hmm_n_emit_state(h); ++st) ascr->sen_active[senp[st]] = 1; } } } return SRCH_SUCCESS; }
int32 hmm_vit_eval(hmm_t * hmm) { if (hmm_is_mpx(hmm)) { if (hmm_n_emit_state(hmm) == 5) return hmm_vit_eval_5st_lr_mpx(hmm); else if (hmm_n_emit_state(hmm) == 3) return hmm_vit_eval_3st_lr_mpx(hmm); else return hmm_vit_eval_anytopo(hmm); } else { if (hmm_n_emit_state(hmm) == 5) return hmm_vit_eval_5st_lr(hmm); else if (hmm_n_emit_state(hmm) == 3) return hmm_vit_eval_3st_lr(hmm); else return hmm_vit_eval_anytopo(hmm); } }
void acmod_activate_hmm(acmod_t *acmod, hmm_t *hmm) { int i; if (acmod->compallsen) return; if (hmm_is_mpx(hmm)) { switch (hmm_n_emit_state(hmm)) { case 5: MPX_BITVEC_SET(acmod, hmm, 4); MPX_BITVEC_SET(acmod, hmm, 3); case 3: MPX_BITVEC_SET(acmod, hmm, 2); MPX_BITVEC_SET(acmod, hmm, 1); MPX_BITVEC_SET(acmod, hmm, 0); break; default: for (i = 0; i < hmm_n_emit_state(hmm); ++i) { MPX_BITVEC_SET(acmod, hmm, i); } } } else { switch (hmm_n_emit_state(hmm)) { case 5: NONMPX_BITVEC_SET(acmod, hmm, 4); NONMPX_BITVEC_SET(acmod, hmm, 3); case 3: NONMPX_BITVEC_SET(acmod, hmm, 2); NONMPX_BITVEC_SET(acmod, hmm, 1); NONMPX_BITVEC_SET(acmod, hmm, 0); break; default: for (i = 0; i < hmm_n_emit_state(hmm); ++i) { NONMPX_BITVEC_SET(acmod, hmm, i); } } } }
static int32 hmm_vit_eval_anytopo(hmm_t * hmm) { hmm_context_t *ctx = hmm->ctx; int32 to, from, bestfrom; int32 newscr, scr, bestscr; int final_state; /* Compute previous state-score + observation output prob for each emitting state */ ctx->st_sen_scr[0] = hmm_in_score(hmm) + hmm_senscr(hmm, 0); for (from = 1; from < hmm_n_emit_state(hmm); ++from) { if ((ctx->st_sen_scr[from] = hmm_score(hmm, from) + hmm_senscr(hmm, from)) WORSE_THAN WORST_SCORE) ctx->st_sen_scr[from] = WORST_SCORE; } /* FIXME/TODO: Use the BLAS for all this. */ /* Evaluate final-state first, which does not have a self-transition */ final_state = hmm_n_emit_state(hmm); to = final_state; scr = WORST_SCORE; bestfrom = -1; for (from = to - 1; from >= 0; --from) { if ((hmm_tprob(hmm, from, to) BETTER_THAN TMAT_WORST_SCORE) && ((newscr = ctx->st_sen_scr[from] + hmm_tprob(hmm, from, to)) BETTER_THAN scr)) { scr = newscr; bestfrom = from; } } hmm_out_score(hmm) = scr; if (bestfrom >= 0) hmm_out_history(hmm) = hmm_history(hmm, bestfrom); bestscr = scr; /* Evaluate all other states, which might have self-transitions */ for (to = final_state - 1; to >= 0; --to) { /* Score from self-transition, if any */ scr = (hmm_tprob(hmm, to, to) BETTER_THAN TMAT_WORST_SCORE) ? ctx->st_sen_scr[to] + hmm_tprob(hmm, to, to) : WORST_SCORE; /* Scores from transitions from other states */ bestfrom = -1; for (from = to - 1; from >= 0; --from) { if ((hmm_tprob(hmm, from, to) BETTER_THAN TMAT_WORST_SCORE) && ((newscr = ctx->st_sen_scr[from] + hmm_tprob(hmm, from, to)) BETTER_THAN scr)) { scr = newscr; bestfrom = from; } } /* Update new result for state to */ if (to == 0) { hmm_in_score(hmm) = scr; if (bestfrom >= 0) hmm_in_history(hmm) = hmm_history(hmm, bestfrom); } else { hmm_score(hmm, to) = scr; if (bestfrom >= 0) hmm_history(hmm, to) = hmm_history(hmm, bestfrom); } /* Propagate ssid for multiplex HMMs */ if (bestfrom >= 0 && hmm_is_mpx(hmm)) hmm->senid[to] = hmm->senid[bestfrom]; if (bestscr WORSE_THAN scr) bestscr = scr; } hmm_bestscore(hmm) = bestscr; return bestscr; }