1#ifndef STAN_MATH_PRIM_PROB_CATEGORICAL_RNG_HPP
2#define STAN_MATH_PRIM_PROB_CATEGORICAL_RNG_HPP
7#include <boost/random/uniform_01.hpp>
8#include <boost/random/variate_generator.hpp>
15 const Eigen::Matrix<double, Eigen::Dynamic, 1>& theta, RNG& rng) {
16 using boost::uniform_01;
17 using boost::variate_generator;
18 static constexpr const char* function =
"categorical_rng";
21 variate_generator<RNG&, uniform_01<> > uniform01_rng(rng, uniform_01<>());
23 Eigen::VectorXd index(theta.rows());
28 double c = uniform01_rng();
30 while (c > index(b, 0)) {
int categorical_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &theta, RNG &rng)
auto cumulative_sum(T_vec &&v)
Return the cumulative sum of the specified vector.
void check_simplex(const char *function, const char *name, const T &theta)
Throw an exception if the specified vector is not a simplex.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...