* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Random numbers in simulation
Survey
Document related concepts
Approximations of π wikipedia , lookup
Location arithmetic wikipedia , lookup
Mathematics of radio engineering wikipedia , lookup
Infinitesimal wikipedia , lookup
Georg Cantor's first set theory article wikipedia , lookup
Positional notation wikipedia , lookup
List of prime numbers wikipedia , lookup
Real number wikipedia , lookup
Large numbers wikipedia , lookup
Karhunen–Loève theorem wikipedia , lookup
Infinite monkey theorem wikipedia , lookup
Quadratic reciprocity wikipedia , lookup
Central limit theorem wikipedia , lookup
Proofs of Fermat's little theorem wikipedia , lookup
Collatz conjecture wikipedia , lookup
Transcript
Random Number Generators & Simulation. This is a story of a “multibillion” dollar industry involving considerable research and sophisticated high speed computers. We’d only look at it with squinting eyes from afar. A uniformly distributed pseudo random number generator (RNG) might be designed as follows: 1. Initialize seed x0 S 2. Obtain seed xn1 (axn b) mod M The set { x1, x2 ,...} is a RN set. Example. S 2137 , a 2701, b 31951, M 112357 Some results 73781 105471 16269 42933 89077 72591 1653 2424 25097 67677 84057 108768 91359 56638 18530 82616 19980 66571 33461 75084 25286 16381 84127 41560 37277 62469 22689 764 93312 36765 69022 29450 … … 73124 40868 45256 506 80375 73089 50912 10628 60110 27645 81845 23991 50373 51102 34091 20295 87144 33196 96048 ■ n xn M ■ Therefore, n U n xn (0.0,1.0) M The following shows these random numbers U bounded as 0.0 U 1.0 . 0.656666 0.144797 0.792803 0.014712 0.223368 0.748124 0.813114 0.164921 0.177826 0.29781 0.225051 0.938713 0.382112 0.646075 0.021574 0.602339 0.968057 0.504090 0.735299 0.592495 0.668263 0.145794 0.748747 0.369892 0.331773 0.555987 0.201937 0.006800 0.830496 0.327216 0.61431 0.262111 0.650818 0.363733 0.402788 0.004504 0.715354 0.650507 0.453127 0.094591 0.534991 0.246046 0.728437 0.213525 0.448330 0.454818 0.303417 0.18063 0.775599 0.295451 0.854847 ■ The maximum cycle length = N ■ The most tested RNG is the one with a 16807 , b = 0 and N 231 1 2147483647. ■ Ideally, a and N should be primes. These random numbers U1,U 2 ,U3 ,... are “claimed” to be statistically independent and identically (uniformly) distributed over the interval (0,1). If they are not ‘random’ with the above properties, we seek a way to generate such random numbers. Several approaches: A. Using transcendental numbers like , e . Take successive digits of a transcendental numbers to generate U i . e.g. 3. 14159265358979323846264338327950288 … We can construct 8-digit U numbers as U1 0.14159265 U 2 0.35897932 U3 0.38462643 U 4 0.38327950 … Generation process is long and time consuming. Storage problem crops up if we need to generate all at one go and save them. A slow I/O will tie up CPU considerably. So, a table of RN is not a good idea. B. The Mid-square method as used in hashing. Square a 2n -digit number to produce a 4n digit next number. Take the middle 2n digits to generate next U number. Not a preferred technique. The cycle length may be rather short unless one starts with a complex sequence of 2n -digits. Again, time consuming. C. Additive congruence. Specify a set of numbers at the outset: x0 , x1, x2 ,..., xk 1. Then for n k , k 1,... Obtain xn ( xn1 xn k ) mod M for some M . k has to be large, otherwise correlated sets will be generated. k 2 corresponds to Fibonacci series method. D. Linear recurrences. Similar to C. Specify a set of random numbers at the outset: x0 , x1, x2 ,..., xk 1. Then for n k , k 1,... obtain xn (a1xn1 a2 xn 2 ... ak xn k c) mod m for some a1, a2 ,.., ak , c, m. E. Most frequently used RNG. xn1 (axn c) mod m . Special case of D if k 1. Notice that we can define a multiplicative congruential design in the following sense: xn x n mod m x.xn1 mod m . This is a special case of generator E with c 0. F. Composite Generator by Fatin Sezgin (1991) for 16bit machines. Generate wi 44wi 1 mod P1 yi 45 yi 1 mod P2 zi 41zi 1 mod P3 With w0 y0 z0 1, and P1 2039 , P2 2027 , and P3 2003 Then U i wi y zi i P1 P1P2 P1P2 P2 G. A “Trusty” Random Number Generator. W. J. J. Rey (1990) 2 and xi FR( xi 1 (i xi 1) sin(i)) . 1 5 The only problem is the computation of sin(i ) for large i . FR(.) picks the fractional part. Define x0 Test of randomness: ■ Suppose a RNG produces integer random numbers bounded as 1 Q . If the total number of random numbers produced is M , the expected number of M occurrence of n for any 1 n Q is . Q 1 ■ The pair ( xi , xk ) i, k [1, M ] would be uniformly distributed scatter-points over the plane. ■ Gap Test. Choose 0.0 1.0. Consider a sequence of RN given as {U1,U 2 ,..., }. For each U i define i such that i 1 if Ui 0, otherwise Let p . If the numbers are random, probability that k 0s will occur after a 1 and before the next 1 in the sequence would be given by a geometric distribution pk p(1 p) k for k 0,1,2,... ■ Poker Test. Given a set {U i } map it to a set of integers as follows: f : Ui Qi {1,2,3,...,10} such as if 0.0 Ui 0.1 then Qi 1 if 0.1 Ui 0.2 then Qi 2 … If 0.4 Ui 0.5 then Qi 5 … If 0.9 Ui 1.0 then Qi 10 Thus, the new set of random integers Q would be all from 1 to 10. Case I: Take any five consecutive Qs. For each set determine the category it belongs: ♦ All same number: AAAAA ♦ Four of a kind + : AAAAB ♦ Three of a kind and a pair: AAABB ♦ Three of a kind: AAABC ♦Two pairs: AABBC ♦ A pair: AABCD ♦ All distinct cards: ABCDE For every five consecutive cards, we’d have exactly one of the possibilities. And their probabilities should be: p ( AAAAA ) 0.001, p ( AAAAB ) 0.0045 p ( AAABB ) 0.009, p ( AAABC ) 0.0720 p ( AABBC ) 0.108, p ( AABCD ) 0.5040 p ( ABCDE ) 0.3024 Case II: This time we test how many different cards appear in each 5 selected? Probabilities should be: p (1 different) 0.0001 p (2 different) 0.135 p (3 different) 0.180 p (4 different) 0.504 p (5 different) 0.3024 Other cases may similarly be constructed. Brownian Motion. Random movement of a particle suspended on a liquid or a gas. Try this applet to see what is involved. http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=24 Movement of a neutron inside a neutron shield once released by a neutron gun. http://www.doc.ic.ac.uk/~nd/surprise_95/journal/vol4/ykl/report.html There are other applications. Monte Carlo Integration scheme. Suppose, we are asked to find the integration of the following function f (x) where f (x) is difficult to compute analytically. f (x) a 0 a We want to compute y f ( x ) dx . One way to do it is to 0 enclose it in a rectangular area (whose area we know), and then randomly throw “darts” onto this area. From the total number of throws captured within the function, we could compute the area underneath the function and the x-axis. 0 a In this way, we can approximately compute the areas and volumes of computationally challenging geometrical objects.