| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
neg_binomial_2_log_rng.hpp
Go to the documentation of this file.
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
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/meta/OperandsAndPartials.hpp>
8 #include <stan/math/prim/scal/err/check_consistent_sizes.hpp>
9 #include <stan/math/prim/scal/err/check_positive_finite.hpp>
10 #include <stan/math/prim/scal/err/check_nonnegative.hpp>
11 #include <stan/math/prim/scal/err/check_less.hpp>
12 #include <stan/math/prim/scal/fun/constants.hpp>
13 #include <stan/math/prim/scal/fun/binomial_coefficient_log.hpp>
14 #include <stan/math/prim/scal/fun/multiply_log.hpp>
15 #include <stan/math/prim/scal/fun/digamma.hpp>
16 #include <stan/math/prim/scal/fun/lgamma.hpp>
17 #include <stan/math/prim/scal/fun/value_of.hpp>
18 #include <stan/math/prim/scal/meta/include_summand.hpp>
19 #include <stan/math/prim/scal/prob/gamma_rng.hpp>
20 #include <stan/math/prim/scal/prob/poisson_rng.hpp>
21 #include <stan/math/prim/scal/fun/grad_reg_inc_beta.hpp>
22
23 namespace stan {
24
25 namespace math {
26
27 template <class RNG>
28 inline int
29 neg_binomial_2_log_rng(const double eta,
30 const double phi,
31 RNG& rng) {
32 using boost::variate_generator;
33 using boost::random::negative_binomial_distribution;
34 using boost::random::poisson_distribution;
35 using boost::gamma_distribution;
36
37 static const char* function("stan::math::neg_binomial_2_log_rng");
38
39 check_finite(function, "Log-location parameter", eta);
40 check_positive_finite(function, "Precision parameter", phi);
41
42 double exp_eta_div_phi = std::exp(eta)/phi;
43
44 // gamma_rng params must be positive and finite
45 check_positive_finite(function,
46 "Exponential of the log-location parameter divided by "
47 "the precision parameter", exp_eta_div_phi);
48
49 double rng_from_gamma =
50 variate_generator<RNG&, gamma_distribution<> >
51 (rng, gamma_distribution<>(phi, exp_eta_div_phi))();
52
53 // same as the constraints for poisson_rng
54 check_less(function,
55 "Random number that came from gamma distribution",
56 rng_from_gamma, POISSON_MAX_RATE);
57 check_not_nan(function,
58 "Random number that came from gamma distribution",
59 rng_from_gamma);
60 check_nonnegative(function,
61 "Random number that came from gamma distribution",
62 rng_from_gamma);
63
64 return variate_generator<RNG&, poisson_distribution<> >
65 (rng, poisson_distribution<>(rng_from_gamma))();
66 }
67 }
68 }
69 #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:63
check_positive_finite.hpp
digamma.hpp
gamma_rng.hpp
binomial_coefficient_log.hpp
include_summand.hpp
multiply_log.hpp
check_nonnegative.hpp
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
OperandsAndPartials.hpp
stan::math::POISSON_MAX_RATE
const double POISSON_MAX_RATE
Largest rate parameter allowed in Poisson RNG.
Definition: constants.hpp:72
grad_reg_inc_beta.hpp
stan::math::check_finite
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
Definition: check_finite.hpp:62
constants.hpp
stan::math::neg_binomial_2_log_rng
int neg_binomial_2_log_rng(const double eta, const double phi, RNG &rng)
Definition: neg_binomial_2_log_rng.hpp:29
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:66
value_of.hpp
check_less.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–2015, Stan Development Team.