Stan Math Library  2.20.0
reverse mode automatic differentiation
poisson_log_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_POISSON_LOG_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_POISSON_LOG_RNG_HPP
3 
7 #include <boost/random/poisson_distribution.hpp>
8 #include <boost/random/variate_generator.hpp>
9 
10 namespace stan {
11 namespace math {
12 
26 template <typename T_rate, class RNG>
28  const T_rate& alpha, RNG& rng) {
29  using boost::random::poisson_distribution;
30  using boost::variate_generator;
31 
32  static const char* function = "poisson_log_rng";
33  static const double POISSON_MAX_LOG_RATE = 30 * std::log(2);
34 
35  check_finite(function, "Log rate parameter", alpha);
36  check_less(function, "Log rate parameter", alpha, POISSON_MAX_LOG_RATE);
37 
38  scalar_seq_view<T_rate> alpha_vec(alpha);
39  size_t N = length(alpha);
41 
42  for (size_t n = 0; n < N; ++n) {
43  variate_generator<RNG&, poisson_distribution<> > poisson_rng(
44  rng, poisson_distribution<>(std::exp(alpha_vec[n])));
45  output[n] = poisson_rng();
46  }
47 
48  return output.data();
49 }
50 
51 } // namespace math
52 } // namespace stan
53 #endif
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:12
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...
Definition: poisson_rng.hpp:29
size_t length(const std::vector< T > &x)
Returns the length of the provided std::vector.
Definition: length.hpp:16
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...
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:11
VectorBuilder allocates type T1 values to be used as intermediate values.
void check_less(const char *function, const char *name, const T_y &y, const T_high &high)
Check if y is strictly less than high.
Definition: check_less.hpp:63

     [ Stan Home Page ] © 2011–2018, Stan Development Team.