Stan Math Library  2.11.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 
19  namespace math {
20 
21  template <class RNG>
22  inline double
23  double_exponential_rng(const double mu,
24  const double sigma,
25  RNG& rng) {
26  static const char* function("stan::math::double_exponential_rng");
27 
28  using boost::variate_generator;
29  using boost::random::uniform_01;
30  using std::log;
31  using std::abs;
34  using stan::math::log1m;
35 
36  check_finite(function, "Location parameter", mu);
37  check_positive_finite(function, "Scale parameter", sigma);
38 
39  variate_generator<RNG&, uniform_01<> >
40  rng_unit_01(rng, uniform_01<>());
41  double a = 0;
42  double laplaceRN = rng_unit_01();
43  if (0.5 - laplaceRN > 0)
44  a = 1.0;
45  else if (0.5 - laplaceRN < 0)
46  a = -1.0;
47  return mu - sigma * a * log1m(2 * abs(0.5 - laplaceRN));
48  }
49  }
50 }
51 #endif
fvar< T > abs(const fvar< T > &x)
Definition: abs.hpp:15
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
double double_exponential_rng(const double mu, const double sigma, RNG &rng)
bool check_positive_finite(const char *function, const char *name, const T_y &y)
Return true if y is positive and finite.
fvar< T > log1m(const fvar< T > &x)
Definition: log1m.hpp:16

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