1 #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_LOG_RNG_HPP 2 #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_LOG_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_loc,
typename T_inv,
class RNG>
41 using boost::gamma_distribution;
42 using boost::random::poisson_distribution;
43 using boost::variate_generator;
45 static const char*
function =
"neg_binomial_2_log_rng";
50 "Inverse dispersion parameter", phi);
57 for (
size_t n = 0;
n < N; ++
n) {
58 double exp_eta_div_phi
59 =
std::exp(static_cast<double>(eta_vec[
n])) / phi_vec[
n];
63 "Exponential of the log-location parameter " 64 "divided by the precision parameter",
67 double rng_from_gamma = variate_generator<RNG&, gamma_distribution<> >(
68 rng, gamma_distribution<>(phi_vec[
n], exp_eta_div_phi))();
71 check_less(
function,
"Random number that came from gamma distribution",
73 check_not_nan(
function,
"Random number that came from gamma distribution",
76 "Random number that came from gamma distribution",
79 output[
n] = variate_generator<RNG&, poisson_distribution<> >(
80 rng, poisson_distribution<>(rng_from_gamma))();
void check_finite(const char *function, const char *name, const T_y &y)
VectorBuilder< true, int, T_loc, T_inv >::type neg_binomial_2_log_rng(const T_loc &eta, const T_inv &phi, 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)
fvar< T > exp(const fvar< T > &x)
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)