1 #ifndef STAN_MATH_PRIM_SCAL_PROB_VON_MISES_RNG_HPP 2 #define STAN_MATH_PRIM_SCAL_PROB_VON_MISES_RNG_HPP 11 #include <boost/random/uniform_real_distribution.hpp> 12 #include <boost/random/variate_generator.hpp> 45 template <
typename T_loc,
typename T_conc,
class RNG>
47 const T_loc& mu,
const T_conc& kappa, RNG& rng) {
48 using boost::random::uniform_real_distribution;
49 using boost::variate_generator;
50 static const char*
function =
"von_mises_rng";
55 "Concentration Parameter", kappa);
62 variate_generator<RNG&, uniform_real_distribution<> >
uniform_rng(
63 rng, uniform_real_distribution<>(0.0, 1.0));
65 for (
size_t n = 0; n < N; ++n) {
66 double r = 1 +
std::pow((1 + 4 * kappa_vec[n] * kappa_vec[n]), 0.5);
67 double rho = 0.5 * (r -
std::pow(2 * r, 0.5)) / kappa_vec[n];
68 double s = 0.5 * (1 + rho * rho) / rho;
74 W = (1 + s * Z) / (s + Z);
75 double Y = kappa_vec[n] * (s - W);
77 done = Y * (2 - Y) - U2 > 0;
80 done =
std::log(Y / U2) + 1 - Y >= 0;
84 double sign = ((U3 >= 0) - (U3 <= 0));
fvar< T > cos(const fvar< T > &x)
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
VectorBuilder< true, double, T_loc, T_conc >::type von_mises_rng(const T_loc &mu, const T_conc &kappa, RNG &rng)
Return a von Mises random variate for the given location and concentration using the specified random...
fvar< T > log(const fvar< T > &x)
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
fvar< T > fmod(const fvar< T > &x1, const fvar< T > &x2)
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...
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
size_t max_size(const T1 &x1, const T2 &x2)
fvar< T > acos(const fvar< T > &x)
VectorBuilder allocates type T1 values to be used as intermediate values.
double pi()
Return the value of pi.
fvar< T > pow(const fvar< T > &x1, const fvar< T > &x2)
void check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
Check if the dimension of x1 is consistent with x2.