Stan
1.3
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
math
functions
binomial_coefficient_log.hpp
Go to the documentation of this file.
1
#ifndef __STAN__MATH__FUNCTIONS__BINOMIAL_COEFFICIENT_LOG_HPP__
2
#define __STAN__MATH__FUNCTIONS__BINOMIAL_COEFFICIENT_LOG_HPP__
3
4
#include <boost/math/special_functions/gamma.hpp>
5
#include <boost/math/tools/promotion.hpp>
6
7
namespace
stan {
8
9
namespace
math {
10
29
template
<
typename
T_N,
typename
T_n>
30
inline
typename
boost::math::tools::promote_args<T_N, T_n>::type
31
binomial_coefficient_log
(
const
T_N N,
const
T_n n) {
32
using
std::log
;
33
using
boost::math::lgamma
;
34
35
const
double
cutoff = 1000;
36
if
((N < cutoff) || (N - n < cutoff)) {
37
return
lgamma
(N + 1.0) -
lgamma
(n + 1.0) -
lgamma
(N - n + 1.0);
38
}
else
{
39
return
n *
log
(N - n) + (N + 0.5) *
log
(N/(N-n))
40
+ 1/(12*N) - n - 1/(12*(N-n)) -
lgamma
(n + 1.0);
41
}
42
}
43
44
}
45
}
46
47
#endif
[
Stan Home Page
]
© 2011–2013, Stan Development Team.