Automatic Differentiation
 
Loading...
Searching...
No Matches
rayleigh_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_RAYLEIGH_RNG_HPP
2#define STAN_MATH_PRIM_PROB_RAYLEIGH_RNG_HPP
3
9#include <boost/random/uniform_real_distribution.hpp>
10#include <boost/random/variate_generator.hpp>
11#include <cmath>
12
13namespace stan {
14namespace math {
15
29template <typename T_scale, class RNG>
31 const T_scale& sigma, RNG& rng) {
32 using boost::variate_generator;
33 using boost::random::uniform_real_distribution;
34 static constexpr const char* function = "rayleigh_rng";
35 const auto& sigma_ref = to_ref(sigma);
36 check_positive_finite(function, "Scale parameter", sigma_ref);
37
38 scalar_seq_view<T_scale> sigma_vec(sigma_ref);
39 size_t N = stan::math::size(sigma);
41
42 variate_generator<RNG&, uniform_real_distribution<> > uniform_rng(
43 rng, uniform_real_distribution<>(0.0, 1.0));
44 for (size_t n = 0; n < N; ++n) {
45 output[n] = sigma_vec[n] * std::sqrt(-2.0 * std::log(uniform_rng()));
46 }
47
48 return output.data();
49}
50
51} // namespace math
52} // namespace stan
53#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, 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< 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...
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
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...