Julius 4.2
libsent/src/phmm/calc_mix.c
説明を見る。
00001 
00018 /*
00019  * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University
00020  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00021  * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology
00022  * All rights reserved
00023  */
00024 
00025 #include <sent/stddefs.h>
00026 #include <sent/htk_hmm.h>
00027 #include <sent/htk_param.h>
00028 #include <sent/hmm.h>
00029 #include <sent/hmm_calc.h>
00030 
00040 LOGPROB
00041 calc_mix(HMMWork *wrk)
00042 {
00043   int i;
00044   LOGPROB logprob, logprobsum;
00045   PROB *w;
00046   int *id;
00047   int s;
00048   PROB stream_weight;
00049 
00050   /* compute Gaussian set */
00051   logprobsum = 0.0;
00052   for(s=0;s<wrk->OP_nstream;s++) {
00053     /* set stream weight */
00054     if (wrk->OP_state->w) stream_weight = wrk->OP_state->w->weight[s];
00055     else stream_weight = 1.0;
00056     /* setup storage pointer for this mixture pdf */
00057     wrk->OP_vec = wrk->OP_vec_stream[s];
00058     wrk->OP_veclen = wrk->OP_veclen_stream[s];
00059     /* compute output probabilities */
00060     /* computed Gaussians will be set in:
00061        score ... OP_calced_score[0..OP_calced_num]
00062        id    ... OP_calced_id[0..OP_calced_num] */    
00063     (*(wrk->compute_gaussset))(wrk, wrk->OP_state->pdf[s]->b, wrk->OP_state->pdf[s]->mix_num, NULL, 0);
00064     /* add weights */
00065     id = wrk->OP_calced_id;
00066     w = wrk->OP_state->pdf[s]->bweight;
00067     for(i=0;i<wrk->OP_calced_num;i++) {
00068       //printf("s%d-m%d: %f %f\n", s+1, i+1, wrk->OP_calced_score[i], w[id[i]]);
00069       wrk->OP_calced_score[i] += w[id[i]];
00070     }
00071     /* add log probs */
00072     logprob = addlog_array(wrk->OP_calced_score, wrk->OP_calced_num);
00073     /* if outprob of a stream is zero, skip this stream */
00074     if (logprob <= LOG_ZERO) continue;
00075     /* sum all the obtained mixture scores */
00076     logprobsum += logprob * stream_weight;
00077   }
00078   if (logprobsum == 0.0) return(LOG_ZERO); /* no valid stream */
00079   if (logprobsum <= LOG_ZERO) return(LOG_ZERO); /* lowest == LOG_ZERO */
00080   return (logprobsum * INV_LOG_TEN);
00081 }