ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gammdev.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include "df1b2fun.h"
13  const df3_two_variable& a);
14 
16  const df3_two_variable& a);
17 
19  double inv_cumd_gamma(double y,double _a);
20 
22  const df3_two_variable& a);
23 
29  {
30  df1b2variable& x= (df1b2variable&)(_x);
31  df1b2variable& a= (df1b2variable&)(_a);
32 
34  y=.9999*y+.00005;
35 
36  //df1b2variable z=inv_cumd_gamma(y,a);
38 
39  return z;
40  }
41 
47  {
48  df1b2variable& y= (df1b2variable&)(_y);
49  df1b2variable& a= (df1b2variable&)(_a);
50  // get the inverse values
51  double x=inv_cumd_gamma(value(y),value(_a));
52 
55  //init_df3_two_variable xx(1.0);
56  //init_df3_two_variable aa(2.0);
57  *xx.get_u_x()=1.0;
58  *aa.get_u_y()=1.0;
59 
61 
62  // now use the derivatives of z to get the
63  //derivatives of x wrt y,a and save them
64 
65  //double ca=value(a);
66 
67  double F_x=1.0/(*z.get_u_x());
68 
69  double F_y=-F_x* *z.get_u_y();
70  double F_xx=-F_x* *z.get_u_xx()/square(*z.get_u_x());
71 
72  double F_xy=-(F_xx * *z.get_u_x() * *z.get_u_y() + F_x * *z.get_u_xy())/
73  *z.get_u_x();
74 
75  double F_yy=-(F_xx * square(*z.get_u_y())
76  +2.0* F_xy* *z.get_u_y()
77  +F_x * *z.get_u_yy());
78 
79  double F_xxx=-(F_x* *z.get_u_xxx()
80  +3.0*F_xx* *z.get_u_x() * *z.get_u_xx())
81  /cube(*z.get_u_x());
82 
83  double F_xxy=-(F_xxx * square(*z.get_u_x())* *z.get_u_y()
84  + 2.0*F_xx* *z.get_u_x()* *z.get_u_xy()
85  + F_xx* *z.get_u_xx() * *z.get_u_y()
86  + F_xy * *z.get_u_xx()
87  + F_x * *z.get_u_xxy())/
88  square(*z.get_u_x());
89 
90  double F_xyy=-(F_xxx* *z.get_u_x() *square(*z.get_u_y())
91  +2.0* F_xx * *z.get_u_xy() * *z.get_u_y()
92  +2.0*F_xxy * *z.get_u_x() * *z.get_u_y()
93  + 2.0*F_xy * *z.get_u_xy()
94  + F_xx * *z.get_u_x() * *z.get_u_yy()
95  + F_x * *z.get_u_xyy())/
96  *z.get_u_x();
97  double F_yyy=-(F_xxx*cube(*z.get_u_y())+
98  +3.0*F_xxy*square(*z.get_u_y())
99  +3.0*F_xx* *z.get_u_y() * *z.get_u_yy()
100  +3.0*F_xy* *z.get_u_yy()
101  +3.0*F_xyy * *z.get_u_y()
102  +F_x * *z.get_u_yyy());
103 
104  df1b2variable zz;
105  double * xd=_y.get_u_dot();
106  double * yd=_a.get_u_dot();
107  double * zd=zz.get_u_dot();
108  *zz.get_u()=x;
109 
110  for (unsigned int i=0;i<df1b2variable::nvar;i++)
111  {
112  *zd++ = F_x * *xd++ + F_y * *yd++;
113  }
115  {
116  f1b2gradlist->write_pass1(&_y,&_a,&zz,
117  F_x,F_y,
118  F_xx,F_xy,F_yy,
119  F_xxx,F_xxy,F_xyy,F_yyy);
120  }
121  return zz;
122  }
df1b2_gradlist * f1b2gradlist
Definition: df1b2glo.cpp:49
double * get_u_xy(void) const
Definition: df32fun.h:82
double * get_u() const
Definition: df1b2fun.h:228
Description not yet available.
Definition: df32fun.h:55
#define x
double inv_cumd_gamma(double y, double a)
Definition: cgamdev.cpp:124
Description not yet available.
Definition: df32fun.h:130
double cumd_gamma(double x, double a)
Definition: cgamdev.cpp:38
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_y(void) const
Definition: df32fun.h:74
double * get_u_xx(void) const
Definition: df32fun.h:78
double * get_u_dot() const
Definition: df1b2fun.h:229
double * get_u_x(void) const
Definition: df32fun.h:70
double * get_u_xyy(void) const
Definition: df32fun.h:98
static int no_derivatives
Definition: df1b2fun.h:759
double * get_u_xxy(void) const
Definition: df32fun.h:94
double * get_u_yyy(void) const
Definition: df32fun.h:102
double * get_u_yy(void) const
Definition: df32fun.h:86
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
double cumd_exponential(double x)
Description not yet available.
Definition: ccumdexp.cpp:26
Description not yet available.
double cumd_cauchy(const double &x)
Description not yet available.
Definition: cumd_cau.cpp:17
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
double cumd_norm(const double &x)
Culative normal distribution; constant objects.
Definition: cumdist.cpp:90
double square(const double value)
Return square of value; constant object.
Definition: d3arr4.cpp:16
double * get_u_xxx(void) const
Definition: df32fun.h:90
double gamma_deviate(double _x, double _a)