1 #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_RNG_HPP 2 #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_RNG_HPP 13 #include <boost/random/gamma_distribution.hpp> 14 #include <boost/random/poisson_distribution.hpp> 15 #include <boost/random/variate_generator.hpp> 38 template <
typename T_shape,
typename T_inv,
class RNG>
40 const T_shape& alpha,
const T_inv&
beta, RNG& rng) {
41 using boost::gamma_distribution;
42 using boost::random::poisson_distribution;
43 using boost::variate_generator;
45 static const char*
function =
"neg_binomial_rng";
51 "Inverse scale Parameter", beta);
58 for (
size_t n = 0;
n < N; ++
n) {
59 double rng_from_gamma = variate_generator<RNG&, gamma_distribution<> >(
60 rng, gamma_distribution<>(alpha_vec[
n], 1.0 / beta_vec[
n]))();
63 check_less(
function,
"Random number that came from gamma distribution",
65 check_not_nan(
function,
"Random number that came from gamma distribution",
68 "Random number that came from gamma distribution",
71 output[
n] = variate_generator<RNG&, poisson_distribution<> >(
72 rng, poisson_distribution<>(rng_from_gamma))();
VectorBuilder< true, int, T_shape, T_inv >::type neg_binomial_rng(const T_shape &alpha, const T_inv &beta, RNG &rng)
void check_nonnegative(const char *function, const char *name, const T_y &y)
void check_positive_finite(const char *function, const char *name, const T_y &y)
void check_not_nan(const char *function, const char *name, const T_y &y)
size_t max_size(const T1 &x1, const T2 &x2)
const double POISSON_MAX_RATE
void check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
void check_less(const char *function, const char *name, const T_y &y, const T_high &high)