Stan Math Library  2.11.0
reverse mode automatic differentiation
poisson_log_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_POISSON_LOG_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_POISSON_LOG_RNG_HPP
3 
12 #include <boost/math/special_functions/fpclassify.hpp>
13 #include <boost/random/poisson_distribution.hpp>
14 #include <boost/random/variate_generator.hpp>
15 #include <limits>
16 
17 namespace stan {
18 
19  namespace math {
20 
21  template <class RNG>
22  inline int
23  poisson_log_rng(const double alpha,
24  RNG& rng) {
25  using boost::variate_generator;
26  using boost::random::poisson_distribution;
27 
28  static const char* function("stan::math::poisson_log_rng");
29  static const double POISSON_MAX_LOG_RATE = 30 * std::log(2);
30 
34  using std::exp;
35 
36  check_not_nan(function, "Log rate parameter", alpha);
37  check_less(function, "Log rate parameter", alpha, POISSON_MAX_LOG_RATE);
38 
39  variate_generator<RNG&, poisson_distribution<> >
40  poisson_rng(rng, poisson_distribution<>(exp(alpha)));
41  return poisson_rng();
42  }
43  }
44 }
45 #endif
bool check_less(const char *function, const char *name, const T_y &y, const T_high &high)
Return true if y is strictly less than high.
Definition: check_less.hpp:81
bool check_not_nan(const char *function, const char *name, const T_y &y)
Return true if y is not NaN.
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
int poisson_log_rng(const double alpha, RNG &rng)
int poisson_rng(const double lambda, RNG &rng)
Definition: poisson_rng.hpp:24
bool check_nonnegative(const char *function, const char *name, const T_y &y)
Return true if y is non-negative.

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