Пример #1
0
void config(int rt, int rmax, int ic)  {
    int r1, i;
    double ewens_form(int *r, int r_top, double *mpt), test_value;
    double F(int *r), F_test, multiplicity;
    void print_config(int *r);
    
    if (ic == k - 1)
        for (i=min(rmax,rt-1); i>=((rt%2)?(rt+1)/2:rt/2); i--) {
            r[ic] = i;
            r[ic+1] = rt - i;
            test_value = ewens_form(r, r_top, &multiplicity);
            tot_sum += multiplicity * test_value;
            F_test = F(r);
            if (test_value <= obs_value)
                sig_sum += multiplicity * test_value;
            if (F_test <= F_obs)
                F_sig_sum += multiplicity * test_value;
        }
    else  {
        for(r1=((rt%k)?rt/k+1:rt/k);r1<=(min(rmax,rt-k+ic+1));r1++)  { 
            if (ic == 1)
                r_top = r1;
            r[ic] = r1;
            config(rt-r1, r1, ic+1);
        }
    }
}  /*  end, config  */
Пример #2
0
int main(int argc, char *argv[]) {
	int i, count, readfile;
	void config(int rt, int rmax, int ic);
	double ewens_form(int *r, int r_tot, double *mpt);
	double F(int *r), multiplicity;
	double theta_est(int k_obs, int n);
	void print_config(int *r);
	long start_time, finish_time, net_time;
	void fill_factors();
    
	start_time = time(NULL);
	if (argc == 1)  {
        printf("Specify the configuration on the command line\n");
		exit(0);
    }
	k = argc - 1;
	for (i=1; i<=k; i++)  {
		r_obs[i] = atoi(argv[i]);
		r_tot += r_obs[i];
    }
	F_obs = F(r_obs);
	printf("\nn = %d, k = %d, theta = %g, F = %g\n",
           r_tot, k, theta_est(k, r_tot), F_obs);
	if (r_tot >= RLIM)  {
		printf("n = %d is too large..\n", r_tot);
		exit(0);
    }
	if (k >= KLIMIT)  {
		printf("k = %d is too large.\n", k);
		exit(0);
    }
	for (i=1;
         i<k; i++)
		if (r_obs[i] < r_obs[i+1])  {
			print_config(r_obs);
			printf(" is not a valid configuration.\n");
			exit(0);
        }
	r_top = r_tot - 1;
	Fsig = Esig = 0;
	fill_factors();
	obs_value = ewens_form(r_obs, r_obs[1], &multiplicity);
	config(r_tot, r_tot-k+1, 1);
	print_config(r_obs);
	printf(":  P_E = %g, ", sig_sum / tot_sum);
	printf("P_H = %g\n", F_sig_sum / tot_sum);
	finish_time = time(NULL);
	net_time = time(NULL) - start_time;
	if (net_time < 60)
		printf("Program took %ld seconds\n", net_time);
	else
		printf("Program took %4.2f minutes\n", net_time / 60.0);
}  /*  end, main  */
Пример #3
0
void Slatkin::GetEwens(int* r_obs_param, int k_param, double& theta_rval, double& F_rval, double& p_e_rval, double& p_h_rval) {
  void config(int rt, int rmax, int ic);
  void fill_factors();
  void print_config(int *r);
  double ewens_form(int *r, int r_top, double *mpt);  
  double F(int *r), multiplicity;
  double theta_est(int k_obs, int n);
  double kval(double x, int n);

  init();

  k = k_param;
  for (int i = 0; i < k; i++) {
    r_obs[i+1] = r_obs_param[i];
  }

  printf("[get_ewens]\tentering with k=%d\n", k);
  printf("\t\tr_obs: ");
  int i;
  long start_time, finish_time, net_time;
  start_time = time(NULL);
  r_tot = 0;
  for (i=1; i<=k; i++)  {
    r_tot += r_obs[i];
    printf("%d ", r_obs[i]); fflush(stdout);
  }
  printf("\n");
  F_obs = F(r_obs);
  theta_rval = theta_est(k, r_tot);
  //printf("\nn = %d, k = %d, theta = %g, F = %g\n",r_tot, k, theta_rval, F_obs);
  F_rval = F_obs;
  if (r_tot >= RLIM)  {
    printf("n = %d is too large..\n", r_tot);
    exit(0);
  }
  if (k >= KLIMIT)  {
    printf("k = %d is too large.\n", k);
    exit(0);
  }
  for (i=1; i<k; i++)
    if (r_obs[i] < r_obs[i+1])  {
      //print_config(r_obs);
      printf(" is not a valid configuration.\n");
      exit(0);
    }
  r_top = r_tot - 1;
  Fsig = Esig = 0;
  fill_factors();
  obs_value = ewens_form(r_obs, r_obs[1], &multiplicity);
  config(r_tot, r_tot-k+1, 1);
  //print_config(r_obs);
  p_e_rval = sig_sum / tot_sum;
  p_h_rval = F_sig_sum / tot_sum;
  //printf(":  P_E = %g, ", p_e_rval);
  //printf("P_H = %g\n", p_h_rval);
  finish_time = time(NULL);
  net_time = time(NULL) - start_time;
  //if (net_time < 60)
  //  printf("Program took %ld seconds\n", net_time);
  //else
  //  printf("Program took %4.2f minutes\n", net_time / 60.0);
}