Julius 4.2
|
00001 00018 /* 00019 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00020 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00021 * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology 00022 * All rights reserved 00023 */ 00024 00025 #include <sent/stddefs.h> 00026 #include <sent/htk_hmm.h> 00027 #include <sent/htk_param.h> 00028 #include <sent/hmm.h> 00029 #include <sent/hmm_calc.h> 00030 00031 00038 void 00039 put_htk_trans(FILE *fp, HTK_HMM_Trans *t) 00040 { 00041 int i,j; 00042 00043 if (fp == NULL) return; 00044 if (t == NULL) { 00045 fprintf(fp, "no transition\n"); 00046 } else { 00047 for (i=0;i<t->statenum;i++) { 00048 for (j=0;j<t->statenum;j++) { 00049 fprintf(fp, " %e", t->a[i][j]); 00050 } 00051 fprintf(fp, "\n"); 00052 } 00053 } 00054 } 00055 00062 void 00063 put_htk_var(FILE *fp, HTK_HMM_Var *v) 00064 { 00065 int i; 00066 00067 if (fp == NULL) return; 00068 if (v == NULL) { 00069 fprintf(fp, "no covariance\n"); 00070 } else { 00071 fprintf(fp, "variance(%d): (may be inversed)", v->len); 00072 for (i=0;i<v->len;i++) { 00073 fprintf(fp, " %e", v->vec[i]); 00074 } 00075 fprintf(fp, "\n"); 00076 } 00077 } 00078 00085 void 00086 put_htk_dens(FILE *fp, HTK_HMM_Dens *d) 00087 { 00088 int i; 00089 00090 if (fp == NULL) return; 00091 if (d == NULL) { 00092 fprintf(fp, "no dens\n"); 00093 } else { 00094 fprintf(fp, "mean(%d):", d->meanlen); 00095 for (i=0;i<d->meanlen;i++) { 00096 fprintf(fp, " %e", d->mean[i]); 00097 } 00098 fprintf(fp, "\n"); 00099 put_htk_var(fp, d->var); 00100 fprintf(fp, "gconst: %e\n", d->gconst); 00101 } 00102 } 00103 00110 void 00111 put_htk_mpdf(FILE *fp, HTK_HMM_PDF *m) 00112 { 00113 int i; 00114 GCODEBOOK *book; 00115 00116 if (m == NULL) { 00117 fprintf(fp, "no mixture pdf\n"); 00118 return; 00119 } 00120 if (m->name != NULL) fprintf(fp, " [~p \"%s\"] (stream %d)\n", m->name, m->stream_id + 1); 00121 if (m->tmix) { 00122 book = (GCODEBOOK *)m->b; 00123 fprintf(fp, " tmix codebook = \"%s\" (size=%d)\n", book->name, book->num); 00124 for (i=0;i<m->mix_num;i++) { 00125 fprintf(fp, " weight%d = %f\n", i, exp(m->bweight[i])); 00126 } 00127 } else { 00128 for (i=0;i<m->mix_num;i++) { 00129 fprintf(fp, "-- d%d (weight=%f)--\n",i+1,exp(m->bweight[i])); 00130 put_htk_dens(fp, m->b[i]); 00131 } 00132 } 00133 } 00134 00141 void 00142 put_htk_state(FILE *fp, HTK_HMM_State *s) 00143 { 00144 int st; 00145 00146 if (fp == NULL) return; 00147 if (s == NULL) { 00148 fprintf(fp, "no output state\n"); 00149 } else { 00150 if (s->name != NULL) fprintf(fp, "[~s \"%s\"]\n", s->name); 00151 for (st=0;st<s->nstream;st++) { 00152 fprintf(fp, "stream %d:", st + 1); 00153 if (s->w != NULL) { 00154 fprintf(fp, " (weight=%f", s->w->weight[st]); 00155 if (s->w->name != NULL) { 00156 fprintf(fp, " <- ~w \"%s\"", s->w->name); 00157 } 00158 fprintf(fp, ")"); 00159 } 00160 fprintf(fp, "\n"); 00161 put_htk_mpdf(fp, s->pdf[st]); 00162 } 00163 } 00164 } 00165 00172 void 00173 put_htk_hmm(FILE *fp, HTK_HMM_Data *h) 00174 { 00175 int i; 00176 00177 if (fp == NULL) return; 00178 fprintf(fp, "name: %s\n", h->name); 00179 fprintf(fp, "state num: %d\n", h->state_num); 00180 for (i=0;i<h->state_num;i++) { 00181 fprintf(fp, "**** state %d ****\n",i+1); 00182 put_htk_state(fp, h->s[i]); 00183 } 00184 put_htk_trans(fp, h->tr); 00185 } 00186 00193 void 00194 put_logical_hmm(FILE *fp, HMM_Logical *logical) 00195 { 00196 if (fp == NULL) return; 00197 fprintf(fp, "name: %s\n", logical->name); 00198 if (logical->is_pseudo) { 00199 fprintf(fp, "mapped to: %s (pseudo)\n", logical->body.pseudo->name); 00200 } else { 00201 fprintf(fp, "mapped to: %s\n", logical->body.defined->name); 00202 } 00203 } 00204 00211 void 00212 put_hmm_arc(FILE *fp, HMM *d) 00213 { 00214 A_CELL *ac; 00215 int i; 00216 00217 if (fp == NULL) return; 00218 fprintf(fp, "total len: %d\n", d->len); 00219 for (i=0;i<d->len;i++) { 00220 fprintf(fp, "node-%d\n", i); 00221 for (ac=d->state[i].ac;ac;ac=ac->next) { 00222 fprintf(fp, " arc: %d %f (%f)\n",ac->arc, ac->a, pow(10.0, ac->a)); 00223 } 00224 } 00225 if (d->accept_ac_a != LOG_ZERO) { 00226 fprintf(fp, "last arc to accept state: %f\n", d->accept_ac_a); 00227 } 00228 } 00229 00236 void 00237 put_hmm_outprob(FILE *fp, HMM *d) 00238 { 00239 int i; 00240 00241 if (fp == NULL) return; 00242 fprintf(fp, "total len: %d\n", d->len); 00243 for (i=0;i<d->len;i++) { 00244 fprintf(fp, "n%d\n", i); 00245 if (d->state[i].is_pseudo_state) { 00246 fprintf(fp, "[[[pseudo state cluster with %d states]]]\n", d->state[i].out.cdset->num); 00247 } else { 00248 put_htk_state(fp, d->state[i].out.state); 00249 } 00250 } 00251 } 00252 00259 void 00260 put_hmm(FILE *fp, HMM *d) 00261 { 00262 if (fp == NULL) return; 00263 put_hmm_arc(fp, d); 00264 put_hmm_outprob(fp, d); 00265 } 00266 00273 void 00274 put_param_head(FILE *fp, HTK_Param_Header *h) 00275 { 00276 char buf[128]; 00277 00278 if (fp == NULL) return; 00279 fprintf(fp, "num of samples: %d\n", h->samplenum); 00280 fprintf(fp, "window shift: %d ms\n", h->wshift / 10000); 00281 fprintf(fp, "bytes per sample: %d\n", h->sampsize); 00282 fprintf(fp, "parameter type: %s\n", param_code2str(buf, h->samptype, FALSE)); 00283 } 00284 00293 void 00294 put_vec(FILE *fp, VECT **p, int num, short veclen) 00295 { 00296 int t,v; 00297 00298 if (fp == NULL) return; 00299 for (t=0;t<num;t++) { 00300 fprintf(fp, "%d:\t%8.3f",t,p[t][0]); 00301 for (v=1;v<veclen;v++) { 00302 if ((v % 10) ==0) fprintf(fp, "\n\t"); 00303 fprintf(fp, "%8.3f", p[t][v]); 00304 } 00305 fprintf(fp, "\n"); 00306 } 00307 } 00308 00315 void 00316 put_param(FILE *fp, HTK_Param *pinfo) 00317 { 00318 if (fp == NULL) return; 00319 put_param_head(fp, &(pinfo->header)); 00320 put_vec(fp, pinfo->parvec, pinfo->samplenum, pinfo->veclen); 00321 } 00322 00329 void 00330 put_param_info(FILE *fp, HTK_Param *pinfo) 00331 { 00332 HTK_Param_Header *h; 00333 float sec; 00334 00335 if (fp == NULL) return; 00336 h = &(pinfo->header); 00337 sec = (float)h->samplenum * (float)h->wshift / 10000000; 00338 fprintf(fp, "length: %d frames (%.2f sec.)\n", h->samplenum, sec); 00339 } 00340 00347 void 00348 print_hmmdef_info(FILE *fp, HTK_HMM_INFO *hmminfo) 00349 { 00350 char buf[128]; 00351 int i, d; 00352 00353 if (fp == NULL) return; 00354 fprintf(fp, " HMM Info:\n"); 00355 fprintf(fp, " %d models, %d states, %d mpdfs, %d Gaussians are defined\n", hmminfo->totalhmmnum, hmminfo->totalstatenum, hmminfo->totalpdfnum, hmminfo->totalmixnum); 00356 fprintf(fp, "\t model type = "); 00357 if (hmminfo->is_tied_mixture) fprintf(fp, "has tied-mixture, "); 00358 if (hmminfo->opt.stream_info.num > 1) fprintf(fp, "multi-stream, "); 00359 #ifdef ENABLE_MSD 00360 if (hmminfo->has_msd) fprintf(fp, "MSD-HMM, "); 00361 #endif 00362 fprintf(fp, "context dependency handling %s\n", 00363 (hmminfo->is_triphone) ? "ON" : "OFF"); 00364 00365 fprintf(fp, " training parameter = %s\n",param_code2str(buf, hmminfo->opt.param_type, FALSE)); 00366 fprintf(fp, "\t vector length = %d\n", hmminfo->opt.vec_size); 00367 fprintf(fp, "\tnumber of stream = %d\n", hmminfo->opt.stream_info.num); 00368 fprintf(fp, "\t stream info ="); 00369 for(d=0,i=0;i<hmminfo->opt.stream_info.num;i++) { 00370 if (hmminfo->opt.stream_info.vsize[i] == 1) { 00371 fprintf(fp, " [%d]", d); 00372 } else { 00373 fprintf(fp, " [%d-%d]", d, d + hmminfo->opt.stream_info.vsize[i] - 1); 00374 } 00375 d += hmminfo->opt.stream_info.vsize[i]; 00376 } 00377 fprintf(fp, "\n"); 00378 fprintf(fp, "\tcov. matrix type = %s\n", get_cov_str(hmminfo->opt.cov_type)); 00379 fprintf(fp, "\t duration type = %s\n", get_dur_str(hmminfo->opt.dur_type)); 00380 00381 if (hmminfo->is_tied_mixture) { 00382 fprintf(fp, "\t codebook num = %d\n", hmminfo->codebooknum); 00383 fprintf(fp, " max codebook size = %d\n", hmminfo->maxcodebooksize); 00384 } 00385 fprintf(fp, "\tmax mixture size = %d Gaussians\n", hmminfo->maxmixturenum); 00386 fprintf(fp, " max length of model = %d states\n", hmminfo->maxstatenum); 00387 00388 fprintf(fp, " logical base phones = %d\n", hmminfo->basephone.num); 00389 00390 fprintf(fp, " model skip trans. = "); 00391 if (hmminfo->need_multipath) { 00392 fprintf(fp, "exist, require multi-path handling\n"); 00393 } else { 00394 fprintf(fp, "not exist, no multi-path handling\n"); 00395 } 00396 00397 if (hmminfo->need_multipath) { 00398 fprintf(fp, " skippable models ="); 00399 { 00400 HTK_HMM_Data *dtmp; 00401 int n = 0; 00402 for (dtmp = hmminfo->start; dtmp; dtmp = dtmp->next) { 00403 if (is_skippable_model(dtmp)) { 00404 fprintf(fp, " %s", dtmp->name); 00405 n++; 00406 } 00407 } 00408 if (n == 0) { 00409 fprintf(fp, " none\n"); 00410 } else { 00411 fprintf(fp, " (%d model(s))\n", n); 00412 } 00413 } 00414 } 00415 }