November 12, 2013---Class 23---Serial Correlation Tests, Autocorrelations of PRNG
Activities:
Serial Correlation Tests
------------------------
In addition to having a uniform probability density, a pseudo random
number generator should have zero autocorrelation. There are tests
based on looking at pairs or triplets of numbers. For linear
congruential random number generators, there is a well known
problem that like the rain in Spain they tend to fall mainly in
the planes. This can be demonstrated by showing a two dimensional
scatter plot of (r_n, r_{n+1}). If you would like to see this, there
is an executable in ~sg/bin called random_lc:
random_lc | axis m 0 | xplot
will show you the correlations. The code is in ~sg/src and this
makes use of a poor linear congruential random number generator. You
would not see the same pattern with the fsr random number generator.
We looked in detail at another test of correlations based on
triplets of numbers. If we divide the interval (0,1) into L bins,
and look at triplets in the resulting L^3 cells, we derived that
the probability of having a cell remain unoccupied is exponentially
falling. Specifially, if we examine the occupancy after tL^3
triplets have been generated, the number of unoccupied cells should
be L^3 Exp[-t].
The box_rand.c code in ~sg/src implements this code for L=10.
(You can change the define statement near the top of the code to
use other values of L.) To compile the code use the command:
cc -o box_rand box_rand.c
Running box_rand
----------------
We ran a few tests with the fsr random number generator and saw that
the number of unoccupied cells was decreasing. Then using a
for bash shell command, we ran the code 50 times, putting the reults
in a file box_rand.apr3. Using awk and aver, it was easy to get
the average of the 50 trials and plot the result with a semilog
scale using axis. The result clearly shows exponential decay of
the number of unoccupied boxes.
Autocorrelations of Pseudo Random Number Generators, or
comparing drand48 and fsr
-------------------------------------------------------
Before class I prepared codes to test the drand48 random number
generator that comes with Unix. The codes can be found in my src/misc
directory. random_drand48.c puts out two numbers per line and
can be used for a scatter plot or to calculate autocorrelations.
box_drand48.c can be used to test triplets of random numbers as
we did before with box_rand.c for the fsr random number generator.
We compared the autocorrelation of the two random number generators
out to a lag of 20. Doing about 50 trials in each case, we found
that drand48 seemed to have a smaller dispersion than fsr, but that
it seemed to have more negative values of autocorrelation than
positive values. (I also passed around a similar graph from a test
of a linear congruential random number generator that had some much
larger values of the autorcorrelations for some lags.)
We created lists of random numbers as long as 250,000 and looked
at autocorrelations with lags as large as 250. We also histogrammed
the autocorrelations and found a distribution that appears Gaussian.