Stan
1.0
probability, sampling & optimization
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerator
Friends
Macros
Pages
src
stan
prob
distributions
univariate
discrete
hypergeometric.hpp
Go to the documentation of this file.
1
#ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__HYPERGEOMETRIC_HPP__
2
#define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__HYPERGEOMETRIC_HPP__
3
4
#include <
stan/math/error_handling.hpp
>
5
#include <
stan/math/special_functions.hpp
>
6
#include <
stan/prob/traits.hpp
>
7
#include <
stan/prob/constants.hpp
>
8
9
namespace
stan {
10
11
namespace
prob {
12
13
// Hypergeometric(n|N,a,b) [0 <= n <= a; 0 <= N-n <= b; 0 <= N <= a+b]
14
// n: #white balls drawn; N: #balls drawn;
15
// a: #white balls; b: #black balls
16
template
<
bool
propto,
17
class
Policy>
18
double
19
hypergeometric_log
(
const
unsigned
int
n,
20
const
unsigned
int
N,
21
const
unsigned
int
a,
22
const
unsigned
int
b,
23
const
Policy&) {
24
static
const
char
*
function
=
"stan::prob::hypergeometric_log(%1%)"
;
25
26
using
stan::math::check_finite
;
27
using
stan::math::check_bounded
;
28
using
stan::math::check_greater
;
29
30
double
lp(0.0);
31
if
(!
check_bounded
(
function
, n, 0U, a,
"Successes variable"
, &lp, Policy()))
32
return
lp;
33
if
(!
check_greater
(
function
, N, n,
"Population size parameter"
, &lp, Policy()))
34
return
lp;
35
if
(!
check_bounded
(
function
, N-n, 0U, b,
"Population size parameter minus success variable,"
, &lp, Policy()))
36
return
lp;
37
if
(!
check_bounded
(
function
, N, 0U, a+b,
"Population size parameter"
, &lp, Policy()))
38
return
lp;
39
40
41
if
(
include_summand<propto>::value
)
42
lp +=
math::binomial_coefficient_log
(a,n)
43
+
math::binomial_coefficient_log
(b,N-n)
44
-
math::binomial_coefficient_log
(a+b,N);
45
return
lp;
46
}
47
48
49
template
<
bool
propto>
50
inline
51
double
52
hypergeometric_log
(
const
unsigned
int
n,
53
const
unsigned
int
N,
54
const
unsigned
int
a,
55
const
unsigned
int
b) {
56
return
hypergeometric_log<propto>(n,N,a,b,
stan::math::default_policy
());
57
}
58
59
template
<
class
Policy>
60
inline
61
double
62
hypergeometric_log
(
const
unsigned
int
n,
63
const
unsigned
int
N,
64
const
unsigned
int
a,
65
const
unsigned
int
b,
66
const
Policy&) {
67
return
hypergeometric_log<false>(n,N,a,b,Policy());
68
}
69
70
inline
71
double
72
hypergeometric_log
(
const
unsigned
int
n,
73
const
unsigned
int
N,
74
const
unsigned
int
a,
75
const
unsigned
int
b) {
76
return
hypergeometric_log<false>(n,N,a,b,
stan::math::default_policy
());
77
}
78
79
80
}
81
}
82
#endif
[
Stan Home Page
]
© 2011–2012, Stan Development Team.