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
7
8namespace stan {
9namespace math {
10
31template <typename T_N, typename T_shape1, typename T_shape2, class RNG>
33beta_binomial_rng(const T_N &N, const T_shape1 &alpha, const T_shape2 &beta,
34 RNG &rng) {
35 using T_N_ref = ref_type_t<T_N>;
36 using T_alpha_ref = ref_type_t<T_shape1>;
37 using T_beta_ref = ref_type_t<T_shape2>;
38 static constexpr const char *function = "beta_binomial_rng";
39 check_consistent_sizes(function, "First prior sample size parameter", alpha,
40 "Second prior sample size parameter", beta);
41
42 T_N_ref N_ref = N;
43 T_alpha_ref alpha_ref = alpha;
44 T_beta_ref beta_ref = beta;
45 check_nonnegative(function, "Population size parameter", N_ref);
46 check_positive_finite(function, "First prior sample size parameter",
47 alpha_ref);
48 check_positive_finite(function, "Second prior sample size parameter",
49 beta_ref);
50
51 auto p = beta_rng(alpha_ref, beta_ref, rng);
52 return binomial_rng(N_ref, p, rng);
53}
54
55} // namespace math
56} // namespace stan
57#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:36
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
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:55
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...