+ All Categories
Home > Documents > Lesson 1: Introduction to Monte Carlo

Lesson 1: Introduction to Monte Carlo

Date post: 21-Jan-2016
Category:
Upload: olympe
View: 27 times
Download: 0 times
Share this document with a friend
Description:
Lesson 1: Introduction to Monte Carlo. Go over outline and syllabus Background and course overview Statistical Formulae: Mean SD of population SD of mean A little practice. Background and course overview. - PowerPoint PPT Presentation
Popular Tags:
29
1 Lesson 1: Introduction to Monte Carlo Go over outline and syllabus Go over outline and syllabus Background and course overview Background and course overview Statistical Formulae: Statistical Formulae: Mean Mean SD of population SD of population SD of mean SD of mean A little practice A little practice
Transcript
Page 1: Lesson 1: Introduction to Monte Carlo

1

Lesson 1: Introduction to Monte CarloLesson 1: Introduction to Monte Carlo

• Go over outline and syllabusGo over outline and syllabus• Background and course overviewBackground and course overview• Statistical Formulae:Statistical Formulae:

• MeanMean• SD of populationSD of population• SD of meanSD of mean

• A little practiceA little practice

Page 2: Lesson 1: Introduction to Monte Carlo

2

Background and course overviewBackground and course overview

• Monte Carlo methods are a branch of mathematics Monte Carlo methods are a branch of mathematics that involves the stochastic solution of problems. that involves the stochastic solution of problems.

• Experimental approach to solving a problem. Experimental approach to solving a problem. (“Method of Statistical Trials”)(“Method of Statistical Trials”)

• When the analyst is trying to use a Monte Carlo When the analyst is trying to use a Monte Carlo approach to estimate a physically measurable approach to estimate a physically measurable variable, the approach breaks itself down into two variable, the approach breaks itself down into two steps: steps:

1.1. Devise a numerical experiment whose expected value Devise a numerical experiment whose expected value would correspond to the desired measurable value . would correspond to the desired measurable value .

2.2. Run the problem to determine an estimate to this variable. Run the problem to determine an estimate to this variable. We call the estimate . We call the estimate . • Many (probably most) Monte Carlo problems are of the “Hit or Many (probably most) Monte Carlo problems are of the “Hit or

Miss” category, which finds the probability of some event Miss” category, which finds the probability of some event occurring. (e.g., hitting a straight flush, neutron escaping occurring. (e.g., hitting a straight flush, neutron escaping through a surface, etc.)through a surface, etc.)

x

Page 3: Lesson 1: Introduction to Monte Carlo

3

BG and Overview (2)BG and Overview (2)

• The first step can either be very simple or very The first step can either be very simple or very complicated, based on the particulars features of the complicated, based on the particulars features of the problem. problem.

• If the problem is itself stochastic, the experimental If the problem is itself stochastic, the experimental design step is very simple: Let the mathematical design step is very simple: Let the mathematical simulation simulate the problem. This is an simulation simulate the problem. This is an analoganalog simulation, since the calculation is a perfect analog to simulation, since the calculation is a perfect analog to the problem.the problem.

• Lucky for us, the transport of neutral particles is a Lucky for us, the transport of neutral particles is a stochastic situation. All we HAVE to do to get a guess stochastic situation. All we HAVE to do to get a guess at a measurable effect from a transport situation is to at a measurable effect from a transport situation is to simulate the stochastic "decisions" that nature makes.simulate the stochastic "decisions" that nature makes.

Page 4: Lesson 1: Introduction to Monte Carlo

4

BG and Overview (3)BG and Overview (3)• For processes that are NOT inherently stochastic, the For processes that are NOT inherently stochastic, the

experimental design is more complex and generally requires that experimental design is more complex and generally requires that the analyst: the analyst:

1.1. Derive an equation (e.g., heat transfer equation, Boltzmann Derive an equation (e.g., heat transfer equation, Boltzmann transport equation) from whose solution an estimate of the transport equation) from whose solution an estimate of the effect of interest can be inferred. effect of interest can be inferred.

2.2. Develop a Monte Carlo method to solve the equation. Develop a Monte Carlo method to solve the equation. • In this course we will do BOTH approaches:In this course we will do BOTH approaches:

• 3 weeks of event-based mathematical basic3 weeks of event-based mathematical basic• 4 weeks of optimization of event-based transport methods4 weeks of optimization of event-based transport methods• 3 weeks function-based, using a more formal “functional analysis” 3 weeks function-based, using a more formal “functional analysis”

approach to the solution of integral and differential equations (with the approach to the solution of integral and differential equations (with the BTE as an example)BTE as an example)

Page 5: Lesson 1: Introduction to Monte Carlo

5

Our First Example: Finding Our First Example: Finding

• Our first example will be a numerical estimation of , Our first example will be a numerical estimation of , based on use of a “hit or miss” approach. We know that based on use of a “hit or miss” approach. We know that the ratio of the area of circle to the area of the square the ratio of the area of circle to the area of the square that (just barely) encloses it is:that (just barely) encloses it is:

• Knowing this, we can design an experiment that will Knowing this, we can design an experiment that will deliver an expected value of deliver an expected value of

2

2Pr{hitting circle}=42

r

r

Page 6: Lesson 1: Introduction to Monte Carlo

6

Our First Example (2)Our First Example (2)

1.1. Choose a point at random inside a 2x2 square by: Choose a point at random inside a 2x2 square by:

A.A. Choosing a random number (Choosing a random number (11) between -1 and 1 for the x ) between -1 and 1 for the x coordinate, and coordinate, and

B.B. Choosing a random number (Choosing a random number (22) between -1 and 1 for the y ) between -1 and 1 for the y coordinate.coordinate.

NOTE: By doing this you have made an implicit “change of NOTE: By doing this you have made an implicit “change of variable” to this (which is called a “unit hypercube of order 2”):variable” to this (which is called a “unit hypercube of order 2”):

Page 7: Lesson 1: Introduction to Monte Carlo

7

Our First Example (3)Our First Example (3)

2.2. Score the result of a the trial: Consider a "hit" (score = 4) to Score the result of a the trial: Consider a "hit" (score = 4) to be the situation when the chosen point is inside the circle, i.e.,be the situation when the chosen point is inside the circle, i.e.,

a "miss" scoring 0. (Why does a success score 4?)a "miss" scoring 0. (Why does a success score 4?)3.3. Run the experiment a large number (N) of times, with the final Run the experiment a large number (N) of times, with the final

estimate of the circle's area being an average of the results:estimate of the circle's area being an average of the results:

122 yx

N

ii

N

s

N

Page 8: Lesson 1: Introduction to Monte Carlo

8

CodingCoding

• This course will require lots of coding. You need to be able to This course will require lots of coding. You need to be able to write code in SOME language. In order of my preference:write code in SOME language. In order of my preference:

• FORTRANFORTRAN• JavaJava• C or C++C or C++• BASIC or QBASICBASIC or QBASIC• MatLabMatLab

• If you have no better option, program in QBASICIf you have no better option, program in QBASIC• Very simple syntaxVery simple syntax• QBASIC available on the public area of the courseQBASIC available on the public area of the course• Get QBASIC.EXE, QBASIC.HLP, MCBASE.BASGet QBASIC.EXE, QBASIC.HLP, MCBASE.BAS

Page 9: Lesson 1: Introduction to Monte Carlo

9

Basic view of MC processBasic view of MC process

• Our basic view of a Monte Carlo process is a black box that Our basic view of a Monte Carlo process is a black box that has a stream of random numbers (between 0 and 1) as input has a stream of random numbers (between 0 and 1) as input and a stream of estimates of the effect of interest as output:and a stream of estimates of the effect of interest as output:

• Sometimes the estimates can be quite approximate, but with Sometimes the estimates can be quite approximate, but with a long enough stream of estimates, we can get a good a long enough stream of estimates, we can get a good sample.sample.

Page 10: Lesson 1: Introduction to Monte Carlo

10

3 Formulae3 Formulae

• There are three statistical formulae that we There are three statistical formulae that we will be using over and over in this course: will be using over and over in this course: • Our estimate of the expected value, Our estimate of the expected value, • Our estimate of the variance of the sample.Our estimate of the variance of the sample.• Our estimate of the variance of the expected Our estimate of the variance of the expected

value.value.

• You must be able to tell them apartYou must be able to tell them apart

Page 11: Lesson 1: Introduction to Monte Carlo

11

Estimate of the expected valueEstimate of the expected value

• The first, and most important, deals with the how we The first, and most important, deals with the how we gather from the stream of estimates the BEST gather from the stream of estimates the BEST POSSIBLE estimate of the expected value. The resulting POSSIBLE estimate of the expected value. The resulting formula for is:formula for is:

• Thus, our best estimate is the unweighted average of the Thus, our best estimate is the unweighted average of the individual estimates. This is not surprising, of course. individual estimates. This is not surprising, of course.

• Let’s compare with a couple of exact formulae.Let’s compare with a couple of exact formulae.

ˆNx

N

ii

N

xx

N

Page 12: Lesson 1: Introduction to Monte Carlo

12

Mean of continuous distributionMean of continuous distribution

• For a continuous distribution, For a continuous distribution, (x)(x), over a range , over a range (a,b)(a,b) (i.e., (i.e., x=a to x=bx=a to x=b). the true mean, , is the first ). the true mean, , is the first moment of x:moment of x:

• where we have assumed that where we have assumed that (x)(x) is a true probability is a true probability density function (pdf), obeying the following:density function (pdf), obeying the following:

x

b

a

x x x dx

0, in the range (a,b)

( ) 1

x

x dx

Page 13: Lesson 1: Introduction to Monte Carlo

13

Mean of discrete distributionMean of discrete distribution

• For a discrete distribution we choose one of For a discrete distribution we choose one of M choices, each of which probabilityM choices, each of which probability

• The equation for the mean is:The equation for the mean is:

• Again, we have limitations on the Again, we have limitations on the probabilities:probabilities:

i

1

M

i ii

x x

1

0, for all i

1

i

M

ii

Page 14: Lesson 1: Introduction to Monte Carlo

14

Example: problemExample: problem

• For our example of finding , we were dealing with a For our example of finding , we were dealing with a binomial distribution (i.e., two possible outcomes): binomial distribution (i.e., two possible outcomes):

• Outcome 1 = Hit the circle: Outcome 1 = Hit the circle:

• Outcome 2 = Miss the circle: Outcome 2 = Miss the circle:

• Therefore, the expected value is: Therefore, the expected value is:

1

0.7854 4 0.2146 0M

i ii

x

1 14 / 4 0.7854x

2 20 1 / 4 0.2146x

Page 15: Lesson 1: Introduction to Monte Carlo

15

Estimate of the sample varianceEstimate of the sample variance

• Variance = Expected squared errorVariance = Expected squared error

• MC estimate of variance:MC estimate of variance:

22

2

1

for a continuous distribution

for a discrete distribution

b

a

M

i ii

x x x x dx

x x

2 222 2

1 1 1

ˆ

1 1

N N Ni N i i

ni i i

x x x xNx S x

N N N N

Page 16: Lesson 1: Introduction to Monte Carlo

16

Sample standard deviationSample standard deviation

• The standard deviation is the square root of The standard deviation is the square root of the variance.the variance.

• The same is true of our estimate of it:The same is true of our estimate of it:

(Many texts call the estimate the “standard error”)(Many texts call the estimate the “standard error”)

• Recall that we have been talking about Recall that we have been talking about properties of the properties of the sample distributionsample distribution: How : How much the individual estimates differ from each much the individual estimates differ from each otherother

nn xSxS 2

Page 17: Lesson 1: Introduction to Monte Carlo

17

Example: problemExample: problem

• Using the same outcomes as before:Using the same outcomes as before:

• Very non-normal distributionVery non-normal distribution

22

1

2 2 0.7854 4 0.2146

2.697

2.697 1.642

M

i ii

x x x

x

Page 18: Lesson 1: Introduction to Monte Carlo

18

Estimate of the variance of meanEstimate of the variance of mean

• Turn our attention to the variance and Turn our attention to the variance and standard deviation of the standard deviation of the meanmean..• How much confidence we have in the mean that How much confidence we have in the mean that

we obtained from N sampleswe obtained from N samples

• We could estimate this by making We could estimate this by making manymany estimates of the mean (each using N estimates of the mean (each using N independent samples) and do a statistical independent samples) and do a statistical analysis on these estimates.analysis on these estimates.

• To our great relief, we can streamline this To our great relief, we can streamline this process and get an estimate of the mean from process and get an estimate of the mean from a a singlesingle set of N samples set of N samples

Page 19: Lesson 1: Introduction to Monte Carlo

19

Variance of mean (cont’d)Variance of mean (cont’d)

• The text has a derivation showing that the The text has a derivation showing that the variance of the mean is related to the variance of the mean is related to the variance of the distribution by:variance of the distribution by:

• Since we do not know the actual variance, we Since we do not know the actual variance, we have to use our estimate:have to use our estimate:

22 ˆN

xx

N

22 2ˆ ˆ

ˆ ˆ

iN N

iN N

S xx S x

NS x

x S xN

Page 20: Lesson 1: Introduction to Monte Carlo

20

Example: problemExample: problem

• Back to our example of finding , using the Back to our example of finding , using the probabilities from the previous example, the probabilities from the previous example, the standard deviation of the mean for a sample standard deviation of the mean for a sample of N=10,000 would be:of N=10,000 would be:

• This brings us to the famous principle of This brings us to the famous principle of Monte Carlo: Each extra digit of accuracy Monte Carlo: Each extra digit of accuracy requires that the problem be run with 100 requires that the problem be run with 100 times as many histories. times as many histories.

1.642ˆ ˆ 0.01642

10,000i

N N

S xx S x

N

21

N

Page 21: Lesson 1: Introduction to Monte Carlo

21

Markov inequalityMarkov inequality

• Most distributions are not normalMost distributions are not normal• What can we say about the probability of a What can we say about the probability of a

selection being with 1 selection being with 1 when it is NOT normal? when it is NOT normal?• An upper bound is given by the Chebyshev An upper bound is given by the Chebyshev

inequality, but before attacking it, we need to inequality, but before attacking it, we need to build a tool we will use: The Markov inequalitybuild a tool we will use: The Markov inequality

• Thought experiment: If I tell you that a group of Thought experiment: If I tell you that a group of people has an average weight of 100 pounds, people has an average weight of 100 pounds, what can you say about the number that weigh what can you say about the number that weigh more than 200 pounds?more than 200 pounds?

Page 22: Lesson 1: Introduction to Monte Carlo

22

Markov inequality (2)Markov inequality (2)

0

(Because the range of integration is smaller)

(Because is the lower limit of x)

(Because is a constant)

Pr

nx

nx

nx

E x x x x dx

x x dx

nx x dx nx

nx x dx nx

nx x

(Because the integral defines the probability)

1 Pr

nx

x nxn

Page 23: Lesson 1: Introduction to Monte Carlo

23

Chebyshev inequalityChebyshev inequality

• The Chebyshev applies the Markov to the The Chebyshev applies the Markov to the variancevariance instead of the instead of the averageaverage::

• Replace n with its square (it’s just a positive Replace n with its square (it’s just a positive number!)number!)

2 22 2 2

2 2

Pr

1 Pr

E x x n x x n

x x nn

2 2 22

2

1Pr

1Pr

x x nn

x x nn

Page 24: Lesson 1: Introduction to Monte Carlo

24

Chebyshev inequality (2)Chebyshev inequality (2)• The resulting statements you can say are not very satisfying to us The resulting statements you can say are not very satisfying to us

(especially since we are used to normal distributions):(especially since we are used to normal distributions):• Normal: 68.3% within 1 Normal: 68.3% within 1 vs Chebyshev: ? vs Chebyshev: ?• Normal: 95.4% within 2 Normal: 95.4% within 2 vs Chebyshev: ? vs Chebyshev: ?• Normal: 99.7% within 3 Normal: 99.7% within 3 vs Chebyshev: ? vs Chebyshev: ?

• But, Chebyshev is extremely valuable to theoretical mathematicians But, Chebyshev is extremely valuable to theoretical mathematicians because it proves that the integral over the “tails” is guaranteed to because it proves that the integral over the “tails” is guaranteed to decrease with n, with a limit of 0.decrease with n, with a limit of 0.

• Replace n with its square (it’s just a number!)Replace n with its square (it’s just a number!)

Page 25: Lesson 1: Introduction to Monte Carlo

25

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 26: Lesson 1: Introduction to Monte Carlo

26

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 27: Lesson 1: Introduction to Monte Carlo

27

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 28: Lesson 1: Introduction to Monte Carlo

28

Page 29: Lesson 1: Introduction to Monte Carlo

29


Recommended