PageRenderTime 24ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/files/asobiba/juliustest/juliustest/juliustest/libsent/src/phmm/outprob_init.c

https://github.com/rti7743/rtilabs
C | 236 lines | 129 code | 14 blank | 93 comment | 44 complexity | 0e0f2b64e3eb95304046938605f81718 MD5 | raw file
  1. /**
  2. * @file outprob_init.c
  3. *
  4. * <JA>
  5. * @brief 音響尤度計算ルーチンの初期化とセットアップ
  6. *
  7. * 音響モデルのタイプにあわせた計算ルーチンの選択や,計算用の各種
  8. * パラメータの初期化を行います.これらの初期化関数は音響尤度計算を始める前に
  9. * 呼び出される必要があります.
  10. *
  11. * 音響尤度計算関数の使用方法:
  12. * -# 最初に outprob_init() を呼んで初期化とセットアップを行います.
  13. * -# 各入力に対して,以下を行います.
  14. * -# outprob_prepare() で必要な尤度キャッシュを確保します.
  15. * -# outprob(t, hmmstate, param) で各状態に対する音響尤度を計算して
  16. * 返します.
  17. * </JA>
  18. *
  19. * <EN>
  20. * @brief Initialize and setup the acoustic computation routines
  21. *
  22. * These functions switch computation function suitable for the given %HMM
  23. * types (tied-mixture or shared-state, use GMS or not, and so on). It also
  24. * sets various parameters and global pointers for the likelihood computation.
  25. * These functions should be called at first.
  26. *
  27. * How to usage these acoustic computation routines:
  28. * -# First call outprob_init() on startup to configure and setup functions
  29. * -# For each input,
  30. * -# call outprob_prepare() to prepare cache
  31. * -# use outprob(t, hmmstate, param) to get output probability of a state
  32. * </EN>
  33. *
  34. * @author Akinobu LEE
  35. * @date Thu Feb 17 13:35:37 2005
  36. *
  37. * $Revision: 1.5 $
  38. *
  39. */
  40. /*
  41. * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University
  42. * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
  43. * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology
  44. * All rights reserved
  45. */
  46. #include <sent/stddefs.h>
  47. #include <sent/htk_hmm.h>
  48. #include <sent/htk_param.h>
  49. #include <sent/hmm.h>
  50. #include <sent/hmm_calc.h>
  51. /**
  52. * Initialize and setup acoustic computation functions.
  53. *
  54. * @param wrk [i/o] HMM computation work area
  55. * @param hmminfo [in] HMM definition
  56. * @param gshmm [in] GMS HMM definition if exist, or NULL if not
  57. * @param gms_num [in] number of GMS HMM to compute (valid if gshmm != NULL)
  58. * @param gprune_method [in] gaussian pruning method
  59. * @param gprune_mixnum [in] number of pdf to compute at a codebook
  60. * in gaussian pruning
  61. *
  62. * @return TRUE on success, FALSE on failure.
  63. */
  64. boolean
  65. outprob_init(HMMWork *wrk, HTK_HMM_INFO *hmminfo,
  66. HTK_HMM_INFO *gshmm, int gms_num,
  67. int gprune_method, int gprune_mixnum
  68. )
  69. {
  70. int i;
  71. /* check if variances are inversed */
  72. if (!hmminfo->variance_inversed) {
  73. /* here, inverse all variance values for faster computation */
  74. htk_hmm_inverse_variances(hmminfo);
  75. hmminfo->variance_inversed = TRUE;
  76. }
  77. /* check if variances are inversed */
  78. if (gshmm) {
  79. if (!gshmm->variance_inversed) {
  80. /* here, inverse all variance values for faster computation */
  81. htk_hmm_inverse_variances(gshmm);
  82. gshmm->variance_inversed = TRUE;
  83. }
  84. }
  85. /** select functions **/
  86. /* select pruning function to compute likelihood of a mixture component
  87. and set the pointer to global */
  88. #ifdef ENABLE_MSD
  89. /* currently MSD model works only for non pruning mode */
  90. if (hmminfo->has_msd && gprune_method != GPRUNE_SEL_NONE) {
  91. jlog("Error: outprob_init: only \"-gprune none\" is supported when MSD-HMM enabled\n");
  92. return FALSE;
  93. }
  94. #endif
  95. switch(gprune_method) {
  96. case GPRUNE_SEL_NONE:
  97. wrk->compute_gaussset = gprune_none;
  98. wrk->compute_gaussset_init = gprune_none_init;
  99. wrk->compute_gaussset_free = gprune_none_free;
  100. break;
  101. case GPRUNE_SEL_SAFE:
  102. wrk->compute_gaussset = gprune_safe;
  103. wrk->compute_gaussset_init = gprune_safe_init;
  104. wrk->compute_gaussset_free = gprune_safe_free;
  105. break;
  106. case GPRUNE_SEL_HEURISTIC:
  107. wrk->compute_gaussset = gprune_heu;
  108. wrk->compute_gaussset_init = gprune_heu_init;
  109. wrk->compute_gaussset_free = gprune_heu_free;
  110. break;
  111. case GPRUNE_SEL_BEAM:
  112. wrk->compute_gaussset = gprune_beam;
  113. wrk->compute_gaussset_init = gprune_beam_init;
  114. wrk->compute_gaussset_free = gprune_beam_free;
  115. break;
  116. case GPRUNE_SEL_USER:
  117. /* assume user functions are already registered to the entries */
  118. break;
  119. }
  120. /* select caching function to compute output probability of a mixture */
  121. if (hmminfo->is_tied_mixture) {
  122. /* check if all mixture PDFs are tied-mixture */
  123. {
  124. HTK_HMM_PDF *p;
  125. boolean ok_p = TRUE;
  126. for (p = hmminfo->pdfstart; p; p = p->next) {
  127. if (p->tmix == FALSE) {
  128. ok_p = FALSE;
  129. break;
  130. }
  131. }
  132. if (ok_p) {
  133. jlog("Stat: outprob_init: all mixture PDFs are tied-mixture, use calc_tied_mix()\n");
  134. wrk->calc_outprob = calc_tied_mix; /* enable book-level cache, typically for a tied-mixture model */
  135. } else {
  136. jlog("Stat: outprob_init: tied-mixture PDF exist (not all), calc_compound_mix()\n");
  137. wrk->calc_outprob = calc_compound_mix; /* enable book-level cache, typically for a tied-mixture model */
  138. }
  139. }
  140. } else {
  141. jlog("Stat: outprob_init: state-level mixture PDFs, use calc_mix()\n");
  142. wrk->calc_outprob = calc_mix; /* no mixture-level cache, for a shared-state, non tied-mixture model */
  143. }
  144. /* select back-off functon for state probability calculation */
  145. if (gshmm != NULL) {
  146. wrk->calc_outprob_state = gms_state; /* enable GMS */
  147. } else {
  148. wrk->calc_outprob_state = wrk->calc_outprob; /* call mixture outprob directly */
  149. }
  150. /* store common variable to global */
  151. wrk->OP_hmminfo = hmminfo;
  152. wrk->OP_gshmm = gshmm; /* NULL if GMS not used */
  153. wrk->OP_gprune_num = gprune_mixnum;
  154. /* store multi-stream data */
  155. wrk->OP_nstream = hmminfo->opt.stream_info.num;
  156. for(i=0;i<wrk->OP_nstream;i++) {
  157. wrk->OP_veclen_stream[i] = hmminfo->opt.stream_info.vsize[i];
  158. }
  159. /* generate addlog table */
  160. make_log_tbl();
  161. /* initialize work area for mixture component pruning function */
  162. if ((*(wrk->compute_gaussset_init))(wrk) == FALSE) return FALSE; /* OP_gprune may change */
  163. /* initialize work area for book level cache on tied-mixture model */
  164. if (hmminfo->is_tied_mixture) {
  165. if (calc_tied_mix_init(wrk) == FALSE) return FALSE;
  166. }
  167. /* initialize work area for GMS */
  168. if (wrk->OP_gshmm != NULL) {
  169. wrk->my_nbest = gms_num;
  170. if (gms_init(wrk) == FALSE) return FALSE;
  171. }
  172. /* initialize cache for all output probabilities */
  173. if (outprob_cache_init(wrk) == FALSE) return FALSE;
  174. /* initialize word area for computation of pseudo HMM set when N-max is specified */
  175. if (hmminfo->cdset_method == IWCD_NBEST) {
  176. outprob_cd_nbest_init(wrk, hmminfo->cdmax_num);
  177. }
  178. return TRUE;
  179. }
  180. /**
  181. * Prepare for the next input of given frame length.
  182. *
  183. * @param wrk [i/o] HMM computation work area
  184. * @param framenum [in] input length in frame.
  185. *
  186. * @return TRUE on success, FALSE on failure.
  187. */
  188. boolean
  189. outprob_prepare(HMMWork *wrk, int framenum)
  190. {
  191. if (outprob_cache_prepare(wrk) == FALSE) return FALSE;
  192. if (wrk->OP_gshmm != NULL) {
  193. if (gms_prepare(wrk, framenum) == FALSE) return FALSE;
  194. }
  195. if (wrk->OP_hmminfo->is_tied_mixture) {
  196. if (calc_tied_mix_prepare(wrk, framenum) == FALSE) return FALSE;
  197. }
  198. /* reset last time */
  199. wrk->OP_last_time = wrk->OP_time = -1;
  200. return TRUE;
  201. }
  202. /**
  203. * Free all work area for outprob computation.
  204. *
  205. * @param wrk [i/o] HMM computation work area
  206. *
  207. */
  208. void
  209. outprob_free(HMMWork *wrk)
  210. {
  211. (*(wrk->compute_gaussset_free))(wrk);
  212. if (wrk->OP_hmminfo->is_tied_mixture) {
  213. calc_tied_mix_free(wrk);
  214. }
  215. if (wrk->OP_gshmm != NULL) {
  216. gms_free(wrk);
  217. }
  218. outprob_cache_free(wrk);
  219. if (wrk->OP_hmminfo->cdset_method == IWCD_NBEST) {
  220. outprob_cd_nbest_free(wrk);
  221. }
  222. }