Stan  1.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
poisson.hpp
Go to the documentation of this file.
1 #ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__POISSON_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__POISSON_HPP__
3 
7 #include <stan/prob/traits.hpp>
8 
9 namespace stan {
10 
11  namespace prob {
12 
13  // Poisson(n|lambda) [lambda > 0; n >= 0]
14  template <bool propto,
15  typename T_rate,
16  class Policy>
17  typename boost::math::tools::promote_args<T_rate>::type
18  poisson_log(const unsigned int n, const T_rate& lambda,
19  const Policy&) {
20 
21  static const char* function = "stan::prob::poisson_log(%1%)";
22 
25  using boost::math::tools::promote_args;
26 
27  typename promote_args<T_rate>::type lp;
28  if (!check_nonnegative(function, n, "Random variable", &lp, Policy()))
29  return lp;
30  if (!check_not_nan(function, lambda,
31  "Rate parameter", &lp, Policy()))
32  return lp;
33  if (!check_nonnegative(function, lambda,
34  "Rate parameter", &lp, Policy()))
35  return lp;
36 
37  if (lambda == 0)
38  return n == 0 ? 0 : LOG_ZERO;
39 
41  if (std::isinf(lambda))
42  return LOG_ZERO;
43 
44  lp = 0.0;
46  lp -= lgamma(n + 1.0);
48  lp += multiply_log(n, lambda) - lambda;
49  return lp;
50  }
51 
52  template <bool propto,
53  typename T_rate>
54  inline
55  typename boost::math::tools::promote_args<T_rate>::type
56  poisson_log(const unsigned int n, const T_rate& lambda) {
57  return poisson_log<propto>(n,lambda,stan::math::default_policy());
58  }
59 
60 
61  template <typename T_rate,
62  class Policy>
63  inline
64  typename boost::math::tools::promote_args<T_rate>::type
65  poisson_log(const unsigned int n, const T_rate& lambda,
66  const Policy&) {
67  return poisson_log<false>(n,lambda,Policy());
68  }
69 
70 
71  template <typename T_rate>
72  inline
73  typename boost::math::tools::promote_args<T_rate>::type
74  poisson_log(const unsigned int n, const T_rate& lambda) {
75  return poisson_log<false>(n,lambda,stan::math::default_policy());
76  }
77 
78 
79  }
80 }
81 #endif

     [ Stan Home Page ] © 2011–2012, Stan Development Team.