| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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>
6 #include <stan/math/prim/scal/meta/OperandsAndPartials.hpp>
7 #include <stan/math/prim/scal/err/check_consistent_sizes.hpp>
8 #include <stan/math/prim/scal/err/check_finite.hpp>
9 #include <stan/math/prim/scal/err/check_not_nan.hpp>
10 #include <stan/math/prim/scal/err/check_positive_finite.hpp>
11 #include <stan/math/prim/scal/fun/value_of.hpp>
12 #include <stan/math/prim/scal/fun/log1m.hpp>
13
14 #include <stan/math/prim/scal/fun/constants.hpp>
15 #include <stan/math/prim/scal/meta/include_summand.hpp>
16 #include <stan/math/prim/scal/fun/sign.hpp>
17
18 namespace stan {
19
20 namespace math {
21
22 template <class RNG>
23 inline double
24 double_exponential_rng(const double mu,
25 const double sigma,
26 RNG& rng) {
27 static const char* function("stan::math::double_exponential_rng");
28
29 using boost::variate_generator;
30 using boost::random::uniform_01;
31 using std::log;
32 using std::abs;
33 using stan::math::check_finite;
34 using stan::math::check_positive_finite;
35 using stan::math::log1m;
36
37 check_finite(function, "Location parameter", mu);
38 check_positive_finite(function, "Scale parameter", sigma);
39
40 variate_generator<RNG&, uniform_01<> >
41 rng_unit_01(rng, uniform_01<>());
42 double a = 0;
43 double laplaceRN = rng_unit_01();
44 if (0.5 - laplaceRN > 0)
45 a = 1.0;
46 else if (0.5 - laplaceRN < 0)
47 a = -1.0;
48 return mu - sigma * a * log1m(2 * abs(0.5 - laplaceRN));
49 }
50 }
51 }
52 #endif
check_not_nan.hpp
stan::math::abs
fvar< T > abs(const fvar< T > &x)
Definition: abs.hpp:15
check_positive_finite.hpp
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
include_summand.hpp
OperandsAndPartials.hpp
log1m.hpp
stan::math::check_finite
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
Definition: check_finite.hpp:62
constants.hpp
sign.hpp
check_finite.hpp
value_of.hpp
stan::math::double_exponential_rng
double double_exponential_rng(const double mu, const double sigma, RNG &rng)
Definition: double_exponential_rng.hpp:24
check_consistent_sizes.hpp
stan::math::check_positive_finite
bool check_positive_finite(const char *function, const char *name, const T_y &y)
Return true if y is positive and finite.
Definition: check_positive_finite.hpp:28
stan::math::log1m
fvar< T > log1m(const fvar< T > &x)
Definition: log1m.hpp:16

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