1 #ifndef STAN_MATH_PRIM_MAT_PROB_DIRICHLET_RNG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_DIRICHLET_RNG_HPP
4 #include <boost/math/special_functions/gamma.hpp>
5 #include <boost/random/gamma_distribution.hpp>
6 #include <boost/random/uniform_real_distribution.hpp>
7 #include <boost/random/variate_generator.hpp>
45 inline Eigen::VectorXd
48 using boost::variate_generator;
49 using boost::gamma_distribution;
50 using boost::random::uniform_real_distribution;
51 using Eigen::VectorXd;
56 if (alpha.minCoeff() < 1) {
57 variate_generator<RNG&, uniform_real_distribution<> >
58 uniform_rng(rng, uniform_real_distribution<>(0.0, 1.0));
59 VectorXd log_y(alpha.size());
60 for (
int i = 0; i < alpha.size(); ++i) {
61 variate_generator<RNG&, gamma_distribution<> >
62 gamma_rng(rng, gamma_distribution<>(alpha(i) + 1, 1));
67 VectorXd theta(alpha.size());
68 for (
int i = 0; i < alpha.size(); ++i)
69 theta(i) =
exp(log_y(i) - log_sum_y);
74 Eigen::VectorXd y(alpha.rows());
75 for (
int i = 0; i < alpha.rows(); i++) {
76 variate_generator<RNG&, gamma_distribution<> >
77 gamma_rng(rng, gamma_distribution<>(alpha(i, 0), 1
e-7));
double gamma_rng(const double alpha, const double beta, RNG &rng)
fvar< T > log(const fvar< T > &x)
fvar< T > log_sum_exp(const std::vector< fvar< T > > &v)
Eigen::VectorXd dirichlet_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &alpha, RNG &rng)
Return a draw from a Dirichlet distribution with specified parameters and pseudo-random number genera...
fvar< T > exp(const fvar< T > &x)
double uniform_rng(const double alpha, const double beta, RNG &rng)
double e()
Return the base of the natural logarithm.