46 return (q < p) ? 0.0 : 1.0;
50 static double beta(
double alpha,
double beta,
double q) {
66 static int binomial(
int n,
double p,
double q) {
79 static double cauchy(
double median,
double scale,
double q) {
80 return median + scale * tan(M_PI * (q - 0.5));
85 if (q < 0.0 || q > 1.0 || df < 1)
92 if (q < 0.0 || q > 1.0 || lambda <= 0.0)
94 return -log(1.0 - q) / lambda;
98 static double f(
int df1,
int df2,
double q) {
99 if (q <= 0.0 || q >= 1.0 || df1 <= 0 || df2 <= 0)
101 return (
inverseBeta(0.5 * df2, 0.5 * df1, q) * df2) /
102 (
inverseBeta(0.5 * df2, 0.5 * df1, 1.0 - q) * df1);
106 static double gamma(
double shape,
double scale,
double q) {
107 if (q < 0.0 || q > 1.0 || shape <= 0.0 || scale <= 0.0)
114 if (q < 0.0 || q > 1.0 || shape <= 0.0)
116 return 1.0 /
gamma(shape, 1.0 / shape, 1.0 - q);
121 const int maxIterations = 200;
122 const double epsilon = 1.0e-15;
124 double bt = (x == 0.0 || x == 1.0)
127 a * log(x) + b * log(1.0 - x));
129 if (x < (a + 1.0) / (a + b + 2.0))
136 double x, y, tmp, ser;
137 static const double cof[6] = {76.18009172947146,
141 0.1208650973866179e-2,
142 -0.5395239384953e-5};
147 tmp -= (x + 0.5) * log(tmp);
148 ser = 1.000000000190015;
149 for (j = 0; j < 6; j++)
151 return -tmp + log(2.5066282746310005 * ser / x);
155 const int maxIterations = 200;
156 const double epsilon = 1.0e-15;
162 double qap = a + 1.0;
163 double qam = a - 1.0;
164 double bz = 1.0 - qab * x / qap;
166 double em, tem, d, ap, bp, app, bpp;
169 for (m = 1; m <= maxIterations; m++) {
172 d = em * (b - m) * x / ((qam + tem) * (a + tem));
175 d = -(a + em) * (qab + em) * x / ((a + tem) * (qap + tem));
184 if (fabs(az - aold) < (epsilon * fabs(az)))
197 if (k == 0 || k == n)
204 for (
int i = 0; i < k; ++i) {
static int binomial(int n, double p, double q)
static int binomialCoefficient(int n, int k)
static double beta(double alpha, double beta, double q)
static double chiSquared(int df, double q)
static double inverseGamma(double shape, double q)
static double bernoulli(double p, double q)
static double f(int df1, int df2, double q)
static double gamma(double shape, double scale, double q)
static double gammaLn(double xx)
static double betaContinuedFraction(double a, double b, double x)
static double exponential(double lambda, double q)
static double cauchy(double median, double scale, double q)
static double inverseBeta(double a, double b, double q)
static double incompleteBeta(double a, double b, double x)