17
Generating Continuous Generating Continuous Random Variables Random Variables som som e e

Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Generating ContinuousGenerating Continuous

Random VariablesRandom Variables

somsomee

Page 2: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Quasi-random numbersQuasi-random numbers So far, we learned about pseudo-random sequences So far, we learned about pseudo-random sequences

and a common method for generating them. These and a common method for generating them. These will be the inputs to our Monte Carlo processes. will be the inputs to our Monte Carlo processes.

Alternate source: Quasi-random numbersAlternate source: Quasi-random numbers– They are not really random, so they have to be used very They are not really random, so they have to be used very

carefully. carefully. – They are not used very much for Monte Carlo methods in They are not used very much for Monte Carlo methods in

radiation transport. radiation transport.

But, because they are of such importance to the But, because they are of such importance to the general field of Monte Carlo (i.e., beyond transport general field of Monte Carlo (i.e., beyond transport methods), you should have a taste of what they are, methods), you should have a taste of what they are, how to get and use them.how to get and use them.

Page 3: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Quasi-random numbers (2)Quasi-random numbers (2) "Quasi"-random numbers are not random at all; "Quasi"-random numbers are not random at all;

they are a deterministic, equal-division, sequence they are a deterministic, equal-division, sequence that are "ordered" in such a way that they can be that are "ordered" in such a way that they can be used by Monte Carlo methods. used by Monte Carlo methods.

The easiest to generate are Halton sequences, The easiest to generate are Halton sequences, which are found by "reflecting" the digits of prime which are found by "reflecting" the digits of prime base counting integers about their radix point. base counting integers about their radix point.

– You pick a prime number base.You pick a prime number base.

– Count in that base.Count in that base.

– Reflect the numberReflect the number

– Interpret as base 10. Interpret as base 10.

Page 4: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Quasi-random numbers (3)Quasi-random numbers (3) After M=BaseAfter M=BaseNN-1 numbers in the sequence, the -1 numbers in the sequence, the

sequence consists of the equally spaced fractions sequence consists of the equally spaced fractions (i/(M+1), i=1,2,3,...M). (i/(M+1), i=1,2,3,...M).

Therefore, the sequence is actually deterministic, Therefore, the sequence is actually deterministic, not stochastic. (Like a numerical method.)not stochastic. (Like a numerical method.)

The beauty of the sequence is that the re-ordering The beauty of the sequence is that the re-ordering results in the an even coverage of the domain (0,1) results in the an even coverage of the domain (0,1) even if you stop in the middle.even if you stop in the middle.

Because you need ALL of the numbers in the Because you need ALL of the numbers in the sequence to cover the (0,1) range (which is not true sequence to cover the (0,1) range (which is not true of the pseudo-random sequence), it is important that of the pseudo-random sequence), it is important that all of the numbers of the sequence be used on the all of the numbers of the sequence be used on the SAME decision. SAME decision.

Page 5: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

For a Monte Carlo process that has more than one For a Monte Carlo process that has more than one decision, a different sequence must be used for decision, a different sequence must be used for each decision. (This is why we don’t use them.)each decision. (This is why we don’t use them.)

The most common way this situation is handled The most common way this situation is handled is to use prime numbers in order—2,5,7,11,etc.—is to use prime numbers in order—2,5,7,11,etc.—for decisions. (“Halton” sequence, after UNC for decisions. (“Halton” sequence, after UNC professor)professor)

Asymptotic estimate of error is Asymptotic estimate of error is which means closer to ~ 1/Nwhich means closer to ~ 1/N

The resulting standard deviations calculated and The resulting standard deviations calculated and printed by standard MC codes are NOT accurate:printed by standard MC codes are NOT accurate:

– Get estimates by “oversetting”Get estimates by “oversetting”

N

N d 110 )(log

Page 6: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Generating ContinuousGenerating Continuous

Random VariablesRandom Variables

somsomee

Page 7: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Generating Continuous Random Generating Continuous Random VariablesVariables

Suppose that X is a continuous random variable with cdf F(x).

Furthermore, suppose that you can invert F.

Note that if U~unif(0,1), the random variable

F-

1(U)

has the same distribution as X!

Page 8: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Generating Continuous Random Generating Continuous Random VariablesVariables

Example: To generate exponential rate rv’s:

0x ,e f(x) x- pdf:

cdf: 0x ,e-1 du e F(x) x-x

0

u-

x)-ln(1 1

- (x)F 1-

Now plug in

a uniform!

Page 9: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Generating Continuous Random Generating Continuous Random VariablesVariables

The standard normal distribution:

x- ,e 2

1 f(x)

2x 21

-

There is no closed form expression for the cdf!

normal

Page 10: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Generating Continuous Random Generating Continuous Random VariablesVariables

The Box-Muller Transformation:

Let U1 and U2 be independent unif(0,1) rv’s.

normal

)U cos(2 U ln 2- X 211

Then

is normally distributed with mean 0 and variance 1.So is )U sin(2 U ln 2- X 212

and X1 and X2 are independent!

Page 11: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Generating Continuous Random Generating Continuous Random VariablesVariables

Acceptance/Rejection Method:

• want to simulate a rv X with pdf f

x f(x) g(x)

• need to find another function g so that

• normalize g to a pdf g(x) c1

h(x)

where dx g(x) c

Page 12: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

• want to simulate a rv X with pdf f

x f(x) g(x)

• need to find another function g so that

• normalize g to a pdf g(x) c1

h(x)

where dx g(x) c

• generate Y with pdf h

• generate U~unif(0,1) (indep of Y)

• if U<f(Y)/g(Y), “accept” Y, set X=Y

• otherwise, “reject” Y, return to

Page 13: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Proof: (discrete case)

1n

th try n on happens accept first and xXP x)P(X

1nnn

1-n

1-n1-n1-n1-n

1

1111 g(x)

f(x)Ux, Y,

)g(y)f(y

U ,yY , ,)g(y)f(y

U ,yYP

1nnn g(x)

f(x)Ux,YP ~sx' no~P

1n g(x)f(x)

Ux,YP ~sx' no~P

Page 14: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Proof: (continued)

1n

~)sx' noP(~ g(x)f(x)

Ux,YP

sx' no

g(x)f(x)

Ux,YP

sx' no g(x)f(x)

g(x)

sx' no f(x)

Page 15: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Proof: (continued)

sx' no f(x) x)P(X

So, using this algorithm,

Sum both sides over x:

xx

f(x) sx' no x)P(X

1 sx' no 1

f(x) x)P(X 1 sx' no

What we wanted!

Page 16: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Acceptance/Rejection Method Example:

Example:

Target Density: 0x e 9x f(x) -3x ,

-2x2 2e (x)f

-2xce g(x)Try

works

-19ec-2x-1e 9e g(x)

Page 17: Generating Continuous Random Variables some. Quasi-random numbers So far, we learned about pseudo-random sequences and a common method for generating

Acceptance/Rejection Method Example:

RESULTS: 100,000 draws

Target Density: 0x e 9x f(x) -3x ,