📄 search_bestfirst_v2.c
字号:
/** * @file search_bestfirst_v2.c * * <JA> * @brief 妈2パスのViterbi遍换および簿棱スコア纷换 (奶撅惹) * * ここでは·妈2パスにおいて玫瑚面の簿棱のViterbiスコアの构糠遍换· * 肌帽胳とのトレリス儡鲁·および簿棱のスコア纷换を乖う簇眶が年盗されて * います. * * 帽胳儡鲁婶の帽胳粗不燎茨董巴赂拉は·赖澄な nextscan アルゴリズムを脱います. * このファイルで年盗されている簇眶は·config.h において PASS2_STRICT_IWCD * が define であるときに蝗脱されます. 嫡に惧淡が undef であるときは· * search_bestfirst_v1.c の簇眶が脱いられます. * * Backscan では·デコ〖ディングの篮刨を脚浑して·肌帽胳とその涟の帽胳に * おける帽胳粗不燎コンテキストは簿棱鸥倡箕にすべて阜泰に纷换されます. * Backscan を乖なう search_bestfirst_v1.c が·簿棱の POP 箕に乖なうのに * 孺べて·ここでは簿棱栏喇の箕爬で赖澄なスコアを纷换するため· * スコア篮刨は光い. ただし·栏喇されるすべての簿棱に滦して * (たとえスタックに掐らない簿棱であっても)トライフォンの浩纷换を乖なうため· * 纷换翁は backscan に孺べて笼络します. * </JA> * * <EN> * @brief Viterbi path update and scoring on the second pass (standard version) * * This file has functions for score calculations on the 2nd pass. * It includes Viterbi path update calculation of a hypothesis, calculations * of scores and word trellis connection at word expansion. * * The cross-word triphone will be computed just at word expansion time, * for precise scoring. This is called "nextscan" altgorithm. These * functions are enabled when PASS2_STRICT_IWCD is DEFINED in config.h. * If undefined, the "backscan" functions in search_bestfirst_v1.c will be * used instead. * * Here in nextscan algorithm, all cross-word context dependencies between * next word and source hypothesis are computed as soon as a new hypotheses * is expanded. As the precise cross-word triphone score is applied on * hypothesis generation with no delay, more accurate search-time score can * be obtained than the delayed backscan method in search_bestfirst_v1.c. * On the other hand, the computational cost grows much by re-calculating * forward score of cross-word triphones for all the generated hypothethes, * even non-promising ones. * </EN> * * @author Akinobu Lee * @date Mon Sep 12 00:58:50 2005 * * $Revision: 1.4 $ * *//* * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology * All rights reserved *//* By "fast" setting (default), search_bestfirst_v1.c is used for faster decoding. Please specify option "--enable-setup=standard" or "--enable-strict-iwcd2" at "./configure" to activate this. */#include <julius/julius.h>#ifdef PASS2_STRICT_IWCD#undef TCD ///< Define if want triphone debug messages/**********************************************************************//************ 簿棱ノ〖ドの答塑拎侯 ************//************ Basic functions for hypothesis node handling ************//**********************************************************************/#undef STOCKER_DEBUG#ifdef STOCKER_DEBUGstatic int stocked_num = 0;static int reused_num = 0;static int new_num = 0;static int request_num = 0;#endif/** * <JA> * 簿棱ノ〖ドを悸狠にメモリ惧から豺庶する. * * @param node [in] 簿棱ノ〖ド * </JA> * <EN> * Free a hypothesis node actually. * * @param node [in] hypothesis node * </EN> */static voidfree_node_exec(NODE *node){ if (node == NULL) return; free(node->g);#ifdef GRAPHOUT_PRECISE_BOUNDARY if (node->region->graphout) { free(node->wordend_frame); free(node->wordend_gscore); }#endif free(node);}/** * <JA> * 簿棱ノ〖ドの网脱を姜位してリサイクル脱にストックする * * @param node [in] 簿棱ノ〖ド * </JA> * <EN> * Stock an unused hypothesis node for recycle. * * @param node [in] hypothesis node * </EN> * @callgraph * @callergraph */voidfree_node(NODE *node){ if (node == NULL) return; if (node->region->graphout) { if (node->prevgraph != NULL && node->prevgraph->saved == FALSE) { wordgraph_free(node->prevgraph); } } /* save to stocker */ node->next = node->region->pass2.stocker_root; node->region->pass2.stocker_root = node;#ifdef STOCKER_DEBUG stocked_num++;#endif}/** * <JA> * リサイクル脱ノ〖ド呈羌杆を鄂にする. * * @param s [in] stack decoding work area * * </JA> * <EN> * Clear the node stocker for recycle. * * @param s [in] stack decoding work area * * </EN> * @callgraph * @callergraph */voidclear_stocker(StackDecode *s){ NODE *node, *tmp; node = s->stocker_root; while(node) { tmp = node->next; free_node_exec(node); node = tmp; } s->stocker_root = NULL;#ifdef STOCKER_DEBUG jlog("DEBUG: %d times requested, %d times newly allocated, %d times reused\n", request_num, new_num, reused_num); stocked_num = 0; reused_num = 0; new_num = 0; request_num = 0;#endif}/** * <JA> * 簿棱をコピ〖する. * * @param dst [out] コピ〖黎の簿棱 * @param src [in] コピ〖傅の簿棱 * * @return @a dst を手す. * </JA> * <EN> * Copy the content of node to another. * * @param dst [out] target hypothesis * @param src [in] source hypothesis * * @return the value of @a dst. * </EN> * @callgraph * @callergraph */NODE *cpy_node(NODE *dst, NODE *src){ int peseqlen; peseqlen = src->region->peseqlen; dst->next = src->next; dst->prev = src->prev; memcpy(dst->g, src->g, sizeof(LOGPROB) * peseqlen); memcpy(dst->seq, src->seq, sizeof(WORD_ID) * MAXSEQNUM);#ifdef CM_SEARCH#ifdef CM_MULTIPLE_ALPHA { int w; for(w=0;w<src->seqnum;w++) { memcpy(dst->cmscore[w], src->cmscore[w], sizeof(LOGPROB) * src->region->config->annotate.cm_alpha_num); } } #else memcpy(dst->cmscore, src->cmscore, sizeof(LOGPROB) * MAXSEQNUM);#endif#endif /* CM_SEARCH */ dst->seqnum = src->seqnum; dst->score = src->score; dst->bestt = src->bestt; dst->estimated_next_t = src->estimated_next_t; dst->endflag = src->endflag; dst->state = src->state; dst->tre = src->tre; if (src->region->ccd_flag) { dst->last_ph = src->last_ph; dst->last_ph_sp_attached = src->last_ph_sp_attached; } dst->totallscore = src->totallscore; dst->final_g = src->final_g;#ifdef VISUALIZE dst->popnode = src->popnode;#endif if (src->region->graphout) {#ifdef GRAPHOUT_PRECISE_BOUNDARY memcpy(dst->wordend_frame, src->wordend_frame, sizeof(short) * peseqlen); memcpy(dst->wordend_gscore, src->wordend_gscore, sizeof(LOGPROB) * peseqlen);#endif dst->prevgraph = src->prevgraph; dst->lastcontext = src->lastcontext;#ifndef GRAPHOUT_PRECISE_BOUNDARY dst->tail_g_score = src->tail_g_score;#endif } return(dst);}/** * <JA> * 糠たな簿棱ノ〖ドを充り烧ける. もし呈羌杆に笆涟活脱されなくなった * ノ〖ドがある眷圭はそれを浩网脱する. なければ糠たに充り烧ける. * * @param r [in] 千急借妄インスタンス * * @return 糠たに充り烧けられた簿棱ノ〖ドへのポインタを手す. * </JA> * <EN> * Allocate a new hypothesis node. If the node stocker is not empty, * the one in the stocker is re-used. Otherwise, allocate as new. * * @param r [in] recognition process instance * * @return pointer to the newly allocated node. * </EN> * @callgraph * @callergraph */NODE *newnode(RecogProcess *r){ NODE *tmp; int i; int peseqlen; peseqlen = r->peseqlen;#ifdef STOCKER_DEBUG request_num++;#endif if ((tmp = r->pass2.stocker_root) != NULL) { /* re-use ones in the stocker */ r->pass2.stocker_root = tmp->next;#ifdef STOCKER_DEBUG stocked_num--; reused_num++;#endif } else { /* allocate new */ tmp = (NODE *)mymalloc(sizeof(NODE)); tmp->g = (LOGPROB *)mymalloc(sizeof(LOGPROB) * peseqlen);#ifdef GRAPHOUT_PRECISE_BOUNDARY if (r->graphout) { tmp->wordend_frame = (short *)mymalloc(sizeof(short) * peseqlen); tmp->wordend_gscore = (LOGPROB *)mymalloc(sizeof(LOGPROB) * peseqlen); }#endif#ifdef STOCKER_DEBUG new_num++;#endif } /* clear the data */ /*bzero(tmp,sizeof(NODE));*/ tmp->next=NULL; tmp->prev=NULL; tmp->last_ph = NULL; tmp->last_ph_sp_attached = FALSE; if (r->ccd_flag) { tmp->totallscore = LOG_ZERO; } tmp->endflag = FALSE; tmp->seqnum = 0; for(i = 0; i < peseqlen; i++) { tmp->g[i] = LOG_ZERO; } tmp->final_g = LOG_ZERO;#ifdef VISUALIZE tmp->popnode = NULL;#endif if (r->graphout) { tmp->prevgraph = NULL; tmp->lastcontext = NULL; } tmp->region = r; return(tmp);}/**********************************************************************//************ 涟羹きトレリス鸥倡と锑刨纷换 ****************//************ Expand trellis and update forward score *****************//**********************************************************************//** * <JA> * 1帽胳尸のトレリス纷换脱のワ〖クエリアを澄瘦. * * @param r [in] 千急借妄インスタンス * * </JA> * <EN> * Allocate work area for trellis computation of a word. * * @param r [in] recognition process instance * * </EN> * @callgraph * @callergraph */voidmalloc_wordtrellis(RecogProcess *r){ int maxwn; StackDecode *dwrk; maxwn = r->lm->winfo->maxwn + 10; /* CCDによる恃瓢を雇胃 */ dwrk = &(r->pass2); dwrk->wordtrellis[0] = (LOGPROB *)mymalloc(sizeof(LOGPROB) * maxwn); dwrk->wordtrellis[1] = (LOGPROB *)mymalloc(sizeof(LOGPROB) * maxwn);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -