?? hmodel.c
字號(hào):
if (!ReadMatrix(src,m,tok->binForm)){ HMError(src,"Transform Matrix expected"); return(NULL); } } else if ((tok->sym==MACRO && tok->macroType=='x') && (hset != NULL)) { if((m=(SMatrix)GetStructure(hset,src,'x'))==NULL){ HMError(src,"GetStructure Failed"); return(NULL); } IncUse(m); } else{ HMError(src,"<Xform> symbol expected in GetTransform"); return(NULL); } if(GetToken(src,tok)<SUCCESS){ HMError(src,"GetToken failed"); return(NULL); } return m;}/* GetDuration: parse src and return Duration structure */static SVector GetDuration(HMMSet *hset, Source *src, Token *tok){ SVector v = NULL; short size; if (trace&T_PAR) printf("HModel: GetDuration\n"); if (tok->sym==DURATION) { if (!ReadShort(src,&size,1,tok->binForm)){ HMError(src,"Size of Duration Vector expected"); return(NULL); } v = CreateSVector(hset->hmem,size); if (!ReadVector(src,v,tok->binForm)){ HMError(src,"Duration Vector expected"); return(NULL); } } else if (tok->sym==MACRO && tok->macroType=='d'){ if((v=(SVector)GetStructure(hset,src,'d'))==NULL){ HMError(src,"GetStructure Failed"); return(NULL); } IncUse(v); } else{ HMError(src,"<Duration> symbol expected in GetDuration"); return(NULL); } if(GetToken(src,tok)<SUCCESS){ HMError(src,"GetToken failed"); return(NULL); } return v;}/* GetSWeights: parse src and return vector of stream weights */static SVector GetSWeights(HMMSet *hset, Source *src, Token *tok){ SVector v = NULL; short size; if (trace&T_PAR) printf("HModel: GetSWeights\n"); if (tok->sym==SWEIGHTS) { if (!ReadShort(src,&size,1,tok->binForm)){ HMError(src,"Num stream weights expected"); return(NULL); } v = CreateSVector(hset->hmem,size); if (!ReadVector(src,v,tok->binForm)){ HMError(src,"Stream Weights expected"); return(NULL); } } else if (tok->sym==MACRO && tok->macroType=='w'){ if((v=(SVector)GetStructure(hset,src,'w'))==NULL){ HMError(src,"GetStructure Failed"); return(NULL); } IncUse(v); } else{ HMError(src,"<SWeights> symbol expected in GetSWeights"); return(NULL); } if(GetToken(src,tok)<SUCCESS){ HMError(src,"GetToken failed"); return(NULL); } return v;}/* GetMixPDF: parse src and return MixPDF structure */static MixPDF *GetMixPDF(HMMSet *hset, Source *src, Token *tok){ MixPDF *mp; if (trace&T_PAR) printf("HModel: GetMixPDF\n"); if (tok->sym==MACRO && tok->macroType=='m') { if ((mp = (MixPDF *)GetStructure(hset,src,'m'))==NULL){ HMError(src,"GetStructure Failed"); return(NULL); } ++mp->nUse; if(GetToken(src,tok)<SUCCESS){ HMError(src,"GetToken failed"); return(NULL); } } else { mp = (MixPDF *)New(hset->hmem,sizeof(MixPDF)); mp->nUse = 0; mp->hook = NULL; mp->gConst = LZERO; mp->rClass = 0; if (tok->sym == RCLASS) { short r; if (!ReadShort(src,&r,1,tok->binForm)){ HMError(src,"Regression Class Number expected"); return(NULL); } mp->rClass = r; if(GetToken(src,tok)<SUCCESS){ HMError(src,"GetToken failed"); return(NULL); } } if((mp->mean = GetMean(hset,src,tok))==NULL){ HMError(src,"GetMean Failed"); return(NULL); } if (tok->sym==VARIANCE || (tok->sym==MACRO && tok->macroType=='v')) { if((mp->cov.var = GetVariance(hset,src,tok))==NULL){ HMError(src,"GetVariance Failed"); return(NULL); } if (hset->ckind == DIAGC || hset->ckind == NULLC) mp->ckind = DIAGC; else{ HRError(7032,"GetMixPDF: trying to change global cov type to DiagC"); return(NULL); } } else if (tok->sym==INVCOVAR || (tok->sym==MACRO && tok->macroType=='i')){ if((mp->cov.inv = GetCovar(hset,src,tok))==NULL){ HMError(src,"GetCovar Failed"); return(NULL); } if (hset->ckind == FULLC || hset->ckind == NULLC) mp->ckind = FULLC; else{ HRError(7032,"GetMixPDF: trying to change global cov type to FullC"); return(NULL); } } else if (tok->sym==LLTCOVAR || (tok->sym==MACRO && tok->macroType=='c')){ if((mp->cov.inv = GetCovar(hset,src,tok))==NULL){ HMError(src,"GetCovar Failed"); return(NULL); } if (hset->ckind == LLTC || hset->ckind == NULLC) mp->ckind = LLTC; else{ HRError(7032,"GetMixPDF: trying to change global cov type to LLTC"); return(NULL); } } else if (tok->sym==XFORM || (tok->sym==MACRO && tok->macroType=='x')){ if((mp->cov.xform = GetTransform(hset,src,tok))==NULL){ HMError(src,"GetTransform Failed"); return(NULL); } if (hset->ckind == XFORMC || hset->ckind == NULLC) mp->ckind = XFORMC; else{ HRError(7032,"GetMixPDF: trying to change global cov type to XFormC"); return(NULL); } } else{ HMError(src,"Variance or Xform expected in GetMixPDF"); return(NULL); } if (tok->sym==GCONST) { ReadFloat(src,&mp->gConst,1,tok->binForm); if(GetToken(src,tok)<SUCCESS){ HMError(src,"GetToken failed"); return(NULL); } } } return mp; }/* CreateCME: create an array of M Continuous MixtureElems */static MixtureElem *CreateCME(HMMSet *hset, int M){ int m; MixtureElem *me,*p; me = (MixtureElem *)New(hset->hmem,M*sizeof(MixtureElem)); p = me-1; for (m=1;m<=M;m++,me++){ me->weight = 0.0; me->mpdf = NULL; } return p;}/* CreateTME: create an array of M Tied Mix Weights (ie floats) */static Vector CreateTME(HMMSet *hset, int M){ int m; Vector v; v = CreateVector(hset->hmem,M); for (m=1;m<=M;m++) v[m] = 0; return v;}/* CreateDME: create an array of M Discrete Mix Weights (ie shorts) */static ShortVec CreateDME(HMMSet *hset, int M){ int m; ShortVec v; v = CreateShortVec(hset->hmem,M); for (m=1;m<=M;m++) v[m] = 0; return v;}/* GetMixture: parse src and store a MixtureElem in spdf array */static ReturnStatus GetMixture(HMMSet *hset,Source *src,Token *tok,int M,MixtureElem *spdf){ float w = 1.0; short m = 1; if (trace&T_PAR) printf("HModel: GetMixture\n"); if (tok->sym == MIXTURE) { if (!ReadShort(src,&m,1,tok->binForm)){ HMError(src,"Mixture Index expected"); return(FAIL); } if (m<1 || m>M){ HMError(src,"Mixture index out of range"); return(FAIL); } if (!ReadFloat(src,&w,1,tok->binForm)){ HMError(src,"Mixture Weight expected"); return(FAIL); } if(GetToken(src,tok)<SUCCESS){ HMError(src,"GetToken failed"); return(FAIL); } } spdf[m].weight = w; if((spdf[m].mpdf = GetMixPDF(hset,src,tok))==NULL){ HMError(src,"Regression Class Number expected"); return(FAIL); } return(SUCCESS);} /* CreateSE: create an array of S StreamElems */static StreamElem *CreateSE(HMMSet *hset, int S){ int s; StreamElem *se,*p; se = (StreamElem *)New(hset->hmem,S*sizeof(StreamElem)); p = se-1; for (s=1;s<=S;s++,se++){ se->hook = NULL; se->spdf.cpdf = NULL; } return p;}/* EmptyMixPDF: return an empty Diag Covariance MixPDF */static MixPDF *EmptyMixPDF(HMMSet *hset, int vSize, int s){ int i; static Boolean isInitialised = FALSE; static MixPDF *t[SMAX]; static int size[SMAX]; if (!isInitialised){ for (i=0; i<SMAX; i++) t[i]=NULL; isInitialised = TRUE; } if (t[s] != NULL) { if (size[s] != vSize){ HRError(7090,"EmptyMixPDF: Size mismatch %d vs %d in EmptyDiagMixPDF", vSize,size[s]); return(NULL); } } size[s] = vSize; t[s] = (MixPDF *)New(hset->hmem,sizeof(MixPDF)); t[s]->ckind = DIAGC; t[s]->nUse = 0; t[s]->hook = NULL; t[s]->gConst = LZERO; t[s]->mean = CreateSVector(hset->hmem,vSize); ZeroVector(t[s]->mean); t[s]->cov.var = CreateSVector(hset->hmem,vSize); for (i=1; i<=vSize; i++) t[s]->cov.var[i] = 1.0; return t[s];}/* GetStream: parse src and store a StreamElem in pdf array */static ReturnStatus GetStream(HMMSet *hset, Source *src, Token *tok, StreamElem *pdf, short *nMix){ int m,S,M; short s; MixtureElem *cpdf; S=hset->swidth[0]; if (trace&T_PAR) { printf("HModel: GetStream - nMix ="); for (s=1; s<=S; s++) printf(" %d",nMix[s]); printf("\n"); } s = 1; if (tok->sym == STREAM) { if (!ReadShort(src,&s,1,tok->binForm)){ HMError(src,"Stream Index expected"); return(FAIL); } if (s<1 || s>S){ HMError(src,"Stream Index out of range"); return(FAIL); } if(GetToken(src,tok)<SUCCESS){ HMError(src,"GetToken failed"); return(FAIL); } } M = nMix[s]; pdf[s].nMix = M; if (tok->sym == TMIX ) { if (hset->hsKind == PLAINHS) hset->hsKind = TIEDHS; else if (hset->hsKind != TIEDHS){ HRError(7032,"GetStream: change to TIEDHS from other than PLAINHS"); return(FAIL); } pdf[s].spdf.tpdf = CreateTME(hset,M); if((GetTiedMixtures(hset,src,tok,M,s,pdf[s].spdf.tpdf))<SUCCESS){ HMError(src,"GetTiedMixtures failed"); return(FAIL); } } else if (tok->sym == DPROB) { if (hset->hsKind == PLAINHS) hset->hsKind = DISCRETEHS; else if (hset->hsKind != DISCRETEHS){ HRError(7032,"GetStream: change to DISCRETEHS from other than PLAINHS"); return(FAIL); } pdf[s].spdf.dpdf = CreateDME(hset,M); if((GetDiscreteWeights(src,tok,M,pdf[s].spdf.dpdf))<SUCCESS){ HMError(src,"GetDiscreteWeights failed"); return(FAIL); } } else { /* PLAIN/SHARED Mixtures */ cpdf = pdf[s].spdf.cpdf = CreateCME(hset,M); if((GetMixture(hset,src,tok,M,cpdf))<SUCCESS){ HMError(src,"GetMixtures failed"); return(FAIL); } while (tok->sym==MIXTURE) if((GetMixture(hset,src,tok,M,cpdf))<SUCCESS){ HMError(src,"GetMixtures failed"); return(FAIL); } for (m=1; m<=M; m++) if (cpdf[m].mpdf == NULL){ if((cpdf[m].mpdf = EmptyMixPDF(hset,hset->swidth[s],s))==NULL){ HMError(src,"EmptyMixPDF failed"); return(FAIL); } cpdf[m].weight = 0.0; } } return(SUCCESS);} /* GetStateInfo: parse src and return StateInfo structure */static StateInfo *GetStateInfo(HMMSet *hset, Source *src, Token *tok){ StateInfo *si; int i,S; short nMix[SMAX]; if (trace&T_PAR) printf("HModel: GetStateInfo\n"); S = hset->swidth[0]; if (tok->sym==MACRO && tok->macroType=='s') { if((si = (StateInfo *)GetStructure(hset,src,'s'))==NULL){ HMError(src,"GetStructure failed"); return(NULL); } ++si->nUse; if(GetToken(src,tok)<SUCCESS){ HMError(src,"GetToken failed"); return(NULL); } } else { if (tok->sym == NUMMIXES){ if (!ReadShort(src,nMix+1,S,tok->binForm)){ HMError(src,"Num Mix in Each Stream expected"); return(NULL); } if(GetToken(src,tok)<SUCCESS){ HMError(src,"GetToken failed"); return(NULL); } } else { for (i=1;i<=S;i++) nMix[i] = 1; } si = (StateInfo *)New(hset->hmem,sizeof(StateInfo)); si->nUse = 0; si->hook = NULL; si->weights = NULL; si->pdf = CreateSE(hset,S); if (tok->sym==SWEIGHTS || (tok->sym==MACRO && tok->macroType=='w')){ if((si->weights = GetSWeights(hset,src,tok))==NULL){ HMError(src,"GetSWeights failed"); return(NULL); }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -