libsent/src/phmm/outprob_init.c

Go to the documentation of this file.
00001 
00040 /*
00041  * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
00042  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00043  * Copyright (c) 2005-2007 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   /* check if variances are inversed */
00074   if (!hmminfo->variance_inversed) {
00075     /* here, inverse all variance values for faster computation */
00076     htk_hmm_inverse_variances(hmminfo);
00077     hmminfo->variance_inversed = TRUE;
00078   }
00079   /* check if variances are inversed */
00080   if (gshmm) {
00081     if (!gshmm->variance_inversed) {
00082       /* here, inverse all variance values for faster computation */
00083       htk_hmm_inverse_variances(gshmm);
00084       gshmm->variance_inversed = TRUE;
00085     }
00086   }
00087 
00089   /* select pruning function to compute likelihood of a mixture component
00090      and set the pointer to global */
00091   switch(gprune_method) {
00092   case GPRUNE_SEL_NONE:
00093     wrk->compute_gaussset = gprune_none;
00094     wrk->compute_gaussset_init = gprune_none_init;
00095     wrk->compute_gaussset_free = gprune_none_free;
00096     break;
00097   case GPRUNE_SEL_SAFE:
00098     wrk->compute_gaussset = gprune_safe;
00099     wrk->compute_gaussset_init = gprune_safe_init;
00100     wrk->compute_gaussset_free = gprune_safe_free;
00101     break;
00102   case GPRUNE_SEL_HEURISTIC:
00103     wrk->compute_gaussset = gprune_heu;
00104     wrk->compute_gaussset_init = gprune_heu_init;
00105     wrk->compute_gaussset_free = gprune_heu_free;
00106     break;
00107   case GPRUNE_SEL_BEAM:
00108     wrk->compute_gaussset = gprune_beam;
00109     wrk->compute_gaussset_init = gprune_beam_init;
00110     wrk->compute_gaussset_free = gprune_beam_free;
00111     break;
00112   }
00113   /* select caching function to compute output probability of a mixture */
00114   if (hmminfo->is_tied_mixture) {
00115     wrk->calc_outprob = calc_tied_mix; /* enable book-level cache, typically for a tied-mixture model */
00116   } else {
00117     wrk->calc_outprob = calc_mix; /* no mixture-level cache, for a shared-state, non tied-mixture model */
00118   }
00119   
00120   /* select back-off functon for state probability calculation */
00121   if (gshmm != NULL) {
00122     wrk->calc_outprob_state = gms_state; /* enable GMS */
00123   } else {
00124     wrk->calc_outprob_state = wrk->calc_outprob; /* call mixture outprob directly */
00125   }
00126 
00127   /* store common variable to global */
00128   wrk->OP_hmminfo = hmminfo;
00129   wrk->OP_gshmm = gshmm;                /* NULL if GMS not used */
00130   wrk->OP_gprune_num = gprune_mixnum;
00131 
00132   /* generate addlog table */
00133   make_log_tbl();
00134   
00135   /* initialize work area for mixture component pruning function */
00136   if ((*(wrk->compute_gaussset_init))(wrk) == FALSE) return FALSE; /* OP_gprune may change */
00137   /* initialize work area for book level cache on tied-mixture model */
00138   if (hmminfo->is_tied_mixture) {
00139     if (calc_tied_mix_init(wrk) == FALSE) return FALSE;
00140   }
00141   /* initialize work area for GMS */
00142   if (wrk->OP_gshmm != NULL) {
00143     wrk->my_nbest = gms_num;
00144     if (gms_init(wrk) == FALSE) return FALSE;
00145   }
00146   /* initialize cache for all output probabilities */
00147   if (outprob_cache_init(wrk) == FALSE)  return FALSE;
00148 
00149   /* initialize word area for computation of pseudo HMM set when N-max is specified */
00150   if (hmminfo->cdset_method == IWCD_NBEST) {
00151     outprob_cd_nbest_init(wrk, hmminfo->cdmax_num);
00152   }
00153 
00154   return TRUE;
00155 }
00156 
00165 boolean
00166 outprob_prepare(HMMWork *wrk, int framenum)
00167 {
00168   if (outprob_cache_prepare(wrk) == FALSE) return FALSE;
00169   if (wrk->OP_gshmm != NULL) {
00170     if (gms_prepare(wrk, framenum) == FALSE) return FALSE;
00171   }
00172   if (wrk->OP_hmminfo->is_tied_mixture) {
00173     if (calc_tied_mix_prepare(wrk, framenum) == FALSE) return FALSE;
00174   }
00175   /* reset last time */
00176   wrk->OP_last_time = wrk->OP_time = -1;
00177   return TRUE;
00178 }
00179 
00186 void
00187 outprob_free(HMMWork *wrk)
00188 {
00189   (*(wrk->compute_gaussset_free))(wrk);
00190   if (wrk->OP_hmminfo->is_tied_mixture) {
00191     calc_tied_mix_free(wrk);
00192   }
00193   if (wrk->OP_gshmm != NULL) {
00194     gms_free(wrk);
00195   }
00196   outprob_cache_free(wrk);
00197   if (wrk->OP_hmminfo->cdset_method == IWCD_NBEST) {
00198     outprob_cd_nbest_free(wrk);
00199   }
00200 
00201 }

Generated on Tue Dec 18 15:59:56 2007 for Julius by  doxygen 1.5.4