void ArcFromLat(ArcInfo *aInfo, HMMSet *hset){ Lattice *lat; int larcid,seg; int start_time; HArc *arc; int l; float framedur; if(!StackInitialised) CreateHeap(&tempArcStack, "tempArcStore", MSTAK, 1, 0.5, 1000, 10000); aInfo->start=aInfo->end=0; aInfo->nArcs=0; if(IsLMScale) aInfo->lmScale = LMSCALE; else /* If none is specified use the one from the lattice. */ aInfo->lmScale = aInfo->lat[0]->lmscale; /* Lattices actually never specify frame duration. Usual source is config, FRAMEDUR. */ /* if(lat->framedur != 0) framedur = lat->framedur / 10000000; */ if (FRAMEDUR) framedur = FRAMEDUR; /* config. */ else framedur = 0.01; aInfo->framedur = framedur; if(!IsWdPen) aInfo->insPen = aInfo->lat[0]->wdpenalty; else aInfo->insPen = WDPEN; /* Add all the arcs in the lattice into the Arc structure. */ for(l=0;l<aInfo->nLats;l++) /* this handles multiple lattices so e.g. the correct lattice can be added to the recognition lattice in case it happens to be absent. */ { lat = aInfo->lat[l]; ZeroHooks(lat); FixLatTimes(lat); /* this can be deleted at some point. */ for(larcid=0;larcid<lat->na;larcid++){ start_time = TimeToNFrames(lat->larcs[larcid].start->time, aInfo); for(seg=0;seg<lat->larcs[larcid].nAlign;seg++){ arc = CreateArc(aInfo->mem, lat, lat->larcs+larcid, start_time, seg, ++aInfo->nArcs, (seg==0?NULL:aInfo->end), aInfo->insPen, aInfo->lmScale, hset, aInfo); /* this creates the phone arc and also the transitions between them. (confusingly, phone arcs are actually nodes in the datastructure used here, and transitions are arcs) */ /*Insert into the linked list of arcs:*/ if(!aInfo->start) aInfo->start=arc; arc->prec = aInfo->end; arc->foll = NULL; if(aInfo->end) aInfo->end->foll = arc; aInfo->end = arc; start_time = aInfo->end->t_end; } } } SortArcs(aInfo); /* Sort the arcs in order of start & end time [ & in such a way that ones with identical HMMs are adjacent.] */ if(BackTransitions(aInfo)){ /* A check-- should never be true if properly sorted */ HError(1, "Error: file %s: back transitions exist.\n", (aInfo->lat[0]->utterance?aInfo->lat[0]->utterance:"[unknown]")); } /* Pool sets of identical models with identical start & end times. */ for(arc=aInfo->start; arc; arc=arc->foll){ HArc *arc2; if((arc2=arc->prec) != NULL && arc2->t_end==arc->t_end && arc2->t_start==arc->t_start && arc2->hmm==arc->hmm){ if(arc2->calcArc == NULL) arc->calcArc = arc2; else arc->calcArc = arc2->calcArc; } } { /* Set up the structures which relate to the computation of model likelihoods. */ int q=0,Q; MLink macroName; int T=0,t; for(arc=aInfo->start;arc;arc=arc->foll){ if(arc->calcArc) arc->id = GHOST_ARC; else{ arc->id = ++q; } T=MAX(T,arc->t_end); } aInfo->Q = Q = q; /* num unique arcs. */ aInfo->T = T; aInfo->ac = (Acoustic*)New(aInfo->mem, sizeof(Acoustic) * (q+1)); q=0; for(arc=aInfo->start;arc;arc=arc->foll){ if(!arc->calcArc){ /* if this is one of the 'calculated' arcs */ Acoustic *ac = arc->ac = aInfo->ac + ++q; ac->myArc=arc; ac->t_start=arc->t_start; ac->t_end=arc->t_end; if((macroName=FindMacroName(hset,'l',arc->phone))==NULL) HError(2321,"CreateArc: Unknown align label %s",arc->phone->name); ac->hmm = (HLink)macroName->structure; ac->Nq = ac->hmm->numStates; /* could be either HMM, same structure. */ if(ac->t_start == ac->t_end+1){ ac->SP=TRUE; ac->alphat=ac->alphat1=NULL;ac->betaPlus=NULL;ac->otprob=NULL; } else { int j,s,SS,S = hset->swidth[0]; /* probably just 1. */ StreamElem *ste; SS=(S==1)?1:S+1; ac->SP=FALSE; ac->alphat = CreateDVector(aInfo->mem, ac->Nq); ac->alphat1 = CreateDVector(aInfo->mem, ac->Nq); ac->betaPlus = ((DVector*)New(aInfo->mem, sizeof(DVector)*(ac->t_end-ac->t_start+1)))-ac->t_start; ac->otprob = ((float****)New(aInfo->mem, sizeof(float***)*(ac->t_end-ac->t_start+1)))-ac->t_start; for(t=ac->t_start;t<=ac->t_end;t++){ ac->betaPlus[t] = CreateDVector(aInfo->mem,ac->Nq); ac->otprob[t] = ((float***)New(aInfo->mem,(ac->Nq-2)*sizeof(float **)))-2; for(j=2;j<ac->Nq;j++){ ac->otprob[t][j] = (float**)New(aInfo->mem,SS*sizeof(float*)); /*2..Nq-1*/ ste = ac->hmm->svec[j].info->pdf+1; if (S==1) { ac->otprob[t][j][0] = NULL; } else { ac->otprob[t][j][0] = (float*)New(aInfo->mem,sizeof(float)); ac->otprob[t][j][0][0] = LZERO; for (s=1;s<=S;s++,ste++) ac->otprob[t][j][s] = NULL; } } } } } } for(arc=aInfo->start;arc;arc=arc->foll) if(arc->calcArc) arc->ac = arc->calcArc->ac; /* Set up arrays qLo[t] and qHi[t] which are used to speed up iterations over q. */ aInfo->qLo = (int*)New(aInfo->mem, sizeof(int)*(aInfo->T+1)); /* For efficiency later, work out min & max q active at each time t. */ aInfo->qHi = (int*)New(aInfo->mem, sizeof(int)*(aInfo->T+1)); for(t=1;t<=T;t++){ aInfo->qLo[t] = T+1; aInfo->qHi[t] = -1; } for(q=1;q<=Q;q++){ for(t=aInfo->ac[q].t_start;t<=MAX(aInfo->ac[q].t_end,aInfo->ac[q].t_start);t++){ /* the MAX above is to handle tee models, so they will be in beam at t==t_start. */ aInfo->qLo[t] = MIN(aInfo->qLo[t], q); aInfo->qHi[t] = MAX(aInfo->qHi[t], q); } } } if(trace&T_ARC && debug++ < 100){ printf("[HArc:] %d arcs, depth %f, depth[reduced] %f\n", aInfo->nArcs, Depth(aInfo,TRUE), Depth(aInfo,FALSE)); if(trace&T_ARC2) PrintArcs(stdout, aInfo->start); } ResetHeap(&tempArcStack); }
/* InitMgeTrnInfo: Initialize all info struct for MGE training */ static void InitMgeTrnInfo() { int i, p, nWin; /* setup GenInfo */ genInfo->genMem = &genStack; genInfo->hset = &hset; genInfo->maxStates = MaxStatesInSet(&hset); genInfo->MSDthresh = MSDthresh; genInfo->frameRate = frameRate; genInfo->stateAlign = TRUE; CheckGenSetUp(); /* setup MTStatInfo */ statInfo->order = GetTotalOrder(mtInfo->genInfo); for (p = 1; p <= genInfo->nPdfStream[0]; p++) { statInfo->initErrAcc[p] = CreateDVector(&gstack, genInfo->pst[p].order * 2); statInfo->prevErrAcc[p] = CreateDVector(&gstack, genInfo->pst[p].order * 2); statInfo->currErrAcc[p] = CreateDVector(&gstack, genInfo->pst[p].order * 2); ZeroDVector(statInfo->initErrAcc[p]); ZeroDVector(statInfo->prevErrAcc[p]); ZeroDVector(statInfo->currErrAcc[p]); } nWin = mtInfo->genInfo->pst[1].win.num; for (p = 1; p <= genInfo->nPdfStream[0]; p++) { statInfo->pnMeanFloor[p] = (IMatrix *) New(&gstack, statInfo->order * sizeof(IMatrix *)); statInfo->pnMeanFloor[p]--; statInfo->pnVarFloor[p] = (IMatrix *) New(&gstack, statInfo->order * sizeof(IMatrix *)); statInfo->pnVarFloor[p]--; for (i = 1; i <= statInfo->order; i++) { statInfo->pnMeanFloor[p][i] = CreateIMatrix(&gstack, nWin, 2); /* 2: High & Low floor */ ZeroIMatrix(statInfo->pnMeanFloor[p][i]); statInfo->pnVarFloor[p][i] = CreateIMatrix(&gstack, nWin, 2); /* 2: High & Low floor */ ZeroIMatrix(statInfo->pnVarFloor[p][i]); } } /* setup MgeTrnInfo */ mtInfo->nBoundAdjWin = nBoundAdjWin; mtInfo->fGVDistWght = fGVDistWght; mtInfo->uFlags = uFlags; mtInfo->funcType = funcType; for (p = 1; p <= genInfo->nPdfStream[0]; p++) { mtInfo->SRMean[p] = CreateVector(&gstack, genInfo->pst[p].order); mtInfo->SRVar[p] = CreateVector(&gstack, genInfo->pst[p].order); mtInfo->DWght[p] = CreateVector(&gstack, genInfo->pst[p].order); ZeroVector(mtInfo->SRMean[p]); ZeroVector(mtInfo->SRVar[p]); ZeroVector(mtInfo->DWght[p]); } if (scalefn != NULL) { LoadScaleRate(scalefn); mtInfo->bMScale = TRUE; } else mtInfo->bMScale = FALSE; CheckMTInfoSetUp(); return; }