libsent/src/hmminfo/rdhmmdef_tiedmix.c

説明を見る。
00001 
00017 /*
00018  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00019  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00020  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00021  * All rights reserved
00022  */
00023 
00024 #include <sent/stddefs.h>
00025 #include <sent/htk_hmm.h>
00026 
00027 extern char *rdhmmdef_token;    
00028 
00037 static GCODEBOOK *
00038 codebook_lookup(HTK_HMM_INFO *hmm, char *keyname)
00039 {
00040   GCODEBOOK *book;
00041 
00042   if (hmm->codebook_root == NULL) return(NULL);
00043   book = aptree_search_data(keyname, hmm->codebook_root);
00044   if (strmatch(book->name, keyname)) {
00045     return book;
00046   } else {
00047     return NULL;
00048   }
00049 }
00050 
00057 void
00058 codebook_add(HTK_HMM_INFO *hmm, GCODEBOOK *new)
00059 {
00060   GCODEBOOK *match;
00061   if (hmm->codebook_root == NULL) {
00062     hmm->codebook_root = aptree_make_root_node(new);
00063   } else {
00064     match = aptree_search_data(new->name, hmm->codebook_root);
00065     if (strmatch(match->name, new->name)) {
00066       j_printerr("Error: ~s \"%s\" is already defined\n", new->name);
00067       rderr(NULL);
00068     } else {
00069       aptree_add_entry(new->name, new, match->name, &(hmm->codebook_root));
00070     }
00071   }
00072 }
00073 
00090 static void
00091 tmix_create_codebook_index(HTK_HMM_INFO *hmminfo, GCODEBOOK *book)
00092 {
00093   char *mixname;
00094   HTK_HMM_Dens *dtmp;
00095   int i;
00096   int realbooknum = 0;
00097 
00098   mixname = (char *)mymalloc(strlen(book->name)+30);
00099   book->d = (HTK_HMM_Dens **) mybmalloc2(sizeof(HTK_HMM_Dens *) * book->num, &(hmminfo->mroot));
00100   for (i=0;i<book->num;i++) {
00101     sprintf(mixname, "%s%d", book->name, i + 1);
00102     if ((dtmp = dens_lookup(hmminfo, mixname)) == NULL) {
00103 /* 
00104  *       j_printerr("Error: mixture \"%s\" (%dth mixture in codebook \"%s\") not found\n", mixname, i + 1, book->name);
00105  *       rderr(NULL);
00106  */
00107       book->d[i] = NULL;
00108     } else {
00109       book->d[i] = dtmp;
00110       realbooknum++;
00111     }
00112   }
00113   if (realbooknum < book->num) {
00114     j_printerr("Warning: book [%s]: defined=%d < %d\n",
00115                book->name, realbooknum, book->num);
00116   }
00117   
00118   free(mixname);
00119 }
00120 
00135 void
00136 tmix_read(FILE *fp, HTK_HMM_State *state, HTK_HMM_INFO *hmm)
00137 {
00138   char *bookname;
00139   GCODEBOOK *thebook;
00140   int mid, i;
00141 
00142   NoTokErr("missing TMIX bookname");
00143   bookname = rdhmmdef_token;
00144   /* check whether the specified codebook exist */
00145   if ((thebook = codebook_lookup(hmm, bookname)) == NULL) {
00146     /* create GCODEBOOK global index structure from mixture macros */
00147     thebook = (GCODEBOOK *)mybmalloc2(sizeof(GCODEBOOK), &(hmm->mroot));
00148     thebook->name = mybstrdup2(bookname, &(hmm->mroot));
00149     thebook->num = state->mix_num;
00150     /* map codebook id to HTK_HMM_Dens* */
00151     tmix_create_codebook_index(hmm, thebook);
00152     /* register the new codebook */
00153     codebook_add(hmm, thebook);
00154     thebook->id = hmm->codebooknum;
00155     hmm->codebooknum++;
00156     /* set maximum codebook size */
00157     if (hmm->maxcodebooksize < thebook->num) hmm->maxcodebooksize = thebook->num;
00158   } else {
00159     /* check coherence */
00160     if (state->mix_num != thebook->num) {
00161       rderr("tmix_read: TMIX weight num don't match the codebook size");
00162     }
00163   }
00164 
00165   /* set pointer to the GCODEBOOK structure  */
00166   state->b = (HTK_HMM_Dens **)thebook;
00167 
00168   /* store the weights to `state->bweight[]' */
00169   read_token(fp);
00170   state->bweight = (PROB *) mybmalloc2(sizeof(PROB) * state->mix_num, &(hmm->mroot));
00171   {
00172     int len;
00173     double w;
00174 
00175     mid = 0;
00176     while (mid < state->mix_num)
00177     {
00178       char *p, q;
00179       NoTokErr("missing some TMIX weights");
00180       if ((p = strchr(rdhmmdef_token, '*')) == NULL) {
00181         len = 1;
00182         w = atof(rdhmmdef_token);
00183       } else {
00184         len = atoi(p+1);
00185         q = *p;
00186         *p = '\0';
00187         w = atof(rdhmmdef_token);
00188         *p = q;
00189       }
00190       read_token(fp);
00191       for(i=0;i<len;i++) {
00192         state->bweight[mid] = (PROB)log(w);
00193         mid++;
00194       }
00195     }
00196   }
00197 
00198   /* mark info as tied mixture */
00199   hmm->is_tied_mixture = TRUE;
00200 }
00201 

Juliusに対してTue Dec 26 16:19:28 2006に生成されました。  doxygen 1.5.0