exponential_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_EXPONENTIAL_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_EXPONENTIAL_RNG_HPP
3 
8 #include <boost/random/exponential_distribution.hpp>
9 #include <boost/random/variate_generator.hpp>
10 
11 namespace stan {
12 namespace math {
13 
14 /**
15  * Return a exponential random variate with inverse scale beta
16  * using the specified random number generator.
17  *
18  * beta can be a scalar or a one-dimensional container.
19  *
20  * @tparam T_inv Type of inverse scale parameter
21  * @tparam RNG class of random number generator
22  * @param beta (Sequence of) positive inverse scale parameter(s)
23  * @param rng random number generator
24  * @return (Sequence of) exponential random variate(s)
25  * @throw std::domain_error if beta is nonpositive
26  */
27 template <typename T_inv, class RNG>
29  const T_inv& beta, RNG& rng) {
30  using boost::exponential_distribution;
31  using boost::variate_generator;
32 
33  static const char* function = "exponential_rng";
34 
35  check_positive_finite(function, "Inverse scale parameter", beta);
36 
37  scalar_seq_view<T_inv> beta_vec(beta);
38  size_t N = length(beta);
40 
41  for (size_t n = 0; n < N; ++n) {
42  variate_generator<RNG&, exponential_distribution<> > exp_rng(
43  rng, exponential_distribution<>(beta_vec[n]));
44  output[n] = exp_rng();
45  }
46 
47  return output.data();
48 }
49 
50 } // namespace math
51 } // namespace stan
52 #endif
ofstream output
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
Double_t beta
void check_positive_finite(const char *function, const char *name, const T_y &y)
VectorBuilder< true, double, T_inv >::type exponential_rng(const T_inv &beta, RNG &rng)