/* UpWeights: update given mixture weights */ void UpWeights(int i, int s, int M, WtAcc *wa, StreamInfo *sti) { int m; float sum=0.0; if (wa->occ == 0.0) HError(2127,"UpWeights: zero occ i=%d/s=%d",i,s); for (m=1; m<=M; m++){ sum += wa->c[m]; switch(hset.hsKind){ case PLAINHS: case SHAREDHS: sti->spdf.cpdf[m].weight = wa->c[m] / wa->occ; break; case TIEDHS: sti->spdf.tpdf[m] = wa->c[m] / wa->occ; break; } } if (fabs(sum-wa->occ)/sum > 0.001) HError(2190,"UpWeights: mix weight sum error"); if (mixWeightFloor>0.0) { switch(hset.hsKind) { case PLAINHS: case SHAREDHS: FloorMixes(sti->spdf.cpdf+1,M,mixWeightFloor); break; case TIEDHS: FloorTMMixes(sti->spdf.tpdf,M,mixWeightFloor); break; } } }
/* UpdateWeights: use acc values to calc new estimate of mix weights */ void UpdateWeights(HLink hmm) { int i,s,m,M=0,N; float x,occi; WALink wa; StateElem *se; StreamElem *ste; MLink q; q=FindMacroStruct(&hset,'h',hmm); N = hmm->numStates; se = hmm->svec+2; for (i=2; i<N; i++,se++){ ste = se->info->pdf+1; for (s=1;s<=nStreams; s++,ste++){ wa = (WALink)ste->hook; if (wa != NULL) { switch(hsKind){ case TIEDHS: M = hset.tmRecs[s].nMix; break; case DISCRETEHS: M = ste->nMix; break; } occi = wa->occ; if (occi>0) { for (m=1; m<=M; m++){ x = wa->c[m]/occi; if (x>1.0){ if (x>1.001) HError(-2490,"UpdateWeights: Model [%s]: mix too big in %d.%d.%d",q->id->name,i,s,m); x = 1.0; } switch (hsKind){ case TIEDHS: ste->spdf.tpdf[m] = (x>MINMIX) ? x : 0; break; case DISCRETEHS: ste->spdf.dpdf[m] = (x>MINMIX) ? DProb2Short(x) :DLOGZERO; break; } } if (mixWeightFloor>0.0){ switch (hsKind){ case DISCRETEHS: FloorDProbs(ste->spdf.dpdf,M,mixWeightFloor); break; case TIEDHS: FloorTMMixes(ste->spdf.tpdf,M,mixWeightFloor); break; } } }else HError(-2427,"UpdateWeights: Model [%s]: no use of mixtures in %d.%d",q->id->name,i,s); ste->hook = NULL; } } } }
static void FloorMixtures(HSetKind hskind, StreamInfo *sti, int M, float floor) { switch (hskind){ case DISCRETEHS: FloorDProbs(sti->spdf.dpdf,M,floor); break; case TIEDHS: FloorTMMixes(sti->spdf.tpdf,M,floor); break; case PLAINHS: case SHAREDHS: FloorMixes(sti->spdf.cpdf+1,M,floor); break; } }
case 'l': maxSpUtt = GetChkedInt(0,0100000,s); break; case 'E': if (NextArg()!=STRINGARG) HError(2319,"HERest: parent transform directory expected"); xfInfo.usePaXForm = TRUE; xfInfo.paXFormDir = GetStrArg(); if (NextArg()==STRINGARG) xfInfo.paXFormExt = GetStrArg(); if (NextArg() != SWITCHARG) HError(2319,"HERest: cannot have -E as the last option"); break; case 'J': if (NextArg()!=STRINGARG) HError(2319,"HERest: input transform directory expected"); AddInXFormDir(&hset,GetStrArg()); if (NextArg()==STRINGARG) { if (xfInfo.inXFormExt == NULL) xfInfo.inXFormExt = GetStrArg(); else HError(2319,"HERest: only one input transform extension may be specified"); } if (NextArg() != SWITCHARG) HError(2319,"HERest: cannot have -J as the last option"); break; case 'K': if (NextArg()!=STRINGARG) HError(2319,"HERest: output transform directory expected"); xfInfo.outXFormDir = GetStrArg(); if (NextArg()==STRINGARG) xfInfo.outXFormExt = GetStrArg(); if (NextArg() != SWITCHARG) HError(2319,"HERest: cannot have -K as the last option"); break; case 'z': if (NextArg() != STRINGARG) HError(2319,"HERest: output TMF file expected");
/* UniformSegment: and cluster within each state/segment */ void UniformSegment(void) { Sequence ***seqMat; /* Matrix [2..numStates-1][1..numStreams][1..nKindS]*/ Sequence seq; int count,size,i,s,n,m,M,j,k,sumItems; long vqidx; ClusterSet *cset; Cluster *c; StreamInfo *sti; Covariance cov; CovKind ck; MixPDF *mp; TMixRec *tmRec = NULL; ShortVec dw; float x,z; Vector floor; SpaceInfo *si; void FloorMixes (MixtureElem *mixes, const int M, const float floor); void FloorTMMixes(Vector mixes, const int M, const float floor); if (trace & T_UNI) printf(" Uniform Segmentation\n"); seqMat = CreateSeqMat(); cov.var = NULL; /* dummy */ UCollectData(seqMat); if (trace&T_UNI) ShowSeqMat(seqMat); /* Cluster Each State/Stream and Init HMM Parms */ for (n=2; n<nStates; n++) { if (trace&T_UNI) printf(" state %d ",n); for (s=1; s<=nStreams; s++){ floor = vFloor[s]; sti = hmmLink->svec[n].info->pdf[s].info; if (hset.hsKind == TIEDHS){ tmRec = &(hset.tmRecs[s]); M = tmRec->nMix; tmRec->topM = tmRec->nMix; } else M = sti->nMix; if (trace&T_UNI) printf(" stream %d\n",s); switch (hset.hsKind){ case PLAINHS: case SHAREDHS: ck = sti->spdf.cpdf[1].mpdf->ckind; sumItems = 0; for(k=1; k<=msdInfo[n][s]->nKindS; k++) sumItems += seqMat[n][s][k]->nItems; for(k=1,si=msdInfo[n][s]->next; k<=msdInfo[n][s]->nKindS; k++,si=si->next){ seq = seqMat[n][s][k]; if(seq->nItems == 0){ for (m=1; m<=si->count; m++) if (uFlags&UPMIXES) sti->spdf.cpdf[si->sindex[m]].weight = 0; } else { cset = FlatCluster(&clustSetStack,seq,si->count,NULLC,ck,cov); if (trace&T_UNI) ShowClusterSet(cset); for (m=1; m<=si->count; m++){ mp = sti->spdf.cpdf[si->sindex[m]].mpdf; size = VectorSize(mp->mean); if (mp->ckind != ck) HError(2123,"UniformSegment: different covkind within a mix\n"); c = cset->cl+m; if (uFlags&UPMIXES) sti->spdf.cpdf[si->sindex[m]].weight = (float)((double)c->csize/(double)sumItems); if (uFlags&UPMEANS) CopyRVector(c->vCtr,mp->mean,si->order); if (uFlags&UPVARS){ switch(ck){ case DIAGC: for (j=1; j<=size; j++){ z= c->cov.var[j]; mp->cov.var[j] = (z<floor[j])?floor[j]:z; } break; case FULLC: for (j=1; j<=size; j++){ for (k=1; k<j; k++) { mp->cov.inv[j][k] = c->cov.inv[j][k]; } z = c->cov.inv[j][j]; mp->cov.inv[j][j] = (z<floor[j])?floor[j]:z; } break; default: HError(2124,"UniformSegment: bad cov kind %d\n",ck); } } } } } FloorMixes(sti->spdf.cpdf+1,M,mixWeightFloor); break; case DISCRETEHS: size = hset.swidth[s]; seq = seqMat[n][s][1]; count = 0; dw = sti->spdf.dpdf; ZeroShortVec(dw); for (i=1; i<=seq->nItems; i++){ vqidx = (long)GetItem(seq,i); if (vqidx<1 || vqidx>M) HError(2170,"UniformSegment: vqidx out of range[%ld]",vqidx); ++dw[vqidx]; ++count; } for (m=1; m<=M; m++){ x = (float)dw[m]/(float)count; if (x<mixWeightFloor) x = mixWeightFloor; dw[m] = DProb2Short(x); } break; case TIEDHS: size = hset.swidth[s]; seq = seqMat[n][s][1]; ck = tmRec->mixes[1]->ckind; cset = FlatCluster(&clustSetStack,seq,M,NULLC,ck,cov); if (trace&T_UNI) ShowClusterSet(cset); for (m=1; m<=M; m++){ mp = tmRec->mixes[m]; if (mp->ckind != ck) HError(2123,"UniformSegment: different covkind within a mix\n"); c = cset->cl+m; if (uFlags&UPMIXES) sti->spdf.tpdf[m] = (float)c->csize/(float)seq->nItems; if (uFlags&UPMEANS) CopyVector(c->vCtr,mp->mean); if (uFlags&UPVARS) switch(ck){ case DIAGC: for (j=1; j<=size; j++){ z= c->cov.var[j]; mp->cov.var[j] = (z<floor[j])?floor[j]:z; } break; case FULLC: for (j=1; j<=size; j++){ for (k=1; k<j; k++) { mp->cov.inv[j][k] = c->cov.inv[j][k]; } z = c->cov.inv[j][j]; mp->cov.inv[j][j] = (z<floor[j])?floor[j]:z; } break; default: HError(2124,"UniformSegment: bad cov kind %d\n",ck); } } FloorTMMixes(sti->spdf.tpdf,M,mixWeightFloor); break; } ResetHeap(&clustSetStack); } if ((hset.hsKind == PLAINHS) || (hset.hsKind == SHAREDHS)) FixGConsts(hmmLink); } ResetHeap(&sequenceStack); }