ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vbetai.cpp
Go to the documentation of this file.
1 
9 #include <fvar.hpp>
10 #include <math.h>
11 
23 dvariable betai(const dvariable a, const dvariable b, const dvariable x, int maxit)
24 {
25  dvariable bt;
26 
27  if (x < 0.0 || x > 1.0) cerr << "Bad x in routine betai" << endl;
28  if (x == 0.0 || x == 1.0) bt=0.0;
29  else
30  bt=exp(gammln(a+b)-gammln(a)-gammln(b)+a*log(x)+b*log(1.0-x));
31  if (x < (a+1.0)/(a+b+2.0))
32  return bt*betacf(a,b,x,maxit)/a;
33  else
34  return 1.0-bt*betacf(b,a,1.0-x,maxit)/b;
35 }
36 
48 dvariable pbeta(const dvariable x, const dvariable a, const dvariable b, int maxit){
49  return betai(a, b, x, maxit);
50 }
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
prnstream & endl(prnstream &)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
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
Float betacf(Float a, Float b, Float x, int MAXIT)
Definition: betacf_val.hpp:13
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