Stan Math Library  2.20.0
reverse mode automatic differentiation
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 
6 #include <boost/random/exponential_distribution.hpp>
7 #include <boost/random/variate_generator.hpp>
8 
9 namespace stan {
10 namespace math {
11 
25 template <typename T_inv, class RNG>
27  const T_inv& beta, RNG& rng) {
28  using boost::exponential_distribution;
29  using boost::variate_generator;
30 
31  static const char* function = "exponential_rng";
32 
33  check_positive_finite(function, "Inverse scale parameter", beta);
34 
35  scalar_seq_view<T_inv> beta_vec(beta);
36  size_t N = length(beta);
38 
39  for (size_t n = 0; n < N; ++n) {
40  variate_generator<RNG&, exponential_distribution<> > exp_rng(
41  rng, exponential_distribution<>(beta_vec[n]));
42  output[n] = exp_rng();
43  }
44 
45  return output.data();
46 }
47 
48 } // namespace math
49 } // namespace stan
50 #endif
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
size_t length(const std::vector< T > &x)
Returns the length of the provided std::vector.
Definition: length.hpp:16
fvar< T > beta(const fvar< T > &x1, const fvar< T > &x2)
Return fvar with the beta function applied to the specified arguments and its gradient.
Definition: beta.hpp:51
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
VectorBuilder allocates type T1 values to be used as intermediate values.
VectorBuilder< true, double, T_inv >::type exponential_rng(const T_inv &beta, RNG &rng)
Return a exponential random variate with inverse scale beta using the specified random number generat...

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