Skip to content

Commit 944d989

Browse files
committed
add binom coeff func
1 parent 5c927dd commit 944d989

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/rv_eval.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ double inv_logit(const double &r);
6868
double log_inv_logit(const double &r);
6969

7070

71+
////////////////////////////////////////////////
72+
/////// Other Math Functions ///////
73+
////////////////////////////////////////////////
74+
75+
76+
unsigned int nChooseK(unsigned int n, unsigned int k);
77+
7178

7279
////////////////////////////////////////////////
7380
///////// double evals /////////

src/rv_eval.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ double rveval::log_inv_logit(const double& r)
5252
}
5353

5454

55+
unsigned int sf::nChoosek( unsigned int n, unsigned int k )
56+
{
57+
if (k > n) return 0;
58+
if (k * 2 > n) /*return*/ k = n-k; //remove the commented section
59+
if (k == 0) return 1;
60+
61+
int result = n;
62+
for( int i = 2; i <= k; ++i ) {
63+
result *= (n-i+1);
64+
result /= i;
65+
}
66+
return result;
67+
}
68+
69+
5570
double rveval::evalUnivNorm(const double &x, const double &mu, const double &sigma, bool log)
5671
{
5772
double exponent = -.5*(x - mu)*(x-mu)/(sigma*sigma);

0 commit comments

Comments
 (0)