Stan Math Library  2.11.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 
26  namespace math {
27 
28  template <class RNG>
29  inline double
30  gamma_rng(const double alpha,
31  const double beta,
32  RNG& rng) {
33  using boost::variate_generator;
34  using boost::gamma_distribution;
35 
36  static const char* function("stan::math::gamma_rng");
37 
39 
40  check_positive_finite(function, "Shape parameter", alpha);
41  check_positive_finite(function, "Inverse scale parameter", beta);
42 
43  /*
44  the boost gamma distribution is defined by
45  shape and scale, whereas the stan one is defined
46  by shape and rate
47  */
48  variate_generator<RNG&, gamma_distribution<> >
49  gamma_rng(rng, gamma_distribution<>(alpha, 1.0 / beta));
50  return gamma_rng();
51  }
52 
53  }
54 }
55 
56 #endif
double gamma_rng(const double alpha, const double beta, RNG &rng)
Definition: gamma_rng.hpp:30
bool check_positive_finite(const char *function, const char *name, const T_y &y)
Return true if y is positive and finite.

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