ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cnegbin.cpp
Go to the documentation of this file.
1 
11 #include "fvar.hpp"
12 
22  double log_density_negbinomial(double x,double mu,double tau)
23  {
24  if (tau-1.0<0.0)
25  {
26  cerr << "tau <=1 in log_negbinomial_density " << endl;
27  ad_exit(1);
28  }
29  double r=mu/(1.e-120+(tau-1.0));
30  return gammln(x+r)-gammln(r)-gammln(x+1)
31  +r*log(r)+x*log(mu)-(r+x)*log(r+mu);
32  }
33 
43  double density_negbinomial(double x,double mu,double tau)
44  {
45  if (tau-1.0<0.0)
46  {
47  cerr << "tau <=1 in negbinomial_density " << endl;
48  ad_exit(1);
49  }
50  double r=mu/(1.e-120+(tau-1.0));
51  return exp(gammln(x+r)-gammln(r)-gammln(x+1)
52  +r*log(r)+x*log(mu)-(r+x)*log(r+mu));
53  }
54 
61  double log_density_poisson(double x,double mu)
62  {
63  return -mu+x*log(mu)-gammln(x+1);
64  }
double gammln(double xx)
Log gamma function.
Definition: combc.cpp:52
#define x
exitptr ad_exit
Definition: gradstrc.cpp:53
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 log_density_poisson(double x, double mu)
Log Poisson density; constant objects.
Definition: cnegbin.cpp:61
double log_density_negbinomial(double x, double mu, double tau)
Log negative bionomial density; constant objects.
Definition: cnegbin.cpp:22
double density_negbinomial(double x, double mu, double tau)
Negative bionomial density; constant objects.
Definition: cnegbin.cpp:43
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13