/* -- accessor functions -- */
void removeStates(Model *m, int *xu, Hmm *hmm)
{
  int v, u, w, old_uu = m->uu;
  Hmm *phmm = m->hmm;
  for(u = 0; u < m->uu; ){
    if(xu[u]){
      if(u < m->uu - 1){
	for(v = u; v < m->uu - 1; v ++){
	  xu[v] = xu[v+1];
	  copyFFM(m->ffm[v], m->ffm[v+1]);
	  set_model_b(m, v, my_exp(VECTOR(phmm->logB)[v+1]));
	  VECTOR(hmm->logB)[v] = VECTOR(hmm->logB)[v+1];
	  copyRVec(MATRIX(phmm->logA)[v], MATRIX(phmm->logA)[v+1], m->uu);
	  copyRVec(MATRIX(hmm->logA)[v], MATRIX(hmm->logA)[v+1], m->uu);
	  for(w = 0; w < m->uu; w ++){
	    set_model_a(m, w, v, my_exp(MATRIX(phmm->logA)[w][v+1]));
	    MATRIX(hmm->logA)[w][v] = MATRIX(hmm->logA)[w][v+1];
	  }
	}
      }
      m->uu --;
      phmm->uu --;
      hmm->uu --;
    }
    else u ++;
  }
  assert(m->uu > 0);

  /* Clean up the redundant memory. DO NOT clean up hmm matrix now. It will be released 
     according to the size of RMat instead of hmm->uu. */
  for(u = m->uu; u < old_uu; u ++)
    freeFFM(m->ffm[u]);
}
Exemple #2
0
void copyHMM(Hmm *m1, Hmm *m2)
{ int u;

  if(m1->uu != m2->uu){
    freeHMM(m1);
    m1 = allocHMM(m2->uu);
  }

  copyRVec(VECTOR(m1->logB), VECTOR(m2->logB), m1->uu);
  for (u = 0; u<m1->uu; u++)
  { copyRVec(MATRIX(m1->logA)[u], MATRIX(m2->logA)[u], m1->uu);}
}
void copyHMM(Hmm *m1, Hmm *m2)
{ int u;
  //assert(m1->uu>=m2->uu);   /* Take into account the elimination of unreachable states */

  if(m1->uu != m2->uu){
    freeHMM(m1);
    m1 = allocHMM(m2->uu);
  }

  copyRVec(VECTOR(m1->logB), VECTOR(m2->logB), m1->uu);
  for (u = 0; u<m1->uu; u++)
  { copyRVec(MATRIX(m1->logA)[u], MATRIX(m2->logA)[u], m1->uu);}
}