Automatic Differentiation
 
Loading...
Searching...
No Matches
beta_proportion_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_BETA_PROPORTION_RNG_HPP
2#define STAN_MATH_PRIM_PROB_BETA_PROPORTION_RNG_HPP
3
9#include <boost/random/variate_generator.hpp>
10
11namespace stan {
12namespace math {
13
34template <typename T_loc, typename T_prec, class RNG>
36beta_proportion_rng(const T_loc &mu, const T_prec &kappa, RNG &rng) {
37 using T_mu_ref = ref_type_t<T_loc>;
38 using T_kappa_ref = ref_type_t<T_prec>;
39 static constexpr const char *function = "beta_proportion_rng";
40 check_consistent_sizes(function, "Location parameter", mu,
41 "Precision parameter", kappa);
42 T_mu_ref mu_ref = mu;
43 T_kappa_ref kappa_ref = kappa;
44 check_positive(function, "Location parameter", mu_ref);
45 check_less(function, "Location parameter", mu_ref, 1.0);
46 check_positive_finite(function, "Precision parameter", kappa_ref);
47
48 scalar_seq_view<T_mu_ref> mu_vec(mu_ref);
49 scalar_seq_view<T_kappa_ref> kappa_vec(kappa_ref);
50 size_t N = max_size(mu, kappa);
52
53 for (size_t n = 0; n < N; ++n) {
54 double alpha = mu_vec[n] * kappa_vec[n];
55 double beta = kappa_vec[n] - alpha;
56 output[n] = beta_rng(alpha, beta, rng);
57 }
58
59 return output.data();
60}
61
62} // namespace math
63} // namespace stan
64#endif
typename helper::type type
VectorBuilder allocates type T1 values to be used as intermediate values.
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:36
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...
size_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
Definition max_size.hpp:19
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
void check_less(const char *function, const char *name, const T_y &y, const T_high &high, Idxs... idxs)
Throw an exception if y is not strictly less than high.
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.
typename ref_type_if< true, T >::type ref_type_t
Definition ref_type.hpp:55
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9