Exemplo n.º 1
0
double
gsl_cdf_lognormal_Q (const double x, const double zeta, const double sigma)
{
  double u = (log (x) - zeta) / sigma;
  double Q = gsl_cdf_ugaussian_Q (u);
  return Q;
}
Exemplo n.º 2
0
double
gsl_cdf_gamma_Q (const double x, const double a, const double b)
{
  double P;
  double y = x / b;

  if (x <= 0.0)
    {
      return 1.0;
    }

#if 0  /* Not currently working to sufficient accuracy in tails */
  if (a > LARGE_A)
    {
      /*
       * Peizer and Pratt's approximation mentioned above.
       */
      double z = norm_arg (y, a);
      P = gsl_cdf_ugaussian_Q (z);
    }
  else
#endif
    {
      P = gsl_sf_gamma_inc_Q (a, y);
    }

  return P;
}
Exemplo n.º 3
0
double
gsl_cdf_tdist_Q (const double x, const double nu)
{
  double Q;

  double x2 = x * x;

  if (nu > 30 && x2 < 10 * nu)
    {
      double u = cornish_fisher (x, nu);
      Q = gsl_cdf_ugaussian_Q (u);

      return Q;
    }

  if (x2 < nu)
    {
      double u = x2 / nu;
      double eps = u / (1 + u);

      if (x >= 0)
        {
          Q = beta_inc_AXPY (-0.5, 0.5, 0.5, nu / 2.0, eps);
        }
      else
        {
          Q = beta_inc_AXPY (0.5, 0.5, 0.5, nu / 2.0, eps);
        }
    }
  else
    {
      double v = nu / (x * x);
      double eps = v / (1 + v);

      if (x >= 0)
        {
          Q = beta_inc_AXPY (0.5, 0.0, nu / 2.0, 0.5, eps);
        }
      else
        {
          Q = beta_inc_AXPY (-0.5, 1.0, nu / 2.0, 0.5, eps);
        }
    }

  return Q;
}
Exemplo n.º 4
0
/* Purpose: calculate z test for proportions, two-tailed for two-sided hypothesis H1 != H0
   Parameters:  p_sample = proportion of events in sample [0..1] 
	 	p_population  = proportion of events in population [0..1] 
 		n  = sample size 
   Returns: Probability of making an error when rejecting the NULL hypothesis 
*/
double gstats_test_ZP2 (double p_sample, double p_population, int n) {
	double z;
	double result = 0.0;
	
	
	if ((p_sample < 0.0) || (p_sample > 1.0)) {
		gstats_error ("z-stat: sample proportion must be given as 0.0 - 1.0.");
	}
	
	if ((p_population < 0.0) || (p_population > 1.0)) {
		gstats_error ("z-stat: population proportion must be given as 0.0 - 1.0.");
	}
	
	if (n < 2) {
		gstats_error ("z-stat: size of population must be a positive integer > 0.");
	}
	
	z = (p_sample - p_population) / 
	    (sqrt ( (p_population * (1-p_population)) / n) );
	
	/* determine direction of numeric integration */
	if ( p_sample > p_population ) {		
		/* we use a normal distribution, if n is at least 30, */
		/* t-distribution with n - 1 degress of freedom, otherwise */
		if (n >= 30) {
			result = gsl_cdf_ugaussian_Q (z);
		} else {
			result = gsl_cdf_tdist_Q (z, (double) n-1);
		}
	}
	if ( p_sample < p_population ) {
		/* we use a normal distribution, if n is at least 30, */
		/* t-distribution with n - 1 degress of freedom, otherwise */
		if (n >= 30) {
			result = gsl_cdf_ugaussian_P (z);
		} else {
			result = gsl_cdf_tdist_P (z, (double) n-1);
		}
	}
	if ( p_sample == p_population ) {
		result = 0.5;
	}
	
	return (result * 2);	
}
Exemplo n.º 5
0
int maurer_test(seq_t *seq, double *pvalue, void *param)
{
	unsigned int i, ps, L, Q, K, *p; 
	double sum, sigma;

	double Lparams[11][2] = {
			{5.2177052, 2.954},
			{6.19662507, 3.125},
			{7.1836656, 3.258},
			{8.1764248, 3.311},
			{9.1723243, 3.356},
			{10.170032, 3.384},
			{11.168765, 3.401},
			{12.168070, 3.410},
			{13.167693, 3.416},
			{14.167488, 3.419},
			{15.167379, 3.421}
	};

	if ( seq->n < 1010*6*((unsigned int)pow(2,6)) ) {
		fprintf(stderr, "Error[Maurer Test]: Sequence length too short\n");
		return -1;
	}

	for ( L = 6; L <= 16; L++ ) {
		if ( seq->n <= 1010*(L + 1)*((unsigned int)pow(2,L + 1)) )
			break;
	}

	fprintf(stdout, "L=%d\n", L);

	ps =(int)pow(2,L);
	p = (unsigned int *)malloc(ps*sizeof(unsigned int));
	if ( !p ) {
		fprintf(stderr, "Error[Maurer Test]: Memory allocation failed\n");
		return -2;
	}

	memset(p, 0, ps*sizeof(unsigned int));

	Q = 10*((unsigned int)pow(2,L));

	for ( i = 0; i < Q; i++ )
		*(p + dec(seq, i*L, L)) = i + 1;

	K = (int)(seq->n/L) - Q;

	for ( sum = 0; i < Q + K; i ++ ) {
		sum += log( (double)(i + 1) - (double)(*(p + dec(seq, i*L, L))))/log(2);
		*(p + dec(seq, i*L, L)) = i + 1;
	} 

	sum /= (double)K;
	sigma = (0.7 - 0.8/((double)L) + (4.0 + 32.0/((double)L))*pow(K, -3.0/((double)L))/15.0)*sqrt(Lparams[L - 6][1]/((double)K));

	*pvalue = 2*gsl_cdf_ugaussian_Q(fabs((sum - Lparams[L - 6][0])/sigma));

	free(p);

	return 0;
}
Exemplo n.º 6
0
void MBitBer::Finish() {

  ofstream ofs;

  string fn( fname() );

  if (fn != "cout")
    ofs.open( fname(),ios::app);

  if (! ofs ) {
    cerr << BlockName << ": error opening "
	 << fn << endl;
    exit(_ERROR_OPEN_FILE_);
  }

  unsigned int minimum, maximum, sum;
  minimum = (unsigned int)GSL_POSINF;
  maximum = sum = 0;

  for (int u=0;u<M();u++) { // user loop

    if (gsl_vector_uint_get(bitcount,u)!=0) {
      if (fn != "cout") {
	ofs.width(NUMWIDTH);
	ofs << u;
	ofs.width(NUMWIDTH);
	ofs << value();
	ofs.width(NUMWIDTH);
	ofs << 1.0*gsl_vector_uint_get(errcount,u)/gsl_vector_uint_get(bitcount,u);
	ofs.width(NUMWIDTH);
	ofs << gsl_vector_uint_get(bitcount,u);
	ofs.width(NUMWIDTH);
	ofs << gsl_vector_uint_get(errcount,u) << endl;
      }
      else {
	cout.width(NUMWIDTH);
	cout << u;
	cout.width(NUMWIDTH);
	cout << value();
	cout.width(NUMWIDTH);
	cout << 1.0*gsl_vector_uint_get(errcount,u)/gsl_vector_uint_get(bitcount,u);
	cout.width(NUMWIDTH);
	cout << gsl_vector_uint_get(bitcount,u);
	cout.width(NUMWIDTH);
	cout << gsl_vector_uint_get(errcount,u) << endl;
      }
    }
    // find maximum
    if (gsl_vector_uint_get(errcount,u)>maximum)
        	maximum = gsl_vector_uint_get(errcount,u);
    // find minimum
    if (gsl_vector_uint_get(errcount,u)<minimum)
        	minimum = gsl_vector_uint_get(errcount,u);
    sum += gsl_vector_uint_get(errcount,u);

  } // user loop

  // min, max and mean
  if (gsl_vector_uint_get(bitcount,0)!=0) {
    if (fn != "cout") {
	ofs.width(NUMWIDTH);
	ofs << "min";
	ofs.width(NUMWIDTH);
	ofs << value();
	ofs.width(NUMWIDTH);
	ofs << 1.0*minimum/gsl_vector_uint_get(bitcount,0);
	ofs.width(NUMWIDTH);
	ofs << gsl_vector_uint_get(bitcount,0);
	ofs.width(NUMWIDTH);
	ofs << minimum << endl;

	ofs.width(NUMWIDTH);
	ofs << "max";
	ofs.width(NUMWIDTH);
	ofs << value();
	ofs.width(NUMWIDTH);
	ofs << 1.0*maximum/gsl_vector_uint_get(bitcount,0);
	ofs.width(NUMWIDTH);
	ofs << gsl_vector_uint_get(bitcount,0);
	ofs.width(NUMWIDTH);
	ofs << maximum << endl;

	ofs.width(NUMWIDTH);
	ofs << "mean";
	ofs.width(NUMWIDTH);
	ofs << value();
	ofs.width(NUMWIDTH);
	ofs << 1.0*sum/gsl_vector_uint_get(bitcount,0)/M();
	ofs.width(NUMWIDTH);
	ofs << gsl_vector_uint_get(bitcount,0);
	ofs.width(NUMWIDTH);
	ofs << sum/M() << endl;


    }
    else {
	cout.width(NUMWIDTH);
	cout << "min";
	cout.width(NUMWIDTH);
	cout << value();
	cout.width(NUMWIDTH);
	cout << 1.0*minimum/gsl_vector_uint_get(bitcount,0);
	cout.width(NUMWIDTH);
	cout << gsl_vector_uint_get(bitcount,0);
	cout.width(NUMWIDTH);
	cout << minimum << endl;

	cout.width(NUMWIDTH);
	cout << "max";
	cout.width(NUMWIDTH);
	cout << value();
	cout.width(NUMWIDTH);
	cout << 1.0*maximum/gsl_vector_uint_get(bitcount,0);
	cout.width(NUMWIDTH);
	cout << gsl_vector_uint_get(bitcount,0);
	cout.width(NUMWIDTH);
	cout << maximum << endl;

	cout.width(NUMWIDTH);
	cout << "mean";
	cout.width(NUMWIDTH);
	cout << value();
	cout.width(NUMWIDTH);
	cout << 1.0*sum/gsl_vector_uint_get(bitcount,0)/M();
	cout.width(NUMWIDTH);
	cout << gsl_vector_uint_get(bitcount,0);
	cout.width(NUMWIDTH);
	cout << sum/M() << endl;

    }
  }


  ofs.close();
  
  double ebnol=pow(10.0,(value()/10.0));
  cout << "\n BPSK reference BER (AWGN) = " << gsl_cdf_ugaussian_Q(sqrt(2*ebnol)) << endl;
  
  gsl_vector_uint_free(lasterrs);
  gsl_vector_uint_free(errcount);
  gsl_vector_uint_free(bitcount);
  gsl_vector_uint_free(dumperrs);


}
Exemplo n.º 7
0
double
gsl_cdf_gaussian_Q (const double x, const double sigma)
{
  return gsl_cdf_ugaussian_Q (x / sigma);
}