Exemplo n.º 1
0
Arquivo: test.c Projeto: CNMAT/gsl
double
test_gamma_knuth_vlarge_pdf (double x)
{
  double c = 2.71828181565;
  double b = 6.32899304917e-10;
  double d = 1e4;
  return gsl_ran_gamma_pdf ((x / d) + c, 4294967296.0, b) / d;
}
Exemplo n.º 2
0
double
gamma (double x, void *p)
{
  double * c = (double *)p;
  return gsl_ran_gamma_pdf (x, c[0], c[1]);
}
Exemplo n.º 3
0
double
gsl_cdf_gamma_Pinv (const double P, const double a, const double b)
{
  double x;

  if (P == 1.0)
    {
      return GSL_POSINF;
    }
  else if (P == 0.0)
    {
      return 0.0;
    }

  /* Consider, small, large and intermediate cases separately.  The
     boundaries at 0.05 and 0.95 have not been optimised, but seem ok
     for an initial approximation.

     BJG: These approximations aren't really valid, the relevant
     criterion is P*gamma(a+1) < 1. Need to rework these routines and
     use a single bisection style solver for all the inverse
     functions.
  */

  if (P < 0.05)
    {
      double x0 = exp ((gsl_sf_lngamma (a) + log (P)) / a);
      x = x0;
    }
  else if (P > 0.95)
    {
      double x0 = -log1p (-P) + gsl_sf_lngamma (a);
      x = x0;
    }
  else
    {
      double xg = gsl_cdf_ugaussian_Pinv (P);
      double x0 = (xg < -0.5*sqrt (a)) ? a : sqrt (a) * xg + a;
      x = x0;
    }

  /* Use Lagrange's interpolation for E(x)/phi(x0) to work backwards
     to an improved value of x (Abramowitz & Stegun, 3.6.6) 

     where E(x)=P-integ(phi(u),u,x0,x) and phi(u) is the pdf.
   */

  {
    double lambda, dP, phi;
    unsigned int n = 0;

  start:
    dP = P - gsl_cdf_gamma_P (x, a, 1.0);
    phi = gsl_ran_gamma_pdf (x, a, 1.0);

    if (dP == 0.0 || n++ > 32)
      goto end;

    lambda = dP / GSL_MAX (2 * fabs (dP / x), phi);

    {
      double step0 = lambda;
      double step1 = -((a - 1) / x - 1) * lambda * lambda / 4.0;

      double step = step0;
      if (fabs (step1) < 0.5 * fabs (step0))
        step += step1;

      if (x + step > 0)
        x += step;
      else
        {
          x /= 2.0;
        }

      if (fabs (step0) > 1e-10 * x || fabs(step0 * phi) > 1e-10 * P)
        goto start;
    }

  end:
    if (fabs(dP) > GSL_SQRT_DBL_EPSILON * P)
      {
        GSL_ERROR_VAL("inverse failed to converge", GSL_EFAILED, GSL_NAN);
      }
    
    return b * x;
  }
}
Exemplo n.º 4
0
double
gsl_cdf_gamma_Qinv (const double Q, const double a, const double b)
{
  double x;

  if (Q == 1.0)
    {
      return 0.0;
    }
  else if (Q == 0.0)
    {
      return GSL_POSINF;
    }

  /* Consider, small, large and intermediate cases separately.  The
     boundaries at 0.05 and 0.95 have not been optimised, but seem ok
     for an initial approximation. */

  if (Q < 0.05)
    {
      double x0 = -log (Q) + gsl_sf_lngamma (a);
      x = x0;
    }
  else if (Q > 0.95)
    {
      double x0 = exp ((gsl_sf_lngamma (a) + log1p (-Q)) / a);
      x = x0;
    }
  else
    {
      double xg = gsl_cdf_ugaussian_Qinv (Q);
      double x0 = (xg < -0.5*sqrt (a)) ? a : sqrt (a) * xg + a;
      x = x0;
    }

  /* Use Lagrange's interpolation for E(x)/phi(x0) to work backwards
     to an improved value of x (Abramowitz & Stegun, 3.6.6) 

     where E(x)=P-integ(phi(u),u,x0,x) and phi(u) is the pdf.
   */

  {
    double lambda, dQ, phi;
    unsigned int n = 0;

  start:
    dQ = Q - gsl_cdf_gamma_Q (x, a, 1.0);
    phi = gsl_ran_gamma_pdf (x, a, 1.0);

    if (dQ == 0.0 || n++ > 32)
      goto end;

    lambda = -dQ / GSL_MAX (2 * fabs (dQ / x), phi);

    {
      double step0 = lambda;
      double step1 = -((a - 1) / x - 1) * lambda * lambda / 4.0;

      double step = step0;
      if (fabs (step1) < 0.5 * fabs (step0))
        step += step1;

      if (x + step > 0)
        x += step;
      else
        {
          x /= 2.0;
        }

      if (fabs (step0) > 1e-10 * x)
        goto start;
    }

  }

end:
  return b * x;
}
Exemplo n.º 5
0
double pdf_Gamma(double a, double x)               { return gsl_ran_gamma_pdf(x,a,1); }
Exemplo n.º 6
0
double
test_gamma_large_pdf (double x)
{
  return gsl_ran_gamma_pdf (x, 20.0, 2.17);
}
Exemplo n.º 7
0
double
test_gamma_int_pdf (double x)
{
  return gsl_ran_gamma_pdf (x, 10.0, 2.17);
}
Exemplo n.º 8
0
double
test_gamma1_pdf (double x)
{
  return gsl_ran_gamma_pdf (x, 1.0, 2.17);
}
Exemplo n.º 9
0
double
test_gamma_pdf (double x)
{
  return gsl_ran_gamma_pdf (x, 2.5, 2.17);
}
Exemplo n.º 10
0
// --------------------------------------------------
double
BasicPdfsGsl::gammaPdfActualValue(double x, double a, double b) const
{
  return gsl_ran_gamma_pdf(x,a,b);
}
Exemplo n.º 11
0
double sncp_model::calculate_pdf(double value, double alpha,double z){
  double pdf =  gsl_ran_gamma_pdf(value,alpha,1.0/(double)z);
  return pdf;
}
Exemplo n.º 12
0
double
test_gamma_mt_small_pdf (double x)
{
  return gsl_ran_gamma_pdf (x, 0.92, 2.17);
}
Exemplo n.º 13
0
 double get_posterior ( vector<double> &parameter){ 
     return gsl_ran_gamma_pdf (parameter[0], 1.7, 1/4.4);
 }
Exemplo n.º 14
0
double poly_gamma_pdf(double x, double constr, size_t nterms, double* terms, double shape, double scale) {
	return (x>constr) ? poly_eval_mult_regular(x,nterms,terms) * gsl_ran_gamma_pdf(x,shape,scale) : 0;
}
Exemplo n.º 15
0
double poly_gamma_proposal_pdf(double x, poly_gamma_proposal_param_t par) {
	double dist = gsl_ran_gamma_pdf(x-par.theta,par.shape,par.scale);
	return dist;
}
Exemplo n.º 16
0
double
gen_gamma_pdf (double x, double a, double b)
{
	return (gsl_ran_gamma_pdf(x, a, b));
}