CS 1538 Introduction
to Simulation
In-class Extra Credit
Exercise
Handed out: Tuesday, November 3, 2009 during
class
Due: Demonstration of your working program by the end of
class
Motivation:
We have seen a number of tests for random number generators, and you are
implementing some of them in Project 2.
To give you a chance for some extra credit, and to give you some help
with the project, and to give you some practice with programming these tests,
in lieu of a regular lecture today we will have an in-class extra credit
exercise. There is no penalty for
not doing this exercise, but if you complete it you can receive up to 15 extra credit project points.
Description and Specifications:
One additional test of random number generators, as described in Knuth[1]
is the "maximum-of-t" test.
In this test, given a sequence of n uniform random values in U[0,1), we divide the sequence into (n/t) subsequences of t
consecutive values. For each
subsequence we determine the maximum value and store it. After the n values have been processed,
we end up with (n/t) values, each of which is the "maximum-of-t" for
a subsequence. Call the array of these
values S and let an arbitrary value be Si.
The values S should have a distribution function F(x) = xt. See Knuth and notes on board for
reasoning. We can test our points
against this distribution directly if we so choose. However, if we raise each of them to the power t, the result
should be a uniform distribution over [0,1). We can then test the resulting distribution using the Kolmogorov-Smirnov test.
In this exercise you must implement the maximum-of-t test on three
different generators:
The
predefined Random generator in Java using nextDouble()
The
Rand2 generator provided online using nextDouble()
The
Rand2 generator provided online using nextDouble32()
Specifically, you should do the following:
á
Input from the
user the values of n, t and a (you can restrict a to 0.1, .05 or 0.01)
á
Create a new
random object for each of the generators to be tested
á
Create an array
of size (n/t) + 1 for each of the generators to be tested
á
Generate n
points for each generator, storing each max-of-t (n/t of these total) in the
array (i.e. process the points t at a time and only store the max for each
group)
á
Raise all of
the points in each array to the power t
á
Sort the values
in each array from low to high
á
Run the Kolmogorov-Smirnov test on each array. The D+ and D- values can be calculated
in a fairly simple manner using a for loop
á
Determine the
critical values for the degrees of freedom (n/t) and the a values provided. This can be calculated from the formulas at the bottom of
the table on p. 601 in the Banks text
á
Determine
whether each generator has passed the test or not and output the result
I will give you a LOT of hints and help during class – the coding
is not hard if you know how to approach it.
I will put my solution online later in the week.
[1] The Art of Computer Programming, Volume 2: Seminumerical Algorithms, Third Edition by Donald Knuth (Addison Wesley, 1998)