public class Binomial
extends java.lang.Object
n choose 0 = n choose n = 1. For 0 < k < n, (the recursive formula) n choose k = (n-1 choose k) + (n-1 choose k-1)Builds a two-dimensional table choose and fills it in first in order of increasing n and within each value of n, in order of increasing k. This is known as Pascal's Triangle.
Note that the largest MaxVal allowed is N = 1029. Anything higher than this will cause an ArithmeticException to be thrown, as 1030 choose 500 is the highest value allowed by java type double.
Since this is held as an array, computing choose(N,k) is a constant time lookup.
Modifier and Type | Field and Description |
---|---|
private static double[][] |
choose |
private static int |
MAX_N |
Constructor and Description |
---|
Binomial() |
Modifier and Type | Method and Description |
---|---|
static double |
choose(int n,
int k) |
static double |
cumProb(int N,
int k,
double p)
Returns the cumulative probability as the sum of i=k to N prob(N, i, p).
|
private static void |
fillTriangle(double[][] triangle)
Creates Pascal's Triangle for the size of choose.
|
static double |
prob(int N,
int k,
double p)
Computets the probability that something that occurs with probability p will occur EXACTLY k times, given N chances.
|
static double |
probAtLeastOnce(int N,
double p) |
static double |
stirlingChoose(int n,
int k)
Returns the Choose(n,k) in log space, as computed using Stirling's approximation, where appropriate.
|
static double |
stirlingCumProb(int N,
int k,
double p)
Computes the cumulative probability using stirling's approximation.
|
static double |
stirlingProb(int N,
int k,
double p)
Computes the probability using stirling approximation, for sufficiently large N and K.
|
private static double[][] choose
private static final int MAX_N
public static double choose(int n, int k)
public static double cumProb(int N, int k, double p)
private static void fillTriangle(double[][] triangle)
public static double prob(int N, int k, double p)
public static double probAtLeastOnce(int N, double p)
public static double stirlingChoose(int n, int k)
public static double stirlingCumProb(int N, int k, double p)
public static double stirlingProb(int N, int k, double p)