ca.cas.utilities
Class ProbDist

java.lang.Object
  extended by ca.cas.utilities.ProbDist
Direct Known Subclasses:
ConstantDist, ExponentialDist, OneDist, Poisson, ZeroDist

public abstract class ProbDist
extends java.lang.Object

Each class which extends ProbDist represents a probability distribution. The ProbDist abstract class provides methods for calculating the probability of elements and sets of elements according to the probability distribution represented by the class which extends ProbDist. ProbDist also provides a method for finding an element at random from the probability distribution that the class which extends ProbDist represents


Field Summary
static int CONSTANT
           
static int EXP
           
protected  int max
           
protected  int min
           
static int ONE
           
static int POISSON
           
protected  java.util.Vector probs
           
static int ZERO
           
 
Constructor Summary
ProbDist()
           
 
Method Summary
 int getMax()
          Returns the greatest number in this probability distribution which has a calculated probability
static ProbDist getProbDist(int type, double[] parameters)
          A static factory method used to generate a probability distribution from an integer flag indicating a type (as above) and some parameters.
 int next(java.util.Random r)
          Returns a number at random from this probability distribution
 double probFor(int n)
          Calculates the probability of n in this probability distribution
 double probMoreThan(int n)
          Calculates the probability for all numbers strictly greater than n in this probability distribution
 double probUpTo(int n)
          Calculates the sum of the probabilities for 0 to n inclusive in this probability distribution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

public static final int ZERO
See Also:
Constant Field Values

ONE

public static final int ONE
See Also:
Constant Field Values

CONSTANT

public static final int CONSTANT
See Also:
Constant Field Values

EXP

public static final int EXP
See Also:
Constant Field Values

POISSON

public static final int POISSON
See Also:
Constant Field Values

probs

protected java.util.Vector probs

min

protected int min

max

protected int max
Constructor Detail

ProbDist

public ProbDist()
Method Detail

probFor

public double probFor(int n)
Calculates the probability of n in this probability distribution

Parameters:
n - the int which represents the number for which the probability is to be calculated
Returns:
the probability of n as a double

probUpTo

public double probUpTo(int n)
Calculates the sum of the probabilities for 0 to n inclusive in this probability distribution.

Parameters:
n - the int which represents the last number in the set of numbers whose probabilities are to be summed
Returns:
the sum of the probabilities for 0 to n inclusive as a double

probMoreThan

public double probMoreThan(int n)
Calculates the probability for all numbers strictly greater than n in this probability distribution

Parameters:
n - the int which represents the greatest integer not in the set of integers whos probabilities are to be summed
Returns:
the sum of the probabilities of all n strictly greater than n as a double

next

public int next(java.util.Random r)
Returns a number at random from this probability distribution

Parameters:
r - a Random object used to find the number to return
Returns:
a random number from this probability distribution

getMax

public int getMax()
Returns the greatest number in this probability distribution which has a calculated probability

Returns:
the greatest number in this probability distribution that has a calculated probability

getProbDist

public static ProbDist getProbDist(int type,
                                   double[] parameters)
A static factory method used to generate a probability distribution from an integer flag indicating a type (as above) and some parameters. In the case of ZeroDist and OneDist, the presence or absence of parameters is a non-issue. In the case of Poisson and Exponential, if there are no parameters specified, it will set lambda/alpha to 1 and precision to 1E-5d. If only one parameter is specified, it will set lambda/alpha to that value and precision to 1E-5d. If more than two or more values are given, the first two will be used to specify lambda and precision repectively. Lastly, for a Constant distribution, only the first parameter will be used and if no such parameter is specified, 1 will be used in its place. Note, since constant takes an int and this is a double array of parameters, we're going to use a type conversion. This is probably a bad idea. I think Java 1.5 allows for a nicer way to handle unknown numbers/types of parameters, something to do with the new formatted print statement, but this ought to work just fine.