12 static void gcf(
double& gammcf,
double a,
double x,
double &gln);
13 static void gser(
double& gamser,
double a,
double x,
double& gln);
34 static double gammp(
double a,
double x)
36 double gamser = 0.0,gammcf,gln;
38 if (x < 0.0 || a <= 0.0)
39 cerr <<
"Invalid arguments in routine gammp" <<
endl;
55 static void gcf(
double& gammcf,
double a,
double x,
double &gln)
58 double an,b,c,d,del,h;
65 for (i=1;i<=
ITMAX;i++) {
78 cerr <<
"a too large, ITMAX too small in gcf" <<
endl;
79 gammcf=
exp(-x+a*
log(x)-(gln))*h;
88 static void gser(
double& gamser,
double a,
double x,
double& gln)
96 cerr <<
"x less than 0 in routine gser" <<
endl;
102 for (n=1;n<=
ITMAX;n++) {
107 gamser=sum*
exp(-x+a*
log(x)-(gln));
111 cerr <<
"a too large, ITMAX too small in routine gser" <<
endl;
118 double Sn(
double x,
double a);
130 cerr <<
"a musdt be > 0.1" <<
endl;
143 double fprime=
exp(log_fprime);
146 if (loop_counter>1000)
148 cerr <<
"Error in inv_cumd_gamma"
149 " maximum number of interations exceeded for values"
150 << endl <<
" x = " << y <<
" a = " << a <<
" h = " << h <<
endl;
153 while(
fabs(h)>1.e-12);
164 double F_y=-F_x*(*z.
get_u_y());
170 &(vz.v->x),&(_y.
v->
x),F_x,&(_a.
v->
x),F_y);
178 double Sn(
double x,
double a)
189 double summand=xp/prod;
190 if (summand<1.e-4)
break;
195 cerr <<
"convergence error" <<
endl;
203 const double c=0.57721;
206 double logQ=
log(1-y);
207 double logB=logQ+
gammln(a);
209 double log_x0=1.e+100;
213 if ( logB>
log(.6) || (logB >
log(.45) && a>=.3) )
216 if (logB+logQ >
log(1.e-8))
218 logu=(logP+
gammln(1.0+a))/a;
222 logu=-
exp(logQ)/a -c;
226 double tmp=
log(1-u/(1.0+a));
230 else if ( a<.3 &&
log(.35) <= logB && logB <=
log(.6) )
232 double t=
exp(-c-
exp(logB));
233 double logt=-c-
exp(logB);
238 else if ( (
log(.15)<=logB && logB <=
log(.35)) ||
239 ((
log(.15)<=logB && logB <=
log(.45)) && a>=.3) )
242 double v=y-(1-a)*
log(y);
243 x0=y-(1-a)*
log(v)-
log(1+(1.0-a)/(1.0+v));
246 else if (
log(.01)<logB && logB <
log(.15))
249 double v=y-(1-a)*
log(y);
250 x0=y-(1-a)*
log(v)-
log((v*v+2*(3-a)*v+(2-a)*(3-a))/(v*v +(5-a)*v+2));
253 else if (logB <
log(.01))
256 double v=y-(1-a)*
log(y);
257 x0=y-(1-a)*
log(v)-
log((v*v+2*(3-a)*v+(2-a)*(3-a))/(v*v +(5-a)*v+2));
262 cerr <<
"this can't happen" <<
endl;
268 const double a0 = 3.31125922108741;
269 const double b1 = 6.61053765625462;
270 const double a1 = 11.6616720288968;
271 const double b2 = 6.40691597760039;
272 const double a2 = 4.28342155967104;
273 const double b3 = 1.27364489782223;
274 const double a3 = .213623493715853;
275 const double b4 = .03611708101884203;
290 double t=
sqrt(-2.0*logtau);
292 double num = (((a3*t+a2)*t+a1)*t)+a0;
293 double den = ((((b4*t+b3)*t+b2)*t)+b1)*t+1;
294 double s=sgn*(t-num/den);
299 double roota=
sqrt(a);
300 double w=a+s*roota+(s2-1)/3.0+(s3-7.0*s)/(36.*roota)
301 -(3.0*s4+7.0*s2-16)/(810.0*a)
302 +(9.0*s5+256.0*s3-433.0*s)/(38880.0*a*roota);
311 double v=logP+
gammln(a+1);
312 double u1=
exp(v+w)/a;
313 double S1=1+u1/(a+1);
314 double u2=
exp((v+u1-
log(S1))/a);
315 double S2=1+u2/(a+1)+u2*u2/((a+1)*(a+2));
316 double u3=
exp((v+u2-
log(S2))/a);
317 double S3=1+u3/(a+1)+u3*u3/((a+1)*(a+2))
318 + u3*u3*u3/((a+1)*(a+2)*(a+3));
319 double z=
exp((v+u3-
log(S3))/a);
327 double zbar=
exp((v+z-
log(sn))/a);
328 x0=zbar*(1.0-(a*
log(zbar)-zbar-v+
log(sn))/(a-zbar));
335 double u = -logB +(a-1.0)*
log(w)-
log(1.0+(1.0-a)/(1+w));
345 return log_x0-
log(a);
Base class for dvariable.
double gammln(double xx)
Log gamma function.
Description not yet available.
double inv_cumd_gamma(double y, double a)
Description not yet available.
double cumd_gamma(double x, double a)
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
df1_two_variable fabs(const df1_two_variable &x)
ivector sgn(const dvector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void set_gradient_stack(void(*func)(void), double *dep_addr, double *ind_addr1=NULL, double mult1=0, double *ind_addr2=NULL, double mult2=0)
Description not yet available.
double * get_u_y(void) const
double * get_u_x(void) const
prnstream & endl(prnstream &)
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
double get_initial_u(double a, double y)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
double gammp(double a, double x)
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
void default_evaluation(void)
Description not yet available.
void gcf(double &gammcf, double a, double x, double &gln)
Incomplete gamma function.
double_and_int * v
pointer to the data
void gser(double &gamser, double a, double x, double &gln)
Incomplete gamma function.
double Sn(double x, double a)
dvector value(const df1_one_vector &v)
static _THREAD grad_stack * GRAD_STACK1
double cumd_norm(const double &x)
Culative normal distribution; constant objects.
Description not yet available.
Fundamental data type for reverse mode automatic differentiation.
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
double x
< value of the variable
double gamma_deviate(double _x, double _a)