Exemplo n.º 1
0
/*===========================================================================*/
int main(int argc, char **argv) {

    char *docname, *writename;
    int mo_number = 0;
    ghmm_cmodel ** smo;
    ghmm_set_loglevel(5+1);

    if(argc <= 1) {
        printf("Usage: %s docname.smo docname.xml", argv[0]);
        return(0);
    }

    docname = argv[1];

    smo = ghmm_cmodel_read(docname, &mo_number);

    printf("Models %d", mo_number);

    /* simple test */
    if (smo) {
        writename = argv[2];
        ghmm_cmodel_xml_write(smo, writename, mo_number);
    }


    return(0);
}
Exemplo n.º 2
0
static int smix_hmm_run(int argc, char* argv[]) {
#define CUR_PROC "smix_hmm_run"

  int k, exitcode = -1, smo_number, sqd_fields;
  ghmm_cseq **sqd = NULL;
  ghmm_cmodel **smo = NULL;
  double **cp = NULL;
  FILE *outfile = NULL;

  /* read sequences and initial models */
  sqd = ghmm_cseq_read(argv[1], &sqd_fields);
  if (!sqd) {GHMM_LOG_QUEUED(LCONVERTED); goto STOP;}
  if (sqd_fields > 1)
    printf("Warning: Seq. File contains multiple Seq. Fields; use only the first one\n");
  smo = ghmm_cmodel_read(argv[2], &smo_number);
  if (!smo) {GHMM_LOG_QUEUED(LCONVERTED); goto STOP;}

  /* open output file */
  if(!(outfile = ighmm_mes_fopen(argv[3], "wt"))) {GHMM_LOG_QUEUED(LCONVERTED); goto STOP;}
  
  /* matrix for component probs., */
  cp = ighmm_cmatrix_alloc(sqd[0]->seq_number, smo_number);
  if (!cp) { GHMM_LOG_QUEUED(LCONVERTED); goto STOP;}

  /* set last arg in ghmm_smixturehmm_init() : 
     1 = strict random partition; cp = 0/1
     2. ghmm_smap_bayes from initial models
     3. cp = 1 for best model, cp = 0 for other models 
     4. open
     5. no start partition == equal cp for each model
  */
  if (ghmm_smixturehmm_init(cp, sqd[0], smo, smo_number, 5) == -1) {
    GHMM_LOG_QUEUED(LCONVERTED); goto STOP;
  }
  /* clustering */
  if (ghmm_smixturehmm_cluster(outfile, cp, sqd[0], smo, smo_number) == -1) {
    GHMM_LOG_QUEUED(LCONVERTED); goto STOP;
  }

  /* print trained models */
  for (k = 0; k < smo_number; k++)
    ghmm_cmodel_print(outfile, smo[k]);  

  if (outfile) fclose(outfile);
  exitcode = 0;
 STOP:
  return exitcode;

# undef CUR_PROC
}
Exemplo n.º 3
0
int main(int argc, char* argv[]) {
# define CUR_PROC "main"


#ifdef GHMM_OBSOLETE

  int mo_number, smo_number;
#ifdef CMODEL_INCLUDED
  int cmo_number;
#endif
  int discrete = 0, smodelflag = 0;
  int T, i, j;
  ghmm_dmodel **mo = NULL;
#ifdef CMODEL_INCLUDED
  cmodel **cmo = NULL;
#endif
  ghmm_cmodel **smo = NULL;
  double d;
  /*  double dangle, ddiff, s1, s2; */

  if (argc != 5) {
    printf("Usage: main <Model File> <discrete-flag> <T> <smodel flag>\n");
    exit(1);
  }

  discrete = atoi(argv[2]);
  T = atoi(argv[3]);
  smodelflag = atoi(argv[4]);

  ghmm_rng_init();
  if (smodelflag) {
    smo = ghmm_cmodel_read(argv[1], &smo_number);
    if (!smo)  {GHMM_LOG_QUEUED(LCONVERTED); return -1;}  
    if (smo_number < 2) {
      printf("Need at least two HMMs to compare (read %d)\n", smo_number);
      return -1;
    }
    for (i = 0; i < smo_number - 1; i++)
      for (j = i + 1; j < smo_number; j++) {
	printf("#----- mo[%d], mo[%d] \n", i , j);
	/* syntax prob_dist: (smo1, smo2, total seqlen., symmetric, verbose) */
	d = ghmm_cmodel_prob_distance(smo[i], smo[j], T, 1, 0);
	printf("probdist = %f\n",d);

      }

  }  
  else if (discrete) {

    mo = ghmm_dmodel_read(argv[1], &mo_number);
    if (!mo) {GHMM_LOG_QUEUED(LCONVERTED); return -1;}        

    if (mo_number < 2) {
      printf("Need at least two HMMs to compare\n");
      return -1;
    }

    printf("#----- mo[0], mo[1] \n");
    d = ghmm_dmodel_prob_distance(mo[0],mo[1], T, 0, 1);
    printf("d=%f\n",d);
    
    printf("#----- mo[1], mo[0] \n");
    d = ghmm_dmodel_prob_distance(mo[1],mo[0], T, 0, 1);
    printf("d=%f\n",d);
    
    printf("#----- mo[0], mo[1] \n");
    d = ghmm_dmodel_prob_distance(mo[0],mo[1], T, 0, 0);
    printf("d=%f\n",d);
    
    printf("#----- mo[1], mo[0] \n");
    d = ghmm_dmodel_prob_distance(mo[1],mo[0], T, 0, 0);
    printf("d=%f\n",d);
    
    printf("#----- mo[0], mo[1] \n");
    d = ghmm_dmodel_prob_distance(mo[0],mo[1], T, 1, 1);
    printf("d=%f\n",d);
    
    printf("#----- mo[0], mo[1] \n");
    d = ghmm_dmodel_prob_distance(mo[0],mo[1], T, 1, 0);
    printf("d=%f\n",d);
    
  }    

#ifdef CMODEL_INCLUDED
  else {
    
    cmo = cmodel_read(argv[1], &cmo_number);
    if (!cmo) {GHMM_LOG_QUEUED(LCONVERTED); return -1;}        
    
    if (cmo_number < 2) {
      printf("Need at least two CHMMs to compare\n");
      return -1;
    }
    
    printf("#----- cmo[0], cmo[1] \n");
    d = cmodel_prob_distance(cmo[0], cmo[1], T, 0, 1);
    printf("d=%f\n",d);
    
    printf("#----- cmo[1], cmo[0] \n");
    d = cmodel_prob_distance(cmo[1], cmo[0], T, 0, 1);
    printf("d=%f\n",d);
    
    printf("#----- cmo[0], cmo[1] \n");
    d = cmodel_prob_distance(cmo[0], cmo[1], T, 0, 0);
    printf("d=%f\n",d);
    
    printf("#----- cmo[1], cmo[0] \n");
    d = cmodel_prob_distance(cmo[1], cmo[0], T, 0, 0);
    printf("d=%f\n",d);
    
    printf("#----- cmo[0], cmo[1] \n");
    d = cmodel_prob_distance(cmo[0], cmo[1], T, 1, 1);
    printf("d=%f\n",d);
    
    printf("#----- cmo[0], cmo[1] \n");
    d = cmodel_prob_distance(cmo[0], cmo[1], T, 1, 0);
    printf("d=%f\n",d);
    
    /* coemission likelihood */
    printf("#----- cmo[0]/cmo[1] \n");
    if (cmodel_coemission_likelihood(cmo[0], cmo[1], &d) == -1) d = -1;
    printf("Coemission Likelihood = %e\n",d); 
    printf("#----- cmo[0]/cmo[0] \n");
    if (cmodel_coemission_likelihood(cmo[0], cmo[0], &d) == -1) d = -1;
    printf("Coemission Likelihood = %e\n",d); 
    printf("#----- cmo[1]/cmo[1] \n");
    if (cmodel_coemission_likelihood(cmo[1], cmo[1], &d) == -1) d = -1;
    printf("Coemission Likelihood = %e\n",d); 
    
    printf("#----- D_angle, D_diff, S1, S2\n");
    cmodel_measures(cmo[0], cmo[1], &dangle, &ddiff, &s1, &s2);
    printf("D_angle = %e\n", dangle);
    printf("D_diff  = %e\n", ddiff); 
    printf("S1      = %e\n", s1);
    printf("S2      = %e\n", s2); 
  }
#endif /* CMODEL_INCLUDED*/

#else  /* GHMM_OBSOLETE */
  fprintf (stderr, "probdist is obsolete. If you need it rebuild the GHMM with \"GHMM_OBSOLETE\".\n");
#endif /* GHMM_OBSOLETE */
  
  return 0;
}