public class DiscreteVariate extends RandomVariateBase
Modifier and Type | Field and Description |
---|---|
private double[] |
cdf
Holds the cdf defined for this RandomVariate.
|
private double[] |
frequencies |
private double[] |
values
Holds the values at which the cdf changes for this RandomVariate.
|
rng
Constructor and Description |
---|
DiscreteVariate()
Constructs a new DiscreteVariate with an undefined cdf.
|
Modifier and Type | Method and Description |
---|---|
double |
generate()
Generate a random variate having this class's distribution.
|
double[] |
getCDF() |
java.lang.Object[] |
getParameters()
Returns the values and probabilities that define this RandomVariate.
|
double[] |
getProbabilities() |
double[] |
getValues() |
protected double[] |
normalize(double[] freq)
Convert the given array of probabilities/frequencies to a cdf.
|
void |
setFrequencies(double[] frequencies)
Sets the cdf of this RandomVariate based on the contents of the given
array.
|
protected void |
setFrequencies(java.lang.Double[] frequencies) |
void |
setParameters(java.lang.Object... params)
Defines the cdf for this RandomVariate.
|
void |
setValues(double[] values)
Warning: This array must be the same length as the probability and cdf
arrays, however no checking is done by this method.
|
protected void |
setValues(java.lang.Double[] values) |
java.lang.String |
toString()
Returns a String containing a table representation of the pdf and cdf.
|
getRandomNumber, setRandomNumber
private double[] cdf
private double[] values
private double[] frequencies
public DiscreteVariate()
public void setParameters(java.lang.Object... params)
params
- (values, prob) as (double[], double[])java.lang.IllegalArgumentException
- If the given array does not have 1 or 2
elements, if the elements are not arrays of doubles, or if the two double
arrays are not the same length.java.lang.IllegalArgumentException
- If any of the probabilities/frequencies
are negative or their sums are zero.public java.lang.Object[] getParameters()
public double generate()
RandomVariate
protected double[] normalize(double[] freq)
freq
- array of frequencies or probabilitiesjava.lang.IllegalArgumentException
- If any of the probabilities/frequencies
are negative or they sum to zero.public java.lang.String toString()
toString
in class java.lang.Object
public void setValues(double[] values)
values
- the array of values at which the cdf changes values.protected void setValues(java.lang.Double[] values)
public void setFrequencies(double[] frequencies)
frequencies
- An array containing either the probabilities or frequecies at
the points contained in the values array.protected void setFrequencies(java.lang.Double[] frequencies)
public double[] getValues()
public double[] getCDF()
public double[] getProbabilities()