1 #ifndef STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__HYPERGEOMETRIC_HPP
2 #define STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__HYPERGEOMETRIC_HPP
4 #include <boost/math/distributions.hpp>
21 template <
bool propto,
22 typename T_n,
typename T_N,
23 typename T_a,
typename T_b>
26 const T_a& a,
const T_b& b) {
27 static const char*
function =
"stan::prob::hypergeometric_log(%1%)";
50 check_bounded(
function, n, 0, a,
"Successes variable", &logp);
52 for (
size_t i = 0; i <
size; i++) {
54 "Draws parameter minus successes variable", &logp);
56 "Draws parameter", &logp);
60 "Successes variable",
"Draws parameter",
61 "Successes in population parameter",
62 "Failures in population parameter",
70 for (
size_t i = 0; i <
size; i++)
77 template <
typename T_n,
87 return hypergeometric_log<false>(n,N,a,b);
96 using boost::variate_generator;
98 static const char*
function =
"stan::prob::hypergeometric_rng(%1%)";
103 check_bounded(
function, N, 0, a+b,
"Draws parameter", (
int*)0);
105 check_positive(
function,a,
"Successes in population parameter", (
int*)0);
106 check_positive(
function,b,
"Failures in population parameter", (
int*)0);
108 boost::math::hypergeometric_distribution<>
dist (b, N, a + b);
109 std::vector<double> index(a);
110 for(
int i = 0; i < a; i++)
111 index[i] = cdf(dist, i + 1);
118 mid = (min +
max) / 2;
bool check_bounded(const char *function, const T_y &y, const T_low &low, const T_high &high, const char *name, T_result *result)
bool check_greater(const char *function, const T_y &y, const T_low &low, const char *name, T_result *result)
double max(const double a, const double b)
boost::math::tools::promote_args< T_N, T_n >::type binomial_coefficient_log(const T_N N, const T_n n)
Return the log of the binomial coefficient for the specified arguments.
bool check_finite(const char *function, const T_y &y, const char *name, T_result *result)
Checks if the variable y is finite.
double hypergeometric_log(const T_n &n, const T_N &N, const T_a &a, const T_b &b)
int hypergeometric_rng(const int N, const int a, const int b, RNG &rng)
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
double uniform_rng(const double alpha, const double beta, RNG &rng)
bool check_consistent_sizes(const char *function, const T1 &x1, const T2 &x2, const char *name1, const char *name2, T_result *result)
size_t max_size(const T1 &x1, const T2 &x2)
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result)
int size(const std::vector< T > &x)
double min(const double a, const double b)
VectorView is a template metaprogram that takes its argument and allows it to be used like a vector...
double dist(const std::vector< double > &x, const std::vector< double > &y)