Stan Math Library  2.14.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/random/poisson_distribution.hpp>
13 #include <boost/random/variate_generator.hpp>
14 #include <limits>
15 
16 namespace stan {
17  namespace math {
18 
19  template <class RNG>
20  inline int
21  poisson_log_rng(double alpha,
22  RNG& rng) {
23  using boost::variate_generator;
24  using boost::random::poisson_distribution;
25 
26  static const char* function("poisson_log_rng");
27  static const double POISSON_MAX_LOG_RATE = 30 * std::log(2);
28 
29  using std::exp;
30 
31  check_not_nan(function, "Log rate parameter", alpha);
32  check_less(function, "Log rate parameter", alpha, POISSON_MAX_LOG_RATE);
33 
34  variate_generator<RNG&, poisson_distribution<> >
35  poisson_rng(rng, poisson_distribution<>(exp(alpha)));
36  return poisson_rng();
37  }
38 
39  }
40 }
41 #endif
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14
int poisson_rng(double lambda, RNG &rng)
Definition: poisson_rng.hpp:22
int poisson_log_rng(double alpha, RNG &rng)
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
void check_less(const char *function, const char *name, const T_y &y, const T_high &high)
Check if y is strictly less than high.
Definition: check_less.hpp:78

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