| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

neg_binomial_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_RNG_HPP
3
4 #include <boost/math/special_functions/digamma.hpp>
5 #include <boost/random/negative_binomial_distribution.hpp>
6 #include <boost/random/variate_generator.hpp>
7 #include <stan/math/prim/scal/err/check_consistent_sizes.hpp>
8 #include <stan/math/prim/scal/err/check_nonnegative.hpp>
9 #include <stan/math/prim/scal/err/check_positive_finite.hpp>
10 #include <stan/math/prim/scal/fun/constants.hpp>
11 #include <stan/math/prim/scal/fun/value_of.hpp>
12 #include <stan/math/prim/scal/fun/binomial_coefficient_log.hpp>
13 #include <stan/math/prim/scal/fun/multiply_log.hpp>
14 #include <stan/math/prim/scal/fun/digamma.hpp>
15 #include <stan/math/prim/scal/fun/lgamma.hpp>
16 #include <stan/math/prim/scal/fun/lbeta.hpp>
17 #include <stan/math/prim/scal/meta/include_summand.hpp>
18 #include <stan/math/prim/scal/prob/gamma_rng.hpp>
19 #include <stan/math/prim/scal/prob/poisson_rng.hpp>
20 #include <stan/math/prim/scal/fun/grad_reg_inc_beta.hpp>
21 #include <stan/math/prim/scal/fun/inc_beta.hpp>
22
23 namespace stan {
24 namespace math {
25
26 template <class RNG>
27 inline int
28 neg_binomial_rng(const double alpha,
29 const double beta,
30 RNG& rng) {
31 using boost::variate_generator;
32 using boost::random::negative_binomial_distribution;
33 using boost::random::poisson_distribution;
34 using boost::gamma_distribution;
35
36 static const char* function("neg_binomial_rng");
37
38 // gamma_rng params must be positive and finite
39 check_positive_finite(function, "Shape parameter", alpha);
40 check_positive_finite(function, "Inverse scale parameter", beta);
41
42 double rng_from_gamma =
43 variate_generator<RNG&, gamma_distribution<> >
44 (rng, gamma_distribution<>(alpha, 1.0 / beta))();
45
46 // same as the constraints for poisson_rng
47 check_less(function,
48 "Random number that came from gamma distribution",
49 rng_from_gamma, POISSON_MAX_RATE);
50 check_not_nan(function,
51 "Random number that came from gamma distribution",
52 rng_from_gamma);
53 check_nonnegative(function,
54 "Random number that came from gamma distribution",
55 rng_from_gamma);
56
57 return variate_generator<RNG&, poisson_distribution<> >
58 (rng, poisson_distribution<>(rng_from_gamma))();
59 }
60
61 }
62 }
63 #endif
stan::math::check_less
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
lgamma.hpp
poisson_rng.hpp
stan::math::check_not_nan
bool check_not_nan(const char *function, const char *name, const T_y &y)
Return true if y is not NaN.
Definition: check_not_nan.hpp:60
check_positive_finite.hpp
stan
Definition: log_sum_exp.hpp:8
digamma.hpp
gamma_rng.hpp
stan::math::neg_binomial_rng
int neg_binomial_rng(const double alpha, const double beta, RNG &rng)
Definition: neg_binomial_rng.hpp:28
binomial_coefficient_log.hpp
include_summand.hpp
multiply_log.hpp
check_nonnegative.hpp
stan::math::POISSON_MAX_RATE
const double POISSON_MAX_RATE
Largest rate parameter allowed in Poisson RNG.
Definition: constants.hpp:71
grad_reg_inc_beta.hpp
constants.hpp
lbeta.hpp
inc_beta.hpp
stan::math::check_nonnegative
bool check_nonnegative(const char *function, const char *name, const T_y &y)
Return true if y is non-negative.
Definition: check_nonnegative.hpp:64
value_of.hpp
check_consistent_sizes.hpp
stan::math::check_positive_finite
bool check_positive_finite(const char *function, const char *name, const T_y &y)
Return true if y is positive and finite.
Definition: check_positive_finite.hpp:28

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