/* SetCovs: set covariance values in hmm */
void SetCovs(void)
{
   int i,s,m;
   StateElem *se;
   StreamElem *ste;
   MixtureElem *me;
   MixPDF *mp;

   CalcCovs();
   if (trace&T_TOP) {
      printf("Updating HMM ");
      if (meanUpdate) printf("Means and ");
      printf("Covariances\n");
   }
   for (i=2,se=hmmLink->svec+2; i < hmmLink->numStates; i++,se++)
      for (s=1,ste=se->info->pdf+1; s <= hset.swidth[0]; s++,ste++)
         for (m=1,me = ste->spdf.cpdf+1; m<=ste->nMix; m++, me++) {
            mp = me->mpdf;
            if (meanUpdate && !IsSeenV(mp->mean)){      /* meanSum now holds mean */
               CopyVector(accs[s].meanSum,mp->mean); 
               TouchV(mp->mean);
            }
            if (!IsSeenV(mp->cov.var)){
               if (mp->ckind==FULLC)
                  CopyMatrix(accs[s].fixed.inv,mp->cov.inv);
               else if (fullcNeeded[s])  /* dont need full cov, but its all we have */                
                  TriDiag2Vector(accs[s].fixed.inv,mp->cov.var);
               else
                  CopyVector(accs[s].fixed.var,mp->cov.var);
               TouchV(mp->cov.var);
            }
         }
   ClearSeenFlags(&hset,CLR_ALL);
}
Ejemplo n.º 2
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.º 3
0
/* EXPORT->ConvDiagC Convert Diagonal Covariance Kind
  Converts all the HMMs in hset to INVDIAGC from DIAGC
  or vice versa. If convData is TRUE then each variance element is
  replaced by its reciprocal - otherwise only the CovKind in each HMM
  is changed and no data conversions are performed. */
void ConvDiagC(HMMSet *hset, Boolean convData)
{
   HMMScanState hss;
   SVector v;
   int k;

   if (hset->hsKind == DISCRETEHS || hset->hsKind == TIEDHS)
      return;
   NewHMMScan(hset, &hss);
   while (GoNextMix(&hss,FALSE)) {
      if (hss.mp->ckind == DIAGC || hss.mp->ckind == INVDIAGC){
         hss.mp->ckind = (hss.mp->ckind == DIAGC)?INVDIAGC:DIAGC;
         if (convData){
            v = hss.mp->cov.var;
            if (! IsSeenV(v)) {
               for (k=1; k<=hset->swidth[hss.s]; k++) {
                  if (v[k] > MAXVAR) v[k] = MAXVAR;
                  if (v[k] < MINVAR) v[k] = MINVAR;
                  v[k] = 1/v[k];
               }
               TouchV(v);
            }
         }
      }
   }
   EndHMMScan(&hss);
   ClearSeenFlags(hset,CLR_ALL);
}
Ejemplo n.º 4
0
static int TotMixInSet(HMMSet *hset)
{
   HMMScanState hss;
   HLink hmm;
   int nmix=0;

   NewHMMScan(hset,&hss);
   do {
     hmm = hss.hmm;
     while (GoNextState(&hss,TRUE)) {
       while (GoNextStream(&hss,TRUE)) {
	 if (hss.isCont)                     /* PLAINHS or SHAREDHS */
	   while (GoNextMix(&hss,TRUE)) {
	     if (!IsSeenV(hss.mp->mean)) {
	       nmix++;
	       TouchV(hss.mp->mean);
	     } 
	   }
       }
     }
   } while (GoNextHMM(&hss));
   EndHMMScan(&hss);
   return(nmix);
}