1 #ifndef STAN__PROB__DISTRIBUTIONS__MULTIVARIATE__CONTINUOUS__DIRICHLET_HPP
2 #define STAN__PROB__DISTRIBUTIONS__MULTIVARIATE__CONTINUOUS__DIRICHLET_HPP
4 #include <boost/math/special_functions/gamma.hpp>
5 #include <boost/random/gamma_distribution.hpp>
6 #include <boost/random/variate_generator.hpp>
43 template <
bool propto,
44 typename T_prob,
typename T_prior_sample_size>
45 typename boost::math::tools::promote_args<T_prob,T_prior_sample_size>::type
47 const Eigen::Matrix<T_prior_sample_size,Eigen::Dynamic,1>& alpha) {
48 static const char*
function =
"stan::prob::dirichlet_log(%1%)";
50 using boost::math::tools::promote_args;
56 typename promote_args<T_prob,T_prior_sample_size>::type lp(0.0);
58 "probabilities",
"prior sample sizes",
65 for (
int k = 0; k < alpha.rows(); ++k)
69 for (
int k = 0; k < theta.rows(); ++k)
74 template <
typename T_prob,
typename T_prior_sample_size>
76 typename boost::math::tools::promote_args<T_prob,T_prior_sample_size>::type
78 const Eigen::Matrix<T_prior_sample_size,Eigen::Dynamic,1>& alpha) {
79 return dirichlet_log<false>(theta,alpha);
83 inline Eigen::VectorXd
86 using boost::variate_generator;
87 using boost::gamma_distribution;
90 Eigen::VectorXd y(alpha.rows());
91 for(
int i = 0; i < alpha.rows(); i++) {
92 variate_generator<RNG&, gamma_distribution<> >
93 gamma_rng(rng, gamma_distribution<>(alpha(i,0),1));
98 for(
int i = 0; i < alpha.rows(); i++)
boost::math::tools::promote_args< T_a, T_b >::type multiply_log(const T_a a, const T_b b)
Calculated the value of the first argument times log of the second argument while behaving properly w...
bool check_simplex(const char *function, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta, const char *name, T_result *result)
Return true if the specified vector is simplex.
fvar< T > sum(const Eigen::Matrix< fvar< T >, R, C > &m)
fvar< T > lgamma(const fvar< T > &x)
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
Eigen::VectorXd dirichlet_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &alpha, RNG &rng)
bool check_consistent_sizes(const char *function, const T1 &x1, const T2 &x2, const char *name1, const char *name2, T_result *result)
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result)
fvar< T > multiply_log(const fvar< T > &x1, const fvar< T > &x2)
double gamma_rng(const double alpha, const double beta, RNG &rng)
boost::math::tools::promote_args< T_prob, T_prior_sample_size >::type dirichlet_log(const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta, const Eigen::Matrix< T_prior_sample_size, Eigen::Dynamic, 1 > &alpha)
The log of the Dirichlet density for the given theta and a vector of prior sample sizes...