Stan Math Library  2.15.0
reverse mode automatic differentiation
double_exponential_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_DOUBLE_EXPONENTIAL_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_DOUBLE_EXPONENTIAL_RNG_HPP
3 
4 #include <boost/random/uniform_01.hpp>
5 #include <boost/random/variate_generator.hpp>
12 
16 
17 namespace stan {
18  namespace math {
19 
31  template <class RNG>
32  inline double
34  double sigma,
35  RNG& rng) {
36  static const char* function("double_exponential_rng");
37 
38  using boost::variate_generator;
39  using boost::random::uniform_01;
40  using std::log;
41  using std::abs;
42 
43  check_finite(function, "Location parameter", mu);
44  check_positive_finite(function, "Scale parameter", sigma);
45 
46  variate_generator<RNG&, uniform_01<> >
47  rng_unit_01(rng, uniform_01<>());
48  double a = 0;
49  double laplaceRN = rng_unit_01();
50  if (0.5 - laplaceRN > 0)
51  a = 1.0;
52  else if (0.5 - laplaceRN < 0)
53  a = -1.0;
54  return mu - sigma * a * log1m(2 * abs(0.5 - laplaceRN));
55  }
56  }
57 }
58 #endif
fvar< T > abs(const fvar< T > &x)
Definition: abs.hpp:15
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
double double_exponential_rng(double mu, double sigma, RNG &rng)
Return a pseudorandom double exponential variate with the given location and scale using the specifie...
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
fvar< T > log1m(const fvar< T > &x)
Definition: log1m.hpp:13

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