ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2negb.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include "df1b2fun.h"
12 
23 /*
24  df1b2variable log_negbinomial_density(double x,const df1b2variable& mu,
25  const df1b2variable& tau)
26  {
27  if (value(tau)<=1.0)
28  {
29  cerr << "tau <=1 in log_negbinomial_density " << endl;
30  ad_exit(1);
31  }
32  df1b2variable r=mu/(tau-1.0);
33  df1b2variable tmp;
34  tmp=gammln(x+r)-gammln(r) -gammln(x+1)
35  +r*log(r)+x*log(mu)-(r+x)*log(r+mu);
36  return tmp;
37  }
38 */
39 
40 
51  const df1b2variable& tau)
52  {
53  if (value(tau)-1<0.0)
54  {
55  cerr << "tau <=1 in log_negbinomial_density " << endl;
56  ad_exit(1);
57  }
58  df1b2variable r=mu/(1.e-120+tau-1.0);
59  df1b2variable tmp;
60  tmp=exp(gammln(x+r)-gammln(r) -gammln(x+1)
61  +r*log(r)+x*log(mu)-(r+x)*log(r+mu));
62  return tmp;
63  }
64 
74  {
75  return -mu+x*log(mu)-gammln(x+1);
76  }
77 
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
Description not yet available.
Definition: df1b2fun.h:266
prnstream & endl(prnstream &)
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
Definition: d3arr2a.cpp:28
Description not yet available.
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
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13