public class EmpiricalWalker extends AbstractDiscreteDistribution
The probability distribution function (pdf) must be provided by the user as an array of positive real numbers. The pdf does not need to be provided in the form of relative probabilities, absolute probabilities are also accepted.
Instance methods operate on a user supplied uniform random number generator; they are unsynchronized.
Implementation: Walker's algorithm. Generating a random number takes O(1), i.e. constant time, as opposed to commonly used algorithms with logarithmic time complexity. Preprocessing time (on object construction) is O(k) where k is the number of elements of the provided empirical pdf. Space complexity is O(k).
This is a port of discrete.c which was written by James Theiler and is distributed with GSL 0.4.1. Theiler's implementation in turn is based upon
Alastair J. Walker, An efficient method for generating discrete random variables with general distributions, ACM Trans Math Soft 3, 253-256 (1977).
See also: D. E. Knuth, The Art of Computer Programming, Volume 2 (Seminumerical algorithms), 3rd edition, Addison-Wesley (1997), p120.
serialVersionUID
Constructor and Description |
---|
EmpiricalWalker(double[] pdf,
int interpolationType,
RandomEngine randomGenerator)
Constructs an Empirical distribution.
|
Modifier and Type | Method and Description |
---|---|
double |
cdf(int k)
Returns the cumulative distribution function.
|
Object |
clone()
Returns a deep copy of the receiver; the copy will produce identical sequences.
|
int |
nextInt()
Returns a random integer k with probability pdf(k).
|
double |
pdf(int k)
Returns the probability distribution function.
|
void |
setState(double[] pdf,
int interpolationType)
Sets the distribution parameters.
|
void |
setState2(double[] pdf)
Sets the distribution parameters.
|
String |
toString()
Returns a String representation of the receiver.
|
nextDouble
apply, apply, makeDefaultGenerator
public EmpiricalWalker(double[] pdf, int interpolationType, RandomEngine randomGenerator)
pdf
- the probability distribution function.interpolationType
- can be either Empirical.NO_INTERPOLATION or Empirical.LINEAR_INTERPOLATION.randomGenerator
- a uniform random number generator.IllegalArgumentException
- if at least one of the three conditions above is violated.public double cdf(int k)
public Object clone()
clone
in class AbstractDistribution
public int nextInt()
nextInt
in class AbstractDiscreteDistribution
public double pdf(int k)
public void setState(double[] pdf, int interpolationType)
pdf
- probability distribution function.IllegalArgumentException
- if at least one of the three conditions above is violated.public void setState2(double[] pdf)
pdf
- probability distribution function.IllegalArgumentException
- if at least one of the three conditions above is violated.Jas4pp 1.5 © Java Analysis Studio for Particle Physics