Stan Math Library  2.9.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 
13 #include <boost/math/special_functions/fpclassify.hpp>
14 #include <boost/random/poisson_distribution.hpp>
15 #include <boost/random/variate_generator.hpp>
16 #include <cmath>
17 #include <limits>
18 
19 namespace stan {
20 
21  namespace math {
22 
23  template <class RNG>
24  inline int
25  poisson_rng(const double lambda,
26  RNG& rng) {
27  using boost::variate_generator;
28  using boost::random::poisson_distribution;
29 
30  static const char* function("stan::math::poisson_rng");
31 
32  check_not_nan(function, "Rate parameter", lambda);
33  check_nonnegative(function, "Rate parameter", lambda);
34  check_less(function, "Rate parameter", lambda, POISSON_MAX_RATE);
35 
36  variate_generator<RNG&, poisson_distribution<> >
37  poisson_rng(rng, poisson_distribution<>(lambda));
38  return poisson_rng();
39  }
40  }
41 }
42 #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.
const double POISSON_MAX_RATE
Largest rate parameter allowed in Poisson RNG.
Definition: constants.hpp:72
int poisson_rng(const double lambda, RNG &rng)
Definition: poisson_rng.hpp:25
bool check_nonnegative(const char *function, const char *name, const T_y &y)
Return true if y is non-negative.

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