uk.ac.liv.prng
Class DiscreteProbabilityDistribution

java.lang.Object
  extended byuk.ac.liv.prng.DiscreteProbabilityDistribution
All Implemented Interfaces:
java.lang.Cloneable, Prototypeable, Resetable, java.io.Serializable

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

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.

Version:
$Revision: 1.7 $
Author:
Steve Phelps
See Also:
Serialized Form

Nested Class Summary
 class DiscreteProbabilityDistribution.ProbabilityError
           
 
Field Summary
protected  int k
          The number of possible events for this distribution.
protected  double[] p
          The probability distribution.
 
Constructor Summary
DiscreteProbabilityDistribution(int k)
          Construct a new distribution with k possible events.
 
Method Summary
 int computeMax()
          Compute the maximum value of the random variable defined by this distribution.
 double computeMean()
          Compute the expected value of the random variable defined by this distribution.
 int computeMin()
          Compute the minimum value of the random variable defined by this distribution.
 void computeStats(CummulativeDistribution stats)
           
 int generateRandomEvent()
          Generate a random event according to the probability distribution.
 double getProbability(int i)
          Get the probability of the ith event.
 java.lang.Object protoClone()
           
 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 double[] p
The probability distribution.


k

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

Constructor Detail

DiscreteProbabilityDistribution

public DiscreteProbabilityDistribution(int k)
Construct a new distribution with k possible events.

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

protoClone

public java.lang.Object protoClone()
Specified by:
protoClone in interface Prototypeable

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.

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

computeMin

public int computeMin()
Compute the minimum value of the random variable defined by this distribution.

Returns:
The minimum integer value

computeMax

public int computeMax()
Compute the maximum value of the random variable defined by this distribution.

Returns:
The maximum integer value

computeStats

public void computeStats(CummulativeDistribution stats)

toString

public java.lang.String toString()