Stan Math Library  2.20.0
reverse mode automatic differentiation
beta_proportion_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_PROPORTION_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_BETA_PROPORTION_RNG_HPP
3 
5 #include <boost/random/variate_generator.hpp>
9 
10 namespace stan {
11 namespace math {
12 
33 template <typename T_loc, typename T_prec, class RNG>
35 beta_proportion_rng(const T_loc &mu, const T_prec &kappa, RNG &rng) {
36  static const char *function = "beta_proportion_rng";
37 
38  check_positive(function, "Location parameter", mu);
39  check_less_or_equal(function, "Location parameter", mu, 1.0);
40  check_positive_finite(function, "Precision parameter", kappa);
41  check_consistent_sizes(function, "Location parameter", mu,
42  "Precision parameter", kappa);
43 
44  scalar_seq_view<T_loc> mu_vec(mu);
45  scalar_seq_view<T_prec> kappa_vec(kappa);
46  size_t N = max_size(mu, kappa);
48 
49  for (size_t n = 0; n < N; ++n) {
50  double alpha = mu_vec[n] * kappa_vec[n];
51  double beta = kappa_vec[n] - alpha;
52  output[n] = beta_rng(alpha, beta, rng);
53  }
54 
55  return output.data();
56 }
57 
58 } // namespace math
59 } // namespace stan
60 #endif
void check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high)
Check if y is less or equal to high.
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
VectorBuilder< true, double, T_shape1, T_shape2 >::type beta_rng(const T_shape1 &alpha, const T_shape2 &beta, RNG &rng)
Return a Beta random variate with the supplied success and failure parameters using the given random ...
Definition: beta_rng.hpp:34
fvar< T > beta(const fvar< T > &x1, const fvar< T > &x2)
Return fvar with the beta function applied to the specified arguments and its gradient.
Definition: beta.hpp:51
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)
Definition: max_size.hpp:9
VectorBuilder allocates type T1 values to be used as intermediate values.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
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.
VectorBuilder< true, double, T_loc, T_prec >::type beta_proportion_rng(const T_loc &mu, const T_prec &kappa, RNG &rng)
Return a Beta random variate specified probability, location, and precision parameters: beta_proporti...

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