Exemple #1
0
/* EstimateModel: top level of iterative estimation process */
void EstimateModel(void)
{
   LogFloat totalP,newP,delta;
   Boolean converged = FALSE;
   int i,iter,numSegs,segLen;    
   IntVec states;  /* array[1..numSegs] of State */
   IntVec *mixes;  /* array[1..S][1..numSegs] of MixComp */

   if (trace&T_TOP) printf("Starting Estimation Process\n");
   if (newModel){
      UniformSegment();
   }
   totalP=LZERO;
   for (iter=1; !converged && iter<=maxIter; iter++){
      ZeroAccs(&hset, uFlags);              /* Clear all accumulators */
      numSegs = NumSegs(segStore);
      /* Align on each training segment and accumulate stats */
      for (newP=0.0,i=1;i<=numSegs;i++) {
         segLen = SegLength(segStore,i);
         states = CreateIntVec(&gstack,segLen);
         mixes  = (hset.hsKind==DISCRETEHS)?NULL:
            CreateMixes(&gstack,segLen);
         newP += ViterbiAlign(i,segLen,states,mixes);
         if (trace&T_ALN) ShowAlignment(i,segLen,states,mixes);
         UpdateCounts(i,segLen,states,mixes);
         FreeIntVec(&gstack,states); /* disposes mixes too */
      }
      /* Update parameters or quit */
      newP /= (float)numSegs;
      delta = newP - totalP;
      converged = (iter>1) && (fabs(delta) < epsilon);
      if (!converged)
         UpdateParameters();
      totalP = newP;
      if (trace & T_TOP){
         printf("Iteration %d: Average LogP =%12.5f",iter,totalP);
         if (iter > 1)
            printf("  Change =%12.5f\n",delta);
         else
            printf("\n");
         fflush(stdout);
      }
   }
   if (trace&T_TOP) {
      if (converged) 
         printf("Estimation converged at iteration %d\n",iter);
      else
         printf("Estimation aborted at iteration %d\n",iter);
      fflush(stdout);
   }
}
Exemple #2
0
void Initialise(char *hmmListFn)
{   
   /* Stacks for global structures requiring memory allocation */
   CreateHeap(&aSetStack,"ASetStore", MSTAK, 1, 0.0, 1000, 1000);
   CreateHeap(&sSetStack,"SSetStore", MSTAK, 1, 0.0, 1000, 1000);
   CreateHeap(&wsStack,"WsStore", MSTAK, 1, 0.0, 1000, 1000);
   CreateHeap(&labIdStack,"LabIdStore", MSTAK, 1, 0.0, 1000, 1000);
   CreateHeap(&wtAccStack,"WtAccStore", MSTAK, 1, 0.0, 1000, 1000);
   
   /* Load HMMs and init HMMSet related global variables */
   if(MakeHMMSet( &hset, hmmListFn )<SUCCESS)
      HError(2429,"Initialise: MakeHMMSet failed");
   if(LoadHMMSet( &hset,hmmDir,newExt)<SUCCESS)
      HError(2429,"Initialise: LoadHMMSet failed");
   AttachAccs(&hset, &gstack,uFlags);
   ZeroAccs(&hset,uFlags);   
   nPhyHmms = hset.numPhyHMM;
   nLogHmms = hset.numLogHMM;
   vSize = hset.vecSize;
   nStreams = hset.swidth[0];
   maxMixes = MaxMixInSet(&hset);
   maxStates = MaxStatesInSet(&hset);
   hsKind = hset.hsKind;

   /* Store for mix weights accs from each input acc file */
   CreateWtStore(&wtAccStack);

   if ((hsKind != TIEDHS) && (hsKind != DISCRETEHS))
      HError(2421,"Initialise: HMM's must be full Tied Mixture or Discrete");

   if (trace&T_TOP) {
      printf("HSmooth  Updating: ");
      if (uFlags&UPTRANS) printf("Transitions "); 
      if (uFlags&UPMEANS) printf("Means "); 
      if (uFlags&UPVARS)  printf("Variances "); 
      if (uFlags&UPMIXES && maxMixes>1)  printf("MixWeights "); 
      printf("\n ");
      printf("   Max Steps: %d, Epsilon : %f, Max Mixes: %d\n",
             maxStep,epsilon,maxMixes);
      printf("%d Logical/%d Physical Models Loaded, VecSize=%d\n",nLogHmms,nPhyHmms,vSize);
      fflush(stdout);
   }

   SetVFloor( &hset, vFloor, minVar);

   aSet=(HLink *)New(&aSetStack, nPhyHmms*sizeof(HLink));
   --aSet;

   sSet=(StreamElem **)New(&sSetStack, nPhyHmms*sizeof(StreamElem *));
   --sSet;   
}
  xf = xfInfo.paXForm;

  if ((xfInfo.paXForm != NULL) && !(uFlags&UPXFORM)) {

    while (xf != NULL) {

       if ((xf->xformSet->xkind != CMLLR) && (xf->xformSet->xkind != SEMIT))

	HError(999,"SAT only supported with SEMIT/CMLLR transforms");

      xf = xf->parentXForm;

    }

  }

}



int main(int argc, char *argv[])

{

   char *datafn=NULL;

   char *datafn2=NULL;

   char *s;

   char *scriptFile;

   char datafn1[MAXSTRLEN];

   char newFn[MAXSTRLEN];

   FILE *f;

   UttInfo *utt;            /* utterance information storage */

   FBInfo *fbInfo;          /* forward-backward information storage */

   HMMSet hset;             /* Set of HMMs to be re-estimated */

   Source src;

   float tmpFlt;

   int tmpInt;

   int numUtt,spUtt=0;



   void Initialise(FBInfo *fbInfo, MemHeap *x, HMMSet *hset, char *hmmListFn);

   void DoForwardBackward(FBInfo *fbInfo, UttInfo *utt, char *datafn, char *datafn2);

   void UpdateModels(HMMSet *hset, ParmBuf pbuf2);

   void StatReport(HMMSet *hset);

   

   if(InitShell(argc,argv,herest_version,herest_vc_id)<SUCCESS)

      HError(2300,"HERest: InitShell failed");

   InitMem();    InitMath();

   InitSigP();   InitAudio();

   InitWave();   InitVQ();

   InitLabel();  InitModel();

   if(InitParm()<SUCCESS)  

      HError(2300,"HERest: InitParm failed");

   InitTrain();

   InitUtil();   InitFB();

   InitAdapt(&xfInfo); InitMap();



   if (!InfoPrinted() && NumArgs() == 0)

      ReportUsage();

   if (NumArgs() == 0) Exit(0);

   al_hmmDir[0] = '\0'; al_hmmExt[0] = '\0'; 

   al_hmmMMF[0] = '\0'; al_hmmLst[0] = '\0'; 

   up_hmmMMF[0] = '\0';

   CreateHeap(&hmmStack,"HmmStore", MSTAK, 1, 1.0, 50000, 500000);

   SetConfParms(); 

   CreateHMMSet(&hset,&hmmStack,TRUE);

   CreateHeap(&uttStack,   "uttStore",    MSTAK, 1, 0.5, 100,   1000);

   utt = (UttInfo *) New(&uttStack, sizeof(UttInfo));

   CreateHeap(&fbInfoStack,   "FBInfoStore",  MSTAK, 1, 0.5, 100 ,  1000 );

   fbInfo = (FBInfo *) New(&fbInfoStack, sizeof(FBInfo));

   CreateHeap(&accStack,   "accStore",    MSTAK, 1, 1.0, 50000,   500000);



   while (NextArg() == SWITCHARG) {

      s = GetSwtArg();

      if (strlen(s)!=1) 

         HError(2319,"HERest: Bad switch %s; must be single letter",s);

      switch(s[0]){

      case 'b':

         if (NextArg()!=STRINGARG)

            HError(2319,"HERest: script file expected");

         scriptFile = GetStrArg(); break;
Exemple #4
0
void Initialise(void)
{
   /* load HMM mmf */
   if (MakeHMMSet(&hmset, GetStrArg()) < SUCCESS)
      HError(9928, "Initialise: MakeHMMSet failed");
   if (LoadHMMSet(&hmset, hmmDir, hmmExt) < SUCCESS)
      HError(9928, "Initialise: LoadHMMSet failed");
   if (hmset.hsKind == DISCRETEHS)
      HError(9999, "Initialise: Only continuous model is surpported");
   ConvDiagC(&hmset, TRUE);

   if (trace & T_TOP) {
      PrintrFlags();
      printf("HMMSet is ");
      switch (hmset.hsKind) {
      case PLAINHS:
         printf("PLAIN\n");
         break;
      case SHAREDHS:
         printf("SHARED\n");
         break;
      case TIEDHS:
         printf("TIED\n");
         break;
      default:
         HError(9999, "Initialise: Only continuous model is supported");
      }

      printf("%d Logical/%d Physical Models Loaded, VecSize=%d\n", hmset.numLogHMM, hmset.numPhyHMM, hmset.vecSize);
      if (hmset.numFiles > 0)
         printf("%d MMF input files\n", hmset.numFiles);
      fflush(stdout);
   }

   /* load duration mmf */
   if (!stateAlign) {
      if (MakeHMMSet(&dmset, GetStrArg()) < SUCCESS)
         HError(9928, "Initialise: MakeHMMSet failed");
      if (LoadHMMSet(&dmset, dmDir, dmExt) < SUCCESS)
         HError(9928, "Initialise: LoadHMMSet failed");
      if (hmset.hsKind == DISCRETEHS)
         HError(9999, "Initialise: Only continuous duration model mmf is surpported");
      ConvDiagC(&dmset, TRUE);

      if (trace & T_TOP) {
         printf("DurationModelSet is ");
         switch (dmset.hsKind) {
         case PLAINHS:
            printf("PLAIN\n");
            break;
         case SHAREDHS:
            printf("SHARED\n");
            break;
         case TIEDHS:
            printf("TIED\n");
            break;
         default:
            HError(9999, "Initialise: Only continuous model is supported");
         }

         printf("%d Logical/%d Physical Models Loaded, VecSize=%d\n", dmset.numLogHMM, dmset.numPhyHMM, dmset.vecSize);
         if (dmset.numFiles > 0)
            printf("%d MMF input files\n", dmset.numFiles);
         fflush(stdout);
      }
   }

   /* setup GenInfo */
   genInfo->genMem = &genStack;
   genInfo->hset = &hmset;
   genInfo->dset = &dmset;
   genInfo->maxStates = MaxStatesInSet(&hmset);
   genInfo->maxMixes = MaxMixInSet(&hmset);
   genInfo->speakRate = speakRate;
   genInfo->MSDthresh = MSDthresh;
   genInfo->modelAlign = modelAlign;
   genInfo->stateAlign = stateAlign;
   genInfo->frameRate = frameRate;

   CheckGenSetUp();

   /* setup EM-based parameter generation */
   AttachAccs(&hmset, &gstack, (UPDSet) 0);
   ZeroAccs(&hmset, (UPDSet) 0);

   if (!stateAlign) {
      AttachAccs(&dmset, &gstack, (UPDSet) 0);
      ZeroAccs(&dmset, (UPDSet) 0);
   }

   if (type != CHOLESKY)
      InitialiseForBack(fbInfo, &fbInfoStack, &hmset, (UPDSet) 0, ((useHMMFB || stateAlign) ? NULL : &dmset), (UPDSet) 0, pruneInit, pruneInc, pruneLim, minFrwdP, useAlign, FALSE);

   /* handle input xform */
   xfInfo_hmm.inFullC = xfInfo_dur.inFullC = TRUE;

   /* semi-tied case */
   if (hmset.semiTied != NULL) {
      SetXForm(&hmset, NULL, hmset.semiTied);
      ApplyHMMSetXForm(&hmset, hmset.semiTied, TRUE);
   }

   /* linear weight -> log weight */
   ConvLogWt(&hmset);
}