|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjstats.Probability
The Probability class deals with probability calculations. A valid probability must always be a number >= 0.0 and <= 1.0.
Most distributions have requirements in order to calculate a valid distribution. A StatisticException will be thrown
when a distribution is given arguments that do not meet that distribution's requirements.
| Constructor Summary | |
Probability()
|
|
| Method Summary | |
static double |
binomialDistribution(double probability,
long trials,
long successes)
Calculates a binomial distribution probability. |
static double |
geometricDistribution(double probability,
long trial)
Computes a geometric probability distribution. |
static double |
hyperGeometricDistribution(long population_a,
long population_b,
long samples,
long expected)
Calculates a hypergeometric distribution. |
static boolean |
isValidProbability(double probability)
Validates that a double is a valid probability (>= 0.0 and <= 1.0). |
static boolean |
isValidProbabilityDistribution(double[] distribution)
Identical to the same method with a delta argument, but uses a default delta of 0.0 (i.e., allows no error tolerance). |
static boolean |
isValidProbabilityDistribution(double[] distribution,
double delta)
Validates that an array of doubles meets the criteria for a valid probability distribution (each value is a valid probability, and the distribution adds up to 1.00). |
static double |
multinomialDistribution(long trials,
double[] probabilities,
long[] outcomes)
Calculates a multinomial probability distribution. |
static double |
multinomialDistribution(long trials,
double[] probabilities,
long[] outcomes,
double delta)
This is the same function as the one without the delta argument, but allows specification of margin of error for the sum of all probabilities. |
static double |
multivariateHypergeometricDistribution(long[] populations,
long[] expected)
Calculates a multivariate hypergeometric distribution. |
static double |
negativeHypergeometricDistribution(long population_a,
long population_b,
long selections,
long expected)
Calculates a negative hypergeometric distribution. |
static double |
poissonApproximation(double probability,
long trials,
long successes)
Approximates a binomial probability using a special form of the Poisson Distribution. |
static double |
poissonDistribution(double mean,
long successes)
Computes the probability of a given number of successes given an average number of successes per unit. |
protected static void |
validateProbability(double probability)
Confirms that the probability passed into the public functions is proper. |
protected static void |
validateProbability(double[] probability)
Validate an array of probabilities |
protected static void |
validateProbabilityDistribution(double[] distribution)
Identical to the same method with a delta, but uses a default delta of 0 (i.e., has no error tolerance). |
protected static void |
validateProbabilityDistribution(double[] distribution,
double delta)
Valid a probability distribution (an array of probabilities, each of which must be a valid probability, and the sum of which must add up to 1.00). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Probability()
| Method Detail |
public static double binomialDistribution(double probability,
long trials,
long successes)
throws StatisticException
Calculates a binomial distribution probability. Trials must be independent and have a fixed probability for each one.
P(x) = n!/(n-x)!x! * p^x * (1-p)^(n-x)
(Note that for n = 0, x = 0, the probability will always be 1.00.)
probability is a valid probability; trials <= successes
probability - the probability of any one trial succeeding (p)trials - the number of trials to perform (n)successes - the number of successes expected as an outcome (x)
StatisticException - if above requirements are not met
public static double geometricDistribution(double probability,
long trial)
throws StatisticException
Computes a geometric probability distribution. The probability of getting the first success on the xth trial is:
P(x) = p(1-p)^(x-1)
probability is valid, trial > 0
probability - the probability of success on any one trial (p)trial - the trial where the first success is expected (x)
StatisticException - if above requirements are not met
public static double hyperGeometricDistribution(long population_a,
long population_b,
long samples,
long expected)
throws StatisticException
Calculates a hypergeometric distribution. When sampling n objects without replacement from a population with A objects of one type and B objects of the other type, the probability of getting x objects of type A and n-x objects of type B is:
A!/(A-x)!x! * B!/(B-n+x)!(n-x)! / (A+B)!/(A+B-n)!n!
or
Comb(a, x) * Comb(b, n-x)/Comb(a+b, n)
Another way to express this is with a population of N, consisting of r elements of one type and N-r elements of the other type. In this case the formula is:
Comb(r, x) * Comb(N-r, n-x)/Comb(N, n)
Use n-r and r, respectively, for the arguments population_a and population_b.
All arguments are whole numbers, samples <= population_a + population_b,
expected <= samples
population_a - number of objects of type Apopulation_b - number of objects of type Bsamples - number of samples takenexpected - desired number of type A objects
StatisticException - if above requirements are not met
public static double negativeHypergeometricDistribution(long population_a,
long population_b,
long selections,
long expected)
throws StatisticException
Comb(n+x-1, n-1) * Comb(N-n-x, a-n)/(N/a)
All arguments are whole numbers, selections > 0, selections >= expected
Note that if selections > population_a or expected > population_b, the probability will always be 0.0.
population_a - number of elements of type Apopulation_b - number of elements of type Bselections - number of elements of type A to be selected (n)expected - number of samples before getting a number of A's equal to selections (x)
StatisticException - if above requirements are not met
public static double multinomialDistribution(long trials,
double[] probabilities,
long[] outcomes)
throws StatisticException
Calculates a multinomial probability distribution. Also known as a multivariate binomial distribution. Given mutually exclusive outcomes O1...Oz, with P(O1)....P(Oz), in n independent trials, the probability of X1 outcomes of O1.. to Xz outcomes of Oz is:
P(x) = n!/(X1!)(X2!)....(Xz!) * P(O1)^X1 * ..... P(Oz)^Xz.
By default, the sum of all probabilities must be exactly 1.00. You may use this method with a delta argument to allow for a degree of difference from 1.00 to account for rounding errors.
trials - number of independent trials (n)probabilities - array of probabilities (P(O1) to P(Oz))outcomes - array of expected outcomes (X1....Xz)
StatisticException - for invalid probabilities, if the sum all probabilities is not 1.00, if #probabilities != #outcomes,
public static double multinomialDistribution(long trials,
double[] probabilities,
long[] outcomes,
double delta)
throws StatisticException
Delta tolerance is not guaranteed to be accurate beyond 6 decimal places (1E-6)
trials - number of independent trials (n)probabilities - array of probabilities (P(O1) to P(Oz))outcomes - array of expected outcomes (X1....Xz)delta - the permissible delta between the sum of probabilities and 1.00
StatisticException - for invalid probabilities, if the sum of all probabilities is not 1.00, if trials < 1 or is not equal to the sum of outcomes,
if #probabilities != #outcomes
public static double multivariateHypergeometricDistribution(long[] populations,
long[] expected)
throws StatisticException
Calculates a multivariate hypergeometric distribution. Given a set of N objects of I different types, with Ri elements for each i (i = 1...I), sampling without replacement n times, the probability of finding Xi objects for each i (i = 1...I) is:
Comb(R1, X1)/Comb(N, n) * ...... Comb(RI, XI)/Comb(N, n)
populations - an array with length = number of different items, each value containing the number of elements of that type (Ri)expected - an array of expected sample outcomes, each value containing the number of expected items of the corresponding population array element type (Xi) ("n" equals the sum of all outcomes)
StatisticException - if the length of the populations and outcomes arrays are not the same, if any population value is 0, if samples <= 0, or
if any outcome value is greater than the population of the corresponding item
public static double poissonApproximation(double probability,
long trials,
long successes)
throws StatisticException
Approximates a binomial probability using a special form of the Poisson Distribution. Often used when the number of trials is large and the probability is small. The formula is:
P(x) = (np)^x * E^(-np)/x!
probability - the probability of any one trial succeeding (p)trials - the number of trials to perform (n)successes - the number of successes expected as an outcome (x)
StatisticException - if probability is invalid, or successes > trials, or any parameter is negative
public static double poissonDistribution(double mean,
long successes)
throws StatisticException
P(x) = u^x * e^-x/x!
Where u is the mean number of successes in a given unit.
mean - the average number of successes (u)successes - the expected number of successes (x)
StatisticException - if mean <= 0 or successes < 0public static boolean isValidProbability(double probability)
probability - a double to test
public static boolean isValidProbabilityDistribution(double[] distribution,
double delta)
distribution - an array of doubles to testdelta - the allowable error tolerance
public static boolean isValidProbabilityDistribution(double[] distribution)
distribution - an array of doubles to test
protected static void validateProbability(double probability)
throws StatisticException
probability - a probability to validate
StatisticException - if probability < 0.0 or > 1.0
protected static void validateProbability(double[] probability)
throws StatisticException
probability - an array of doubles
StatisticException - if any one probability fails to validate
protected static void validateProbabilityDistribution(double[] distribution,
double delta)
throws StatisticException
distribution - an array of doublesdelta - the degree to which the sum of the distribution can vary from 1.00.
StatisticException - if the distribution does not meet the requirements of a probability distribution
protected static void validateProbabilityDistribution(double[] distribution)
throws StatisticException
distribution - an array of doubles
StatisticException - if the distribution does not meet the requirements of a probability distribution
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||