ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vnegbin.cpp
Go to the documentation of this file.
1 
8 #include "fvar.hpp"
9 
10 
22  const prevariable& tau)
23  {
24  if (value(tau)-1.0<0.0)
25  {
26  cerr << "tau <=1 in log_negbinomial_density " << endl;
27  ad_exit(1);
28  }
31 
32  dvariable r=mu/(1.e-120+(tau-1));
33  dvariable tmp;
34  tmp=gammln(x+r)-gammln(r) -gammln(x+1)
35  +r*log(r)+x*log(mu)-(r+x)*log(r+mu);
37  return tmp;
38  }
39 
50  const prevariable& tau)
51  {
52  if (value(tau)-1.0<=0.0)
53  {
54  cerr << "tau <=1 in log_negbinomial_density " << endl;
55  ad_exit(1);
56  }
59  dvariable r=mu/(1.e-120+(tau-1));
60  dvariable tmp;
61  //tmp=exp(gammln(x+r)-gammln(r) -gammln(x+1)
62  // +r*log(r)+x*log(mu)-(r+x)*log(r+mu));
63  tmp=gammln(x+r);
64  tmp-=gammln(r);
65  tmp-=gammln(x+1);
66  tmp+=r*log(r);
67  tmp+=x*log(mu);
68  tmp-=(r+x)*log(r+mu);
69  tmp=exp(tmp);
70 
72  return tmp;
73  }
74 
82  {
83  return -mu+x*log(mu)-gammln(x+1);
84  }
Base class for dvariable.
Definition: fvar.hpp:1315
dvariable negbinomial_density(double x, const prevariable &mu, const prevariable &tau)
Negative bionomial density; variable objects.
Definition: vnegbin.cpp:49
double gammln(double xx)
Log gamma function.
Definition: combc.cpp:52
#define x
exitptr ad_exit
Definition: gradstrc.cpp:53
prnstream & endl(prnstream &)
void RETURN_ARRAYS_INCREMENT()
Definition: gradstrc.cpp:478
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
static _THREAD gradient_structure * _instance
void RETURN_ARRAYS_DECREMENT()
Definition: gradstrc.cpp:511
double log_density_poisson(double x, double mu)
Log Poisson density; constant objects.
Definition: cnegbin.cpp:61
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
double log_negbinomial_density(double x, double mu, double tau)
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