Stan Math Library  2.20.0
reverse mode automatic differentiation
rayleigh_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_RAYLEIGH_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_RAYLEIGH_RNG_HPP
3 
6 #include <boost/random/uniform_real_distribution.hpp>
7 #include <boost/random/variate_generator.hpp>
8 
9 namespace stan {
10 namespace math {
11 
25 template <typename T_scale, class RNG>
27  const T_scale& sigma, RNG& rng) {
28  using boost::random::uniform_real_distribution;
29  using boost::variate_generator;
30 
31  static const char* function = "rayleigh_rng";
32 
33  check_positive_finite(function, "Scale parameter", sigma);
34 
35  scalar_seq_view<T_scale> sigma_vec(sigma);
36  size_t N = length(sigma);
38 
39  variate_generator<RNG&, uniform_real_distribution<> > uniform_rng(
40  rng, uniform_real_distribution<>(0.0, 1.0));
41  for (size_t n = 0; n < N; ++n) {
42  output[n] = sigma_vec[n] * std::sqrt(-2.0 * std::log(uniform_rng()));
43  }
44 
45  return output.data();
46 }
47 
48 } // namespace math
49 } // namespace stan
50 #endif
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:13
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...
size_t length(const std::vector< T > &x)
Returns the length of the provided std::vector.
Definition: length.hpp:16
VectorBuilder< true, double, T_alpha, T_beta >::type uniform_rng(const T_alpha &alpha, const T_beta &beta, RNG &rng)
Return a uniform random variate for the given upper and lower bounds using the specified random numbe...
Definition: uniform_rng.hpp:36
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
VectorBuilder< true, double, T_scale >::type rayleigh_rng(const T_scale &sigma, RNG &rng)
Return a Rayleigh random variate with scale parameter sigma using the specified random number generat...
VectorBuilder allocates type T1 values to be used as intermediate values.

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