net.sourceforge.jabm.prng
Class DiscreteProbabilityDistribution

java.lang.Object
  extended by net.sourceforge.jabm.prng.DiscreteProbabilityDistribution
All Implemented Interfaces:
java.io.Serializable, Resetable

public class DiscreteProbabilityDistribution
extends java.lang.Object
implements Resetable, java.io.Serializable

A class representing a discrete probability distribution which can used to generate random events according to the specified distribution. The output from a uniform PRNG is used to to select from the different possible events.

See Also:
Serialized Form
 

Nested Class Summary
 class DiscreteProbabilityDistribution.ProbabilityActionPair
           
static class DiscreteProbabilityDistribution.ProbabilityError
           
 
Field Summary
protected  int n
          The number of possible events for this distribution.
protected  java.util.TreeSet<DiscreteProbabilityDistribution.ProbabilityActionPair> p
          The probability distribution.
protected  cern.jet.random.engine.RandomEngine prng
           
protected  java.util.TreeMap<java.lang.Integer,java.lang.Double> reverseMap
           
 
Constructor Summary
DiscreteProbabilityDistribution(cern.jet.random.engine.RandomEngine prng, double[] p)
           
DiscreteProbabilityDistribution(cern.jet.random.engine.RandomEngine prng, int n)
          Construct a new distribution with k possible events.
 
Method Summary
 double computeMean()
          Compute the expected value of the random variable defined by this distribution.
 int generateRandomEvent()
          Generate a random event according to the probability distribution.
 int getN()
           
 double getProbability(int i)
          Get the probability of the ith event.
 double getSum()
           
 void initialise()
           
 void initialise(double[] probs)
           
 void reset()
          Reinitialise our state to the original settings.
 void setProbability(int i, double probability)
          Set the probability of the ith event.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

p

protected java.util.TreeSet<DiscreteProbabilityDistribution.ProbabilityActionPair> p
The probability distribution.


reverseMap

protected java.util.TreeMap<java.lang.Integer,java.lang.Double> reverseMap

n

protected int n
The number of possible events for this distribution.


prng

protected cern.jet.random.engine.RandomEngine prng
Constructor Detail

DiscreteProbabilityDistribution

public DiscreteProbabilityDistribution(cern.jet.random.engine.RandomEngine prng,
                                       int n)
Construct a new distribution with k possible events.

Parameters:
k - The number of possible events for this random variable

DiscreteProbabilityDistribution

public DiscreteProbabilityDistribution(cern.jet.random.engine.RandomEngine prng,
                                       double[] p)
Method Detail

initialise

public void initialise()

initialise

public void initialise(double[] probs)

setProbability

public void setProbability(int i,
                           double probability)
Set the probability of the ith event.

Parameters:
i - The event
probability - The probability of event i occuring

getProbability

public double getProbability(int i)
Get the probability of the ith event.

Parameters:
i - The event

generateRandomEvent

public int generateRandomEvent()
Generate a random event according to the probability distribution.

Returns:
An integer value representing one of the possible events.

getSum

public double getSum()

reset

public void reset()
Description copied from interface: Resetable
Reinitialise our state to the original settings.

Specified by:
reset in interface Resetable

computeMean

public double computeMean()
Compute the expected value of the random variable defined by this distribution.

Returns:
The expected value of the distribution

getN

public int getN()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object