예제 #1
0
//only uses first sequence
int* ghmm_bayes_hmm_fbgibbs(ghmm_bayes_hmm *bayes, ghmm_cmodel *mo, ghmm_cseq* seq,
         int burnIn, int seed){
#define CUR_PROC "ghmm_cmodel_fbgibbs"
    //XXX seed
    GHMM_RNG_SET (RNG, seed);
    int max_seq = ghmm_cseq_max_len(seq);
    double **alpha = ighmm_cmatrix_alloc(max_seq,mo->N);
    double ***pmats = ighmm_cmatrix_3d_alloc(max_seq, mo->N, mo->N);
    int **Q; 
    ARRAY_CALLOC(Q, seq->seq_number);
    int seq_iter;
    for(seq_iter = 0; seq_iter < seq->seq_number; seq_iter++){
        ARRAY_CALLOC(Q[seq_iter], seq->seq_len[seq_iter]);
    }

    ghmm_sample_data data;
    ghmm_alloc_sample_data(bayes, &data);
    ghmm_clear_sample_data(&data, bayes);//XXX swap parameter
    for(; burnIn > 0; burnIn--){
        for(seq_iter = 0; seq_iter < seq->seq_number; seq_iter++){
            ghmm_cmodel_fbgibbstep(mo,seq->seq[seq_iter],seq->seq_len[seq_iter], Q[seq_iter],
                    alpha, pmats, NULL);
            ghmm_get_sample_data(&data, bayes, Q[seq_iter], seq->seq[seq_iter], 
                    seq->seq_len[seq_iter]); 
            ghmm_update_model(mo, bayes, &data);
            ghmm_clear_sample_data(&data, bayes);
        }
    }
    ighmm_cmatrix_free(&alpha, max_seq);
    ighmm_cmatrix_3d_free(&pmats, max_seq,mo->N);
    return Q;
STOP:
    return NULL; //XXX error handle
#undef CUR_PROC
}
예제 #2
0
int* ghmm_bayes_hmm_fbgibbs_compressed(ghmm_bayes_hmm *bayes, ghmm_cmodel *mo, ghmm_cseq* seq,
         int burnIn, int seed, double width, double delta, int max_len_permitted){
#define CUR_PROC "ghmm_cmodel_fbgibbs"
    //XXX seed
    GHMM_RNG_SET (RNG, seed);

    block_stats *stats = compress_observations(seq, width*delta, delta);
    stats = merge_observations(seq, width, max_len_permitted, stats);
    print_stats(stats, seq->seq_len[0]);
    //get max_block_len
    int max_block_len = stats->length[0];
    int i;
    for(i = 1; i < stats->total; i++){
        if(max_block_len < stats->length[i])
            max_block_len = stats->length[i];
    }
    //printf("max b len %d\n", max_block_len);
    double ***b = ighmm_cmatrix_3d_alloc(stats->total, mo->N, 2);
    double **alpha = ighmm_cmatrix_alloc(seq->seq_len[0],mo->N);
    double ***pmats = ighmm_cmatrix_3d_alloc(seq->seq_len[0], mo->N, mo->N);
    int *Q; 
    ARRAY_CALLOC(Q, seq->seq_len[0]);//XXX extra length for compressed
    ghmm_sample_data data;
    ghmm_alloc_sample_data(bayes, &data);
    ghmm_clear_sample_data(&data, bayes);//XXX swap parameter 
    for(; burnIn > 0; burnIn--){
        //XXX only using seq 0
        precompute_block_emission(mo, stats, max_block_len, b);//XXX maxlen
        ghmm_cmodel_fbgibbstep(mo,seq->seq[0], stats->total, Q, alpha, pmats, b);
        ghmm_get_sample_data_compressed(&data, bayes, Q, seq->seq[0], 
                stats->total, stats); 
        ghmm_update_model(mo, bayes, &data);
        ghmm_clear_sample_data(&data, bayes);
    }
    ighmm_cmatrix_free(&alpha, seq->seq_len[0]);
    ighmm_cmatrix_3d_free(&pmats, seq->seq_len[0],mo->N);
    ighmm_cmatrix_3d_free(&b, stats->total, mo->N);
    free_block_stats(&stats);
    return Q;
STOP:
    return NULL; //XXX error handle
#undef CUR_PROC
}
예제 #3
0
/*============================================================================*/
static plocal_propagate_store_t * pviterbi_propagate_alloc (ghmm_dpmodel *mo, int len_y) {
#define CUR_PROC "pviterbi_propagate_alloc"
  plocal_propagate_store_t* v = NULL;
  int i, j, k;
  ARRAY_CALLOC (v, 1);

  v->mo = mo;
  v->len_y = len_y;
  /* Allocate the log_in_a's -> individal lenghts */
  ARRAY_CALLOC (v->log_in_a, mo->N);
  /* first index of log_in_a: target state */
  for (j = 0; j < mo->N; j++){ 
    /* second index: source state */
    ARRAY_CALLOC (v->log_in_a[j], mo->s[j].in_states);
    for (i=0; i<mo->s[j].in_states; i++) {
      /* third index: transition classes of source state */
      ARRAY_CALLOC (v->log_in_a[j][i], mo->s[mo->s[j].in_id[i]].kclasses);
    }
  }

  ARRAY_CALLOC (v->log_b, mo->N);
  for (j=0; j<mo->N; j++) {
    ARRAY_CALLOC (v->log_b[j], ghmm_dpmodel_emission_table_size(mo, j) + 1);
  }
  if (!(v->log_b)) {GHMM_LOG_QUEUED(LCONVERTED); goto STOP;}
  v->phi = ighmm_cmatrix_3d_alloc(mo->max_offset_x + 1, len_y + mo->max_offset_y + 1, mo->N);
  if (!(v->phi)) {GHMM_LOG_QUEUED(LCONVERTED); goto STOP;}
  ARRAY_CALLOC (v->phi_new, mo->N);
  ARRAY_CALLOC (v->end_of_first, mo->max_offset_x + 1);
  for (j=0; j<mo->max_offset_x + 1; j++) {
    ARRAY_CALLOC (v->end_of_first[j], len_y + mo->max_offset_y + 1);
    for (i=0; i<len_y + mo->max_offset_y + 1; i++) {
      ARRAY_CALLOC (v->end_of_first[j][i], mo->N);
      for (k=0; k<mo->N; k++)
	v->end_of_first[j][i][k] = NULL;
	/*ARRAY_CALLOC (v->end_of_first[j][i][k], 1);*/
    }
  }
  v->topo_order_length = 0;
  ARRAY_CALLOC (v->topo_order, mo->N);
  return(v);
STOP:     /* Label STOP from ARRAY_[CM]ALLOC */
  pviterbi_propagate_free(&v, mo->N, mo->max_offset_x, mo->max_offset_y, len_y);
  return(NULL);
#undef CUR_PROC
}