public class DiscreteIntegerVariate extends RandomVariateBase implements DiscreteRandomVariate
Generates random variates having an arbitrary discrete distribution with integer val. The input is given by a set of val and a set of either frequencies or frequencies.
The parameters should have signature (int[], double[]), where the int[] array contains the possible val and the double[] array contains the frequencies, which may or may not sum to 1, but which must at least be non-negative. These are normalized to be a cdf inside the class.
Modifier and Type | Field and Description |
---|---|
private double[] |
cdf |
private double[] |
frequencies |
private int[] |
values |
rng
Constructor and Description |
---|
DiscreteIntegerVariate()
Creates a new instance of DiscreteIntegerVariate
|
Modifier and Type | Method and Description |
---|---|
double |
generate()
Generate a random variate having this class's distribution.
|
int |
generateInt() |
double[] |
getCdf() |
double[] |
getFrequencies() |
java.lang.Object[] |
getParameters()
Returns the array of parameters as an Object[].
|
int[] |
getValues() |
private void |
normalize() |
void |
setFrequencies(double[] frequencies) |
protected void |
setFrequencies(java.lang.Double[] frequencies) |
protected void |
setFrequencies(java.util.List<java.lang.Double> frequencies) |
protected void |
setFrequencies(java.lang.Object[] frequencies) |
void |
setParameters(java.lang.Object... params)
Sets the cdf for this DiscreteRandomVariate.
|
void |
setValues(int[] values) |
protected void |
setValues(java.lang.Integer[] values) |
protected void |
setValues(java.lang.Object[] values) |
private void |
toCDF()
Convert the given array of frequencies/frequencies to a cdf.
|
java.lang.String |
toString()
Returns a String containing a table representation of the pdf and cdf.
|
getRandomNumber, setRandomNumber
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getRandomNumber, setRandomNumber
private int[] values
private double[] frequencies
private double[] cdf
public DiscreteIntegerVariate()
public double generate()
RandomVariate
generate
in interface RandomVariate
public void setParameters(java.lang.Object... params)
setParameters
in interface RandomVariate
params
- (val, prob) as (double[], double[])java.lang.IllegalArgumentException
- If the given array does not have 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 frequencies/frequencies
are negative or they're sums are zero.public java.lang.Object[] getParameters()
RandomVariate
getParameters
in interface RandomVariate
public int generateInt()
generateInt
in interface DiscreteRandomVariate
private void toCDF()
java.lang.IllegalArgumentException
- If any of the frequencies/frequencies
are negative or they sum to zero.private void normalize()
public int[] getValues()
public void setValues(int[] values)
protected void setValues(java.lang.Integer[] values)
protected void setValues(java.lang.Object[] values)
public double[] getCdf()
public java.lang.String toString()
toString
in class java.lang.Object
public double[] getFrequencies()
protected void setFrequencies(java.lang.Double[] frequencies)
protected void setFrequencies(java.util.List<java.lang.Double> frequencies)
protected void setFrequencies(java.lang.Object[] frequencies)
public void setFrequencies(double[] frequencies)