📄 hadapt.c
字号:
break; } } if (basename == NULL) { return NULL; } return LoadRegTree(hset,NameOf(basename,macroname),basename); }static BaseClass* GetBaseClass(HMMSet *hset,AdaptXForm *xform){ char* basename = NULL; char macroname[MAXSTRLEN]; if (xformBaseClass != NULL) { basename = xformBaseClass; } else { switch(xform->xformSet->xkind) { case MLLRMEAN: basename = mllrMeanBaseClass; break; case MLLRCOV: basename = mllrCovBaseClass; break; case CMLLR: basename = cmllrBaseClass; break; } } if (basename == NULL) { HError(-1,"No baseclass macro name specified - global transform assumed"); basename = "global"; } /* name may be a complete path, or just the macroname */ return LoadBaseClass(hset,NameOf(basename,macroname),basename);}static int GetVecSizeClass(BaseClass *bclass, int class){ ILink i; MixtureElem *me; /* currently does not check consistency of vecor sizes */ i=bclass->ilist[class]; me = (MixtureElem *)i->item; return VectorSize(me->mpdf->mean);}static IntVec GetBlockSize(AdaptXForm *xform, int class){ IntVec blockSize = NULL; if (xformBlockSize != NULL) { blockSize = xformBlockSize; } else { switch(xform->xformSet->xkind) { case MLLRMEAN: blockSize = mllrMeanBlockSize; break; case MLLRCOV: blockSize = mllrCovBlockSize; break; case CMLLR: blockSize = cmllrBlockSize; break; } } if (blockSize == NULL) { blockSize = CreateIntVec(xform->mem,1); blockSize[1] = GetVecSizeClass(xform->bclass,class); } return blockSize; }/*------------------------------------------------------------------------*//* Internal Structure Support *//*------------------------------------------------------------------------*//* ----------------- Access Routines for the structures ---------------- */static RegAcc *GetRegAcc(MixPDF *mp){ return ((XFormInfo *)mp->info)->regAcc;}static AInfo *GetAInfo(MixPDF *mp){ return ((XFormInfo *)mp->info)->aInfo;}static AInfo *GetPAInfo(MixPDF *mp){ return ((XFormInfo *)mp->info)->paInfo;}static MInfo *GetMInfo(MixPDF *mp){ return ((XFormInfo *)mp->info)->mInfo;}static ObsCache *GetObsCache(MixPDF *mp){ return ((XFormInfo *)mp->info)->oc;}static ObsCache *GetPAObsCache(MixPDF *mp){ return ((XFormInfo *)mp->info)->paoc;}static AccCache *GetPAAccCache(MixPDF *mp){ return ((XFormInfo *)mp->info)->paac;}/* --------------- handling the MInfo structure ------------------ */static MInfo *CreateMInfo(MemHeap *x, MixPDF *mp, AdaptXForm *xform){ MInfo *mi; Boolean adaptMean, adaptCov; AdaptXForm *xf; int size; size = VectorSize(mp->mean); adaptMean = FALSE; adaptCov = FALSE; mi = (MInfo *)New(&infoStack,sizeof(MInfo)); /* depending on the nature of the transform determines the parameters to be stored */ xf = xform; while (xf != NULL) { if (StoreAdaptMean(xf)) adaptMean = TRUE; if (StoreAdaptCov(xf)) adaptCov = TRUE; xf = xf->parentXForm; } if (adaptMean) { mi->mean = CreateVector(x,size); CopyVector(mp->mean,mi->mean); } else mi->mean = NULL; if (adaptCov) { switch(mp->ckind){ case DIAGC: case INVDIAGC: mi->cov.var = CreateVector(x,size); CopyVector(mp->cov.var,mi->cov.var); mi->gConst = mp->gConst; break; default: HError(999,"AccMixPDFStats: bad ckind %d",mp->ckind); } } else { switch(mp->ckind){ case DIAGC: case INVDIAGC: mi->cov.var = NULL; break; default: HError(999,"AccMixPDFStats: bad ckind %d",mp->ckind); } } return mi;}/* Function used to store the original model parameters. May be overriden using HMODEL:STOREMINFO = FALSE*/static void SetMInfo(HMMSet *hset, AdaptXForm *xform){ HMMScanState hss; MixPDF *mp; int nMInfo=0; NewHMMScan(hset,&hss); do { while (GoNextState(&hss,TRUE)) { while (GoNextStream(&hss,TRUE)) { if (hss.isCont) /* PLAINHS or SHAREDHS */ while (GoNextMix(&hss,TRUE)) { mp = hss.mp; ((XFormInfo *)mp->info)->mInfo = CreateMInfo(hset->hmem,mp,xform); nMInfo++; } } } } while (GoNextHMM(&hss)); EndHMMScan(&hss); if (trace&T_ACC) printf("Attached %d MInfo structures\n",nMInfo); hset->attMInfo = TRUE;}static Boolean CompareMInfo(HMMSet *hset, AdaptXForm *xform){ Boolean adaptMean, adaptCov; AdaptXForm *xf; HMMScanState hss; MixPDF *mp; MInfo *mi; adaptMean = FALSE; adaptCov = FALSE; /* depending on the nature of the transform determines the parameters to be stored */ xf = xform; while (xf != NULL) { if (StoreAdaptMean(xf)) adaptMean = TRUE; if (StoreAdaptCov(xf)) adaptCov = TRUE; xf = xf->parentXForm; } /* now check to see what is currently stored */ NewHMMScan(hset,&hss); mp = hss.mp; mi = GetMInfo(mp); if ((adaptMean) && (mi->mean == NULL)) return FALSE; if ((adaptCov) && (mi->cov.var == NULL)) return FALSE; EndHMMScan(&hss); return TRUE;}/* If the model info has already been set need to check that there are no new parameters that need to be stored - add additional storage as required*/static void UpdateMInfo(HMMSet *hset, AdaptXForm *xform){ Boolean adaptMean, adaptCov; AdaptXForm *xf; int size; HMMScanState hss; MixPDF *mp; MInfo *mi; int nMInfo=0; adaptMean = FALSE; adaptCov = FALSE; /* depending on the nature of the transform determines the parameters to be stored */ xf = xform; while (xf != NULL) { if (StoreAdaptMean(xf)) adaptMean = TRUE; if (StoreAdaptCov(xf)) adaptCov = TRUE; xf = xf->parentXForm; } /* now check to see what is currently stored */ NewHMMScan(hset,&hss); do { while (GoNextState(&hss,TRUE)) { while (GoNextStream(&hss,TRUE)) { if (hss.isCont) /* PLAINHS or SHAREDHS */ while (GoNextMix(&hss,TRUE)) { mp = hss.mp; mi = GetMInfo(mp); if ((adaptMean) && (mi->mean == NULL)) { size = VectorSize(mp->mean); mi->mean = CreateVector(hset->hmem,size); CopyVector(mp->mean,mi->mean); nMInfo++; } if (adaptCov) { switch(mp->ckind){ case DIAGC: case INVDIAGC: if (mi->cov.var == NULL) { size = VectorSize(mp->mean); mi->cov.var = CreateVector(hset->hmem,size); CopyVector(mp->cov.var,mi->cov.var); mi->gConst = mp->gConst; } break; default: HError(999,"AccMixPDFStats: bad ckind %d",mp->ckind); } nMInfo++; } } } } } while (GoNextHMM(&hss)); EndHMMScan(&hss); if (trace&T_ACC) printf("Attached %d additional MInfo structures\n",nMInfo);}/* --------------- handling the XFormInfo structure ------------------ */static XFormInfo *CreateXFormInfo(MemHeap *x){ XFormInfo *info; info = (XFormInfo *)New(x,sizeof(XFormInfo)); info->aInfo = NULL; info->mInfo = NULL; info->paInfo = NULL; info->regAcc = NULL; info->paoc = NULL; info->oc = NULL; info->paac = NULL; return info;}static void AttachXFormInfo(HMMSet *hset){ HMMScanState hss; MixPDF *mp; int nXFormInfo=0; NewHMMScan(hset,&hss); do { while (GoNextState(&hss,TRUE)) { while (GoNextStream(&hss,TRUE)) { if (hss.isCont) /* PLAINHS or SHAREDHS */ while (GoNextMix(&hss,TRUE)) { mp = hss.mp; mp->info = (XFormInfo *)CreateXFormInfo(hset->hmem); nXFormInfo++; } else HError(7450, "AttachXFormInfo: Adaptation only available for PLAIN or SHARED systems!"); } } } while (GoNextHMM(&hss)); EndHMMScan(&hss); if (trace&T_ACC) printf("Attached %d XFormInfo structures\n",nXFormInfo); hset->attXFormInfo = TRUE;}static Boolean CompareXFormInfo(AdaptXForm *xform1, AdaptXForm *xform2){ AdaptXForm *xf1, *xf2; Boolean valid=FALSE; if (xform1 == xform2) return TRUE; xf1 = xform1; xf2 = xform2; while ((xf1 != NULL) && (xf2 != NULL)) { if (xf1->bclass != xf2->bclass) return valid; xf1 = xf1->parentXForm; xf2 = xf2->parentXForm; } /* check that they are both the same length */ if ((xf1 == NULL) && (xf2 == NULL)) valid = TRUE; return valid;}/* --------------- handling the AInfo structure ------------------ */static void SetAInfo(HMMSet *hset, AdaptXForm *xform, Boolean parent){ BaseClass *bclass; MixPDF *mp; ILink i; int b, nlevel; AdaptXForm *xf; AInfo *ai; int nAInfo=0; if (!hset->attXFormInfo) AttachXFormInfo(hset); /* transform baseclasses differ reset internal information */ /* ResetHeap(&infoStack); */ if (xform != NULL) { /* setup the adptation information for each component according to the baseclass information. Expect the itemlist to always specify components .... */ nlevel = 0; xf = xform; while (xf != NULL) { nlevel++; bclass = xf->bclass; for (b = 1; b <= bclass->numClasses; b++) { for (i=bclass->ilist[b]; i!=NULL; i=i->next) { mp = ((MixtureElem *)i->item)->mpdf; if (parent) ai = ((XFormInfo *)mp->info)->paInfo; else ai = ((XFormInfo *)mp->info)->aInfo; if (ai == NULL) { if (parent) ((XFormInfo *)mp->info)->paInfo = ai = (AInfo *)New(&infoStack,sizeof(AInfo)); else ((XFormInfo *)mp->info)->aInfo = ai = (AInfo *)New(&infoStack,sizeof(AInfo)); nAInfo++; } else if (nlevel>1) { /* go the end of the chain and add adaptation info, but not at the first level */ /* a fix to tidy memory at this stage is required */ while (ai->next != NULL) ai=ai->next; ai = ai->next = (AInfo *)New(&infoStack,sizeof(AInfo)); nAInfo++; } ai->baseClass = b; ai->level = nlevel; ai->next = NULL; } } xf = xf->parentXForm; } } else { /* This may be called during a reset so set all the ai's to NULL */ HMMScanState hss; NewHMMScan(hset,&hss); do { while (GoNextState(&hss,TRUE)) { while (GoNextStream(&hss,TRUE)) { while (GoNextMix(&hss,TRUE)) { ((XFormInfo *)hss.mp->info)->aInfo = NULL; } } } } while (GoNextHMM(&hss)); EndHMMScan(&hss); } if (trace&T_ACC) printf("Attached %d AInfo structures\n",nAInfo);}/* --------------- handling the RegAcc structure ------------------ */static TriMat *CreateBlockTriMat(MemHeap *x, IntVec blockSize){ TriMat *tm; int nblock, bsize, b, *i; nblock = IntVecSize(blockSize); tm = (TriMat *)New(x,sizeof(TriMat)*(nblock+1)); i = (int *)tm; *i = nblock; for (b=1;b<=nblock;b++) { bsize = blockSize[b]; tm[b] = CreateTriMat(x, bsize); ZeroTriMat(tm[b]); } return(tm);}static void ZeroBlockTriMat(TriMat *bTriMat){ int *nblock,b; nblock = (int *)bTriMat; for (b=1; b<=*nblock; b++) ZeroTriMat(bTriMat[b]); }static void ZeroBaseTriMat(TriMat *bTriMat){ int i; int *vsize; TriMat tm;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -