Top Banner
Simulation Monte Carlo
21

Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Oct 18, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Simulation

Monte Carlo

Page 2: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Stochastic simulation

• In stochastic simulation/sampling we observe

values f(X) where X is from distribution of

interest

– Observed simulation results are samples of random

variates

– Goal of a simulation experiment is to get knowledge

about the distribution of the random variable (mean,

variance, higher moments(?))

– ”Right” value is deterministic but it can not be

determined explicitly.

Page 3: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Stochastic simulation

• Two basic scenarios for drawing X:s

– Distribution of X can be constructed so that

independent samples can be generated (plain Monte

Carlo)

• Stochastic numerical integration

– We can only sample a dependent sequence (Markov

Chain) of X:s that has right limit distribution (MCMC,

Markov Chain Monte Carlo)

• Simulation of systems with internal dynamics

Page 4: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Buffons needle

• Classical example of simulation

experiment where ”exact” result is known. • Count of Buffon presented a method to define the

value for p in 1733.

• Throw a needle of length l on a plane that has

parallel lines with distance d.

• Count how often the needle crosses a line.

• Compute experimental probability for hits P=

#hits/#trials

Page 5: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Buffons needle – Needle hits a line if

• The distance from

the center of the

needle to closest line

is less than l sin a,

where a is the angle

between the needle

and the line

• Angle ~ Unif(0, p/2)

• Center ~ Unif

(0,d/2)

d

l a

Page 6: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Buffons needle – Probability of hit can

be computed using the

volume of the area

bounded by the

sinusoidal curve.

• p= 2l/(pd)

• Hence estimate is p =

2l/(pd) for experimental

value for p.

d/2

l/2

p/2

Page 7: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Buffons needle

– Result of a single throw is random • So is the average of N throws.

• What do we know after N throws?

– Can we define the distribution of the average P after N throws.

• Or at least expectation and variance

• P is an average of N independent random variables

• Single attempts obey binomial distribution with mean p (=2l/(pd))

• E(P)=p.

Page 8: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Buffons needle

– Variance of the result in one throw is p(1-p)

(result is a Bin(p) variable)

• Variance of the average of N independent trials is

p(1-p)/N

• I.e. Var(P) = p(1-p)/N

– So now we have observation of a random

variable with known variance.

– We can estimate the relationship between the

sample average and the expectation.

Page 9: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Confidence interval

– Assume we know a sample average of a

random variable

– Where is the true expectation p with, say 99%

probability.

• Define sc. confidence interval for which P( P-d < p<

P+d) >0.99.

• Can be defined if distribution of P is known.

• P is average of N independent Bin variables. For

large N, P is approximately normally distributed.

• d is of form c(p)N^(-1/2).

Page 10: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Monte Carlo -integration

– Buffon’s needle is a sampled variable

• expectation has a formula as definite integral.

– The approach can be used generally to

approximate integrals.

– Integrate f on [a,b] given that 0<f<c

• If x is Unif(a,b) and y is Unif(0,c), determine

experimentally the probability p for y< f(x).

• The sought integral is p(b-a)c.

Page 11: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Monte Carlo -integration

– More experiments lead to more accurate

estimate for p.

– Confidence interval (error) is proportional to

N^(-1/2).

• Not efficient for one dimensional integrals

• Length of confidence interval and asymptotic

behavior depend only on p, not the dimension of

the integral.

• Efficient way to get rough estimates for high

dimensional integrals.

Page 12: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Monte Carlo

– Previous Monte Carlo does not apply directly to all cases

• Unbounded interval or function

– Possible to give up ”y” variable • Compute only E(f(x))

• Cheaper but error analysis is more demanding

– Flat upper bound c can be replaced • Find a pdf g such that f(x)< cg(x)

• Draw x:s from distribution g

• Aim for success rate p ~ 1

Page 13: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Monte Carlo applications

– Typical Monte Carlo case is (very) high dimensional integral arising from modelling ray propagation in material.

– Each collision is modelled with multidimensional integral

• probabilities for absorption, scattering as functions of incident angle, energy, particle shapes, surface properties, adsorption in free path, etc

– For single ray the complexity grows only linearily with number of collisions.

Page 14: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

M C Example

• Consider scattering of laser beam from a

material layer

• MSc thesis of Jukka Räbinä 2005

• Goal is to simulate different statistics of

the scattered image using Monte-Carlo

Page 15: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Experimental set up

Page 16: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Scattering

• Simulate propagation

of ray in cloud of

particles

• Basically ray tracing

• Positions and

scattering directions

of particles are

random

Page 17: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Goal of simulation

• Compute the

intensity, center of

mass etc of the

scatter image

captured by camera

• I.e. an integral of a

function involving the

intensity distribution.

Page 18: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Simulation experiment

• Send parallel rays

with normally

distributed intensity

• Collect the (few) rays

scattered to the

camera

Page 19: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

Simulation results

• Three different

implementations of M-C

• Each with 100M

simulated rays

• Differences in execution

times and confidence

intervals

• Differences can be

explained after learning

about variance

reduction methods

Page 20: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

MCMC

• In many cases it is not possible to sample

efficiently independent samples from equilibrium

distribution

– Like from equilibrium state of discrete event system

– Sampling from Markov chain having right equilibrium

distribution

• X_n depends on X_(n-1) only, there exists an equilibrium

distribution

• Sampling from any MC with right equilibrium distr is enough

(allows simplifying system dynamics sometimes)

Page 21: Simulation - Jyväskylän yliopistousers.jyu.fi/~tiihonen/simul/slides16/Monte_Carlo.pdf · Monte Carlo applications –Typical Monte Carlo case is (very) high dimensional integral

MCMC

• Main challenges:

– Finding a chain with right equilibrium

• Correct updating steps

– Ensuring that equilibrium is attained

• Long enough simulation runs

– Coping with non-independence/

autocorrelation of the sampled values

• Doing ones math