Пример #1
0
static double 
upper_tail (const unsigned int k, const unsigned int n1,
            const unsigned int n2, const unsigned int t)
{
  double relerr;
  unsigned int i = k + 1;
  double s, Q;
  
  s = gsl_ran_hypergeometric_pdf (i, n1, n2, t);
  Q = s;
  
  while (i < t)
    {
      double factor =
        ((n1 - i) / (i + 1.0)) * ((t - i) / (n2 + i + 1.0 - t));
      s *= factor;
      Q += s;
      relerr = s / Q;
      if (relerr < GSL_DBL_EPSILON)
        break;
      i++;
    }

  return Q;
}
Пример #2
0
static double
lower_tail (const unsigned int k, const unsigned int n1,
            const unsigned int n2, const unsigned int t)
{
  double relerr;
  int i = k;
  double s, P;

  s = gsl_ran_hypergeometric_pdf (i, n1, n2, t);
  P = s;
  
  while (i > 0)
    {
      double factor =
        (i / (n1 - i + 1.0)) * ((n2 + i - t) / (t - i + 1.0));
      s *= factor;
      P += s;
      relerr = s / P;
      if (relerr < GSL_DBL_EPSILON)
        break;
      i--;
    }

  return P;
}
double calculate_S( vector< struct cnfo >* cluster_info, int ne, int nv ){

	unsigned int F = ( nv * ( nv - 1 ) ) / 2;

	unsigned int n = ne;

	unsigned int M = 0;

	unsigned int p = 0;

	for( unsigned int i = 0; i < cluster_info->size(); i++ ){

		unsigned int temp = cluster_info->at(i).value1;

		M = M + ( ( temp ) * ( temp - 1 ) / 2 );

		p = p + cluster_info->at(i).value3;

	}


//	printf("%d\t%d\n", M, n);
	unsigned int upper_limit = min( M , n );
//	printf("%d\n", upper_limit);


	double surprise = 0.0;


//	printf(" Stats:\n ");
//	printf("\tM:%d\tp:%d\tF-M:%d\tn:%d\n", M, p, F-M, n);


	int i = p;

	do{

		surprise += gsl_ran_hypergeometric_pdf( i, M, ( F - M ), n );
//		surprise += gsl_cdf_hypergeometric_P( i, M, (F-M), n );
//		printf("%lf\n", surprise );

		 p = p + 1;

	}

	while( p < upper_limit );

//	printf("\tcalcS: %lf \n", surprise );

//	surprise = gsl_sf_log( surprise );

	return surprise;

}
Пример #4
0
double
test_hypergeometric6_pdf (unsigned int n)
{
  return gsl_ran_hypergeometric_pdf (n, 2, 10, 3);
}
Пример #5
0
double
test_hypergeometric5_pdf (unsigned int n)
{
  return gsl_ran_hypergeometric_pdf (n, 2, 7, 5);
}
Пример #6
0
double
test_hypergeometric4_pdf (unsigned int n)
{
  return gsl_ran_hypergeometric_pdf (n, 5, 7, 20);
}