exp_mod_normal_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_EXP_MOD_NORMAL_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_EXP_MOD_NORMAL_RNG_HPP
3 
11 #include <boost/random/normal_distribution.hpp>
12 #include <boost/random/variate_generator.hpp>
13 
14 namespace stan {
15 namespace math {
16 
17 /**
18  * Return an exponentially modified normal random variate for the
19  * given location, scale, and inverse scale using the specified random
20  * number generator.
21  *
22  * mu, sigma, and lambda can each be a scalar or a one-dimensional container.
23  * Any non-scalar inputs must be the same size.
24  *
25  * @tparam T_loc Type of location parameter
26  * @tparam T_scale Type of scale parameter
27  * @tparam T_inv_scale Type of inverse scale parameter
28  * @tparam RNG type of random number generator
29  * @param mu (Sequence of) location parameter(s)
30  * @param sigma (Sequence of) scale parameter(s)
31  * @param lambda (Sequence of) inverse scale parameter(s)
32  * @param rng random number generator
33  * @return (Sequence of) Exponentially modified normal random variate(s)
34  * @throw std::domain_error if mu is infinite, sigma is nonpositive,
35  * or lambda is nonpositive
36  * @throw std::invalid_argument if non-scalar arguments are of different
37  * sizes
38  */
39 template <typename T_loc, typename T_scale, typename T_inv_scale, class RNG>
41 exp_mod_normal_rng(const T_loc& mu, const T_scale& sigma,
42  const T_inv_scale& lambda, RNG& rng) {
43  static const char* function = "exp_mod_normal_rng";
44 
45  check_finite(function, "Location parameter", mu);
46  check_positive_finite(function, "Scale parameter", sigma);
47  check_positive_finite(function, "Inv_scale parameter", lambda);
48  check_consistent_sizes(function, "Location parameter", mu, "Scale Parameter",
49  sigma, "Inv_scale Parameter", lambda);
50 
51  scalar_seq_view<T_loc> mu_vec(mu);
52  scalar_seq_view<T_scale> sigma_vec(sigma);
53  scalar_seq_view<T_inv_scale> lambda_vec(lambda);
54  size_t N = max_size(mu, sigma, lambda);
56 
57  for (size_t n = 0; n < N; ++n)
58  output[n] = normal_rng(mu_vec[n], sigma_vec[n], rng)
59  + exponential_rng(lambda_vec[n], rng);
60 
61  return output.data();
62 }
63 
64 } // namespace math
65 } // namespace stan
66 #endif
ofstream output
void check_finite(const char *function, const char *name, const T_y &y)
VectorBuilder< true, double, T_loc, T_scale, T_inv_scale >::type exp_mod_normal_rng(const T_loc &mu, const T_scale &sigma, const T_inv_scale &lambda, RNG &rng)
VectorBuilder< true, double, T_loc, T_scale >::type normal_rng(const T_loc &mu, const T_scale &sigma, RNG &rng)
Definition: normal_rng.hpp:35
void check_positive_finite(const char *function, const char *name, const T_y &y)
double sigma(TH1F *hist, double percentile)
size_t max_size(const T1 &x1, const T2 &x2)
Definition: max_size.hpp:9
void check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
VectorBuilder< true, double, T_inv >::type exponential_rng(const T_inv &beta, RNG &rng)