Automatic Differentiation
 
Loading...
Searching...
No Matches
poisson_binomial_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_POISSON_BINOMIAL_RNG_HPP
2#define STAN_MATH_PRIM_PROB_POISSON_BINOMIAL_RNG_HPP
3
7#include <boost/random/bernoulli_distribution.hpp>
8#include <boost/random/variate_generator.hpp>
9
10namespace stan {
11namespace math {
12
24template <typename T_theta, typename RNG,
25 require_eigen_vt<std::is_arithmetic, T_theta>* = nullptr>
26inline int poisson_binomial_rng(const T_theta& theta, RNG& rng) {
27 static constexpr const char* function = "poisson_binomial_rng";
28 check_finite(function, "Probability parameters", theta);
29 check_bounded(function, "Probability parameters", value_of(theta), 0.0, 1.0);
30
31 int y = 0;
32 for (size_t i = 0; i < theta.size(); ++i) {
33 boost::variate_generator<RNG&, boost::bernoulli_distribution<> >
34 bernoulli_rng(rng, boost::bernoulli_distribution<>(theta(i)));
35 y += bernoulli_rng();
36 }
37
38 return y;
39}
40
41} // namespace math
42} // namespace stan
43#endif
VectorBuilder< true, int, T_theta >::type bernoulli_rng(const T_theta &theta, RNG &rng)
Return a Bernoulli random variate with specified chance of success parameter using the specified rand...
int poisson_binomial_rng(const T_theta &theta, RNG &rng)
Return a pseudorandom Poisson binomial random variable for the given vector of success parameters usi...
void check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Check if the value is between the low and high values, inclusively.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9