There are many pseudo random generation libraries

advertisement
1.
2.
3.
4.
5.
There are many pseudo random generation libraries.
They are based on parameterization Methods
The existing libraries are erroneous when there are applied to Real world Applications.
Scalable Library for Pseudorandom Number Generation.
SPRNG designed based on Uniform implementation of parameterized random generators but
avoiding the erroneous results in Monte Carlo – That happened with existing
libraries/procedures.
Introduction:
Problems:
1. There are many cases in the real world when Pseudo Random Generators are erroneous in
terms of results when applied to Monte Carlo applications.
2. Monte Carlo Consumes and Continues to consume High Performance Computing Cycles
3. When applied Parallelism – It further complicates this state of affairs
Solution:
1. SPRNG designed especially to support Monte Carlo Applications on Scalable and Distributed
Architectures.
PARALLEL Pseudorandom-number generation:
1. Methods are based on Parameterization of the generators.
Linear Congruential Generators:
1. Most Commonly used Pseudo Random Numbers
2. Linear Recursion :
3. ‘a’ is multiplier, ‘b’ is linear constant ‘m’ is modules
4. When ‘a’, b & ‘m’ are chosen approximately, one can obtain purely period sequence
5.
When m is power of 2
6.
When m is prime
7. Initial value X0 is called “Seed”
8. Based on ‘m’ Parameterization method varies:
2.1 Prime Modules:
1. Parameterization when ‘m’ is a prime.
2. Need to determine Family of a’s
3. Obtain Maximal period by applying Condition on ‘a’ such that ‘a’ must be primitive element
modulo ‘m’.
If given permittivity
𝛼 = 𝑎𝑖 (𝑚𝑜𝑑 𝑚)
𝑆𝑖𝑛𝑔𝑙𝑒 𝑟𝑒𝑓𝑒𝑟𝑒𝑛𝑐𝑒, 𝑃𝑟𝑖𝑚𝑖𝑡𝑖𝑣𝑒 𝑒𝑙𝑒𝑚𝑒𝑛𝑡 ′𝑎′ & explicit enumeration of the relative prime to m-1
produces jth primitive element:
PROBLEM:
1. Ovearall efficiency ?
Whether to minimize the cost of computing Lj or
To minimize the cost of modular multiplication modulo ‘m’
There are +ve and –ve which based on exponential . Exponentials sums are used in Number
theory
Full period Exponentila sum: Xn are periodic and K is the Period
Partial Period Exponential sum: Xn is periodic and K is leass than the full period
Therefore, the desire is to show that exponential sum opf interests are neither too big nor too
small to reassure us that the sequence in question is theoretically Equidistributed.
Parallel: Considering cross-correlations among the sequences to be used on different processes
and Xn and Yn are two sequences then
Uppper Bound:
2.3 Lagged- Fibonacci Gnerators:
-> We discussed about generators that can be parallelized by varying parameters in the underlying
recursion.
-> Additive lagged-Fibonacci generator can be parameterized through its initial value.
ALFG can be written as Xn= Xn-j + Xn-k (mod 2^m), where j<k
-> It is most popular generator for serial as well as scalable parallel machines.
-> The generator with j=5, k=17 and m=32 was the standard PPRNG
-> This generator is popular for many reasons:
1. Easy to implelement
2. Cheap to compute
3. It does well on statistical tests
-> Imporatnat property of ALFG is maximal period which is (2^k -1)(2^m -1) => 2^((k-1) * (m-1))
different full period cycles
-> The state space of the ALFG is torodial providing the algorithm in one of the tours dimensions.
-> Eqn tells how to cycle over flu period, finding seed that not in a full period cycle gives us second
dimension.
-> Therefore, finning algorithm is key to move in other dimensions
-> With simple enumeration one can move to second dimension. The template is as follows :
{X0, x1, X2…..Xk-1} can be initialized as follows:
// Diagram
--> Each 'square' is a bit location to be assigned
--> Each unique assignment gives a seed in a distinct full period cycle
--> Here, L.S.B 'b0' fixed, nonzero pattern
If we precompute O(k2) to find a L.S.B pattern then the template is as follows:
//
If we think about the exponential sum correlations between these parameterized sequences and
calculating the full period exponential sum correlation between streams is
O(sq.root(2^k-1*2^m-1))
Advantage with this is : It is optimal. Unfortunately there is no proof for this result and improvement
of this analytical result is an open challenge?
But, this is good for Floating point numbers which avoids the constant conversion from integer to
float. However, care must be taken to maintain the uniqueness of the parallel streams.
3. SPRNG:
It is designed to use parameterized random generators to provide random number streams to parallel
processes
It includes the following:
1.
2.
3.
4.
5.
6.
7.
Several, distinct, well-tested, scalable PRNGs
Initialization w/o inter process communication
Reproducibility: by using parameters and single global seed
Minimization of interprocess correlation
Uniformity ::Uniform interface - C, C++, FORTRAN, MPI
Integrated test suites :: such as Physical test and Statistical tests
Extensibility : To implement their own generators in parallel, an provides library
developers a powerful rapid-prototyping tool
Generators available in SPRNG are:
1.
2.
3.
4.
5.
Additive lagged Fibbonacci : Xn=Xn-r+Xn-s(mod 2^m)
Multiplicative lagged Fibbonacci : Xn=Xn-r*Xn-s(mod 2^m)
Prime modulus Multiplicative congruential : Xn=aXn-1(mod m)
power-of-two modules linear congruential: Xn=aXn+b (mod 2^m)
Combined multiplicative recursive generator: Zn=Xn+Yn*2^32
All the above generators are parameterized by a single integer valued function f(.)
where, f(i) gives the appropriate parameter for the ith random-number stream
Because of this uniformity, the random number stream are mapped on to the binary tree through the
canonical enumeration via the index i.
Which allows us to produce new streams from existing streams w/o need of interprocess
communication
> Reuse of stream : can be provided by allowing access to those streams associated with subtree
rooted at the given stream.
--> For this we apply mixing function ps(.) - so that we can map the streams onto the binary tree via
the index ps(i)
Thrrefore, with global seed S on ps(.) can be done in a district way
3.1 Using SPRNG: Some examples
One can download SPRNG library under
http://sprng.cs.fsu.edu
Pre required: we need a g++ compiler which is a c++ compiler
Interface::
Definition of init_sprng routine
A routine that one need to call to initialize the various random-number streams for parallel use
int *init_sprng(int streamnum, int nstreams, int seed, int param)
SPRNG_POINTER init_sprng(integer streamnum, integer nstreams, integer seed, integer param)
 init_sprng : initializes random number streams
 streamnum: umber of different streams initialized across all the processes
 seed : is the seed to he generator. It is not the starting of the seed, it is an encoding of the
starting state. It is acceptable and recommended to use the same seed for all the streams
 param: appropriate parameter: ex: the multiplier for a Linear Congruential Generator or the
Lag for a Lagged Fibbonacci generator
 init_sprng : returns the ID of the stream
/****************************************************************************
/
/*
____Demonstrates the use of sprng without initialization____
*/
/* A few double precision random numbers are generated, without the user
*/
/* explicitly initializing the streams. SPRNG automatically initializes a
*/
/* stream with default seed and parameter the first time 'sprng' is called.
*/
/****************************************************************************
/
#include <cstdio>
#define SIMPLE_SPRNG
#include "sprng.h"
*/
/* simple interface
/* SPRNG header file
*/
using namespace std;
int main()
{
double rn;
int i;
printf(" Printing 3 random numbers in [0,1):\n");
for (i=0;i<3;i++)
{
rn = sprng();
printf("%f\n",rn);
}
/* generate double precision random number
return 0;
}


$> ./simple-simple Spri
Printing 3 random numbers in [0,1):
0.014267
0.749392
0.007316
*/
4. SPRNG TEST SUITE:
The result of a MC computations can be affected by defects such as
correlations in the random number sequence used.
A PPRNG must be tested for two types of correlations :
1. Intrastream correlation : Correlation b/w numbers in the same stream
such as serial enervators.
2. Interstream Correlation : Correaltion b/w random number streams on
different process.
Sinc correlations are difficult to prove mathematically, we need large
empirical tests.
PRNGs that are used today were tested when computation power was much lower.
Therefore, Evaluated with such smaller size later discovered defects in
several generators
> But, SPRNG generators have passed some of the largest empirical random
number tests that have previous records
> SPRNG comes up with Serial as well as Parallel random number sequences.
SPRNG suites consists of
1.Statistical test
2. Physically based tests
1. Statistical test:
Statistics are compared against the expected values. These statistic are
known from the independent identical distributed random samples from the
uniform distribution.
The SPRNG test suites includes all the test that described by the Knuth.
These tests are modified such that these tests to test for parallel
correlation in the following manner:
1. Interleave several streams to form a new stream and this stream is
tested with conventional test as shown:
A 1 2 3
B 1 2 3
C 1 2 3
New : 1 1 1 2 2 2 3 3 3
They produce several such streams and test several blocks of random numbers
from each stream
> The result of the test for each block is a Chi-square value
> They take the chi-square statistics for all the blocks and use the KS test
to verify that they distributed according to chi-square distribution.
If it is between 2.5 and 97.5 percentage
Then ==> Test is passed by the Random number generator
The tests are called as follows:
test.lib nstreams ncombine seed param nblocks skip
test - name of the test
lib- random number library
Ex: eqi-distance.lcg 4 2 0 0 3 1 2 1 00
mpirun -np 2 equidistnce.lcg 4 2 0 0 3 1 2 1 00
Which performs equidistance test with 48 bit Linear congruential generator
The argument
ncombine - (=2 in example) - indicates the no.of streams we inter leave to
form a new stream
nstreams (=4) such new streams
nblocks(=3) block of random numbers from each new stream
seed (=0) is the encoded seed to the random number generator
param(=0) parameter to the generator
skip(=1) how many random numbers we skip after testing a block before we
start a test on the next block
Result:
mpirun -np 2 eqidist.lcg 4 2 0 0 3 1 2 1 00
eqidistance.lcg 4 2 0 0 3 1 2 100
KS value : 0.601252
KS value prob : 17.50
Hence, It is b/w 2.5% and 97.5% It is passed
There are different tests that are described by Knuth are described in SPRNG
library such as
1.
2.
3.
4.
5.
6.
7.
Collision tests
Coupons Collector tests
Equidistance tests
Gap test
Permutation tests
Poker tests
Serial test
4.2 Physically Based Tests:
1. Ising Model :
They test parallel generators on the Ising model applications by assigning
random-number stream for each site
There currently Ising model runs on a single process
They have implemented Metropolis and Wolf algorithms. These takes 6 command
line arguments
seed param lattice_size block_size discard_blocks use_blocks
Ex: mpirun -np 1 metropolis.lcg64 111 0 16 10 10 100
runs the metropolis algorithm using the 64 bit Lnear
Congruential Gnearartor
Seed is 111
Parameter to the generator is 0
16*16 lattice



















The simulation starts with a random initial configuration
The simulation then performs several sweeps through the entire lattice
They record results of blocks of 10 sweeps
They discard the result of the first 10 blocks (there are total of 100
blocks)
They then use the result of next 100 blocks
The last parameter must n=be power of 10
The test carried out until J/KbT=0.4406868
Where J is the energy per bond and T is the temperature
The sample results produced when we run this is :
Stresms are synchronized
Energy Energy_Error Sigma_Energy
Energy_Error - obese red error i Energy
Signma_Error - gives Standard Error
Random Walk Test:
=================
o In the Random walk test, We start a "Random Walker" from certain
position on a two-dimensional lattice
o The random walker then takes a certain number of steps to other
lattice
o Direction determined form returned value by random number
generator
o Series of test is performed
o Final position is noted for each test
o
o 6 command line argument for this test is as follows:
o mpirun -np 2 random_walk.lcg64 2 3 0 0 10 0 100
Download