ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dtweedie.cpp
Go to the documentation of this file.
1 #include <vector>
2 #include <type_traits>
3 #include <fvar.hpp>
4 
5 int imax2(int a, double v)
6 {
7  int b = static_cast<int>(v);
8  return a > b ? a : b;
9 }
10 int imin2(int a, int b)
11 {
12  return a < b ? a : b;
13 }
14 double fmax2(double a, const dvariable& v)
15 {
16  double b = value(v);
17  return a > b ? a : b;
18 }
19 double asDouble(const dvariable& v)
20 {
21  return value(v);
22 }
24 {
25  return gammln(v);
26 }
27 #include "tweedie_logW.cpp"
47 template<class Type>
48 Type _dtweedie(const double y, Type& mu, Type& phi, Type& p, bool give_log) {
49  Type p1 = p - 1.0, p2 = 2.0 - p;
50  Type ans = -pow(mu, p2) / (phi * p2); // log(prob(y=0))
51  if (y > 0) {
52  ans += tweedie_logW(y, phi, p);
53  ans += -y / (phi * p1 * pow(mu, p1)) - log(y);
54  }
55  return ( give_log ? ans : exp(ans) );
56 }
57 
59 dvariable dtweedie(const double y, dvariable& mu, dvariable& phi, dvariable& p, const bool use_log)
60 {
61  return _dtweedie(y, mu, phi, p, use_log);
62 }
Type _dtweedie(const double y, Type &mu, Type &phi, Type &p, bool give_log)
dtweedie function (same as dtweedie.series from R package &#39;tweedie&#39;).
Definition: dtweedie.cpp:48
Base class for dvariable.
Definition: fvar.hpp:1315
double gammln(double xx)
Log gamma function.
Definition: combc.cpp:52
int imax2(int a, double v)
Definition: dtweedie.cpp:5
dvariable lgamma(const prevariable &v)
Definition: dtweedie.cpp:23
double fmax2(double a, const dvariable &v)
Definition: dtweedie.cpp:14
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
dvariable dtweedie(const double y, dvariable &mu, dvariable &phi, dvariable &p, const bool use_log)
dtweedie is a wrapper to _dtweedie using ADMB data types.
Definition: dtweedie.cpp:59
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
double asDouble(const dvariable &v)
Definition: dtweedie.cpp:19
int imin2(int a, int b)
Definition: dtweedie.cpp:10
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
d3_array pow(const d3_array &m, int e)
Description not yet available.
Definition: d3arr6.cpp:17