ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dbeta.cpp
Go to the documentation of this file.
1 #include "statsLib.h"
2 
37 dvariable dbeta( const dvariable& x, const double& shape1, const double& shape2 )
38 {
39  if( x<=0 || x>=1.0 )
40  {
41  cerr<<"x is <=0 or >=1.0 in "
42  "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
43  return 0;
44  }
45 
46  if( shape1<=0 || shape2 <=0 )
47  {
48  cerr<<"shape1 or shape2 is <= 0 in "
49  "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
50  return 0;
51  }
52 
53  double a=shape1;
54  double b=shape2;
55  return -1.* gammln(a+b)+(gammln(a)+gammln(b))-(a-1.)*log(x)-(b-1.)*log(1.-x);
56 }
57 
58 dvariable dbeta( const dvariable& x, const dvariable& shape1, const dvariable& shape2 )
59 {
60  if( x<=0 || x>=1.0 )
61  {
62  cerr<<"x is <=0 or >=1.0 in "
63  "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
64  return 0;
65  }
66 
67  if( shape1<=0 || shape2 <=0 )
68  {
69  cerr<<"shape1 or shape2 is <= 0 in "
70  "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
71  return 0;
72  }
73 
74  dvariable a=shape1;
75  dvariable b=shape2;
76  return -1.* gammln(a+b)+(gammln(a)+gammln(b))-(a-1.)*log(x)-(b-1.)*log(1.-x);
77 }
78 
79 dvariable dbeta( const dvariable& x, const prevariable& shape1, const prevariable& shape2 )
80 {
81  if( x<=0 || x>=1.0 )
82  {
83  cerr<<"x is <=0 or >=1.0 in "
84  "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
85  return 0;
86  }
87 
88  if( shape1<=0 || shape2 <=0 )
89  {
90  cerr<<"shape1 or shape2 is <= 0 in "
91  "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
92  return 0;
93  }
94 
95  dvariable a=shape1;
96  dvariable b=shape2;
97  return -1.* gammln(a+b)+(gammln(a)+gammln(b))-(a-1.)*log(x)-(b-1.)*log(1.-x);
98 }
99 
Base class for dvariable.
Definition: fvar.hpp:1315
double gammln(double xx)
Log gamma function.
Definition: combc.cpp:52
#define x
Library of statistic functions.
dvariable dbeta(const dvariable &x, const double &shape1, const double &shape2)
Definition: dbeta.cpp:37
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13