32
1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing from distributions Discrete Discrete Continuous: Direct Continuous: Direct Continuous: Rejection Continuous: Rejection Probability mixing Probability mixing Metropolis method Metropolis method Stratified sampling Stratified sampling

1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

Embed Size (px)

Citation preview

Page 1: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

1

Lesson 3: Choosing from distributionsLesson 3: Choosing from distributions

• Theory: LLN and Central Limit TheoremTheory: LLN and Central Limit Theorem• Choosing from distributionsChoosing from distributions

• DiscreteDiscrete• Continuous: DirectContinuous: Direct• Continuous: RejectionContinuous: Rejection• Probability mixingProbability mixing• Metropolis methodMetropolis method• Stratified samplingStratified sampling

Page 2: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

2

Law of Large NumbersLaw of Large Numbers

• Theoretical basis of Monte Carlo is the Law of Large Theoretical basis of Monte Carlo is the Law of Large NumbersNumbers

• LLN: The weighted average value of the function, :LLN: The weighted average value of the function, :

• This relates the result of a This relates the result of a continuouscontinuous integration integration with the result of a with the result of a discretediscrete sampling. All MC comes sampling. All MC comes from this.from this.

f

xx

N

xfdxxxff

i

N

ii

N

b

a

usingchosen where

,lim 1

Page 3: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

3

Law of Large Numbers (2)Law of Large Numbers (2)

• At first glance, this looks like this would be useful At first glance, this looks like this would be useful for mathematicians trying to estimate integrals, for mathematicians trying to estimate integrals, but not particularly useful to us—We are not but not particularly useful to us—We are not performing integrations we are simulating physical performing integrations we are simulating physical phenomenaphenomena

• This attitude indicates that you are just not This attitude indicates that you are just not thinking abstractly enough—All Monte Carlo thinking abstractly enough—All Monte Carlo processes are (once you dig down) integrations processes are (once you dig down) integrations over a domain of “all possible outcomes”over a domain of “all possible outcomes”

• Our values of “x” are over all possible lives that a Our values of “x” are over all possible lives that a particle might leadparticle might lead

Page 4: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

4

Central limit theorem Central limit theorem • The second most important (i.e., useful) theoretical result for The second most important (i.e., useful) theoretical result for

Monte Carlo is the Central Limit TheoremMonte Carlo is the Central Limit Theorem• CLT: The sum of a sufficiently large number of independent CLT: The sum of a sufficiently large number of independent

identically distributed random variables (i.i.d.) becomes normally identically distributed random variables (i.i.d.) becomes normally distributed as N increasesdistributed as N increases

• This is useful for us because we can draw useful conclusions from This is useful for us because we can draw useful conclusions from the results from a large number of samples (e.g., 68.7% within one the results from a large number of samples (e.g., 68.7% within one standard deviation, etc.)standard deviation, etc.)

• This relates the result of a This relates the result of a continuouscontinuous integration with the result of integration with the result of a a discretediscrete sampling. All MC comes from this. sampling. All MC comes from this.

Page 5: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

5

Overview of pdf and cdfOverview of pdf and cdf

• Basic definition of probability density Basic definition of probability density function (p.d.f.):function (p.d.f.):

• And its integral, the cumulative distribution And its integral, the cumulative distribution function (c.d.f.):function (c.d.f.):

})d,(in lies Pr{)( xxxxdxx i

} Pr{')'( xxdxxx i

x

Page 6: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

6

Overview of pdf and cdf (2)Overview of pdf and cdf (2)

• Corollaries of these definitions:Corollaries of these definitions:

000.1')'(

} Pr{')'(

} Pr{')'(

dxx

bxadxxab

xxdxxx

i

b

a

i

x

Page 7: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

7

Mapping ->x using p(x)Mapping ->x using p(x)

• Our basic technique is to use a unique Our basic technique is to use a unique y->xy->x• y=y= from (0,1) and x from (a,b) from (0,1) and x from (a,b)• We are going to use the mapping backwardsWe are going to use the mapping backwards

Page 8: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

8

Mapping (2)Mapping (2)

Note that:Note that:• (a)=0(a)=0• (b)=1(b)=1• Function is non-decreasing over domain (a,b)Function is non-decreasing over domain (a,b)

Our problem reduces to:Our problem reduces to:• Finding Finding (x)(x)• Inverting to get x(Inverting to get x(), a formula for turning pseudo-), a formula for turning pseudo-

random numbers into numbers distributed according random numbers into numbers distributed according to desired to desired (x)(x)

Page 9: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

9

Mapping (3)Mapping (3)

• We must have:We must have:

(x)xdxxx

dxxax

xdx

xd

dxxd

xxxx

x

a

x

a

of C.D.F the,)(')'()(

')'()()(

)()(

)(

})d,(in lies Pr{})d,(in lies Pr{

Page 10: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

10

Resulting general procedureResulting general procedure

• Form CDF:Form CDF:

• Set equal to pseudo-random number:Set equal to pseudo-random number:

• Invert to get formula that translates from Invert to get formula that translates from to x: to x:

x

a

dxxx ')'()(

)(x

)(1 x

Page 11: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

11

Uniform distributionUniform distribution

• For our first distribution, pick x uniformly in range For our first distribution, pick x uniformly in range (a,b):(a,b):

• Step 1: Form CDF.Step 1: Form CDF.

abdxdxx

xx

baxx

b

a

b

a

1

1

1

)(~

)(~)(

, ,1)(~

ab

axdxab

dxxxx

a

x

a

'1

')'()(

Page 12: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

12

Uniform distribution (2)Uniform distribution (2)

• Step 2: Set pseudo-random number to CDF:Step 2: Set pseudo-random number to CDF:

• Step 3: Invert to get Step 3: Invert to get x(x())::

• Example: Choose Example: Choose uniformly in (-1,1): uniformly in (-1,1):

ab

ax

)( abax

12))1(1(1

Page 13: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

13

Discrete distributionDiscrete distribution

• For a discrete distribution, we have N For a discrete distribution, we have N choices of state choices of state ii, each with probability , , each with probability , so:so:

• Step 1: Form CDF:Step 1: Form CDF:

ip

)()()()( 2211 NN xpxxpxpx

N

iNi

x

xx

xxx

xxx

xx

dxxx

1

3221

211

1

,1

,

,

,0

')'()(

Page 14: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

14

Discrete distribution (2)Discrete distribution (2)

• Step 2: Set pseudo-random number to Step 2: Set pseudo-random number to CDF:CDF:

• Step 3: Invert to get Step 3: Invert to get x(x())::)(x

1 if ,

if ,

if ,

0 if ,

1

1

1

1

1

2112

11

1

ξx

ξx

x

x

x

N-

iiN

n

ii

n-

iin

Page 15: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

15

Discrete distribution (3)Discrete distribution (3)

• Example: Choose among 3 states with Example: Choose among 3 states with relative probabilities of 4, 5, and 6.relative probabilities of 4, 5, and 6.

Page 16: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

16

Continuous distribution: DirectContinuous distribution: Direct

• This fits the “pure” form developed before.This fits the “pure” form developed before.• Form CDF:Form CDF:

• Set equal to pseudo-random number:Set equal to pseudo-random number:

• Invert to get formula that translates from Invert to get formula that translates from to x: to x:

x

a

dxxx ')'()(

)(x

)(1 x

Page 17: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

17

Continuous: Direct (2)Continuous: Direct (2)

• Example: Pick x from:Example: Pick x from:

xex x 0,)(~

Page 18: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

18

Testing your selectionTesting your selection• There are two simple ways to check a routine that is used to choose from a There are two simple ways to check a routine that is used to choose from a

give distribution: binning or momentsgive distribution: binning or moments• Binning involves dividing the domain (or part of it) into (usually equal-sized) Binning involves dividing the domain (or part of it) into (usually equal-sized)

regions and then counting what fraction of chosen values fall in the region.regions and then counting what fraction of chosen values fall in the region.• The expected answer for a bin that goes from a to b isThe expected answer for a bin that goes from a to b is

• This will be approximately equal to (and close enough for our purposes) the This will be approximately equal to (and close enough for our purposes) the midpoint value times the width:midpoint value times the width:

• The text notes have a Java routine that will perform a bin testingThe text notes have a Java routine that will perform a bin testing• KEY to algorithm: Bin that x is in:(Integer part of (x-a)/(b-a)*N) (maybe +1)KEY to algorithm: Bin that x is in:(Integer part of (x-a)/(b-a)*N) (maybe +1)

Fraction in (a,b) ( ') 'b

i

a

x dx

Fraction in (a,b) ( )( )2i

a bb a

Page 19: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

19

Continuous: RejectionContinuous: Rejection

• Basis of rejection approach:Basis of rejection approach:

Usual procedure (using a flat x distribution):Usual procedure (using a flat x distribution):

1.1. Find a valueFind a value

2.2. ChooseChoose

3.3. Keep iffKeep iff

Otherwise, return to 1. Otherwise, return to 1.

chosen} kept chosen}

kept} ANDchosen

xxx

x

Pr{Pr{

Pr{

max ( ) for all x x

ab

xa,bxi

1)( using

max~

)(

ixix

Page 20: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

20

Continuous: Rejection (3)Continuous: Rejection (3)

• Example: Use rejection to pick x from:Example: Use rejection to pick x from:

20 ,)(~ xex x

Page 21: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

21

Basic idea of probability mixingBasic idea of probability mixing

• Situations arise in which you have multiple Situations arise in which you have multiple distributions involved in a single decision:distributions involved in a single decision:

p.d.f. valida is theofeach and

1

where

)(

N

1i

2211

x

p

xpxpxpx

i

i

NN

Page 22: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

22

Probability mixing procedureProbability mixing procedure

• Real problems do not present themselves Real problems do not present themselves so cleanly and you have to figure it out:so cleanly and you have to figure it out:

)(

')'(~

)(~

')'(~

')'(~

')'(~

)(~)(

,),(~)(~)(~)(~

1

1

21

xp

dxx

x

dxx

dxx

dxx

xx

baxxxxx

i

N

ii

b

a

i

iN

ib

a

b

a

i

b

a

N

Page 23: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

23

Probability mixing procedure (2)Probability mixing procedure (2)

Procedure:Procedure:

1.1. Form and normalize theForm and normalize the

2.2. Choose the distribution Choose the distribution ii using these using these

N

jj

ii

b

a

ii

p

pp

dxxp

1

~

~

')'(~~

ip

ip

Page 24: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

24

Probability mixing procedure (3)Probability mixing procedure (3)

Procedure:Procedure:

3.3. Form the p.d.f. for distribution Form the p.d.f. for distribution ii::

4.4. Choose usingChoose using

i

ib

a

i

ii p

x

dxx

xx ~

)(~

')'(~

)(~)(

ix )(xi

Page 25: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

25

Probability mixing procedure (3)Probability mixing procedure (3)

Example:Use probability mixing to select x from:Example:Use probability mixing to select x from:

2,1,)(~ 2 xexx x

Page 26: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

26

MetropolisMetropolis

• This is a very non-intuitive procedure that falls under the category of Markov chain MC

• It will ULTIMATELY deliver a consistent series of x’s distributed according to a desired functional form (which does NOT have to be normalized nor do you need to know a maximum value)

• It has many advantages for certain physical problems in which the relative probability of a chosen point can be determined even if a closed form of the PDF is not available

• The main disadvantage is that it is very hard to tell when the procedure has “settled in” to the point that the stream of x’s can be trusted to deliver a consistent distribution

• This method was (supposedly) worked out as part of an after-dinner conversation in Los Alamos after WWII

Page 27: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

27

Metropolis (2)Metropolis (2)

• In its simplest form, the procedure is:In its simplest form, the procedure is:• Choose x according to a distribution that has certain properties. Choose x according to a distribution that has certain properties.

We will not go into the details except to say that a uniform We will not go into the details except to say that a uniform distribution has all the properties needed!distribution has all the properties needed!

• Evaluate the PDF at the chosen xEvaluate the PDF at the chosen x• Decide whether to use the new point according to these rules:Decide whether to use the new point according to these rules:

1.1. IF the PDF evaluates higher than the PREVIOUSLY chosen IF the PDF evaluates higher than the PREVIOUSLY chosen point’s PDF, then use the new xpoint’s PDF, then use the new x

2.2. IF the PDF evaluates less than the previous point’s PDF, then IF the PDF evaluates less than the previous point’s PDF, then pull another random number between 0 and 1pull another random number between 0 and 1

If the new random number is LESS than the ratio of (new point’s If the new random number is LESS than the ratio of (new point’s PDF)/(old point’s PDF), then use the new xPDF)/(old point’s PDF), then use the new x

If the previous test fails, then REUSE the old xIf the previous test fails, then REUSE the old x

Page 28: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

28

Stratified samplingStratified sampling

• This method involves reducing variance by forcing more order onto the random number stream used as input

• As the simplest example, it can be implemented by FORCING the random number stream to produce EXACTLY half the numbers below 0.5 and half above 0.5

• In effect, you are dividing the problem into two subproblems with ½ the width of the domain each

• This reduces the discrepancy (proportional to the STANDARD DEVIATION) of each to ½ its previous value, which cuts the variance (per history) in half.

• If time permits, we will work an example in class like the one in the course notes

Page 29: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

29

“Other”: Two alternate“Other”: Two alternate• Choose x fromChoose x from

using:using:

• Choose x from Choose x from

(Gaussian/normal) using: (Gaussian/normal) using:

(Why 12?)(Why 12?)

1,0,)(~ xxx n

1 2 1max , ,...,i nx

612

1

j

jix

2

21

( ) , 2

xx e x

Page 30: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

30

Homework from textHomework from text

Page 31: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

31

Homework from textHomework from text

Page 32: 1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing

32

Homework from textHomework from text