Stan Math Library  2.14.0
reverse mode automatic differentiation
gamma_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_GAMMA_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_GAMMA_RNG_HPP
3 
4 #include <boost/random/gamma_distribution.hpp>
5 #include <boost/random/variate_generator.hpp>
23 
24 namespace stan {
25  namespace math {
26 
27  template <class RNG>
28  inline double
29  gamma_rng(double alpha,
30  double beta,
31  RNG& rng) {
32  using boost::variate_generator;
33  using boost::gamma_distribution;
34 
35  static const char* function("gamma_rng");
36  check_positive_finite(function, "Shape parameter", alpha);
37  check_positive_finite(function, "Inverse scale parameter", beta);
38 
39  /*
40  the boost gamma distribution is defined by
41  shape and scale, whereas the stan one is defined
42  by shape and rate
43  */
44  variate_generator<RNG&, gamma_distribution<> >
45  gamma_rng(rng, gamma_distribution<>(alpha, 1.0 / beta));
46  return gamma_rng();
47  }
48 
49  }
50 }
51 #endif
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
double gamma_rng(double alpha, double beta, RNG &rng)
Definition: gamma_rng.hpp:29

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