290 likes | 485 Views
Lecture 5. Properties of Random Numbers. Random Number Generation. A simulation of any system or process in which there are inherently random components requires a method of generating or obtaining numbers that are random, in some sense.
E N D
Lecture 5 Properties of Random Numbers
Random NumberGeneration • A simulation of any system or process in which there are inherently random components requires a method of generating or obtaining numbers that are random, in some sense. • The earliest methods were carried out by hands such as throwing dice. • As computers (and simulation) became more widely used, increasing attention was paid to methods of random number generation compatible with the computers work.
Random NumberGeneration (cont’) • Therefore, the research in the 1940’s and 1950’s turned to numerical or arithmetic ways to generate “random” numbers. • These method are sequential, with each new number being determined by one or several of its predecessors according to a fixed mathematical formula. • The first such arithmetic generate generator, proposed by von Neumann and Metropolic in the 1940’s is the famous midsquare method.
Midsquare Method • An example of midsquare method for generating a uniform [0, 1] random numbers:
Midsquare Method(cont’) • Drawbacks for midsquare method • If Zi= 0 for some i, then Uj= Zj=0 for all j > i. • Ui+1 is determined by Ui, i.e. Ui+1 is a function of Ui. Therefore, Ui and Ui+1 are not independent. • Nowadays, the random numbers generated from computers are more complicated and appear to be independent, in that they pass a series of statistical test. • But after all, the random numbers generated from computers are still not purely random (pseudorandom, but too awkward to use this term).
Good Random NumberGeneration • A “good” arithmetic random number generator should posses several properties: • Above all, the numbers produced should appear to be distributed uniformly on [0, 1] and should not exhibit any correlation with each other; otherwise, the simulation’s results may be completely invalid. • From a practical standpoint, we would naturally like the generator to be fast and avoid the need for a lot of storage. • We would like to be able to reproduce a given stream of random numbers exactly, for at least two reasons. First, this can sometimes make debugging or verification f the computer program easier. More important, we might want to use identical random numbers in simulating different systems in order to obtain a more precise comparison.
Good Random NumberGeneration (cont’) • There should be provision in the generator for producing several separate “stream” of random numbers. As we shall see, a stream is simply a subsegment of the numbers produced by the generator, with one stream beginning where the previous stream ends.
Methods for Generation • Inverse Transform Technique (ITT) • Exponential distribution • Uniform distribution • Triangular distribution • Empirical discrete distribution • Empirical continuous distribution • Acceptance-Rejection Technique
Inverse TransformTechnique • The inverse transform technique can be used to sample from the exponential, the Weibull and the uniform distributions, and empirical distribution. • Additionally, it is the underlying principle for sampling from a wide variety of discrete distributions. • A step by step procedure for the inverse transform techniques, illustrated by the exponential distribution, is as follows: Step 1 Compute the cdf of the desired random variable. For the exponential distribution, the cdf is
Inverse TransformTechnique (cont’) Step 2 Set F(x) = R on the range of X. For the exponential distribution, it becomes on the range Since X is a random variable (with the exponential distribution in this case), it follows that is also a random variable, here called R. As will be shown later, R has a uniform distribution over the interval (0, 1).
Inverse TransformTechnique (cont’) Step 3 Solve the equation F(X) = R for X in terms of R. For the exponential distribution, the solution proceeds as follows:
Inverse TransformTechnique (cont’) Step 4 Generate (as needed) uniform random number R1, R2, R3,…, and compute the desired random variable by where One simplification that is usually employed is to replace by to yield which is justified since both and are uniformly distributed on (0, 1).
Uniform Distribution 0 a b • Consider a random variable X that is uniformly distributed on the interval [a, b]. • The pdf of X is given by Step 1 The cdf is given by Step 2 Set F(X) = (X – a) / (b – a) = R Step 3 Solving for X in terms of R yields X = a + (b – a) R
Triangular Distribution • Consider a random variable X which has pdf • This distribution is called a triangular distribution with endpoints (0, 2) and mode at 1. Step 1 The cdf is given by f(x) 1 0 1 2
Empirical DiscreteDistributions 1 p(x) 0 1 0.3 0.2 0.1 0 1 2 3 4 5 6 1 Draw a sample from a 0-1 uniform distribution Convert the 0-1 sample to an equivalent sample from the target population 2
Empirical ContinuousDistribution • If the modeler has been unable to find a theoretical distribution that provides a good model for the input data, then it may be necessary to use the empirical distribution of the data. • Suppose that 100 broken-widget repair times have been collected. The data are summarized in the following table in terms of the number of observations in various interval. For example, there were 31 observations between 0 and 0.5 hour, 10 between 0.5 and 1 hour, and so on.
Empirical ContinuousDistribution (cont’) F(x) 1.0 (2.0, 1.0) R1=0.83 0.8 Cumulative probability (1.5, 0.66) 0.6 0.4 (1.0, 0.41) (0.5, 0.31) 0.2 0 0.5 1.0 1.5 2.0 x X1=1.75 Repair times
Acceptance-Rejection Technique • Suppose that we need to devise a method for generating random variates, X, uniformly distributed between ¼ and 1. Step 1: Generate a random number u ~ U (0, 1) Step 2a: If , accept X = u, then go to step 3. Step 2b: If , reject u, and return to step 1. Step 3: If another uniform random variate on [1/4, 1] is needed, repeat the procedure beginning at step 1. If not, stop.
Tests for Random Numbers • The desirable properties of random numbers • uniformity and independence • To insure that these desirable properties are achieved, a number of tests can be performed. • The tests can be placed in two categories according to the properties of interest. • Test for uniformity • Test for independence
Tests for Random Numbers (cont’) • Frequency test: Uses the chi-square test to compare the distribution of the set of numbers generated to a uniform distribution. • Runs test: Tests the runs up and down or the runs above and below the mean by comparing the actual values to expected values. The statistic for comparison is the chi-square.
Frequency Test • FREQUENCY TEST • Random numbers about from the uniform distribution and several tests have been developed to test for this condition. We will consider the 2 goodness-of-fit test. • The goodness-of-fit test requires that: • 50 observations in total • Expected frequency of at least five in each class • The following table shows the results of placing a total of 100 observations in 10 evenly spaced classes
Frequency Test (cont’) • Frequency Test
Frequency Test (cont’) • The question is, • Do these numbers come from the uniform distribution? • Calculating the 2 statistic from the data using the equation • Gives a value of 2 = 2.40. In testing the null hypothesis that the random numbers come from the uniform distribution, H0 : Ri ~ U [0, 1] • one compares the calculated 2 to the value obtained from the table based on (10-1) = 9 degree of freedom and a = 0.05. • This 2 value is found to be 16.919, which is larger than the calculated 2 value. • Therefore, we accepted the null hypothesis, and find our random number generation acceptable.
Run Up and Down Test • RUNS UP AND DOWN TEST • Numbers can pass a uniformity test and still not be random. • For example, the numbers 0.00, 0.10, 0.20, 0.30, 0.40, …obviously are not random. • The numbers also must be sequentially random to be judged truly random. • A variety of runs test can be used for this purpose. • We will consider a run up and down test.
Run Up and Down Test (cont’) • In a sequence of numbers, if a number is followed by a larger number, this is an upward run. • Likewise, a number followed by a smaller number is a downstream run. • If the numbers are truly random, one would expect to find a certain numbers of runs up and down. • In a sequence of N numbers, one should expect to find runs equal to the following equation:
Run Up and Down Test (cont’) • As an example, assume that the following 40 numbers have been generated. 0.43, 0.32, 0.48, 0.23, 0.90, 0.72, 0.94, 0.11, 0.14, 0.67, 0.61, 0.25, 0.45, 0.56, 0.87, 0.54, 0.01, 0.64, 0.65, 0.32, 0.03, 0.93, 0.08, 0.58, 0.41, 0.32, 0.03, 0.18, 0.90, 0.74, 0.32, 0.75, 0.42, 0.71, 0.66, 0.03, 0.44, 0.99, 0.40, 0.51 – + – + – + – + – + – + – + – + – + – + – + – + – +
Run Up and Down Test (cont’) • One should expect to find 26.33 runs • There were 26 runs in the sequence of numbers. • We consider to accept the generated numbers are random.