Ejemplo n.º 1
0
void Population::log() const
{
    Settings::inst()->_log << _current_gen;
    Settings::inst()->_log << ";" << _current.min;
    Settings::inst()->_log << ";" << _current.max;
    Settings::inst()->_log << ";" << _current.average;
    Settings::inst()->_log << ";" << get_sigma();
    Settings::inst()->_log << ";" << _genome[get_best_id()]->to_phenotype_string() << std::endl;
}
Ejemplo n.º 2
0
double perfect(long int seed) {
    /* 
     * The perfect sampling algorithm.
     */
    int t = 100;            // starting value of t
    int increment = 50;     // increment t by this number if coalesence fails
    double Z[MAX_DEPTH+1];  // Grab memory for shocks
    double U[MAX_DEPTH+1];  // Ditto

    // Some boilerplate to set up the random number generator
    const gsl_rng_type * T;
    gsl_rng * rd;
    gsl_rng_env_setup();
    T = gsl_rng_default;
    rd = gsl_rng_alloc (T);
    gsl_rng_set(rd, seed);

    // Draw the first set of random shocks for i = 0,...,t
    int i;
    for (i = 0; i <= t; i++) {
        U[i] = gsl_ran_beta(rd, alpha1, beta1);
        Z[i] = gsl_ran_beta(rd, alpha2, beta2);
    }

    while (t < MAX_DEPTH - 1) {

        int sigma = get_sigma(t, U);
        if (sigma > 0) { 
            double r = compute_singleton(sigma, t, Z, U);
            if (r >= 0) {
                gsl_rng_free(rd);
                return r;
            }
        }

        // Coalescence failed, so lets go round again
        for (i = t+1; i <= t+increment; i++) {
            U[i] = gsl_ran_beta(rd, alpha1, beta1);
            Z[i] = gsl_ran_beta(rd, alpha2, beta2);
        }
        t = t + increment;
    }

    // If we made it this far then we've hit MAX_DEPTH without success, so
    // return a warning and a fail value
    gsl_rng_free(rd);
    printf("Warning: MAX_DEPTH reached, returning fail value!\n");
    printf("If this happens repeatedly, you need to increase MAX_DEPTH.\n");
    return -1.0;
}
Ejemplo n.º 3
0
/*generates statistic results*/
char *report(F_set *File_head, char *query, char *fmt, char *prefix, char *start_timestamp, double prob, int threads)
{
  char *abs_query_path = NULL, *abs_filter_path = NULL;
  static char buffer[800] = {0};
  static char timestamp[40] = {0};
  abs_query_path = get_abs_path(query);
  abs_filter_path = get_abs_path(File_head->filename);
  float _contamination_rate = (float) (File_head->reads_contam) / (float) (File_head->reads_num);
  double p_value = cdf(File_head->hits,get_mu(File_head->all_k,prob),get_sigma(File_head->all_k,prob));

  if(!fmt)
  {
      fprintf(stderr, "Output format not specified\n");
      exit(EXIT_FAILURE);
  } 
  else if(!strcmp(fmt, "json"))
  {
      isodate(timestamp);
      snprintf(buffer, sizeof(buffer),
"{\"begin_timestamp\": \"%s\","
"\"end_timestamp\": \"%s\","
"\"sample\": \"%s\","
"\"bloom_filter\": \"%s\","
"\"total_read_count\": %lld,"
"\"contaminated_reads\": %lld,"
"\"total_hits\": %lld,"
"\"contamination_rate\": %f,"
"\"p_value\": %e,"
"\"threads\": %d"
"}",  start_timestamp, timestamp,abs_query_path, abs_filter_path,
        File_head->reads_num, File_head->reads_contam, File_head->hits,
        _contamination_rate, p_value, threads);
  // TSV output format
  }
  else if (!strcmp(fmt, "tsv"))
  {
  	sprintf(buffer,
"sample\tbloom_filter\ttotal_read_count\t_contaminated_reads\t_contamination_rate\n"
"%s\t%s\t%lld\t%lld\t%f\t%e\n", abs_query_path , abs_filter_path,
                            File_head->reads_num, File_head->reads_contam,
                            _contamination_rate,p_value);
  }
  return buffer;
}
Ejemplo n.º 4
0
void Population::parent_selection_sigma_scaling()
{
    std::vector<float> stacked_fitness;
    float sig = get_sigma();

    stacked_fitness.push_back(get_sigma_scaling(0, sig));
    for (uint64_t i = 1; i < _genome.size(); ++i) {
        stacked_fitness.push_back(get_sigma_scaling(i, sig) + stacked_fitness[i-1]);
    }

    std::uniform_real_distribution<float> rnd_float(0, stacked_fitness[stacked_fitness.size() - 1]);
    for (uint64_t i = 0; i < Settings::inst()->_parent_count; ++i) {
        float r = rnd_float(Settings::inst()->_randomness_source);
        uint64_t par = 0;
        while (par < stacked_fitness.size() && r > stacked_fitness[par])
            ++par;
        _parents.push_back(par);
    }
}
//-----------------------------------------------
double ConfidenceIntervalEstimator::get_delta(CONFIDENCE_LEVEL alpha)
{
	if (!(M > 1)){ cout << "ConfidenceIntervalEstimator::get_delta(): At least two observations are needed!"; exit(1); }

	return st_distribution(M - 1, alpha) * get_sigma() / sqrt(M);
}