List of utility methods to do Binomial Coefficients
long | binomialCoefficient(int n, int k) binomial Coefficient if (k > n || k < 0) { return 0; } else { return factorial(n) / factorial(k) / factorial(n - k); |
long | binomialCoefficient(long n, long k) Binomial coefficient, also known as "n choose k". final long m = Math.max(k, n - k); double temp = 1; for (long i = n, j = 1; i > m; i--, j++) { temp = temp * i / j; return (long) temp; |
double | binomialCoefficientDouble(final int n, final int k) Returns a double representation of the Binomial Coefficient, "n choose k ", the number of k -element subsets that can be selected from an n -element set.
return Math.floor(Math.exp(binomialCoefficientLog(n, k)) + 0.5);
|
double | binomialCoefficientLog(final int n, final int k) Returns the natural log of the Binomial Coefficient, "n choose k ", the number of k -element subsets that can be selected from an n -element set.
if (n < k) { throw new IllegalArgumentException("must have n >= k for binomial coefficient (n,k)"); if (n < 0) { throw new IllegalArgumentException("must have n >= 0 for binomial coefficient (n,k)"); if ((n == k) || (k == 0)) { return 0; ... |
long | binomialCoefficients(int n, int k) binomial Coefficients long Ank = 1; if (k < 0 || k > n) { return 0; long i = n - k + 1; while (i <= n && Ank >= 0) { Ank = Ank * i; i = i + 1; ... |
double | binomialPmf(int k, int n, double p) binomial Pmf if (p == 0.0) { return ((k == 0) ? 1.0 : 0.0); } else if (p == 1.0) { return ((k == n) ? 1.0 : 0.0); } else if ((k < 0) || (k > n)) { return 0.0; } else { return (Math.exp(lngamma(n + 1.0) - lngamma(k + 1.0) - lngamma(n - k + 1.0) + k * Math.log(p) ... |
int | binomialRand(int n, double pp) Binomial random generator from Numerical Recipes int j, k; double am, em, g, p, sq, t, y; double pc, plog, pclog, en; p = (pp <= 0.5) ? pp : 1.0 - pp; am = n * p; if (p == 0.0) { k = 0; } else if (p == 1.0) { ... |