Loading [MathJax]/extensions/TeX/AMSsymbols.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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>
25inline int poisson_binomial_rng(const T_theta& theta, RNG& rng) {
26 static constexpr const char* function = "poisson_binomial_rng";
27 ref_type_t<T_theta> theta_ref = theta;
28 check_finite(function, "Probability parameters", theta_ref);
29 check_bounded(function, "Probability parameters", theta_ref, 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_ref[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.
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
typename ref_type_if< true, T >::type ref_type_t
Definition ref_type.hpp:55
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...