0 Simulation Modeling and Analysis: Input Analysis 7 Random Numbers Ref: Law & Kelton, Chapter 7.

Slides:



Advertisements
Similar presentations
Generating Random Numbers
Advertisements

Random Number Generation Graham Netherton Logan Stelly.
Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
Random Number Generation. Random Number Generators Without random numbers, we cannot do Stochastic Simulation Most computer languages have a subroutine,
Probability Distributions CSLU 2850.Lo1 Spring 2008 Cameron McInally Fordham University May contain work from the Creative Commons.
 1  Outline  generation of random variates  convolution  composition  acceptance/rejection  generation of uniform(0, 1) random variates  linear.
Random Numbers. Two Types of Random Numbers 1.True random numbers: True random numbers are generated in non- deterministic ways. They are not predictable.
Random number generation Algorithms and Transforms to Univariate Distributions.
Theoretical Program Checking Greg Bronevetsky. Background The field of Program Checking is about 13 years old. Pioneered by Manuel Blum, Hal Wasserman,
Chapter 7: Statistical Applications in Traffic Engineering
Random Number Generators. Why do we need random variables? random components in simulation → need for a method which generates numbers that are random.
Simulation Where real stuff starts. ToC 1.What, transience, stationarity 2.How, discrete event, recurrence 3.Accuracy of output 4.Monte Carlo 5.Random.
Pseudorandom Number Generators
Statistics.
Random Number Generation
Distinguishing Features of Simulation Time (CLK)  DYNAMIC focused on this aspect during the modeling section of the course Pseudorandom variables (RND)
CSCE Monte Carlo Methods When you can’t do the math, simulate the process with random numbers Numerical integration to get areas/volumes Particle.
1 Simulation Modeling and Analysis Pseudo-Random Numbers.
1 Chapter 7 Generating and Processing Random Signals 第一組 電機四 B 蔡馭理 資工四 B 林宜鴻.
APPENDIX D RANDOM NUMBER GENERATION
Random-Number Generation. 2 Properties of Random Numbers Random Number, R i, must be independently drawn from a uniform distribution with pdf: Two important.
Fall 2011 CSC 446/546 Part 6: Random Number Generation.
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
ETM 607 – Random Number and Random Variates
Inference for regression - Simple linear regression
Section 5.1 What is Probability? 5.1 / 1. Probability Probability is a numerical measurement of likelihood of an event. The probability of any event is.
Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights.
Random Numbers CSE 331 Section 2 James Daly. Randomness Most algorithms we’ve talked about have been deterministic The same inputs always give the same.
0 Simulation Modeling and Analysis: Input Analysis K. Salah 8 Generating Random Variates Ref: Law & Kelton, Chapter 8.
Sullivan – Fundamentals of Statistics – 2 nd Edition – Chapter 11 Section 1 – Slide 1 of 34 Chapter 11 Section 1 Random Variables.
Random-Number Generation Andy Wang CIS Computer Systems Performance Analysis.
1 Statistical Distribution Fitting Dr. Jason Merrick.
CS433 Modeling and Simulation Lecture 15 Random Number Generator Dr. Anis Koubâa 24 May 2009 Al-Imam Mohammad Ibn Saud Islamic University College Computer.
CPSC 531: RN Generation1 CPSC 531:Random-Number Generation Instructor: Anirban Mahanti Office: ICT Class Location:
Chapter 7 Random-Number Generation
CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring.
Tests for Random Numbers Dr. Akram Ibrahim Aly Lecture (9)
Module 1: Statistical Issues in Micro simulation Paul Sousa.
Basic Concepts in Number Theory Background for Random Number Generation 1.For any pair of integers n and m, m  0, there exists a unique pair of integers.
Modeling and Simulation Random Number Generators
Random Number Generators 1. Random number generation is a method of producing a sequence of numbers that lack any discernible pattern. Random Number Generators.
Pseudo-random generators Random Number Generating There are three types of generators table look-up generators hardware generators algorithmic (software)
Monte Carlo Methods.
Experimental Method and Data Process: “Monte Carlo Method” Presentation # 1 Nafisa Tasneem CHEP,KNU
Monte Carlo Methods So far we have discussed Monte Carlo methods based on a uniform distribution of random numbers on the interval [0,1] p(x) = 1 0  x.
APPENDIX D R ANDOM N UMBER G ENERATION Organization of chapter in ISSO* – General description and linear congruential generators Criteria for “good” random.
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
Tests of Random Number Generators
Validating a Random Number Generator Based on: A Test of Randomness Based on the Consecutive Distance Between Random Number Pairs By: Matthew J. Duggan,
Copyright © 2010, 2007, 2004 Pearson Education, Inc. All Rights Reserved. Section 6-4 Sampling Distributions and Estimators.
Section Copyright © 2014, 2012, 2010 Pearson Education, Inc. Lecture Slides Elementary Statistics Twelfth Edition and the Triola Statistics Series.
Copyright © 2010, 2007, 2004 Pearson Education, Inc. Lecture Slides Elementary Statistics Eleventh Edition and the Triola Statistics Series by.
R ANDOM N UMBER G ENERATORS Modeling and Simulation CS
G. Cowan Lectures on Statistical Data Analysis Lecture 5 page 1 Statistical Data Analysis: Lecture 5 1Probability, Bayes’ theorem 2Random variables and.
Chapter 3 Generating Uniform Random Variables. In any kind of simulation, we need data, or we have to produce them. Especially in Monte Marco simulation.
MONTE CARLO METHOD DISCRETE SIMULATION RANDOM NUMBER GENERATION Chapter 3 : Random Number Generation.
Random Numbers All stochastic simulations need to “generate” IID U(0,1) “random numbers” Other random variates coming from other distribution can be generated.
UNIFORM RANDOM NUMBER GENERATION Chapter 7 (first half) The goal is to generate a sequence of The goal is to generate a sequence of Uniformly distributed.
1.  How does the computer generate observations from various distributions specified after input analysis?  There are two main components to the generation.
Inference: Conclusion with Confidence
Random Number Generators
Random-Number Generation
Chapter 7 Random Number Generation
CS 475/575 Slide set 4 M. Overstreet Old Dominion University
Chapter 7 Random-Number Generation
Properties of Random Numbers
Computing and Statistical Data Analysis Stat 3: The Monte Carlo Method
Validating a Random Number Generator
Computer Simulation Techniques Generating Pseudo-Random Numbers
Random Number Generation
Presentation transcript:

0 Simulation Modeling and Analysis: Input Analysis 7 Random Numbers Ref: Law & Kelton, Chapter 7

1 Simulation Modeling and Analysis: Input Analysis Random Numbers Generating random numbers is important for all simulations (and for a number of other applications). We can generate random numbers physically by: –Rolling a (fair) die –Picking a number –Spinning a roulette wheel Generating random numbers numerically, however, is impossible. What we can do is generate a sequence of numbers that appears to be random and has a number of good characteristics.

2 Simulation Modeling and Analysis: Input Analysis Properties of Random Numbers 01 1 x f(x)

3 Simulation Modeling and Analysis: Input Analysis Properties of Random Numbers Random numbers should be uniformly distributed and independent. Uniformity: If we divide (0,1) into n equal intervals, then we expect the number of observations in each sub-interval to be N/n where N is the total number of observations. Independence: The probability of observing a value in any sub-interval is not influenced by any previous value drawn.

4 Simulation Modeling and Analysis: Input Analysis K. Salah Good Properties Since we cannot generate “true” random numbers we want to generate a sequence of numbers with the following properties: Speed – the algorithm must be quick. Portable – easily moved between different hardware and software. Long cycle (period) – the sequence generated should repeat itself Repeatability – it must be possible to recreate the sequence of numbers (typically for different scenarios). Statistical properties – the generated numbers must be able to pass tests for uniformity and independence.

5 Simulation Modeling and Analysis: Input Analysis K. Salah Linear Congruential Generators The mechanism for generating a random number stream is fairly simple. mod is the modulo operator (i.e. 11 mod 3 = 2) We generate a stream of numbers [0,m) And we convert these to a number [0,1):

6 Simulation Modeling and Analysis: Input Analysis K. Salah Example 1 X 0 = 27 a = 17 c = 43 m = 100 X i+1 = (aX i +c) mod m = (17X i +43) mod 100 X 1 = (17* ) mod 100 = 502 mod 100 = 2 R 1 = X 1 /m = 2/100 =.02 X 2 = (17*2 + 43) mod 100 = 77 mod 100 = 77 R 2 = X 2 /m = 77/100 =.77

7 Simulation Modeling and Analysis: Input Analysis K. Salah Some Notes on LCGs X 0 is called the “seed” If c <> 0, this is called a mixed congruential generator. If c = 0, this is called a multiplicative congruential generator.

8 Simulation Modeling and Analysis: Input Analysis K. Salah How Good are LCGs? In our example R i is an element of {1/m, 2/m, …, m-1/m} Thus, we cannot generate all numbers (0,1). Furthermore, the period of our generator is short. (At best we could get a maximum period of 99 before repeating). If, however, we select very large values of m, we can get a good approximation to U(0,1). Furthermore, if m is large ( or 2 48 ) we can (hopefully) get a period in the range of 2*10 9. However, the performance of LCGs is highly dependent on good choices of a, c, and m. There have been several notoriously bad implementations of LCGs.

9 Simulation Modeling and Analysis: Input Analysis K. Salah Periods If m = 2 b (typically or 2 48 depending on implementation). If a = 1+4k, where k is a positive integer. If c <> 0 and is relatively prime to m (i.e. largest common denominator is 1 Period = 2 b = m If m = 2 b (typically or 2 48 depending on implementation). a = 3+8k OR 5 +8k, where k is a positive integer. c = 0 & X 0 is an odd number Period = 2 b-2 = m/4 It is easier to do modulus operations with m = 2 b, so in general, we conclude that LCGs offer the potential for longer periods than do MCGs. If m is prime. If a has the property that the smallest integer k such that a k -1 is divisible by m is k= m-1. c = 0 Period = m-1

10 Simulation Modeling and Analysis: Input Analysis K. Salah Example Assume we select m = 2 6 =64, c=0, a= 13 (of form 5+8k). The maximum period should be m/4 = 16, depending, of course, on our choice of X 0. Note the short period (16). The choice of seed does affect the period! Look at the gaps in the sequence even for a long period. If we look at X 0 = 1 we see the sequence comes from the set {1, 5, 9, …61}. There are large gaps in our sequence!

11 Simulation Modeling and Analysis: Input Analysis K. Salah Testing Uniformity: Chi-Squared Divide U(0,1) into a number of equal sub-intervals. Generate a number of samples on U(0,1). Count the number of observations in the sub-interval. Check this against the expected number of observations. For example, assume: –X 0 = 1 –a = 11 –c = 3 –m = 101 Assume 10 sub-intervals and 1000 observations. Assuming an α of 0.05, the critical value for X.95, 9 is Thus our generator passes a uniformity test.

12 Simulation Modeling and Analysis: Input Analysis K. Salah Testing Independence: Runs Test* I have produced the 1 st 10 random numbers for our example generator. In the 4 th column, a 1 indicates that the number is followed by a higher number; a –1 indicates that the following number is lower. A series of “1”s or “-1”s is called a run. * From Banks and Carson If a is the total number of runs in a random sequence then:

13 Simulation Modeling and Analysis: Input Analysis K. Salah Testing Independence: Runs Test* * From Banks and Carson If a is the total number of runs in a random sequence then: where N is the number of observations (1000 in our case). Then: In our example: Expected runs (μ a ) = (2(1000)-1)/ σ a 2 = (16(1000)-29)/90 = The actual number of runs was observed to be 620.

14 Simulation Modeling and Analysis: Input Analysis K. Salah Testing Independence: Runs Test* H 0 : The generator produces independent samples. H 1 : The generator does not produce independent samples. If -z α/2 <= Z 0 <= z α/2 where α is the significance level, we will accept H 0. The critical value for z.025 is Thus, we reject H 0 and assume that our sample is not independent. NB: Other types of runs tests are available.

15 Simulation Modeling and Analysis: Input Analysis K. Salah Testing Autocorrelation Test the correlation between the i th and the i+j th random numbers. For example if j = 2, we would check the correlation between the 1 st and 3 rd numbers, the 2 nd and 4 th, … j is sometimes called the lag. ρ j is called the autocorrelation

16 Simulation Modeling and Analysis: Input Analysis K. Salah Autocorrelation Example Consider our example And our sample with a lag of 2 Based on the 1 st 100 random numbers: E(Ri) = 0.499; E(Ri+2) = 0.506; E(Ri, Ri+2) = 0.25 V(Ri) = 0.084; V(Ri+2) = C(Ri,Ri+2) =.25 -(.499)(.506) = ρ 2 = * *A approximate calculation of rho and significance test for autocorrelation is found in L&K in Section 7.4.1

17 Simulation Modeling and Analysis: Input Analysis K. Salah Lattice Plots RNG tend to produce numbers that fall on hyperplanes. If the number of hyperplanes is small, or there are large gaps between the hyperplanes, then the RNG is likely to be poor. Plots of (Ri, Ri+1) produce something called a lattice plot. Using our example generator, we see that the resulting numbers do have a number of large gaps.

18 Simulation Modeling and Analysis: Input Analysis K. Salah Lattice Plot: Excel’s RNG