hmmer-3.3/src/p7_hmm.c
/* Function:  esl_hmm_SampleEnumerable()
 * Synopsis:  Sample an random HMM with no nonzero insertion transitions.
 *
 * Purpose:   Sample a random HMM with random emission and 
 *            transition probabilities with the exception that
 *            all transitions to insert are zero. This makes
 *            it possible to create a model with a finite,
 *            easily enumerable sequence space (all seqs of
 *            length $\leq M).
 *            
 *            To achieve this in the profile as well as the core HMM,
 *            the caller must configure a unihit mode
 *            (<p7_ProfileConfig(hmm, bg, gm, p7_UNILOCAL)> or
 *            <p7_UNIGLOCAL>), and a target length of zero
 *            (<p7_ReconfigLength(gm, 0)>).
 *            
 *            Useful for debugging and validating Forward/Viterbi
 *            algorithms.
 *            
 * Returns:   <eslOK> on success. The newly allocated hmm is returned through
 *            <ret_hmm>. The caller is responsible for freeing this object
 *            with <p7_hmm_Destroy()>.
 *
 * Throws:    <eslEMEM> on allocation error.
 */
esl_hmm_SampleEnumerable()
Synopsis:  Sample an random HMM with no nonzero insertion transitions.

Sample a random HMM with random emission and
transition probabilities with the exception that
all transitions to insert are zero. This makes
it possible to create a model with a finite,
easily enumerable sequence space (all seqs of
length $\leq M).

To achieve this in the profile as well as the core HMM,
the caller must configure a unihit mode
( or
), and a target length of zero
().

Useful for debugging and validating Forward/Viterbi
algorithms.

 on success. The newly allocated hmm is returned through
. The caller is responsible for freeing this object
with .

 on allocation error.
esl_hmm_SampleEnumerable () Synopsis : Sample an random HMM with no nonzero insertion transitions . Sample a random HMM with random emission and transition probabilities with the exception that all transitions to insert are zero . This makes it possible to create a model with a finite easily enumerable sequence space ( all seqs of length $ \ leq M ) . To achieve this in the profile as well as the core HMM the caller must configure a unihit mode ( or ) and a target length of zero () . Useful for debugging and validating Forward / Viterbi algorithms . on success . The newly allocated hmm is returned through . The caller is responsible for freeing this object with . on allocation error .
int
p7_hmm_SampleEnumerable(ESL_RANDOMNESS *r, int M, const ESL_ALPHABET *abc, P7_HMM **ret_hmm)
{
  P7_HMM *hmm    = NULL;
  char   *logmsg = "[random enumerable HMM created by sampling]";
  int     k;
  float   tmp[2];
  int     status;
  hmm = p7_hmm_Create(M, abc);
  if (hmm == NULL) { status = eslEMEM; goto ERROR; }
  for (k = 0; k <= M; k++)
    {
      if (k > 0) esl_dirichlet_FSampleUniform(r, abc->K, hmm->mat[k]); 
      esl_dirichlet_FSampleUniform(r, abc->K, hmm->ins[k]);            
      esl_dirichlet_FSampleUniform(r, 2,      tmp);       
      hmm->t[k][p7H_MM] = tmp[0];
      hmm->t[k][p7H_MI] = 0.;
      hmm->t[k][p7H_MD] = tmp[1];
      hmm->t[k][p7H_IM] = 1.;                                          
      hmm->t[k][p7H_II] = 0.;
      if (k > 0) esl_dirichlet_FSampleUniform(r, 2,      hmm->t[k]+5); 
    }
  hmm->t[M][p7H_MM] = 1.;
  hmm->t[M][p7H_MD] = 0.;	
  hmm->t[M][p7H_DM] = 1.;
  hmm->t[M][p7H_DD] = 0.;
  p7_hmm_SetName(hmm, "sampled-hmm");
  p7_hmm_AppendComlog(hmm, 1, &logmsg);
  p7_hmm_SetCtime(hmm);
  p7_hmm_SetConsensus(hmm, NULL);
  p7_hmm_Validate(hmm, NULL, 0.0001);
  *ret_hmm = hmm;
  return eslOK;
 ERROR:
  if (hmm != NULL) p7_hmm_Destroy(hmm);
  *ret_hmm = NULL;
  return status;
}
int p7_hmm_SampleEnumerable ( ESL_RANDOMNESS * r , int M , const ESL_ALPHABET * abc , P7_HMM * * ret_hmm ) { P7_HMM * hmm = NULL ; char * logmsg = " " ; int k ; float tmp [ 2 ] ; int status ; hmm = p7_hmm_Create ( M , abc ) ; if ( hmm == NULL ) { status = eslEMEM ; goto ERROR ; } for ( k = 0 ; k <= M ; k ++ ) { if ( k > 0 ) esl_dirichlet_FSampleUniform ( r , abc -> K , hmm -> mat [ k ] ) ; esl_dirichlet_FSampleUniform ( r , abc -> K , hmm -> ins [ k ] ) ; esl_dirichlet_FSampleUniform ( r , 2 , tmp ) ; hmm -> t [ k ] [ p7H_MM ] = tmp [ 0 ] ; hmm -> t [ k ] [ p7H_MI ] = 0. ; hmm -> t [ k ] [ p7H_MD ] = tmp [ 1 ] ; hmm -> t [ k ] [ p7H_IM ] = 1. ; hmm -> t [ k ] [ p7H_II ] = 0. ; if ( k > 0 ) esl_dirichlet_FSampleUniform ( r , 2 , hmm -> t [ k ] + 5 ) ; } hmm -> t [ M ] [ p7H_MM ] = 1. ; hmm -> t [ M ] [ p7H_MD ] = 0. ; hmm -> t [ M ] [ p7H_DM ] = 1. ; hmm -> t [ M ] [ p7H_DD ] = 0. ; p7_hmm_SetName ( hmm , " " ) ; p7_hmm_AppendComlog ( hmm , 1 , & logmsg ) ; p7_hmm_SetCtime ( hmm ) ; p7_hmm_SetConsensus ( hmm , NULL ) ; p7_hmm_Validate ( hmm , NULL , 0.0001 ) ; * ret_hmm = hmm ; return eslOK ; ERROR : if ( hmm != NULL ) p7_hmm_Destroy ( hmm ) ; * ret_hmm = NULL ; return status ; }
Function:  esl_hmm_SampleEnumerable()
 Synopsis:  Sample an random HMM with no nonzero insertion transitions.
Function : esl_hmm_SampleEnumerable () Synopsis : Sample an random HMM with no nonzero insertion transitions .
/* match emission probs  */ /* insert emission probs */ /* I transitions irrelevant since I's are unreached. */ /* delete transitions to M,D */ /* Node M is special: no transitions to D, transitions to M
   * are interpreted as transitions to E. Overwrite a little of
   * what we did in node M.
   */ /* Add mandatory annotation
   */ /* SRE DEBUGGING */