sumom****@users*****
sumom****@users*****
2013年 12月 18日 (水) 12:55:21 JST
Index: julius4/libsent/src/phmm/outprob.c diff -u julius4/libsent/src/phmm/outprob.c:1.6 julius4/libsent/src/phmm/outprob.c:1.7 --- julius4/libsent/src/phmm/outprob.c:1.6 Fri Jun 21 02:14:25 2013 +++ julius4/libsent/src/phmm/outprob.c Wed Dec 18 12:55:21 2013 @@ -46,7 +46,7 @@ * @author Akinobu LEE * @date Fri Feb 18 18:45:21 2005 * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * */ /* @@ -186,6 +186,7 @@ LOGPROB outp; int sid; int i, d; + HTK_HMM_State *s; sid = stateinfo->id; @@ -204,6 +205,29 @@ outprob_cache_extend(wrk, t); /* extend cache if needed */ wrk->last_cache = wrk->outprob_cache[t]; /* reduce 2-d array access */ } + + if (param->is_outprob) { + /* return the param as output probability */ + if (sid >= param->veclen) { + jlog("Error: state id in the dummy HMM exceeds vector length (%d > %d)\n", sid, param->veclen); + return(LOG_ZERO); + } + return(param->parvec[t][sid]); + } + + if (wrk->batch_computation) { + /* batch computation: if the frame is not computed yet, pre-compute all */ + s = wrk->OP_hmminfo->ststart; + if (wrk->last_cache[s->id] == LOG_UNDEF) { + for (; s; s = s->next) { + wrk->OP_state = s; + wrk->OP_state_id = s->id; + wrk->last_cache[s->id] = (*(wrk->calc_outprob_state))(wrk); + } + } + wrk->OP_state = stateinfo; + wrk->OP_state_id = sid; + } /* consult cache */ if ((outp = wrk->last_cache[sid]) == LOG_UNDEF) { @@ -383,3 +407,67 @@ return(outprob_state(wrk, t, hmmstate->out.state, param)); } } + + + + +static boolean +mywrite(char *buf, size_t unitbyte, int unitnum, FILE *fp, boolean needswap) +{ + size_t tmp; + + int i; + if (needswap) swap_bytes(buf, unitbyte, unitnum); + if ((tmp = myfwrite(buf, unitbyte, unitnum, fp)) < (size_t)unitnum) { + jlog("Error: outprob_cache_output: failed to write %d bytes\n", unitbyte * unitnum); + return(FALSE); + } + // if (needswap) swap_bytes(buf, unitbyte, unitnum); + return(TRUE); +} + +boolean +outprob_cache_output(FILE *fp, HMMWork *wrk, int framenum) +{ + int s,t; + boolean needswap; + +#ifdef WORDS_BIGENDIAN + needswap = FALSE; +#else /* LITTLE ENDIAN */ + needswap = TRUE; +#endif + + needswap = TRUE; + + if (wrk->outprob_allocframenum < framenum) { + jlog("Error: outprob_cache_output: framenum > allocated (%d > %d)\n", framenum, wrk->outprob_allocframenum); + return FALSE; + } + + { + unsigned int ui; + unsigned short us; + short st; + float f; + + jlog("Stat: outprob_cache_output: %d states, %d samples\n", wrk->statenum, framenum); + + ui = framenum; + if (!mywrite((char *)&ui, sizeof(unsigned int), 1, fp, needswap)) return FALSE; + ui = wrk->OP_param->header.wshift; + if (!mywrite((char *)&ui, sizeof(unsigned int), 1, fp, needswap)) return FALSE; + us = wrk->statenum * sizeof(float); + if (!mywrite((char *)&us, sizeof(unsigned short), 1, fp, needswap)) return FALSE; + st = F_USER; + if (!mywrite((char *)&st, sizeof(short), 1, fp, needswap)) return FALSE; + + for (t = 0; t < framenum; t++) { + for (s = 0; s < wrk->statenum; s++) { + f = wrk->outprob_cache[t][s]; + if (!mywrite((char *)&f, sizeof(float), 1, fp, needswap)) return FALSE; + } + } + } + +} Index: julius4/libsent/src/phmm/outprob_init.c diff -u julius4/libsent/src/phmm/outprob_init.c:1.7 julius4/libsent/src/phmm/outprob_init.c:1.8 --- julius4/libsent/src/phmm/outprob_init.c:1.7 Fri Jun 21 02:14:25 2013 +++ julius4/libsent/src/phmm/outprob_init.c Wed Dec 18 12:55:21 2013 @@ -34,7 +34,7 @@ * @author Akinobu LEE * @date Thu Feb 17 13:35:37 2005 * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * */ /* @@ -186,9 +186,17 @@ outprob_cd_nbest_init(wrk, hmminfo->cdmax_num); } + wrk->batch_computation = FALSE; + return TRUE; } +void +outprob_set_batch_computation(HMMWork *wrk, boolean flag) +{ + wrk->batch_computation = flag; +} + /** * Prepare for the next input of given frame length. *