00001 00039 /* 00040 * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University 00041 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00042 * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology 00043 * All rights reserved 00044 */ 00045 00046 #include <sent/stddefs.h> 00047 #include <sent/htk_hmm.h> 00048 #include <sent/htk_param.h> 00049 #include <sent/hmm.h> 00050 #include <sent/gprune.h> 00051 00052 #define GLOBAL_VARIABLE_DEFINE 00053 #include "globalvars.h" 00054 00055 00061 boolean 00062 outprob_init(HTK_HMM_INFO *hmminfo, 00063 HTK_HMM_INFO *gshmm, int gms_num, 00064 int gprune_method, int gprune_mixnum 00065 ) 00066 { 00067 /* check if variances are inversed */ 00068 if (!hmminfo->variance_inversed) { 00069 /* here, inverse all variance values for faster computation */ 00070 htk_hmm_inverse_variances(hmminfo); 00071 hmminfo->variance_inversed = TRUE; 00072 } 00073 /* check if variances are inversed */ 00074 if (gshmm) { 00075 if (!gshmm->variance_inversed) { 00076 /* here, inverse all variance values for faster computation */ 00077 htk_hmm_inverse_variances(gshmm); 00078 gshmm->variance_inversed = TRUE; 00079 } 00080 } 00081 00083 /* select pruning function to compute likelihood of a mixture component 00084 and set the pointer to global */ 00085 switch(gprune_method) { 00086 case GPRUNE_SEL_NONE: 00087 compute_gaussset = gprune_none; 00088 compute_gaussset_init = gprune_none_init; 00089 compute_gaussset_free = gprune_none_free; 00090 break; 00091 case GPRUNE_SEL_SAFE: 00092 compute_gaussset = gprune_safe; 00093 compute_gaussset_init = gprune_safe_init; 00094 compute_gaussset_free = gprune_safe_free; 00095 break; 00096 case GPRUNE_SEL_HEURISTIC: 00097 compute_gaussset = gprune_heu; 00098 compute_gaussset_init = gprune_heu_init; 00099 compute_gaussset_free = gprune_heu_free; 00100 break; 00101 case GPRUNE_SEL_BEAM: 00102 compute_gaussset = gprune_beam; 00103 compute_gaussset_init = gprune_beam_init; 00104 compute_gaussset_free = gprune_beam_free; 00105 break; 00106 } 00107 /* select caching function to compute output probability of a mixture */ 00108 if (hmminfo->is_tied_mixture) { 00109 calc_outprob = calc_tied_mix; /* enable book-level cache, typically for a tied-mixture model */ 00110 } else { 00111 calc_outprob = calc_mix; /* no mixture-level cache, for a shared-state, non tied-mixture model */ 00112 } 00113 00114 /* select back-off functon for state probability calculation */ 00115 if (gshmm != NULL) { 00116 calc_outprob_state = gms_state; /* enable GMS */ 00117 } else { 00118 calc_outprob_state = calc_outprob; /* call mixture outprob directly */ 00119 } 00120 00121 /* store common variable to global */ 00122 OP_hmminfo = hmminfo; 00123 OP_gshmm = gshmm; /* NULL if GMS not used */ 00124 OP_gprune_num = gprune_mixnum; 00125 00126 /* generate addlog table */ 00127 make_log_tbl(); 00128 00129 /* initialize work area for mixture component pruning function */ 00130 if (compute_gaussset_init() == FALSE) return FALSE; /* OP_gprune may change */ 00131 /* initialize work area for book level cache on tied-mixture model */ 00132 if (hmminfo->is_tied_mixture) { 00133 if (calc_tied_mix_init() == FALSE) return FALSE; 00134 } 00135 /* initialize work area for GMS */ 00136 if (OP_gshmm != NULL) { 00137 if (gms_init(gms_num) == FALSE) return FALSE; 00138 } 00139 /* initialize cache for all output probabilities */ 00140 if (outprob_cache_init() == FALSE) return FALSE; 00141 00142 /* initialize word area for computation of pseudo HMM set when N-max is specified */ 00143 if (hmminfo->cdset_method == IWCD_NBEST) { 00144 outprob_cd_nbest_init(hmminfo->cdmax_num); 00145 } 00146 00147 return TRUE; 00148 } 00149 00157 boolean 00158 outprob_prepare(int framenum) 00159 { 00160 if (outprob_cache_prepare() == FALSE) return FALSE; 00161 if (OP_gshmm != NULL) { 00162 if (gms_prepare(framenum) == FALSE) return FALSE; 00163 } 00164 if (OP_hmminfo->is_tied_mixture) { 00165 if (calc_tied_mix_prepare(framenum) == FALSE) return FALSE; 00166 } 00167 /* reset last time */ 00168 OP_last_time = OP_time = -1; 00169 return TRUE; 00170 } 00171 00176 void 00177 outprob_free() 00178 { 00179 compute_gaussset_free(); 00180 if (OP_hmminfo->is_tied_mixture) { 00181 calc_tied_mix_free(); 00182 } 00183 if (OP_gshmm != NULL) { 00184 gms_free(); 00185 } 00186 outprob_cache_free(); 00187 if (OP_hmminfo->cdset_method == IWCD_NBEST) { 00188 outprob_cd_nbest_free(); 00189 } 00190 00191 }