ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2f20.cpp
Go to the documentation of this file.
1 
11 #include <df1b2fun.h>
12 
18 {
20  df1b2variable u;
21  double z = value(_zz);
22  //double zdot=1.0;
23  const double lpp =0.9189385332046727417803297;
24  unsigned int n=7;
25  const double c[9]={0.99999999999980993,
26  676.5203681218851,
27  -1259.1392167224028,
28  771.32342877765313,
29  -176.61502916214059,
30  12.507343278686905,
31  -0.13857109526572012,
32  9.9843695780195716e-6,
33  1.5056327351493116e-7};
34  z-=1.0;
35  double x=c[0];
36  double xdot=0.0;
37  double x2dot=0.0;
38  double x3dot=0.0;
39  for (unsigned int i=1;i<=n+1;i++)
40  {
41  double zinv=1.0/(z+i);
42  x+=c[i]*zinv;
43  //xdot-=c[i]/square(z+i)*zdot; since zdot=1.0
44  xdot-=c[i]*square(zinv);
45  x2dot+=2.0*c[i]*cube(zinv);
46  x3dot-=6.0*c[i]*fourth(zinv);
47  }
48  double t=z+n+0.5;
49  //return lpp + (z+0.5)*log(t) -t + log(x);
50  double ans= lpp + (z+0.5)*log(t) -t + log(x);
51  //double tdot=zdot;
52  //double dfx=zdot*log(t) + (z+0.5)/t*tdot -tdot +xdot/x;
53  // since tdot=1.0
54  // since zdot=1.0
55  double dfx=log(t) + (z+0.5)/t -1.0 +xdot/x;
56  double d2f=2.0/t -(z+0.5)/square(t)+x2dot/x
57  -square(xdot)/square(x);
58  double d3f=-3.0/square(t) + 2.0*(z+0.5)/cube(t)+ x3dot/x
59  -3.0*x2dot*xdot/square(x)+2.0*cube(xdot)/cube(x);
60 
61  double * xd=zz.get_u_dot();
62  double * zd=u.get_u_dot();
63  *u.get_u()=ans;
64  for (unsigned int i=0;i<df1b2variable::nvar;i++)
65  {
66  *zd++ =dfx * *xd++;
67  }
68 
70  f1b2gradlist->write_pass1(&zz,&u,dfx,d2f,d3f);
71  return(u);
72 }
73 
79 {
80  const double lpi =1.1447298858494001741434272;
81  const double pi =3.1415926535897932384626432;
82  if (value(z)<0.5)
83  {
84  return lpi - log(sin(pi*z)) - gammlnguts(1.0-z);
85  }
86  else
87  {
88  return gammlnguts(z);
89  }
90 }
91 
97  int from=z.indexmin();
98  int to=z.indexmax();
99  df1b2vector ret(from,to);
100  for(int i=from; i<=to; ++i){
101  ret(i)=gammln(z(i));
102  }
103  return(ret);
104 }
105 
111 {
112  return factln(n)-factln(k)-factln(n-k);
113 }
114 
120 {
121  return factln(n)-factln(k)-factln(n-k);
122 }
123 
129 {
130  return factln(n)-factln(k)-factln(n-k);
131 }
132 
138 {
139  return gammln(n+1.0);
140 }
double factln(double n)
Log-factorial .
Definition: combc.cpp:38
double log_comb(double n, double k)
Log of the binomial coefficent; i.e log of &#39;n choose k&#39;.
Definition: combc.cpp:27
df1b2_gradlist * f1b2gradlist
Definition: df1b2glo.cpp:49
double gammln(double xx)
Log gamma function.
Definition: combc.cpp:52
double * get_u() const
Definition: df1b2fun.h:228
#define x
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
Description not yet available.
Definition: df1b2fun.h:953
d3_array sin(const d3_array &arr3)
Returns d3_array results with computed sin from elements in arr3.
Definition: d3arr2a.cpp:43
int indexmin(void) const
Definition: df1b2fun.h:969
d3_array cube(const d3_array &m)
Description not yet available.
Definition: d3arr5.cpp:17
Description not yet available.
Definition: df1b2fun.h:266
double * get_u_dot() const
Definition: df1b2fun.h:229
static int no_derivatives
Definition: df1b2fun.h:759
int write_pass1(const df1b2variable *px, const df1b2variable *py, df1b2variable *pz, df1b2function2 *pf)
Description not yet available.
Definition: df1b2f12.cpp:17
static unsigned int nvar
Definition: df1b2fun.h:290
int indexmax(void) const
Definition: df1b2fun.h:970
Description not yet available.
df1b2variable gammlnguts(const df1b2variable _zz)
Description not yet available.
Definition: df1b2f20.cpp:17
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
double square(const double value)
Return square of value; constant object.
Definition: d3arr4.cpp:16
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13
double fourth(const double m)
Fourth power of a number; constant objects.
Definition: dvector.cpp:704