deps/kb_meme/meme-5.0.1/src/mhmm-state.c
/************************************************************************
 * Compute the indices and values of transitions to or from a state.
 ************************************************************************/
Compute the indices and values of transitions to or from a state.
Compute the indices and values of transitions to or from a state .
void compute_ins_and_outs
  (MHMM_T*   the_hmm,
   bool log_form) 
{
  int i_row, i_col;
  int n = the_hmm->num_states;
  MATRIX_T *trans = the_hmm->trans;
   Visit the transition matrix cells just once each
   to update ntrans, itrans and trans arrays.
   This is quadratic in n. 
  for (i_row = 0; i_row < n; i_row++) {
    for (i_col = 0; i_col < n; i_col++) {
      double p;                          The transition probability.
      int old_n, new_n;                  Number of transitions.
      if (!is_zero((p = get_matrix_cell(i_row, i_col, trans)), log_form)) {
        MHMM_STATE_T * out_state = &(the_hmm->states[i_row]);
        MHMM_STATE_T * in_state = &(the_hmm->states[i_col]);
         out
        old_n = out_state->ntrans_out; 
        new_n = ++out_state->ntrans_out;
        mm_resize(out_state->itrans_out, new_n, int);
        out_state->trans_out = resize_array(out_state->trans_out, new_n);
        out_state->itrans_out[old_n] = i_col;
        set_array_item(old_n, p, out_state->trans_out);
         in
        old_n = in_state->ntrans_in; 
        new_n = ++in_state->ntrans_in;
        mm_resize(in_state->itrans_in, new_n, int);
        in_state->trans_in = resize_array(in_state->trans_in, new_n);
        in_state->itrans_in[old_n] = i_row;
        set_array_item(old_n, p, in_state->trans_in);
      }
    }  col
  }  row
}
void compute_ins_and_outs ( MHMM_T * the_hmm , bool log_form ) { int i_row , i_col ; int n = the_hmm -> num_states ; MATRIX_T * trans = the_hmm -> trans ; for ( i_row = 0 ; i_row < n ; i_row ++ ) { for ( i_col = 0 ; i_col < n ; i_col ++ ) { double p ; int old_n , new_n ; if ( ! is_zero ( ( p = get_matrix_cell ( i_row , i_col , trans ) ) , log_form ) ) { MHMM_STATE_T * out_state = & ( the_hmm -> states [ i_row ] ) ; MHMM_STATE_T * in_state = & ( the_hmm -> states [ i_col ] ) ; old_n = out_state -> ntrans_out ; new_n = ++ out_state -> ntrans_out ; mm_resize ( out_state -> itrans_out , new_n , int ) ; out_state -> trans_out = resize_array ( out_state -> trans_out , new_n ) ; out_state -> itrans_out [ old_n ] = i_col ; set_array_item ( old_n , p , out_state -> trans_out ) ; old_n = in_state -> ntrans_in ; new_n = ++ in_state -> ntrans_in ; mm_resize ( in_state -> itrans_in , new_n , int ) ; in_state -> trans_in = resize_array ( in_state -> trans_in , new_n ) ; in_state -> itrans_in [ old_n ] = i_row ; set_array_item ( old_n , p , in_state -> trans_in ) ; } } } }
Compute the indices and values of transitions to or from a state.
Compute the indices and values of transitions to or from a state .
/* Is the transition matrix in log form? */ // // Visit the transition matrix cells just once each // to update ntrans, itrans and trans arrays. // This is quadratic in n.  // // The transition probability. // Number of transitions. // out // in // col // row