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
10#include <boost/random/variate_generator.hpp>
11
12namespace stan {
13namespace math {
14
35template <typename T_loc, typename T_prec, class RNG>
37beta_proportion_rng(const T_loc &mu, const T_prec &kappa, RNG &rng) {
38 using T_mu_ref = ref_type_t<T_loc>;
39 using T_kappa_ref = ref_type_t<T_prec>;
40 static constexpr const char *function = "beta_proportion_rng";
41 check_consistent_sizes(function, "Location parameter", mu,
42 "Precision parameter", kappa);
43
44 if (size_zero(mu, kappa)) {
45 return {};
46 }
47
48 T_mu_ref mu_ref = mu;
49 T_kappa_ref kappa_ref = kappa;
50 check_positive(function, "Location parameter", mu_ref);
51 check_less(function, "Location parameter", mu_ref, 1.0);
52 check_positive_finite(function, "Precision parameter", kappa_ref);
53
54 scalar_seq_view<T_mu_ref> mu_vec(mu_ref);
55 scalar_seq_view<T_kappa_ref> kappa_vec(kappa_ref);
56 size_t N = max_size(mu, kappa);
58
59 for (size_t n = 0; n < N; ++n) {
60 double alpha = mu_vec[n] * kappa_vec[n];
61 double beta = kappa_vec[n] - alpha;
62 output[n] = beta_rng(alpha, beta, rng);
63 }
64
65 return output.data();
66}
67
68} // namespace math
69} // namespace stan
70#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:37
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...
bool size_zero(const T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
Definition size_zero.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.
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
Definition max_size.hpp:20
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:56
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...