| 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
beta_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_BETA_RNG_HPP
3
4 #include <boost/math/special_functions/gamma.hpp>
5 #include <boost/random/gamma_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_less_or_equal.hpp>
10 #include <stan/math/prim/scal/err/check_nonnegative.hpp>
11 #include <stan/math/prim/scal/err/check_not_nan.hpp>
12 #include <stan/math/prim/scal/err/check_positive_finite.hpp>
13 #include <stan/math/prim/scal/fun/log1m.hpp>
14 #include <stan/math/prim/scal/fun/multiply_log.hpp>
15 #include <stan/math/prim/scal/fun/value_of.hpp>
16 #include <stan/math/prim/scal/fun/digamma.hpp>
17 #include <stan/math/prim/scal/fun/lgamma.hpp>
18 #include <stan/math/prim/scal/fun/lbeta.hpp>
19 #include <stan/math/prim/scal/fun/constants.hpp>
20 #include <stan/math/prim/scal/meta/include_summand.hpp>
21 #include <stan/math/prim/scal/fun/grad_reg_inc_beta.hpp>
22 #include <stan/math/prim/scal/fun/inc_beta.hpp>
23
24 namespace stan {
25
26 namespace math {
27
28 template <class RNG>
29 inline double
30 beta_rng(const double alpha,
31 const double beta,
32 RNG& rng) {
33 using boost::variate_generator;
34 using boost::random::gamma_distribution;
35 // Error checks
36 static const char* function("stan::math::beta_rng");
37
38 using stan::math::check_positive_finite;
39
40 check_positive_finite(function, "First shape parameter", alpha);
41 check_positive_finite(function, "Second shape parameter", beta);
42
43 variate_generator<RNG&, gamma_distribution<> >
44 rng_gamma_alpha(rng, gamma_distribution<>(alpha, 1.0));
45 variate_generator<RNG&, gamma_distribution<> >
46 rng_gamma_beta(rng, gamma_distribution<>(beta, 1.0));
47 double a = rng_gamma_alpha();
48 double b = rng_gamma_beta();
49 return a / (a + b);
50 }
51
52 }
53 }
54 #endif
check_not_nan.hpp
lgamma.hpp
stan::math::beta_rng
double beta_rng(const double alpha, const double beta, RNG &rng)
Definition: beta_rng.hpp:30
check_positive_finite.hpp
digamma.hpp
include_summand.hpp
multiply_log.hpp
check_nonnegative.hpp
check_less_or_equal.hpp
OperandsAndPartials.hpp
log1m.hpp
grad_reg_inc_beta.hpp
constants.hpp
lbeta.hpp
inc_beta.hpp
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–2015, Stan Development Team.