Automatic Differentiation
 
Loading...
Searching...
No Matches
beta_binomial_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_BETA_BINOMIAL_RNG_HPP
2#define STAN_MATH_PRIM_PROB_BETA_BINOMIAL_RNG_HPP
3
8
9namespace stan {
10namespace math {
11
32template <typename T_N, typename T_shape1, typename T_shape2, class RNG>
34beta_binomial_rng(const T_N &N, const T_shape1 &alpha, const T_shape2 &beta,
35 RNG &rng) {
36 using T_N_ref = ref_type_t<T_N>;
37 using T_alpha_ref = ref_type_t<T_shape1>;
38 using T_beta_ref = ref_type_t<T_shape2>;
39 static constexpr const char *function = "beta_binomial_rng";
40 check_consistent_sizes(function, "First prior sample size parameter", alpha,
41 "Second prior sample size parameter", beta);
42
43 if (size_zero(N, alpha, beta)) {
44 return {};
45 }
46
47 T_N_ref N_ref = N;
48 T_alpha_ref alpha_ref = alpha;
49 T_beta_ref beta_ref = beta;
50 check_nonnegative(function, "Population size parameter", N_ref);
51 check_positive_finite(function, "First prior sample size parameter",
52 alpha_ref);
53 check_positive_finite(function, "Second prior sample size parameter",
54 beta_ref);
55
56 auto p = beta_rng(alpha_ref, beta_ref, rng);
57 return binomial_rng(N_ref, p, rng);
58}
59
60} // namespace math
61} // namespace stan
62#endif
typename helper::type type
VectorBuilder< true, int, T_N, T_shape1, T_shape2 >::type beta_binomial_rng(const T_N &N, const T_shape1 &alpha, const T_shape2 &beta, RNG &rng)
Return a beta-binomial random variate with the specified population size, success,...
VectorBuilder< true, int, T_N, T_theta >::type binomial_rng(const T_N &N, const T_theta &theta, RNG &rng)
Return a pseudorandom binomial random variable for the given population size and chance of success pa...
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
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
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.
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 ...