1#ifndef STAN_MATH_PRIM_PROB_DIRICHLET_RNG_HPP
2#define STAN_MATH_PRIM_PROB_DIRICHLET_RNG_HPP
8#include <boost/math/special_functions/gamma.hpp>
9#include <boost/random/gamma_distribution.hpp>
10#include <boost/random/uniform_real_distribution.hpp>
11#include <boost/random/variate_generator.hpp>
40 const Eigen::Matrix<double, Eigen::Dynamic, 1>& alpha, RNG& rng) {
41 using boost::gamma_distribution;
42 using boost::variate_generator;
43 using boost::random::uniform_real_distribution;
44 using Eigen::VectorXd;
49 if (alpha.minCoeff() < 1) {
50 variate_generator<RNG&, uniform_real_distribution<> >
uniform_rng(
51 rng, uniform_real_distribution<>(0.0, 1.0));
52 VectorXd log_y(alpha.size());
53 for (
int i = 0; i < alpha.size(); ++i) {
54 variate_generator<RNG&, gamma_distribution<> >
gamma_rng(
55 rng, gamma_distribution<>(alpha(i) + 1, 1));
60 VectorXd theta(alpha.size());
61 for (
int i = 0; i < alpha.size(); ++i) {
62 theta(i) =
exp(log_y(i) - log_sum_y);
68 Eigen::VectorXd y(alpha.rows());
69 for (
int i = 0; i < alpha.rows(); i++) {
70 variate_generator<RNG&, gamma_distribution<> >
gamma_rng(
71 rng, gamma_distribution<>(alpha(i, 0), 1
e-7));
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...
VectorBuilder< true, double, T_alpha, T_beta >::type uniform_rng(const T_alpha &alpha, const T_beta &beta, RNG &rng)
Return a uniform random variate for the given upper and lower bounds using the specified random numbe...
VectorBuilder< true, double, T_shape, T_inv >::type gamma_rng(const T_shape &alpha, const T_inv &beta, RNG &rng)
Return a gamma random variate for the given shape and inverse scale parameters using the specified ra...
static constexpr double e()
Return the base of the natural logarithm.
fvar< T > log(const fvar< T > &x)
fvar< T > log_sum_exp(const fvar< T > &x1, const fvar< T > &x2)
fvar< T > exp(const fvar< T > &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...