23
From Random Numbers to From Random Numbers to Monte Carlo Monte Carlo Random Numbers, Random Walks, Diffusion, Random Numbers, Random Walks, Diffusion, Monte Carlo integration, and all that … Monte Carlo integration, and all that …

Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

From Random Numbers to From Random Numbers to

Monte CarloMonte Carlo

Random Numbers, Random Walks, Diffusion, Random Numbers, Random Walks, Diffusion,

Monte Carlo integration, and all that …Monte Carlo integration, and all that …

Page 2: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Random Walk Through LifeRandom Walk Through Life•If you flip the coin 25 times you will probably be about five steps away from where you started. This is because five times five equals 25. A random walk is not a very fast way to get anywhere!

When you try this, you will notice that sometimes you go much farther than you expect and sometimes you end up very close to where

you started. But if you repeat it many times or get several of your friends to

do it with you with coins of their own, the average

distance should come out as expected. In science we can often predict what will

happen on the average even when the process is

random.

Page 3: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Random Walk: From Physics to Wall StreetRandom Walk: From Physics to Wall Street

•A random process consisting of a sequence of discrete steps of fixed length: vary greatly depending on the dimension in which the walk occurs and whether it is confined to a lattice.

•The random thermal perturbations in a liquid are responsible for a random walk phenomenon known as Brownian motion.

•The collisions of molecules in a gas are a random walk responsible for diffusion.

Page 4: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

“For over half a century financial experts have regarded the movements

of markets as a random walk -unpredictable meanderings akin to a drunkard's unsteady gait - and this hypothesis has become a cornerstone of modern financial economics and many investment

strategies: markets were "weak-form efficient", implying that past prices could not be used to

forecast future prices changes.Lo and MacKinlay find that markets are not completely random after all, and that predictable components do exist in recent stock and bond returns.”

Page 5: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Einstein (1905): Kinetic Theory of Brownian MotionEinstein (1905): Kinetic Theory of Brownian Motion

•Brownian motion -> The random walk motion of small particles suspended in a fluid due to bombardment by molecules obeying a Maxwellian velocity distribution (J. Ingenhousz 1785; Brown 1828). Brownian

trajectories are continuous, but of infinite length between any two points.

2

2

2 2

( ), 6 ( ) ( )

( ) ( )

1 1 2 1( ) ( ) 0, , (1 ) ,

2 2t

dvm v F t a m xx x xx xF t

dtd d

m xx m xx m x xx xF td dt

kTxF t x F t x kT x t e

α α πη α

α

αγα γ

= − + = ⇔ − = − +

= = − +

= = = = − − =

ɺ ɺ ɺ

ɺ ɺ ɺ ɺ

ɺ

21 2 1 2

2 2 2

,3

3

kT t kT tt x t x

m a

kT tr x r D t

a

γ γπη

πη

− −⇒ = ⇒ =

= ⇒ = =

≪ ≫

Page 6: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Monte Carlo Methods: Not one, but manyMonte Carlo Methods: Not one, but many

•Any method that solves a problem by generating suitable random numbers and observing that fraction of the numbers obeying some property or properties.

•The method is useful for obtaining numerical solutions to

problems which are too complicated to solve analytically.

•It was named by S. Ulam, who in 1946 became the first mathematician to dignify this approach with a name, in honor of a

relative having a propensity to gamble.

•Nicholas Metropolis: Metropolis algorithm in Statistical Physicsamong the top 10 algorithms having the "greatest influence on the development and practice of science and engineering in the 20th century."

Page 7: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Random Numbers in Computers?Random Numbers in Computers?

1 ( ) modn nx ax b m+ = +•Uniform distribution of pseudo-random numbers

can be generated by this linear congruential generator.

•Here a, b and m are carefully chosen fixed integers, a is the multiplier, b is the increment and m is the modulus. The starting value is called the seed. The random number in the interval [0, 1] is . Hence there are at most m random uniformly distributed numbers:

0x/nx m

( ) 1 [0,1]

( ) 0 [0 ,1]

P x if x

P x if x

= ∈= ∉

Page 8: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Is the distribution really uniform?Is the distribution really uniform?

•Knut’s ran3.c or ran3.for portable generator (it does not employ linear congruential method!):

Page 9: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

NonNon--uniform distributionsuniform distributions

( )

| ( ) | | ( ) | ( ) ( )x y y x

y f x

dx dxP x dx P y dy P y P x C

dy dy

=

= ⇒ = =

•Transformation method:

1

0

( ) ( ) ( ) ( )y

x F y P y dy y x F x−= = ⇒ =∫

Page 10: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Example: Exponential DeviatesExample: Exponential Deviates

•Transformation method:

ln( )

( ) , 0yy

y x

P y e y−

= −= ≤ ≤∞

Page 11: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

NonNon--uniformuniform Distributions: Transformation MethodDistributions: Transformation Method

•Transformation method does not always work:

2

2 2

1( ) exp

2 2

1 1exp exp

2 22 2

y

y

yP y

dx y tx dt

dy

π

π π −∞

= −

= − ⇒ = −

•No analytical expression for in the case of Normal Distribution!

( )y x

Page 12: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

NonNon--uniform Distributions: Rejection Methoduniform Distributions: Rejection Method

( ) ( ) , ( )P x f x x f x dx< ∀ < ∞∫

•Suppose we have a comparison function with the properties:( )f x

•Now suppose we can choose a random point in two dimensions that is uniformly distributed in the area under the comparison function . If the point lies outside the area under then reject it and choose again. Otherwise, accept the point. The accepted points are uniformly distributed in the accepted area.

( )f x( )P x

Page 13: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Rejection Method SummarizedRejection Method Summarized

Page 14: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Rejection Method in PracticeRejection Method in Practice

0

( ') 'x

f x dx z=∫

•Choose a comparison function whose indefinite integral is known analytically and is analytically invertible, i.e., you can find x such that :

•Let A be the total area under f(x). Pick a uniform random number . Then find x so that:

•Now pick a random number ybetween 0 and f(x). Accept x if

y<P(x), reject otherwise.

0 Aα< <

0

( ') 'x

f x dx α=∫

Page 15: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Rejection Method: ExampleRejection Method: Example

2 2( ) 30 (1 ) , 0 1

40 1, 0

9 2( )40 1

(1 ), 19 2

P x x x x

x xf x

x x

= − ≤ ≤

≤ ≤= − ≤ ≤

Page 16: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Monte Carlo IntegrationMonte Carlo Integration•The most common application of the Monte Carlo method is Monte Carlo integration (extension of the rejection method).

•In order to integrate a function over a complicated domain D, Monte Carlo integration picks random points over some simple domain D’ which is a superset of D, checks whether each point is within D, and estimates the area of D (volume, n-dimensional content, etc.) as the area of D’ multiplied by the fraction of points falling within D’.

( )

[ , ]

( )

max ( )

bIN

TRIALSa

a b

Nf x dx b a Y

N

Y f x

>

∫ ≃

Page 17: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Ultra Classic Example: A circleUltra Classic Example: A circle•A standard example is to use the Monte Carlo method to find the area of a circle and hence determine a value for .

1

1 1

11 1

2 2

( ) ( )

4( , ) ( , )

1, 1( , )

0, otherwise

b N

iia

N

i ii

b af x dx f x

N

p x y dxdy p x yN

x yp x y

π

=

=− −

−≈

= ≈

+ ≤=

∑∫

∑∫ ∫

π

Page 18: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Monte Carlo Integration: Error EstimateMonte Carlo Integration: Error Estimate

•Suppose we pick N random points uniformly distributed in a multidimensional volume V: . Then the basic theorem of Monte Carlo integration estimates the integral of a function as:

22

2 2

1 1

( )

1 1( ), ( )

N N

i ii i

f ff x dV f V V

N

f f x f f xN N= =

−≈ ±

= =

∑ ∑

1 2, , , nx x x…

( )f x

2

1

1( )

( 1)

trialsN

iitrials

I IN

σ=

= − ⇒− ∑

•General Theory of Statistical Errors:

1/ 2

I

trials

I

SN

S N

σ

=

Page 19: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Monte Carlo Integration: A SphereMonte Carlo Integration: A Sphere

•The same basic method can be used to find the volume of a sphere:

•The accuracy of this Monte Carlo method is proportional to . Hence a large number of random points is needed to get high accuracy. However, Monte Carlo integration is faster than Simpson’s rule in 4 or more dimensions. It is also easy to program and is useful for evaluating 2 and 3 dimensional integrals with complex boundaries.

1 / 2tr ia lsN −

Page 20: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Random Walk in 1DRandom Walk in 1D•In a one-dimensional random walk, the walker can move along a straight line in either the positive direction or the negative direction. Here we will assume that steps are of unit length and that the walker can move in either direction with equal probability.

2

0n

n

x

x t

=

∝•In this case the most likely distance from the starting point after nsteps is 0. The plot shows the distribution of positions (both positive and negative) for 100,000 walkers after 100 steps. The distribution is normal (Gaussian) with standard deviation 10.

Page 21: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

Random Walk in 1D ExplainedRandom Walk in 1D Explained•To see why the variance behaves this way, let be the change in position

during i-th step: .is

•This property is characteristic of random walks and diffusion processes

in any number of dimensions.

1is = ±

1

2

1 1 1 1 1 1

2

1 1 1

1

0

n

n ii

n n n n n n

n i j i j i ji j i j i j

i j i j

i j

n n n

n i j i ii j i

x s

x s s ss ss

i j s s ss

i j ss

x ss ss n

=

= = = = = =

= = =

=

= = =

= ⇒ = ⇒ =

≠ ⇒ =

= = =

∑ ∑ ∑∑ ∑∑

∑∑ ∑

Page 22: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

From Random Walk to DiffusionFrom Random Walk to Diffusion•To see the connection between random walks and diffusion processes, consider the probability p(m,n) that a walker is at position m after n steps. To get to position m, the walker must be at position m-1 or position m+1 at the previous step. In either case, the probability that it moves to position mis 0.5.

[ ]

[ ]

1( , ) ( 1, 1) ( 1, 1)

21

( , ) ( , 1) ( 1, 1) 2 ( , 1) ( 1, 1)2

p m n p m n p m n

p m n p m n p m n p m n p m n

= + − + − −

− − = + − − − + − −

2

2

p pD

t x

∂ ∂=∂ ∂

•Letting the time step and the spatial step become infinitesimally small leads to a diffusion equation.

Page 23: Random Walk: From Physics to Wall Streetbnikolic/teaching/phys660/lectures/random.pdfRandom Walk: From Physics to Wall Street •A random process consisting of a sequence of discrete

SelfSelf--Avoiding Random WalkAvoiding Random Walk•A self-avoiding walk is a path from one point to another which never intersects itself. Such paths are usually considered to occur on lattices, so that steps are only allowed in a discrete number of directions and of certain lengths.

2

1.4, 2

1.25, 3

1.15, 4

1 2

r t

d

d

d

α

α

α

== = =

< <

•SAW can model coiling up of links in a polymer chain.