Ejemplo n.º 1
0
/* UpdateTMVars: use acc values to calc new estimate of variances */
void UpdateTMVars(void)
{
   int s,m,k,l,M,vSize;
   float occim,x,muDiffk,muDiffl;
   Vector minV;
   VaAcc *va;
   MuAcc *ma;
   MixPDF *mpdf;
   Vector mean;
   Covariance cov;
   Boolean mixFloored,shared;

   for (s=1;s<=nStreams;s++){
      vSize = hset.swidth[s];
      minV = vFloor[s];
      M = hset.tmRecs[s].nMix;
      for (m=1;m<=M;m++){
         mpdf = hset.tmRecs[s].mixes[m];
         cov = mpdf->cov;
         va = (VaAcc *) GetHook(cov.var);
         mean = mpdf->mean;
         ma = (MuAcc *) GetHook(mean);     
         if (va != NULL){
            occim = va->occ;
            mixFloored = FALSE;
            if (occim > 0.0){
               shared=(GetUse(cov.var)>1 || ma==NULL || ma->occ<=0.0);
               if ((mpdf->ckind==DIAGC)||(mpdf->ckind==INVDIAGC))
                  for (k=1; k<=vSize; k++){
                     muDiffk=(shared)?0.0:ma->mu[k]/ma->occ;
                     x = va->cov.var[k]/occim - muDiffk*muDiffk;
                     if (x<minV[k]) {
                        x = minV[k];
                        mixFloored = TRUE;
                     }
                     cov.var[k] = x;
                  }
               else { /* FULLC */
                  for (k=1; k<=vSize; k++){
                     muDiffk=(shared)?0.0:ma->mu[k]/ma->occ;
                     for (l=1; l<=k; l++){
                        muDiffl=(shared)?0.0:ma->mu[l]/ma->occ;
                        x = va->cov.inv[k][l]/occim - muDiffk*muDiffl;
                        if (k==l && x<minV[k]){
                           x = minV[k];
                           mixFloored = TRUE;
                        }              
                        cov.inv[k][l] = x;
                     }
                  }
                  CovInvert(cov.inv,cov.inv);
               }
            }
            else
               HError(-2427,"UpdateTMVars: No use of var %d in stream %d",m,s);
            SetHook(cov.var,NULL);
         }
      }
   }
}
Ejemplo n.º 2
0
/* EXPORT->GetMacroUse: Return value of use field for any macro */
int GetMacroUse(MLink ml)
{
   int use;

   switch(ml->type) {
      case 'l': /* HLink */
      case 'h': /* HLink */
         use=((HLink)(ml->structure))->nUse; break;
      case 's': /* StateInfo * */
         use=((StateInfo *)(ml->structure))->nUse; break;
      case 'm': /* MixPDF * */
      use=((MixPDF *)(ml->structure))->nUse; break;
      case 'j': /* InputXForm * */
         use=((InputXForm *)(ml->structure))->nUse; break;
      case 'c': /* STriMat */
      case 'i': /* STriMat */
      case 'x': /* SMatrix */
      case 't': /* SMatrix */
      case 'u': /* SVector */
      case 'd': /* SVector */
      case 'w': /* SVector */
      case 'v': /* SVector */
         use=GetUse(ml->structure); break;
      case '*': /* deleted */
      case 'b':
      case 'r':
         use=-1; break;
      case 'o': /* fake */
      default:
         use=-1;
         HError(7270,"GetMacroUse: Getting use of non-existant macro");
   }
   return(use);
}
Ejemplo n.º 3
0
/* UpdateParameters: in hmm using counts in accumulators */
void UpdateParameters(void)
{
   HMMScanState hss;
   int size;
   StreamInfo *sti;
   WtAcc *wa;
   MuAcc *ma = NULL;
   VaAcc *va;
   TrAcc *ta;
   Boolean hFound = FALSE,shared;

   NewHMMScan(&hset,&hss);
   do if (hmmLink == hss.hmm){
      hFound = TRUE;
      while (GoNextState(&hss,TRUE)) {
         while (GoNextStream(&hss,TRUE)) {
            sti = hss.sti;
            if (hss.M>1 && (uFlags&UPMIXES)){
               wa = (WtAcc *)sti->hook;
               if (hset.hsKind == DISCRETEHS)
                  UpDProbs(hss.i,hss.s,hss.M,wa,sti->spdf.dpdf);
               else
                  UpWeights(hss.i,hss.s,hss.M,wa,sti);
            }
            if (hss.isCont && (uFlags&(UPMEANS|UPVARS)))/*PLAINHS or SHAREDHS*/
               while (GoNextMix(&hss,TRUE)) {
                  size = VectorSize(hss.mp->mean);
                  if (!IsSeenV(hss.mp->mean)) {
                     ma = (MuAcc *)GetHook(hss.mp->mean);
                     if (ma->occ!=0.0)
                     UpMeans(hss.i,hss.s,hss.m,size,ma,hss.mp->mean);
                     /* NB old mean left in ma->mu */
                     TouchV(hss.mp->mean);
                  }
                  if (!IsSeenV(hss.mp->cov.var)) {
                     if (uFlags&UPVARS) {
                        va = (VaAcc *)GetHook(hss.mp->cov.var);
                        shared = (GetUse(hss.mp->cov.var) > 1) ? TRUE:FALSE;
                        if (va->occ!=0.0)
                           UpVars(hss.i,hss.s,hss.m,size,va,ma->mu,hss.mp->mean,shared,hss.mp);
                     }
                     TouchV(hss.mp->cov.var);
                  }
               }
         }
      }
      if (!IsSeenV(hmmLink->transP)) {
         if (uFlags&UPTRANS){
            ta = (TrAcc *)GetHook(hmmLink->transP);
            UpTrans(ta,hmmLink->transP);
         }
         TouchV(hmmLink->transP);       
      }
   } while (!hFound && GoNextHMM(&hss));
   EndHMMScan(&hss);
   if (!hFound)
      HError(2129,"UpdateParameters: hmm not found");
}
Ejemplo n.º 4
0
/* CloneSTriMat: return a clone of given TriMat */
STriMat CloneSTriMat(MemHeap *hmem, STriMat s, Boolean sharing)
{
   STriMat t;  /* the target */

   if (s==NULL) return NULL;
   if (GetUse(s)>0 && sharing) {
      IncUse(s);
      return s;
   }
   t = CreateSTriMat(hmem,TriMatSize(s));
   CopyTriMat(s,t);
   return t;
}
Ejemplo n.º 5
0
/* CloneSMatrix: return a clone of given Matrix */
SMatrix CloneSMatrix(MemHeap *hmem, SMatrix s, Boolean sharing)
{
   SMatrix t;  /* the target */

   if (s==NULL) return NULL;
   if (GetUse(s)>0 && sharing) {
      IncUse(s);
      return s;
   }
   t = CreateSMatrix(hmem,NumRows(s),NumCols(s));
   CopyMatrix(s,t);
   return t;
}
Ejemplo n.º 6
0
/* CloneSVector: return a clone of given matrix */
SVector CloneSVector(MemHeap *hmem, SVector s, Boolean sharing)
{
   SVector t;  /* the target */

   if (s==NULL) return NULL;
   if (GetUse(s)>0 && sharing) {
      IncUse(s);
      return s;
   }
   t = CreateSVector(hmem,VectorSize(s));
   CopyVector(s,t);
   return t;
}
Ejemplo n.º 7
0
/* UpdateVars: use acc values to calc new estimate of variances */
static void UpdateVars(HMMSet *hset, int px, HLink hmm)
{
   int i,s,m,k,M,N,vSize;
   float occim,x,muDiffk,dmu;
   Vector minV;
   VaAcc *va;
   MuAcc *ma;
   StateElem *se;
   StreamElem *ste;
   MixtureElem *me;
   Vector mean,var;
   Covariance cov;
   Boolean mixFloored,shared;
   
   N = hmm->numStates;
   se = hmm->svec+2; 
   for (i=2; i<N; i++,se++){
      ste = se->info->pdf+1;
      for (s=1;s<=S;s++,ste++){
         minV = vFloor[s];
         me = ste->info->spdf.cpdf + 1; 
         M = ste->info->nMix;
         for (m=1;m<=M;m++,me++)
	   if (MixWeight(hset,me->weight) > MINMIX){
               cov = me->mpdf->cov;
               va = GetHook(cov.var);
               mean = me->mpdf->mean;
               vSize = VectorSize(mean);
               ma = GetHook(mean);
               if (va != NULL){
                  occim = va->occ;
                  mixFloored = FALSE;
                  if (occim > 0.0){
                     shared = (GetUse(cov.var)>1 || ma==NULL || ma->occ<=0.0) ? TRUE : FALSE;
                     if (me->mpdf->ckind==DIAGC) {
		         var = cov.var;
			 for (k=1; k<=vSize; k++){
			   if (shared) muDiffk = 0.0;
			   else {
			     dmu = (ma->mu[k])/(mapTau+occim);
			     muDiffk = 2*dmu*ma->mu[k] - dmu*dmu*occim;
			   }
                           x = (mapTau*var[k]  + va->cov.var[k] - muDiffk) / (mapTau + occim);
                           if (applyVFloor && x<minV[k]) {
                             x = minV[k];
                              nFloorVar++;
                              mixFloored = TRUE;
			    }
			   cov.var[k] = x;
			 }
       		     }
                     else { /* FULLC */
		       HError(999,"MAP estimation of full covariance matrices not supported");
		     }
		  }
                  if (mixFloored == TRUE) nFloorVarMix++;
		  SetHook(cov.var,NULL);
               }
            }
      }
   }
}
Ejemplo n.º 8
0
         /* track speakers */	 

         if (UpdateSpkrStats(&hset,&xfInfo, datafn)) spUtt=0;

	 /* Check to see whether set-up is valid */

	 CheckUpdateSetUp();

         fbInfo->inXForm = xfInfo.inXForm;

         fbInfo->al_inXForm = xfInfo.al_inXForm;

         fbInfo->paXForm = xfInfo.paXForm;

         if ((maxSpUtt==0) || (spUtt<maxSpUtt))

            DoForwardBackward(fbInfo, utt, datafn, datafn2) ;

         numUtt += 1; spUtt++;

      }

   } while (NumArgs()>0);



   if (uFlags&UPXFORM) {/* ensure final speaker correctly handled */ 

      UpdateSpkrStats(&hset,&xfInfo, NULL); 

      if (trace&T_TOP) {

         printf("Reestimation complete - average log prob per frame = %e (%d frames)\n",

                totalPr/totalT, totalT);

      }

   } else {

      if (parMode>0  || (parMode==0 && (updateMode&UPMODE_DUMP))){

         MakeFN("HER$.acc",newDir,NULL,newFn);

         f=DumpAccs(&hset,newFn,uFlags,parMode);

         tmpFlt = (float)totalPr;

         WriteFloat(f,&tmpFlt,1,ldBinary);

         WriteInt(f,(int*)&totalT,1,ldBinary);

         fclose( f );

      }

      if (parMode <= 0) {

         if (stats) {

            StatReport(&hset);

         }

         if (updateMode&UPMODE_UPDATE)

            UpdateModels(&hset,utt->pbuf2);

      }

   }

   ResetHeap(&uttStack);

   ResetHeap(&fbInfoStack);

   ResetHeap(&hmmStack);
Ejemplo n.º 9
0
/* EXPORT->FreeSTriMat: Free space allocated for shared tri matrix m */
void FreeSTriMat(MemHeap *x,STriMat m)
{
   DecUse(m);
   if (GetUse(m) <= 0) 
      Dispose(x,(Ptr *)(m) - 2);
}
Ejemplo n.º 10
0
/* EXPORT->FreeSMatrix: Free space allocated for matrix m */
void FreeSMatrix(MemHeap *x, Matrix m)
{
   DecUse(m);
   if (GetUse(m) <= 0)
      Dispose(x,(Ptr *)(m) - 2);
}
Ejemplo n.º 11
0
/* EXPORT->FreeSVector: Free space allocated for vector v[1..size] */
void FreeSVector(MemHeap *x, Vector v)
{
   DecUse(v);
   if (GetUse(v) <= 0)
      Dispose(x,(Ptr *)(v)-2);
}
Ejemplo n.º 12
0
int CInterpreter::GetID( char *id_name )
{
	int		id;

	id = FindSymbol( id_name, m_IDKeywords );

	if ( id == -1 )
		return Error("'%s' : unknown identifier", id_name);

	//FIXME: Function pointers would be awfully nice.. but not inside a class!  Weee!!

	switch (id)
	{
	
	//Affect takes control of an entity

	case ID_AFFECT:
		return GetAffect();
		break;

	//Wait for a specified amount of time

	case ID_WAIT:
		return GetWait();
		break;

	//Generic set call

	case ID_SET:
		return GetSet();
		break;

	case ID_LOOP:
		return GetLoop();
		break;

	case ID_PRINT:
		return GetPrint();
		break;

	case ID_USE:
		return GetUse();
		break;

	case ID_FLUSH:
		return GetFlush();
		break;
		
	case ID_RUN:
		return GetRun();
		break;

	case ID_KILL:
		return GetKill();
		break;

	case ID_REMOVE:
		return GetRemove();
		break;

	case ID_CAMERA:
		return GetCamera();
		break;

	case ID_SOUND:
		return GetSound();
		break;

	case ID_MOVE:
		return GetMove();
		break;

	case ID_ROTATE:
		return GetRotate();
		break;

	case ID_IF:
		return GetIf();
		break;

	case ID_ELSE:
		//return Error("syntax error : else without matching if");
		return GetElse();	//FIXME: Protect this call so that floating else's aren't allowed
		break;

	case ID_GET:
		return Error("syntax error : illegal use of \"get\"");
		break;

	case ID_TAG:
		return Error("syntax error : illegal use of \"tag\"");
		break;

	case ID_TASK:
		return GetTask();
		break;

	case ID_DO:
		return GetDo();
		break;

	case ID_DECLARE:
		return GetDeclare();
		break;

	case ID_FREE:
		return GetFree();
		break;

	case ID_REM:
		GetRem();
		break;

	case ID_DOWAIT:
		GetDoWait();
		break;

	case ID_SIGNAL:
		GetSignal();
		break;

	case ID_WAITSIGNAL:
		GetWaitSignal();
		break;

	case ID_PLAY:
		GetPlay();	//Bad eighties slang joke...  yeah, it's not really funny, I know...
		break;

		//Local variable types
	case TK_FLOAT:
	case TK_INT:
	case TK_STRING:
	case TK_VECTOR:
		GetVariable( id );
		break;

	//Unknown ID

	default:
	case -1:
		return Error("'%s' : unknown identifier", id_name);
		break;
	}

	return true;
}