Пример #1
0
//setting this out to allow for other types of setting
static void set_branch_length_sliding_window(nodeptr p, int numBranches,state * s, boolean record_tmp_bl)
{
  int i;
  double new_value;
  double r,mx,mn;
  for(i = 0; i < numBranches; i++)
  {
    assert(p->z[i] == p->back->z[i]);
    if(record_tmp_bl)
      p->z_tmp[i] = p->back->z_tmp[i] = p->z[i];   /* keep current value */
    r = (double)rand()/(double)RAND_MAX;
    mn = p->z[i]-(s->bl_sliding_window_w/2);
    mx = p->z[i]+(s->bl_sliding_window_w/2);
    new_value = fabs(mn + r * (mx-mn));
    /* Ensure always you stay within this range */
    if(new_value > zmax) new_value = zmax;
    if(new_value < zmin) new_value = zmin;
    assert(new_value <= zmax && new_value >= zmin);

    p->z[i] = p->back->z[i] = new_value;
    //assuming this will be visiting each node, and multiple threads won't be accessing this
     s->bl_prior += log(exp_pdf(s->bl_prior_exp_lambda,new_value));
    //s->bl_prior += 1;
  }
}
Пример #2
0
int32
s2_mixing_weights(float32 ***out_mixw,
		  const char *hmm_file_name)
{
    int magic;		/* SPHINX-II hmm file magic number */
    int n_cw;		/* number of codewords for the model */
    int n_omatrix;	/* number of output pdfs in the model */
    int32 *tmp_opdf;
    uint32 i;
    FILE *fp;
    
    fp = fopen(hmm_file_name, "rb");
    if (fp == NULL) {
	fflush(stdout);
	fprintf(stderr, "%s(%d): ERROR cannot open HMM file %s for reading\n",
		__FILE__, __LINE__, hmm_file_name);
	perror(hmm_file_name);
	fflush(stderr);
	
	return S3_ERROR;
    }

    magic = ckd_read_int32(fp);
    if (!IS_MAGIC(magic)) {
	fflush(stdout);
	fprintf(stderr, "%s(%d): ERROR invalid magic number found.  Byteorder?  Not an HMM?\n", __FILE__, __LINE__);
	fflush(stderr);

	return S3_ERROR;
    }

    n_cw = ckd_read_int32(fp);
    assert(n_cw == S2_N_CODEWORD);

    tmp_opdf = (int32 *)ckd_calloc(n_cw, sizeof(int32));

    n_omatrix = ckd_read_int32(fp);

    assert(n_omatrix == S2_N_STATE-1);

    if ((magic == COUNT_F) || (magic == PROB_F)) {
	for (i = 0; i < n_omatrix; i++) {
	    read_opdf(tmp_opdf, n_cw, fp);
	    if (COUNT_P(magic))
		normalize_opdf(tmp_opdf, n_cw);
	    exp_pdf(out_mixw[i][0], tmp_opdf, n_cw);
	}

	for (i = 0; i < n_omatrix; i++) {
	    read_opdf(tmp_opdf, n_cw, fp);
	    if (COUNT_P(magic))
		normalize_opdf(tmp_opdf, n_cw);
	    exp_pdf(out_mixw[i][1], tmp_opdf, n_cw);
	}

	for (i = 0; i < n_omatrix; i++) {
	    read_opdf(tmp_opdf, n_cw, fp);
	    if (COUNT_P(magic))
		normalize_opdf(tmp_opdf, n_cw);
	    exp_pdf(out_mixw[i][2], tmp_opdf, n_cw);
	}

	for (i = 0; i < n_omatrix; i++) {
	    read_opdf(tmp_opdf, n_cw, fp);
	    if (COUNT_P(magic))
		normalize_opdf(tmp_opdf, n_cw);
	    exp_pdf(out_mixw[i][3], tmp_opdf, n_cw);
	}
    }

    ckd_free(tmp_opdf);
    return 0;
}