00001 00035 /* 00036 * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University 00037 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00038 * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology, Nagoya Institute of Technology 00039 * All rights reserved 00040 */ 00041 00042 #include <sent/stddefs.h> 00043 #include <sent/htk_hmm.h> 00044 #include <sent/htk_param.h> 00045 #include <sent/hmm.h> 00046 #include <sent/gprune.h> 00047 #include "globalvars.h" 00048 00057 LOGPROB 00058 compute_g_base(HTK_HMM_Dens *binfo) 00059 { 00060 VECT tmp, x; 00061 VECT *mean; 00062 VECT *var; 00063 VECT *vec = OP_vec; 00064 short veclen = OP_veclen; 00065 00066 if (binfo == NULL) return(LOG_ZERO); 00067 mean = binfo->mean; 00068 var = binfo->var->vec; 00069 tmp = 0.0; 00070 for (; veclen > 0; veclen--) { 00071 x = *(vec++) - *(mean++); 00072 tmp += x * x / *(var++); 00073 } 00074 return((tmp + binfo->gconst) / -2.0); 00075 } 00076 00083 boolean 00084 gprune_none_init() 00085 { 00086 /* maximum Gaussian set size = maximum mixture size */ 00087 OP_calced_maxnum = OP_hmminfo->maxmixturenum; 00088 OP_calced_score = (LOGPROB *)mymalloc(sizeof(LOGPROB) * OP_calced_maxnum); 00089 OP_calced_id = (int *)mymalloc(sizeof(int) * OP_calced_maxnum); 00090 /* force gprune_num to the max number */ 00091 OP_gprune_num = OP_calced_maxnum; 00092 return TRUE; 00093 } 00094 00109 void 00110 gprune_none(HTK_HMM_Dens **g, int num, int *last_id) 00111 { 00112 int i; 00113 HTK_HMM_Dens *dens; 00114 LOGPROB *prob = OP_calced_score; 00115 int *id = OP_calced_id; 00116 OP_calced_num = 0; 00117 for(i=0; i<num; i++) { 00118 dens = *(g++); 00119 if (!dens) continue; /* skip if density = NULL */ 00120 *(prob++) = compute_g_base(dens); 00121 *(id++) = i; 00122 OP_calced_num++; 00123 } 00124 }