Automatic Differentiation
 
Loading...
Searching...
No Matches
poisson_log_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_POISSON_LOG_RNG_HPP
2#define STAN_MATH_PRIM_PROB_POISSON_LOG_RNG_HPP
3
10#include <boost/random/poisson_distribution.hpp>
11#include <boost/random/variate_generator.hpp>
12#include <cmath>
13
14namespace stan {
15namespace math {
16
30template <typename T_rate, class RNG>
32 const T_rate& alpha, RNG& rng) {
33 using boost::variate_generator;
34 using boost::random::poisson_distribution;
35 static constexpr const char* function = "poisson_log_rng";
36 static constexpr double POISSON_MAX_LOG_RATE = 30 * LOG_TWO;
37 const auto& alpha_ref = to_ref(alpha);
38 check_finite(function, "Log rate parameter", alpha_ref);
39 check_less(function, "Log rate parameter", alpha_ref, POISSON_MAX_LOG_RATE);
40
41 scalar_seq_view<T_rate> alpha_vec(alpha_ref);
42 size_t N = stan::math::size(alpha);
44
45 for (size_t n = 0; n < N; ++n) {
46 variate_generator<RNG&, poisson_distribution<> > poisson_rng(
47 rng, poisson_distribution<>(std::exp(alpha_vec[n])));
48 output[n] = poisson_rng();
49 }
50
51 return output.data();
52}
53
54} // namespace math
55} // namespace stan
56#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...
VectorBuilder< true, int, T_rate >::type poisson_log_rng(const T_rate &alpha, RNG &rng)
Return a Poisson random variate with specified log rate parameter using the given random number gener...
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
static constexpr double LOG_TWO
The natural logarithm of 2, .
Definition constants.hpp:80
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
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 ...