Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Different PRNGs in Matlab The latest version of Matlab has many different methods for creating pseudo-random uniform (0, 1) sequences. You can create multiple sequences
Different PRNGs in Matlab The latest version of Matlab has many different methods for creating pseudo-random uniform (0, 1) sequences. You can create multiple sequences (often called "streams") using different seeds or different methods and compare them. Here's how to create 3 different streams using 3 different methods. methodlRandStream (mcg16807') method2RandSt ream(swb2712') method3-RandStream ('mt 19937ar Method 1 was Matlab's default before 1995. It is a LCG with m 231 - 1 and a -75. It is too simple for modern applications. Method 2 was Matlab's default from 1995 to 2006. It is not a LCG and it is awful. I once spent many hours debugging before I realized that the problem was with this PRNG. Method 3 is the Mersenne Twister, which is currently a very popular PRNG and which is Matlab's default since 2007. Assuming you have a recent version of Matlab, then if you just use rand in Matlab, then you will get method 3 without having to specify anything. To generate an r c array of pseudo-random numbers using one of these streams and store it in the matrix U, type U-rand (method?, r,c); where you replace the ? with one of the numbers 1,2, or 3 to get the desired method. [On later homework sets, when we are finished exploring PRNGs and just want the best PRNG, you can use U-rand (r, c); without specifying a method. This uses the default method 3, in this case_which seems to be the best of Matlab's choices.] Demo Convince yourself that the PRNGs are deterministic. For example, create two copies of method 3, say method3a = Randstream ( ,mt 1 9937ar'); and method3b RandStream('mt 1 9 937ar' ); Now rand (method3a) and rand (method3b) should behave identically. Call them repeatedly to verify. Four different PRNGs A. The LCG that you created in problem 1 [after converting to (0, 1) by dividing each Rn by m] B. Matlab method 1 above. C. Matlab method 2 above. D. Matlab method 3 above. The law of large numbers Recall that the law of large numbers (LLN) states that as n oo for any iid sequence X, X1, X2, . . . for which Eh(X)] exists. So if a pseudo-random sequence U1, U2,... , Un behaves like an iid Uniform(0, 1) sequence, then we better have for large n where U is Uniform(0, 1) 2. For each of the four PRNGs (A-D) defined above, let Ui,... , U10000 be a sequence from the PRNG. Plot n -i Uk versus n and also 1 -i UR versus n for n-1, . . . . 10000, what would you expect these sums to converge to as n -oo for a truly iid sequence? Interpret your results. Correlation between successive pairs For a pair of random variables (X, Y) the correlation coefficient (p) is defined as If X and Y are independent, then the numerator factors into a product of expectations, each of which i zero, so = 0. If (X1, Y), (X2, Y2), . . . , (Xn, Yn) is a sequence of pairs, then we can compute the sample correlation coefficient (P via where X =-k=i Xk and = n i Yk. hen (again by the LLN) we have p -p as n -0o. So if a pseudo-random sequence U1, U2,... behaves like an iid sequence, then the successive pairs (U1, U2), (U3, U4), , (U2n-1, U2n) should be behave like independent pairs, which means the sample correlation coefficient between U2k-1 and U2k should be close to zero for large If X, X1 , X2, . . . are iid and Y. Y , Y2, . .. are id, t Different PRNGs in Matlab The latest version of Matlab has many different methods for creating pseudo-random uniform (0, 1) sequences. You can create multiple sequences (often called "streams") using different seeds or different methods and compare them. Here's how to create 3 different streams using 3 different methods. methodlRandStream (mcg16807') method2RandSt ream(swb2712') method3-RandStream ('mt 19937ar Method 1 was Matlab's default before 1995. It is a LCG with m 231 - 1 and a -75. It is too simple for modern applications. Method 2 was Matlab's default from 1995 to 2006. It is not a LCG and it is awful. I once spent many hours debugging before I realized that the problem was with this PRNG. Method 3 is the Mersenne Twister, which is currently a very popular PRNG and which is Matlab's default since 2007. Assuming you have a recent version of Matlab, then if you just use rand in Matlab, then you will get method 3 without having to specify anything. To generate an r c array of pseudo-random numbers using one of these streams and store it in the matrix U, type U-rand (method?, r,c); where you replace the ? with one of the numbers 1,2, or 3 to get the desired method. [On later homework sets, when we are finished exploring PRNGs and just want the best PRNG, you can use U-rand (r, c); without specifying a method. This uses the default method 3, in this case_which seems to be the best of Matlab's choices.] Demo Convince yourself that the PRNGs are deterministic. For example, create two copies of method 3, say method3a = Randstream ( ,mt 1 9937ar'); and method3b RandStream('mt 1 9 937ar' ); Now rand (method3a) and rand (method3b) should behave identically. Call them repeatedly to verify. Four different PRNGs A. The LCG that you created in problem 1 [after converting to (0, 1) by dividing each Rn by m] B. Matlab method 1 above. C. Matlab method 2 above. D. Matlab method 3 above. The law of large numbers Recall that the law of large numbers (LLN) states that as n oo for any iid sequence X, X1, X2, . . . for which Eh(X)] exists. So if a pseudo-random sequence U1, U2,... , Un behaves like an iid Uniform(0, 1) sequence, then we better have for large n where U is Uniform(0, 1) 2. For each of the four PRNGs (A-D) defined above, let Ui,... , U10000 be a sequence from the PRNG. Plot n -i Uk versus n and also 1 -i UR versus n for n-1, . . . . 10000, what would you expect these sums to converge to as n -oo for a truly iid sequence? Interpret your results. Correlation between successive pairs For a pair of random variables (X, Y) the correlation coefficient (p) is defined as If X and Y are independent, then the numerator factors into a product of expectations, each of which i zero, so = 0. If (X1, Y), (X2, Y2), . . . , (Xn, Yn) is a sequence of pairs, then we can compute the sample correlation coefficient (P via where X =-k=i Xk and = n i Yk. hen (again by the LLN) we have p -p as n -0o. So if a pseudo-random sequence U1, U2,... behaves like an iid sequence, then the successive pairs (U1, U2), (U3, U4), , (U2n-1, U2n) should be behave like independent pairs, which means the sample correlation coefficient between U2k-1 and U2k should be close to zero for large If X, X1 , X2, . . . are iid and Y. Y , Y2, . .. are id, t
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started