| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

hypergeometric_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_HYPERGEOMETRIC_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_HYPERGEOMETRIC_RNG_HPP
3
4 #include <boost/math/distributions/hypergeometric.hpp>
5
6 #include <stan/math/prim/scal/err/check_bounded.hpp>
7 #include <stan/math/prim/scal/err/check_positive.hpp>
8 #include <stan/math/prim/scal/prob/uniform_rng.hpp>
9
10 namespace stan {
11 namespace math {
12
13 template <class RNG>
14 inline int
15 hypergeometric_rng(int N, int a, int b, RNG& rng) {
16 using boost::variate_generator;
17 using boost::math::hypergeometric_distribution;
18
19 static const char* function("hypergeometric_rng");
20
21 check_bounded(function, "Draws parameter", N, 0, a+b);
22 check_positive(function, "Draws parameter", N);
23 check_positive(function, "Successes in population parameter", a);
24 check_positive(function, "Failures in population parameter", b);
25
26 hypergeometric_distribution<> dist(b, N, a + b);
27
28 double u = uniform_rng(0.0, 1.0, rng);
29 int min = 0;
30 int max = a - 1;
31 while (min < max) {
32 int mid = (min + max) / 2;
33 if (cdf(dist, mid + 1) > u)
34 max = mid;
35 else
36 min = mid + 1;
37 }
38 return min + 1;
39 }
40
41 }
42 }
43 #endif
stan::math::min
int min(const std::vector< int > &x)
Returns the minimum coefficient in the specified column vector.
Definition: min.hpp:20
check_positive.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::check_bounded
bool check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Return true if the value is between the low and high values, inclusively.
Definition: check_bounded.hpp:95
uniform_rng.hpp
stan::math::check_positive
bool check_positive(const char *function, const char *name, const T_y &y)
Return true if y is positive.
Definition: check_positive.hpp:66
stan::math::uniform_rng
double uniform_rng(const double alpha, const double beta, RNG &rng)
Definition: uniform_rng.hpp:20
stan::math::max
int max(const std::vector< int > &x)
Returns the maximum coefficient in the specified column vector.
Definition: max.hpp:22
check_bounded.hpp
stan::math::hypergeometric_rng
int hypergeometric_rng(int N, int a, int b, RNG &rng)
Definition: hypergeometric_rng.hpp:15

[ Stan Home Page ] © 2011–2016, Stan Development Team.