⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hadapt.c

📁 隐马尔科夫模型工具箱
💻 C
📖 第 1 页 / 共 5 页
字号:
      binary = GetSymbol(src, &sym);   }     /* set some variables */   if (rt->transKind & MEANVAR)      useVar = TRUE;   /* clear all transforms previously stored in memory */   RemoveAllTransforms(rt->rtree, rt);   /* Load the MLLR transforms */   while(sym == TRANSFORM) {      if (!ReadShort(src, &nodeId, 1, binary))         HError(7440, "LoadTransforms: expected a node index");      /* find node with index nodeId */      t = FindNode(rt->rtree, NULL, nodeId);      n = t->nodeInfo;      sym = NULLSYM;      while(sym != TRANSFORM && sym != BASESTATS && sym != EOFSYM) {         binary = GetSymbol(src, &sym);         switch(sym) {         case MEAN_TR:            GetMeanTransformSet(src, n, &rt->transMem, rt->vSize,                                 rt->nBlocks, rt->transKind, binary);            break;         case BIASOFFSET:            GetBiasOffset(src, n, binary);            break;         case VARIANCE_TR:            GetCovarTransformSet(src, n, useVar, binary);            varThere=TRUE;            break;         case TRANSFORM: case BASESTATS: case EOFSYM:            break;         default:            HError(7440, "Unexpected symbol %s", symMap[sym]);            break;         }      }   }   if (varThere == FALSE)      rt->transKind = MEANONLY;     *s = sym;   return binary;}/* Load the transform set header */static void LoadTransformHeader(Source *src, MemHeap *x, TransformId *tId,                                char *hmmSetId, char *uid, MLink m)  {   char buf[256];   /*     Read the transform file header   */   /* Read the user id from the transform file and       check that it matches the current user */   if (!ReadString(src, buf))      HError(7440, "LoadTransformHeader: Expected marker <UID> in the TMF");   if (strcmp(buf, "<UID>"))      HError(7440, "LoadTransformHeader: Expected marker <UID> in the TMF");   if (!ReadString(src, buf))      HError(7440, "LoadTransformHeader: Expected a user identifier in the TMF");   strcpy(tId->uid, buf);   if (uid != NULL)      if (strcmp(uid, tId->uid))         HError(-7440, "LoadTransformHeader: Transform id does not match the user id\n\tTrans id %s, User id %s", tId->uid, uid);   /* Read in the full user name if available (ie optional) */   if (!ReadString(src, buf))      HError(7440, "LoadTransformHeader: Expected marker <NAME> or <MMFID> in the TMF");   if (strcmp(buf, "<NAME>") == 0) {      if (!ReadString(src, buf))         HError(7440, "LoadTransformHeader: Full user name is expected");      if (strcmp(buf, "<MMFID>")) {         strcpy(tId->name, buf);         ReadLine(src, buf);         strcat(tId->name, buf);         SkipWhiteSpace(src);         if (!ReadString(src, buf))            HError(7440, "LoadTransformHeader: Expected marker <MMFID> in the TMF");      }      else {         tId->name = NULL;         HError(-7440, "LoadTransformHeader: User's full name unknown");      }    }   else {      tId->name = NULL;      HError(-7440, "LoadTransformHeader: Users' full name unknown");   }   /* read in the MMF identifier and check it */   if (strcmp(buf, "<MMFID>"))      HError(7440, "LoadTransformHeader: Expected marker <MMFID> in the TMF");   if (!ReadString(src, buf))      HError(7440, "LoadTransformHeader: Expected an MMF identifier in the TMF");     /* if the hmmSet identifiers match then set the transform id hmm id */    if (hmmSetId==NULL || strcmp(hmmSetId, buf))      tId->hmmSetId = NULL;   else      tId->hmmSetId = hmmSetId;   /* Read the regression class set identifier from the transform file */   if (!ReadString(src, buf))      HError(7440, "LoadTransformHeader: Expected marker <RCID> in the TMF");   if (strcmp(buf, "<RCID>"))      HError(7440, "LoadTransformHeader: Expected marker <RCID> in the TMF");     if (!ReadString(src, buf))      HError(7440, "LoadTransformHeader: Expected a transform identifier in the TMF");   strcpy(tId->rcId, buf);   /* read in the microphone/channel description */   if (!ReadString(src, buf))      HError(7440, "LoadTransformHeader: Expected marker <CHAN> in the TMF");   if (strcmp(buf, "<CHAN>"))      HError(7440, "LoadTransformHeader: Expected marker <CHAN> in the TMF");   /* skip the single white space */   SkipWhiteSpace(src);   if (!ReadLine(src, buf))      HError(7440, "LoadTransformHeader: Expected a line describing channel type");     strcpy(tId->chan, buf);     /* Read in the general description */   if (!ReadString(src, buf))      HError(7440, "LoadTransformHeader: Expected marker <DESC> in the TMF");   if (strcmp(buf, "<DESC>"))      HError(7440, "LoadTransformHeader: Expected marker <DESC> in the TMF");   /* skip the single white space */   SkipWhiteSpace(src);   if (!ReadLine(src, buf))      HError(7440, "LoadTransformHeader: Expected a general description line");   SkipWhiteSpace(src);   strcpy(tId->desc, buf);}/* EXPORT->LoadTransformSet: Load the transforms into memory */Boolean LoadTransformSet(HMMSet *hset, char *tfile, char *uid,                          RegTransInfo *rt, Boolean *useStats)  {   Source src;   Symbol sym;   Boolean binary;   MLink m;   int n, h;     if(InitSource(tfile, &src, NoFilter)<SUCCESS)      HError(7410,"LoadTransformSet: Can't open file %s", tfile);   /* get hold of the regression tree macro identifier (if it exists) */   for (n=0,h=0; h<MACHASHSIZE; h++) {      for (m=hset->mtab[h]; m!=NULL; m=m->next)         if (m->type == 'r')            break;      if (m != NULL)         break;   }     /* Load the transform file header */   LoadTransformHeader(&src, rt->hmem, rt->transId, hset->hmmSetId, uid, m);   if (rt->transId->hmmSetId == NULL) {      CloseSource(&src);      return FALSE;   }   /* load the transforms and store in the tree */   binary = LoadTransforms(&src,rt,&sym);   if (*useStats)      HError(-7410,"LoadTransformSet: Loading adaptation statistics is not available");   if (trace & T_RIO) {      PrintTree(rt->rtree, rt);      fflush(stdout);   }    CloseSource(&src);   return TRUE;}/*------------------------------------------------------------------------*//*         Initialisation of accumulate structures and hooks              *//*------------------------------------------------------------------------*//* create a regression accumulation instance (used to link components   in the same regression class together, and if adaptation to store   regression statistics */static RegAcc *CreateRegAccInstance(MemHeap *x, int transKind, int vSize){     RegAcc *ra;     ra = (RegAcc *) New(x, sizeof(RegAcc));   ra->pre.time = -1;   ra->pre.prob = LZERO;   ra->obsSum   = NULL;   ra->obsSqSum = NULL;   ra->occ = 0.0;     return ra;  }/* allocate space in regression accumulator to store statistics */static void CreateRegAccStorage(RegAcc *ra, RegTransInfo *rt) {   ra->obsSum   =  CreateVector(&rt->pdfStatsMem,rt->vSize);   ZeroVector(ra->obsSum);   /* if using variances also */   if (rt->transKind & MEANVAR) {      ra->obsSqSum =  CreateVector(&rt->pdfStatsMem, rt->vSize);      ZeroVector(ra->obsSqSum);   }}/* AttachRegAccs: attach accumulators to hset */static void AttachRegAccs(HMMSet *hset, MemHeap *x, RegTransType transKind,                           int vSize){   HMMScanState hss;   RegAcc *ra;   int nregacc=0;     NewHMMScan(hset,&hss);   do {      while (GoNextState(&hss,TRUE)) {         while (GoNextStream(&hss,TRUE)) {                        if (hss.isCont)                     /* PLAINHS or SHAREDHS */               while (GoNextMix(&hss,TRUE)) {                  nregacc += 1;                  hss.mp->hook = (void *)                     CreateRegAccInstance(x, transKind, vSize);                  ra = GetRegAcc(hss.mp);               }            else               HError(7450, "AttachRegAccs: Adaptation only available for PLAIN or SHARED systems!");         }      }   } while (GoNextHMM(&hss));   EndHMMScan(&hss);     if (trace&T_NAC)      printf("AttachRegAccs: Attached %d regression structures\n",             nregacc);}/*------------------------------------------------------------------------*//*     Initialisation of the component and regression class structures    *//*     and pointers for the adaptation and/or transformation process      *//*------------------------------------------------------------------------*//* GroupRegMixes: For each class build a linked list of mixtures */static void GroupRegMixes(HMMSet *hset, RegTransInfo *rt) {     HMMScanState hss;   IntVec baseMixes;   short classNum;   int i, j, index, n;   char *s;   /* sanity checking structure */   baseMixes = CreateIntVec(&gstack, rt->nBaseTransforms);   ZeroIntVec(baseMixes);   /* allocate memory for the pdfList arrays and initialise */   for (i = 1; i <= rt->nBaseTransforms; i++) {      n = rt->baseforms[i]->nComponents;      rt->baseforms[i]->pdfList = (MixPDF **) New(rt->hmem,                                                   sizeof(MixPDF *) * n);      --(rt->baseforms[i]->pdfList);      for (j = 1; j <= n; j++)         rt->baseforms[i]->pdfList[j] = NULL;      /* printf("%3d -- %3d has %4d\n", i, rt->baseforms[i]->baseformIndex,          rt->baseforms[i]->nComponents);         fflush(stdout); */   }   /* assign mixpdfs to base class pdfLists */    NewHMMScan(hset,&hss);   do {      while (GoNextState(&hss,TRUE)) {         while (GoNextStream(&hss,TRUE)) {            while (GoNextMix(&hss,TRUE)) {                 switch(rt->classKind) {               case ADPTTREE:                  /* Group the components for the regression tree adaptation case */                  classNum = hss.mp->rClass;                  if (classNum > 0) {                     index = FindClassIndex(rt, classNum);                     baseMixes[index] += 1;                     if (baseMixes[index] <= rt->baseforms[index]->nComponents)                        rt->baseforms[index]->pdfList[baseMixes[index]] = hss.mp;                     else                        HError(7425, "GroupRegMixes: Mismatch num of comps for class %d -- %d, expected %d",                               classNum, baseMixes[index], rt->baseforms[index]->nComponents);                     s = HMMPhysName(hset, hss.hmm);                     /* check for speechflag */                     if (!strcmp(s, "sil") || !strcmp(s, "sp")                          || !strcmp(s, "h#") || !strcmp(s, "silist"))                        rt->baseforms[index]->speechFlag = FALSE;                     else                        rt->baseforms[index]->speechFlag = TRUE;                  }                  break;               case ADPTFIXED:                  /* Group the components for the fixed classes adaptation case */                  HError(7401, "GroupRegMixes: Fixed Group not yet available");               case ADPTUNDEF:                  HError(7419, "GroupRegMixes: Regression class type undefined!\n\tCheck config settings!");               }                      }         }      }   } while (GoNextHMM(&hss));   EndHMMScan(&hss);      /* Do sanity check */   if (rt->classKind == ADPTTREE || rt->classKind == ADPTFIXED) {      for (i = 1; i <= rt->nBaseTransforms; i++)         if (rt->baseforms[i]->nComponents != baseMixes[i])            HError(7425, "GroupRegMixes: Mismatch between number of components %d and the expected number %d",                    baseMixes[i], rt->baseforms[i]->nComponents);   }   FreeIntVec(&gstack, baseMixes);  }/* For this node, attach (via the bases member) the base classes */static void AttachBaseformsToNode(RegNode *n, RegTree *t, RegTransInfo *rt) {     short index, i;   if (t != NULL) {      AttachBaseformsToNode(n, t->left, rt);      if (t->left == NULL) {         for (i = 1; i <= n->nBases; i++)            if (n->bases[i] == 0)               break;         /* find the index for this terminal node */         index = FindClassIndex(rt, t->nodeInfo->nodeIndex);         /* store a pointer to this base class for node n */         n->bases[i] = index;      }      AttachBaseformsToNode(n, t->right, rt);   }}/* for each node in the regression tree, attach the node's base classes */static void AttachBaseformsToTree(RegTree *t, RegTransInfo *rt) {     short i;   RegNode *n;   int nTerms=0;   if (t != NULL) {      AttachBaseformsToTree(t->left, rt);      FindNumTerminals(t, &nTerms);      n = t->nodeInfo;      n->nBases = nTerms;      n->bases = CreateShortVec(rt->hmem, n->nBases);      for (i = 1; i <= n->nBases; i++)         n->bases[i] = 0;      AttachBaseformsToNode(n, t, rt);      AttachBaseformsToTree(t->right, rt);   }}static void GetBaseformComps(RegTree *t, RegTransInfo *rt) {     int i;   if (t != NULL) {      GetBaseformComps(t->left, rt);      if (t->left == NULL) {         for (i = 1; i <= rt->nBaseTransforms; i++)            if (rt->baseforms[i]->nComponents == 0) {               rt->baseforms[i]->nComponents = t->nodeInfo->nodeComps;               rt->baseforms[i]->baseformIndex = t->nodeInfo->nodeIndex;               t->nodeInfo->nodeComps = 0;               break;            }      }      GetBaseformComps(t->right, rt);   }}/* allocate further memory requirements to the tree */static void AllocBaseMembers(RegTransInfo *rt){   int i, nTerms = 0;     FindNumTerminals(rt->rtree, &nTerms);   rt->nBaseTransforms = nTerms;   /* create storage for the transform matrices */   rt->baseforms = (BaseformAcc **) New(rt->hmem, rt->nBaseTransforms *                                         sizeof(BaseformAcc *));   --(rt->baseforms);   for (i = 1; i <= rt->nBaseTransforms; i++)      rt->baseforms[i] = CreateBaseform(rt);   GetBaseformComps(rt->rtree, rt);   AllocNodeTransforms(rt->rtree, rt);  }/*------------------------------------------------------------------------*//*                    Main HAdapt initialisations                         *//*------------------------------------------------------------------------*//* Initialise the regression classes (create memory storage etc) */static void InitialiseRegClasses(HMMSet *hset, RegTransInfo *rt) {   int bSize;   RegTree *rtree=NULL;   int h, n;   MLink m;   /* check blockSize */   bSize = rt->vSize/rt->nBlocks;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -