Julius 4.2
|
00001 00040 /* 00041 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00042 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00043 * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology 00044 * All rights reserved 00045 */ 00046 00047 #include <sent/stddefs.h> 00048 #include <sent/htk_hmm.h> 00049 #include <sent/htk_param.h> 00050 #include <sent/hmm.h> 00051 #include <sent/hmm_calc.h> 00052 00053 00067 boolean 00068 outprob_init(HMMWork *wrk, HTK_HMM_INFO *hmminfo, 00069 HTK_HMM_INFO *gshmm, int gms_num, 00070 int gprune_method, int gprune_mixnum 00071 ) 00072 { 00073 int i; 00074 /* check if variances are inversed */ 00075 if (!hmminfo->variance_inversed) { 00076 /* here, inverse all variance values for faster computation */ 00077 htk_hmm_inverse_variances(hmminfo); 00078 hmminfo->variance_inversed = TRUE; 00079 } 00080 /* check if variances are inversed */ 00081 if (gshmm) { 00082 if (!gshmm->variance_inversed) { 00083 /* here, inverse all variance values for faster computation */ 00084 htk_hmm_inverse_variances(gshmm); 00085 gshmm->variance_inversed = TRUE; 00086 } 00087 } 00088 00090 /* select pruning function to compute likelihood of a mixture component 00091 and set the pointer to global */ 00092 #ifdef ENABLE_MSD 00093 /* currently MSD model works only for non pruning mode */ 00094 if (hmminfo->has_msd && gprune_method != GPRUNE_SEL_NONE) { 00095 jlog("Error: outprob_init: only \"-gprune none\" is supported when MSD-HMM enabled\n"); 00096 return FALSE; 00097 } 00098 #endif 00099 switch(gprune_method) { 00100 case GPRUNE_SEL_NONE: 00101 wrk->compute_gaussset = gprune_none; 00102 wrk->compute_gaussset_init = gprune_none_init; 00103 wrk->compute_gaussset_free = gprune_none_free; 00104 break; 00105 case GPRUNE_SEL_SAFE: 00106 wrk->compute_gaussset = gprune_safe; 00107 wrk->compute_gaussset_init = gprune_safe_init; 00108 wrk->compute_gaussset_free = gprune_safe_free; 00109 break; 00110 case GPRUNE_SEL_HEURISTIC: 00111 wrk->compute_gaussset = gprune_heu; 00112 wrk->compute_gaussset_init = gprune_heu_init; 00113 wrk->compute_gaussset_free = gprune_heu_free; 00114 break; 00115 case GPRUNE_SEL_BEAM: 00116 wrk->compute_gaussset = gprune_beam; 00117 wrk->compute_gaussset_init = gprune_beam_init; 00118 wrk->compute_gaussset_free = gprune_beam_free; 00119 break; 00120 case GPRUNE_SEL_USER: 00121 /* assume user functions are already registered to the entries */ 00122 break; 00123 } 00124 /* select caching function to compute output probability of a mixture */ 00125 if (hmminfo->is_tied_mixture) { 00126 /* check if all mixture PDFs are tied-mixture */ 00127 { 00128 HTK_HMM_PDF *p; 00129 boolean ok_p = TRUE; 00130 for (p = hmminfo->pdfstart; p; p = p->next) { 00131 if (p->tmix == FALSE) { 00132 ok_p = FALSE; 00133 break; 00134 } 00135 } 00136 if (ok_p) { 00137 jlog("Stat: outprob_init: all mixture PDFs are tied-mixture, use calc_tied_mix()\n"); 00138 wrk->calc_outprob = calc_tied_mix; /* enable book-level cache, typically for a tied-mixture model */ 00139 } else { 00140 jlog("Stat: outprob_init: tied-mixture PDF exist (not all), calc_compound_mix()\n"); 00141 wrk->calc_outprob = calc_compound_mix; /* enable book-level cache, typically for a tied-mixture model */ 00142 } 00143 } 00144 } else { 00145 jlog("Stat: outprob_init: state-level mixture PDFs, use calc_mix()\n"); 00146 wrk->calc_outprob = calc_mix; /* no mixture-level cache, for a shared-state, non tied-mixture model */ 00147 } 00148 00149 /* select back-off functon for state probability calculation */ 00150 if (gshmm != NULL) { 00151 wrk->calc_outprob_state = gms_state; /* enable GMS */ 00152 } else { 00153 wrk->calc_outprob_state = wrk->calc_outprob; /* call mixture outprob directly */ 00154 } 00155 00156 /* store common variable to global */ 00157 wrk->OP_hmminfo = hmminfo; 00158 wrk->OP_gshmm = gshmm; /* NULL if GMS not used */ 00159 wrk->OP_gprune_num = gprune_mixnum; 00160 00161 /* store multi-stream data */ 00162 wrk->OP_nstream = hmminfo->opt.stream_info.num; 00163 for(i=0;i<wrk->OP_nstream;i++) { 00164 wrk->OP_veclen_stream[i] = hmminfo->opt.stream_info.vsize[i]; 00165 } 00166 00167 /* generate addlog table */ 00168 make_log_tbl(); 00169 00170 /* initialize work area for mixture component pruning function */ 00171 if ((*(wrk->compute_gaussset_init))(wrk) == FALSE) return FALSE; /* OP_gprune may change */ 00172 /* initialize work area for book level cache on tied-mixture model */ 00173 if (hmminfo->is_tied_mixture) { 00174 if (calc_tied_mix_init(wrk) == FALSE) return FALSE; 00175 } 00176 /* initialize work area for GMS */ 00177 if (wrk->OP_gshmm != NULL) { 00178 wrk->my_nbest = gms_num; 00179 if (gms_init(wrk) == FALSE) return FALSE; 00180 } 00181 /* initialize cache for all output probabilities */ 00182 if (outprob_cache_init(wrk) == FALSE) return FALSE; 00183 00184 /* initialize word area for computation of pseudo HMM set when N-max is specified */ 00185 if (hmminfo->cdset_method == IWCD_NBEST) { 00186 outprob_cd_nbest_init(wrk, hmminfo->cdmax_num); 00187 } 00188 00189 return TRUE; 00190 } 00191 00200 boolean 00201 outprob_prepare(HMMWork *wrk, int framenum) 00202 { 00203 if (outprob_cache_prepare(wrk) == FALSE) return FALSE; 00204 if (wrk->OP_gshmm != NULL) { 00205 if (gms_prepare(wrk, framenum) == FALSE) return FALSE; 00206 } 00207 if (wrk->OP_hmminfo->is_tied_mixture) { 00208 if (calc_tied_mix_prepare(wrk, framenum) == FALSE) return FALSE; 00209 } 00210 /* reset last time */ 00211 wrk->OP_last_time = wrk->OP_time = -1; 00212 return TRUE; 00213 } 00214 00221 void 00222 outprob_free(HMMWork *wrk) 00223 { 00224 (*(wrk->compute_gaussset_free))(wrk); 00225 if (wrk->OP_hmminfo->is_tied_mixture) { 00226 calc_tied_mix_free(wrk); 00227 } 00228 if (wrk->OP_gshmm != NULL) { 00229 gms_free(wrk); 00230 } 00231 outprob_cache_free(wrk); 00232 if (wrk->OP_hmminfo->cdset_method == IWCD_NBEST) { 00233 outprob_cd_nbest_free(wrk); 00234 } 00235 00236 }