25
Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number Sequential random number generators generators Parallel random number generators Parallel random number generators Generating non-uniform random Generating non-uniform random numbers numbers Monte Carlo case studies Monte Carlo case studies

Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

  • View
    215

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Lecture 10 Outline

Monte Carlo methodsMonte Carlo methods History of methodsHistory of methods Sequential random number generatorsSequential random number generators Parallel random number generatorsParallel random number generators Generating non-uniform random numbersGenerating non-uniform random numbers Monte Carlo case studiesMonte Carlo case studies

Page 2: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Monte Carlo Methods Monte Carlo is another name for statistical sampling methods Monte Carlo is another name for statistical sampling methods

of great importance to physics and computer scienceof great importance to physics and computer science Applications of Monte Carlo Method Applications of Monte Carlo Method

Evaluating integrals of arbitrary functions of 6+ Evaluating integrals of arbitrary functions of 6+ dimensionsdimensions

Predicting future values of stocksPredicting future values of stocks Solving partial differential equationsSolving partial differential equations Sharpening satellite imagesSharpening satellite images Modeling cell populationsModeling cell populations Finding approximate solutions to NP-hard problemsFinding approximate solutions to NP-hard problems

Page 3: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

• In 1738, Swiss physicist and mathematician Daniel Bernoulli published Hydrodynamica which laid the basis for the kinetic theory of gases: great numbers of molecules moving in all directions, that their impact on a surface causes the gas pressure that we feel, and that what we experience as heat is simply the kinetic energy of their motion.

• In 1859, Scottish physicist James Clerk Maxwell formulated the distribution of molecular velocities, which gave the proportion of molecules having a certain velocity in a specific range. This was the first-ever statistical law in physics. Maxwell used a simple thought experiment: particles must move independent of any chosen coordinates, hence the only possible distribution of velocities must be normal in each coordinate.

• In 1864, Ludwig Boltzmann, a young student in Vienna, came across Maxwell’s paper and was so inspired by it that he spent much of his long, distinguished, and tortured life developing the subject further.

An Interesting History of Statistical Physics

Page 4: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

History of Monte Carlo Method Credit for inventing the Monte Carlo method is shared by Stanislaw Credit for inventing the Monte Carlo method is shared by Stanislaw

Ulam, John von Neuman and Nicholas Metropolis. Ulam, John von Neuman and Nicholas Metropolis. Ulam, a Polish born mathematician, worked for John von Neumann on Ulam, a Polish born mathematician, worked for John von Neumann on

the Manhattan Project. Ulam is known for designing the hydrogen the Manhattan Project. Ulam is known for designing the hydrogen bomb with Edward Teller in 1951. In a thought experiment he bomb with Edward Teller in 1951. In a thought experiment he conceived of the MC method in 1946 while pondering the probabilities conceived of the MC method in 1946 while pondering the probabilities of winning a card game of solitaire. of winning a card game of solitaire.

Ulam, von Neuman, and Metropolis developed algorithms for computer Ulam, von Neuman, and Metropolis developed algorithms for computer implementations, as well as exploring means of transforming non-implementations, as well as exploring means of transforming non-random problems into random forms that would facilitate their solution random problems into random forms that would facilitate their solution via statistical sampling. This work transformed statistical sampling via statistical sampling. This work transformed statistical sampling from a mathematical curiosity to a formal methodology applicable to a from a mathematical curiosity to a formal methodology applicable to a wide variety of problems. It was Metropolis who named the new wide variety of problems. It was Metropolis who named the new methodology after the casinos of Monte Carlo. Ulam and Metropolis methodology after the casinos of Monte Carlo. Ulam and Metropolis published a paper called “The Monte Carlo Method” in published a paper called “The Monte Carlo Method” in Journal of the Journal of the American Statistical AssociationAmerican Statistical Association, 44 (247), 335-341, in 1949. , 44 (247), 335-341, in 1949.

Page 5: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Errors in Estimation and Two Important Questions for Monte Carlo

Errors arise from two sourcesErrors arise from two sources Statistical: using finite number of samples to estimate an inifinte Statistical: using finite number of samples to estimate an inifinte

sum.sum. Computational: using finite state machines to produce statistically Computational: using finite state machines to produce statistically

independent random numbers.independent random numbers. QuestionsQuestions

To ensure a level of statistical accuracy, i.e., m significant digits To ensure a level of statistical accuracy, i.e., m significant digits with probability 1-1/n, how many samples are needed?with probability 1-1/n, how many samples are needed?

Given n samples, how statistically accurate is the estimate?Given n samples, how statistically accurate is the estimate? ““the best methods rarely offers more than 2-3 digit accuracy”-- G. the best methods rarely offers more than 2-3 digit accuracy”-- G.

Fishman, Fishman, Monte Carlo MethodsMonte Carlo Methods, Springer, Springer

Page 6: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Controlling Error

Two tenets from statistics:Two tenets from statistics: Weak Law of Large NumbersWeak Law of Large Numbers

value of a sum of i.i.d random variables converges to me n u value of a sum of i.i.d random variables converges to me n u ( u is mean).( u is mean).

So as n grows approx error vanishesSo as n grows approx error vanishes Central Limit TheoremCentral Limit Theorem

Sum converges to a normal distribution with mean nu and Sum converges to a normal distribution with mean nu and variance n var sqrt(n)variance n var sqrt(n)

So as n grows error can be estimated using normal tables and So as n grows error can be estimated using normal tables and theorems about tails of distribution.theorems about tails of distribution.

CaveatsCaveats Convergence rates differ and can be complexConvergence rates differ and can be complex Results in additional error estimates or need larger sample size Results in additional error estimates or need larger sample size

than normal distribution would indicatethan normal distribution would indicate

Page 7: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Sample Size and Chebyshev’s Theorem

Theorem: If X is a discrete random variable with Theorem: If X is a discrete random variable with mean mean and standard deviation and standard deviation , then for every , then for every positive real number positive real number

or equivalently or equivalently

That is, the probability that a random variable will That is, the probability that a random variable will assume a value more than h standard deviations assume a value more than h standard deviations away from its mean is never greater than the away from its mean is never greater than the square of the reciprocal of h.square of the reciprocal of h.

2/1)( hhXP

)/1(1)( 2hhXP

Page 8: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

An Example: 200 years ago, Comte de Buffon, proposed the following problem. If a needle of length 200 years ago, Comte de Buffon, proposed the following problem. If a needle of length ll is is

dropped at random on the middle of a horizontal surface ruled with parallel lines a distance dropped at random on the middle of a horizontal surface ruled with parallel lines a distance dd > > ll apart, what is the probability that the needle will cross one of the lines?  apart, what is the probability that the needle will cross one of the lines? 

The positioning of the needle relative to nearby lines can be described with a random vector The positioning of the needle relative to nearby lines can be described with a random vector ((AA, theta) is uniformly distributed on the region [0,, theta) is uniformly distributed on the region [0,dd) [0,pi). Accordingly, it has probability ) [0,pi). Accordingly, it has probability density function above. The probability that the needle will cross one of the lines is given by density function above. The probability that the needle will cross one of the lines is given by the integralthe integral

Page 9: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Estimation and variance reduction

This integral is easily solved to obtain the probability This integral is easily solved to obtain the probability

Suppose Buffon’s experiment is performed with the needle being dropped Suppose Buffon’s experiment is performed with the needle being dropped nn times. Let times. Let MM be the random variable for the number of times the needle crosses a line, be the random variable for the number of times the needle crosses a line,

Certain techniques can be used to reduce variance, e.g., an experimenter Fox used five Certain techniques can be used to reduce variance, e.g., an experimenter Fox used five inch needle and made the lines on the surface just two inches apart. Now, the needle inch needle and made the lines on the surface just two inches apart. Now, the needle could cross as many as three lines in a single toss. In 590 tosses, Fox obtained 939 line could cross as many as three lines in a single toss. In 590 tosses, Fox obtained 939 line crossings. This was a precursor of today’s variance reduction techniques. crossings. This was a precursor of today’s variance reduction techniques.

Page 10: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Variance Reduction

There are several ways to reduce the varianceThere are several ways to reduce the variance Importance SamplingImportance Sampling Stratified SamplingStratified Sampling Quasi-random SamplingQuasi-random Sampling Metropolis Random MutationsMetropolis Random Mutations

Page 11: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Simulation Often rely on Other Distributions Analytical transformationsAnalytical transformations Box-Muller TransformationBox-Muller Transformation Rejection methodRejection method

Page 12: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Analytical Transformation-probability density function f(x)-cumulative distribution F(x) In theory of probability, a quantile function of a distribution is the inverse of its cumulative distribution function.

Page 13: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Exponential Distribution:An exponential distribution arises naturally when modeling the time between independent events that happen at a constant average rate and are memoryless. One of the few cases where the quartile function is known analytically.

1.0

mxem

xf /1)(

mxexF /1)(

)1ln()(1 umuF

Page 14: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Example 1:

Produce four samples from an exponential Produce four samples from an exponential distribution with mean 3distribution with mean 3

Uniform sample: 0.540, 0.619, 0.452, 0.095Uniform sample: 0.540, 0.619, 0.452, 0.095 Take natural log of each value and multiply Take natural log of each value and multiply

by -3by -3 Exponential sample: 1.850, 1.440, 2.317, Exponential sample: 1.850, 1.440, 2.317,

7.0727.072

Page 15: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Example 2:

Simulation advances in time steps of 1 secondSimulation advances in time steps of 1 second Probability of an event happening is from an exponential Probability of an event happening is from an exponential

distribution with mean 5 secondsdistribution with mean 5 seconds What is probability that event will happen in next second?What is probability that event will happen in next second? F(x=1/5) =1 - exp(-1/5)) = 0.181269247F(x=1/5) =1 - exp(-1/5)) = 0.181269247 Use uniform random number to test for occurrence of Use uniform random number to test for occurrence of

event (if u < 0.181 then ‘event’ else ‘no event’)event (if u < 0.181 then ‘event’ else ‘no event’)

Page 16: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Normal Distributions:Box-Muller Transformation

Cannot invert cumulative distribution Cannot invert cumulative distribution function to produce formula yielding function to produce formula yielding random numbers from normal (gaussian) random numbers from normal (gaussian) distributiondistribution

Box-Muller transformation produces a pair Box-Muller transformation produces a pair of standard normal deviates of standard normal deviates gg11 and and gg22 from a from a

pair of normal deviates pair of normal deviates uu11 and and uu22

Page 17: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Box-Muller Transformation

repeatv1 2u1 - 1v2 2u2 - 1r v1

2 + v22

until r > 0 and r < 1f sqrt (-2 ln r /r )g1 f v1

g2 f v2

This is a consequence of the fact that the chi-square distribution with two degrees of freedom is an easily-generated exponential random variable.

Page 18: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Example

Produce four samples from a normal Produce four samples from a normal distribution with mean 0 and standard distribution with mean 0 and standard deviation 1deviation 1

uu11 uu22 vv11 vv22 rr ff gg11 gg22

0.2340.234 0.7840.784 -0.532-0.532 0.5680.568 0.6050.605 1.2901.290 -0.686-0.686 0.7320.732

0.8240.824 0.0390.039 0.6480.648 -0.921-0.921 1.2691.269

0.4300.430 0.1760.176 -0.140-0.140 -0.648-0.648 0.4390.439 1.9351.935 -0.271-0.271 -1.254-1.254

Page 19: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Von Neumann’s Rejection Method

Page 20: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Case Studies (Topics Introduced)

Temperature inside a 2-D plate (Random Temperature inside a 2-D plate (Random walk)walk)

Two-dimensional Ising modelTwo-dimensional Ising model(Metropolis algorithm)(Metropolis algorithm)

Room assignment problem (Simulated Room assignment problem (Simulated annealing)annealing)

Parking garage (Monte Carlo time)Parking garage (Monte Carlo time) Traffic circle (Simulating queues)Traffic circle (Simulating queues)

Page 21: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Temperature Inside a 2-D Plate

Random walk

Page 22: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Example of Random Walk }3,2,1,0{410 uu

13121322

Page 23: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Parking Garage

Parking garage has Parking garage has SS stalls stalls Car arrivals fit Poisson distribution with Car arrivals fit Poisson distribution with

mean mean AA: Exponentially distributed inter-: Exponentially distributed inter-arrival timesarrival times

Stay in garage fits a normal distribution Stay in garage fits a normal distribution with mean with mean MM and standard deviation and standard deviation MM//SS

Page 24: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Implementation Idea

101.2 142.1 70.3 91.7 223.1

64.2

Current Time

Times Spaces Are Available

15

Car Count Cars Rejected

2

Page 25: Lecture 10 Outline Monte Carlo methods Monte Carlo methods History of methods History of methods Sequential random number generators Sequential random

Summary

Concepts revealed in case studiesConcepts revealed in case studies Monte Carlo timeMonte Carlo time Random walkRandom walk Metropolis algorithmMetropolis algorithm Simulated annealingSimulated annealing Modeling queuesModeling queues