|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Utility.RandomNumber
The RandomNumber class implements a random number
generator. It behaves as a uniform distribution in [0,1)
that gnerates doubles. It provides no support for
directly generating random integers.
It is intended to be used a parent class for other random
numbers.
Extending this class ...
When creating a subclass, be sure to use the
sample01() function instead of the nextDouble() function.
Both discrete and continuous distributions exist. The
sampleInt() function is intended to be used with discrete
distributions and the sampleDouble() function is intended
to be used with continuous distributions. To make the
class easier to use, it will not be considered an error
to call sampleDouble() for a discrete distribution. The integer
returned from sampleInt() can easily be cast to a double.
But,
in the case of calling sampleInt() for a continous
distribution, a RuntimeException will be thrown. So when
in doubt, use the sampleDouble() function.
Thus, users should pay attention to whether or not a
distribution they are using is continuous or discrete.
The RandomNumber class is treated as a continuous
distribution - Uniform [0,1).
Tests Performed
1000 samples were generated and the means and variances
were examined. Subjectively, they seemed correct.
A goodness of fit test was performed with 100 samples
and 10 intervals. It succeeded about 19/20 times.
Constructor Summary | |
RandomNumber()
|
Method Summary | |
boolean |
goodnessOfFitTest(int sampleSize,
double[] seperators,
double[] expected)
Run a chi squared Goodness of Fit Test. |
boolean |
goodnessOfFitTest(int sampleSize,
double[] seperators,
double[] expected,
int estimatedParams)
Let the user specify how many parameters had to be estimated. |
static int |
randomMixer()
|
static void |
resetRandomMixer(int mixer)
Reset the random_mixer to a value greater than 5, default value is 5 |
protected double |
sample01()
This function returns a uniform double in the interval [0,1). |
double |
sampleDouble()
Draw a random sample. |
int |
sampleInt()
Draw a random sample. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RandomNumber()
Method Detail |
public static void resetRandomMixer(int mixer)
mixer
- Should be an integer >= 5, it denotes the
number of times mix the random number seeds.public static int randomMixer()
public double sampleDouble()
public int sampleInt()
protected double sample01()
public boolean goodnessOfFitTest(int sampleSize, double[] seperators, double[] expected)
sampleSize
- The number of samples to draw.seperators
- The upper bounds of the intervals. The
last upper bound is always +infinity, (and thus not specified).
The bounds are included in the intervals. Ex: seperators[] =
{3,4,5} would indicate four intervals: (-inf,3], (3,4],
(4,5], and (5,+inf).expected
- How many observations are expected to fall in
each of the given intervals.
java.lang.RuntimeException
- Thrown if the length of the
expected array is not one bigger than the length of the
seperators array.public boolean goodnessOfFitTest(int sampleSize, double[] seperators, double[] expected, int estimatedParams)
goodnessOfFitTest(int,double,double).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |