Automatic Differentiation
 
Loading...
Searching...
No Matches
poisson_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_POISSON_RNG_HPP
2#define STAN_MATH_PRIM_PROB_POISSON_RNG_HPP
3
10#include <boost/random/poisson_distribution.hpp>
11#include <boost/random/variate_generator.hpp>
12
13namespace stan {
14namespace math {
15
29template <typename T_rate, class RNG>
31 const T_rate& lambda, RNG& rng) {
32 using boost::variate_generator;
33 using boost::random::poisson_distribution;
34 static constexpr const char* function = "poisson_rng";
35 const auto& lambda_ref = to_ref(lambda);
36 check_positive(function, "Rate parameter", lambda_ref);
37 check_less(function, "Rate parameter", lambda_ref, POISSON_MAX_RATE);
38
39 scalar_seq_view<T_rate> lambda_vec(lambda_ref);
40 size_t N = stan::math::size(lambda);
42
43 for (size_t n = 0; n < N; ++n) {
44 variate_generator<RNG&, poisson_distribution<> > poisson_rng(
45 rng, poisson_distribution<>(lambda_vec[n]));
46 output[n] = poisson_rng();
47 }
48
49 return output.data();
50}
51
52} // namespace math
53} // namespace stan
54#endif
typename helper::type type
VectorBuilder allocates type T1 values to be used as intermediate values.
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
VectorBuilder< true, int, T_rate >::type poisson_rng(const T_rate &lambda, RNG &rng)
Return a Poisson random variate with specified rate parameter using the given random number generator...
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
Definition size.hpp:19
const double POISSON_MAX_RATE
Largest rate parameter allowed in Poisson RNG.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
void check_less(const char *function, const char *name, const T_y &y, const T_high &high, Idxs... idxs)
Throw an exception if y is not strictly less than high.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...