00001
00017
00018
00019
00020
00021
00022
00023
00024 #include <sent/stddefs.h>
00025 #include <sent/htk_hmm.h>
00026 #include <sent/htk_param.h>
00027 #include <sent/hmm.h>
00028
00029 static char buf[512];
00030
00031
00037 void
00038 put_htk_trans(HTK_HMM_Trans *t)
00039 {
00040 int i,j;
00041
00042 if (t == NULL) {
00043 j_printf("no transition\n");
00044 } else {
00045 for (i=0;i<t->statenum;i++) {
00046 for (j=0;j<t->statenum;j++) {
00047 j_printf(" %e", t->a[i][j]);
00048 }
00049 j_printf("\n");
00050 }
00051 }
00052 }
00053
00059 void
00060 put_htk_var(HTK_HMM_Var *v)
00061 {
00062 int i;
00063
00064 if (v == NULL) {
00065 j_printf("no covariance\n");
00066 } else {
00067 j_printf("variance(%d):", v->len);
00068 for (i=0;i<v->len;i++) {
00069 j_printf(" %e", v->vec[i]);
00070 }
00071 j_printf("\n");
00072 }
00073 }
00074
00080 void
00081 put_htk_dens(HTK_HMM_Dens *d)
00082 {
00083 int i;
00084
00085 if (d == NULL) {
00086 j_printf("no dens\n");
00087 } else {
00088 j_printf("mean(%d):", d->meanlen);
00089 for (i=0;i<d->meanlen;i++) {
00090 j_printf(" %e", d->mean[i]);
00091 }
00092 j_printf("\n");
00093 put_htk_var(d->var);
00094 j_printf("gconst: %e\n", d->gconst);
00095 }
00096 }
00097
00103 void
00104 put_htk_state(HTK_HMM_State *s)
00105 {
00106 int i;
00107
00108 if (s == NULL) {
00109 j_printf("no output state\n");
00110 } else {
00111 j_printf("mixture num: %d\n", s->mix_num);
00112 for (i=0;i<s->mix_num;i++) {
00113 j_printf("-- d%d (weight=%f)--\n",i+1,pow(10.0, s->bweight[i]));
00114 put_htk_dens(s->b[i]);
00115 }
00116 }
00117 }
00118
00124 void
00125 put_htk_hmm(HTK_HMM_Data *h)
00126 {
00127 int i;
00128
00129 j_printf("name: %s\n", h->name);
00130 j_printf("state num: %d\n", h->state_num);
00131 for (i=0;i<h->state_num;i++) {
00132 j_printf("**** state %d ****\n",i+1);
00133 put_htk_state(h->s[i]);
00134 }
00135 put_htk_trans(h->tr);
00136 }
00137
00143 void
00144 put_logical_hmm(HMM_Logical *logical)
00145 {
00146 j_printf("name: %s\n", logical->name);
00147 if (logical->is_pseudo) {
00148 j_printf("mapped to: %s (pseudo)\n", logical->body.pseudo->name);
00149 } else {
00150 j_printf("mapped to: %s\n", logical->body.defined->name);
00151 }
00152 }
00153
00159 void
00160 put_hmm_arc(HMM *d)
00161 {
00162 A_CELL *ac;
00163 int i;
00164
00165 j_printf("total len: %d\n", d->len);
00166 for (i=0;i<d->len;i++) {
00167 j_printf("node-%d\n", i);
00168 for (ac=d->state[i].ac;ac;ac=ac->next) {
00169 j_printf(" arc: %d %f (%f)\n",ac->arc, ac->a, pow(10.0, ac->a));
00170 }
00171 }
00172 #ifndef MULTIPATH_VERSION
00173 j_printf("last arc to accept state: %f\n", d->accept_ac_a);
00174 #endif
00175 }
00176
00182 void
00183 put_hmm_outprob(HMM *d)
00184 {
00185 int i;
00186
00187 j_printf("total len: %d\n", d->len);
00188 for (i=0;i<d->len;i++) {
00189 j_printf("n%d\n", i);
00190 if (d->state[i].is_pseudo_state) {
00191 j_printf("[[[pseudo state cluster with %d states]]]\n", d->state[i].out.cdset->num);
00192 } else {
00193 put_htk_state(d->state[i].out.state);
00194 }
00195 }
00196 }
00197
00203 void
00204 put_hmm(HMM *d)
00205 {
00206 put_hmm_arc(d);
00207 put_hmm_outprob(d);
00208 }
00209
00215 void
00216 put_param_head(HTK_Param_Header *h)
00217 {
00218 j_printf("num of samples: %d\n", h->samplenum);
00219 j_printf("window shift: %d ms\n", h->wshift / 10000);
00220 j_printf("bytes per sample: %d\n", h->sampsize);
00221 j_printf("parameter type: %s\n", param_code2str(buf, h->samptype, FALSE));
00222 }
00223
00231 void
00232 put_vec(VECT **p, int num, short veclen)
00233 {
00234 int t,v;
00235
00236 for (t=0;t<num;t++) {
00237 j_printf("%d:\t%8.3f",t,p[t][0]);
00238 for (v=1;v<veclen;v++) {
00239 if ((v % 10) ==0) j_printf("\n\t");
00240 j_printf("%8.3f", p[t][v]);
00241 }
00242 j_printf("\n");
00243 }
00244 }
00245
00251 void
00252 put_param(HTK_Param *pinfo)
00253 {
00254 put_param_head(&(pinfo->header));
00255 put_vec(pinfo->parvec, pinfo->samplenum, pinfo->veclen);
00256 }
00257
00263 void
00264 put_param_info(HTK_Param *pinfo)
00265 {
00266 HTK_Param_Header *h;
00267 float sec;
00268
00269 h = &(pinfo->header);
00270 sec = (float)h->samplenum * (float)h->wshift / 10000000;
00271 j_printf("length: %d frames (%.2f sec.)\n", h->samplenum, sec);
00272 }
00273
00281 static int
00282 get_max_mixture_num(HTK_HMM_INFO *hmminfo)
00283 {
00284 HTK_HMM_State *st;
00285 int maxmixnum;
00286
00287 maxmixnum = 0;
00288 for (st = hmminfo->ststart; st; st = st->next) {
00289 if (maxmixnum < st->mix_num) maxmixnum = st->mix_num;
00290 }
00291 return(maxmixnum);
00292 }
00293
00299 void
00300 print_hmmdef_info(HTK_HMM_INFO *hmminfo)
00301 {
00302 j_printf("HMM Info:\n");
00303 j_printf(" %d models, %d states, %d mixtures are defined\n",
00304 hmminfo->totalhmmnum, hmminfo->totalstatenum, hmminfo->totalmixnum);
00305 j_printf("\t model type = ");
00306 if (hmminfo->is_tied_mixture) j_printf("tied-mixture, ");
00307 j_printf("context dependency handling %s\n",
00308 (hmminfo->is_triphone) ? "ON" : "OFF");
00309 if (hmminfo->is_tied_mixture) {
00310 j_printf("\t codebook num = %d\n", hmminfo->codebooknum);
00311 j_printf("\tmax codebook size= %d\n", hmminfo->maxcodebooksize);
00312 }
00313 j_printf(" training parameter = %s\n",param_code2str(buf, hmminfo->opt.param_type, FALSE));
00314 j_printf("\t vector length = %d\n", hmminfo->opt.vec_size);
00315 j_printf("\tcov. matrix type = %s\n", get_cov_str(hmminfo->opt.cov_type));
00316 j_printf("\t duration type = %s\n", get_dur_str(hmminfo->opt.dur_type));
00317 j_printf("\t mixture num = %d\n", get_max_mixture_num(hmminfo));
00318 j_printf("\t max state num = %d\n", hmminfo->maxstatenum);
00319 #ifdef MULTIPATH_VERSION
00320 j_printf(" skippable models =");
00321 {
00322 HTK_HMM_Data *dtmp;
00323 int n = 0;
00324 for (dtmp = hmminfo->start; dtmp; dtmp = dtmp->next) {
00325 if (is_skippable_model(dtmp)) {
00326 j_printf(" %s", dtmp->name);
00327 n++;
00328 }
00329 }
00330 if (n == 0) {
00331 j_printf(" none\n");
00332 } else {
00333 j_printf(" (%d model(s))\n", n);
00334 }
00335 }
00336 #endif
00337 }