ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2bet.cpp
Go to the documentation of this file.
1 
7 #include <df1b2fun.h>
8 #include "../linad99/betacf_val.hpp"
9 
10 df1b2variable betacf(const df1b2variable& a,const df1b2variable& b, double x, int MAXIT);
11 df1b2variable betacf(const df1b2variable& a,const df1b2variable& b, const df1b2variable& x, int MAXIT);
12 
14 {
15  typedef tiny_ad::variable<3, 3> Float;
16  Float a_ (value(a), 0);
17  Float b_ (value(b), 1);
18  Float x_ (value(x), 2);
19  Float ans = betacf<Float>(a_, b_, x_, MAXIT);
20  double val=ans.value.value.value;
21  tiny_vec<double, 3> der1 = ans.value.value.getDeriv();
22  tiny_vec<double, 9> der2 = ans.value.getDeriv();
23  tiny_vec<double, 27> der3 = ans.getDeriv();
24 
25  df1b2variable tmp;
26  value(tmp)=val;
27  double * xd=a.get_u_dot();
28  double * yd=b.get_u_dot();
29  double * zd=x.get_u_dot();
30  double * tmpd=tmp.get_u_dot();
31  for (unsigned int i=0;i<df1b2variable::nvar;i++)
32  {
33  *tmpd++ = der1[0] * *xd++ + der1[1] * *yd++ + der1[2] * *zd++;
34  }
36  {
37  f1b2gradlist->write_pass1(&a,&b,&x,&tmp,
38  der1[0],der1[1],der1[2],
39  der2[0],der2[1],der2[2],der2[4],der2[5],der2[8],
40  der3[0],der3[1],der3[2],der3[4],der3[5],der3[8],der3[13],der3[14],der3[17],der3[26]);
41  }
42  return tmp;
43 }
44 
56 df1b2variable betai(const df1b2variable & a,const df1b2variable & b,double x, int maxit)
57 {
58  df1b2variable bt;
59 
60  if (x < 0.0 || x > 1.0) cerr << "Bad x in routine betai" << endl;
61  if (x == 0.0 || x == 1.0) bt=double(0.0);
62  else
63  bt=exp(gammln(a+b)-gammln(a)-gammln(b)+a*log(x)+b*log(1.0-x));
64  if (x < (value(a)+1.0)/(value(a)+value(b)+2.0))
65  return bt*betacf(a,b,x,maxit)/a;
66  else
67  return 1.0-bt*betacf(b,a,1.0-x,maxit)/b;
68 }
69 
81 df1b2variable pbeta(double x, const df1b2variable & a,const df1b2variable & b, int maxit){
82  return betai(a,b,x,maxit);
83 }
84 
97 df1b2variable betacf(const df1b2variable& a,const df1b2variable& b, double x, int MAXIT)
98 {
99  df1b2variable xx;
100  xx=x;
101  return betacf(a,b,xx,MAXIT);
102 }
103 
104 df1b2variable pbeta(const df1b2variable & x, const df1b2variable & a, const df1b2variable & b, int maxit)
105 {
106  df1b2variable bt;
107 
108  if (value(x) < 0.0 || value(x) > 1.0) cerr << "Bad x in routine betai" << endl;
109  if (value(x) == 0.0 || value(x) == 1.0) bt=double(0.0);
110  else
111  bt=exp(gammln(a+b)-gammln(a)-gammln(b)+a*log(x)+b*log(1.0-x));
112  if (value(x) < (value(a)+1.0)/(value(a)+value(b)+2.0))
113  return bt*betacf(a,b,x,maxit)/a;
114  else
115  return 1.0-bt*betacf(b,a,1.0-x,maxit)/b;
116 }
117 
118 
119 
df1b2_gradlist * f1b2gradlist
Definition: df1b2glo.cpp:49
double gammln(double xx)
Log gamma function.
Definition: combc.cpp:52
double pbeta(const double x, const double a, const double b, int maxit)
beta distribution function for constant objects (alias of ibeta function with same arguments order as...
Definition: cbetai.cpp:47
#define x
void val(const adstring &s, int &v, int &code)
Definition: val.cpp:11
Description not yet available.
Definition: df1b2fun.h:266
double * get_u_dot() const
Definition: df1b2fun.h:229
prnstream & endl(prnstream &)
#define MAXIT
static int no_derivatives
Definition: df1b2fun.h:759
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
Definition: d3arr2a.cpp:28
double betai(const double a, const double b, const double x, int maxit)
Incomplete beta function for constant objects.
Definition: cbetai.cpp:21
int write_pass1(const df1b2variable *px, const df1b2variable *py, df1b2variable *pz, df1b2function2 *pf)
Description not yet available.
Definition: df1b2f12.cpp:17
Float betacf(Float a, Float b, Float x, int MAXIT)
Definition: betacf_val.hpp:13
static unsigned int nvar
Definition: df1b2fun.h:290
Description not yet available.
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13