Stan Math Library  2.15.0
reverse mode automatic differentiation
poisson_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_POISSON_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_POISSON_RNG_HPP
3 
12 #include <boost/random/poisson_distribution.hpp>
13 #include <boost/random/variate_generator.hpp>
14 #include <cmath>
15 #include <limits>
16 
17 namespace stan {
18  namespace math {
19 
20  template <class RNG>
21  inline int
22  poisson_rng(double lambda,
23  RNG& rng) {
24  using boost::variate_generator;
25  using boost::random::poisson_distribution;
26 
27  static const char* function("poisson_rng");
28 
29  check_not_nan(function, "Rate parameter", lambda);
30  check_nonnegative(function, "Rate parameter", lambda);
31  check_less(function, "Rate parameter", lambda, POISSON_MAX_RATE);
32 
33  variate_generator<RNG&, poisson_distribution<> >
34  poisson_rng(rng, poisson_distribution<>(lambda));
35  return poisson_rng();
36  }
37 
38  }
39 }
40 #endif
int poisson_rng(double lambda, RNG &rng)
Definition: poisson_rng.hpp:22
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
const double POISSON_MAX_RATE
Largest rate parameter allowed in Poisson RNG.
Definition: constants.hpp:71
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.