1 #ifndef STAN_MATH_PRIM_MAT_PROB_CATEGORICAL_RNG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_CATEGORICAL_RNG_HPP
4 #include <boost/random/uniform_01.hpp>
5 #include <boost/random/variate_generator.hpp>
22 using boost::variate_generator;
23 using boost::uniform_01;
26 static const char*
function(
"stan::math::categorical_rng");
30 variate_generator<RNG&, uniform_01<> >
31 uniform01_rng(rng, uniform_01<>());
33 Eigen::VectorXd index(theta.rows());
36 for (
int i = 0; i < theta.rows(); i++) {
37 for (
int j = i; j < theta.rows(); j++)
38 index(j) += theta(i, 0);
41 double c = uniform01_rng();
43 while (c > index(b, 0))
int categorical_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &theta, RNG &rng)
bool check_simplex(const char *function, const char *name, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta)
Return true if the specified vector is simplex.