Mathematical Modelling Lecture 13 Randomnesspjh503/mathematical_model/math_m… · Phil Hasnip...
Transcript of Mathematical Modelling Lecture 13 Randomnesspjh503/mathematical_model/math_m… · Phil Hasnip...
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Mathematical ModellingLecture 13 – Randomness
Phil [email protected]
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Overview of Course
Model construction −→ dimensional analysisExperimental input −→ fittingFinding a ‘best’ answer −→ optimisationTools for constructing and manipulating models −→networks, differential equations, integrationTools for constructing and simulating models −→randomnessReal world difficulties −→ chaos and fractals
A First Course in Mathematical Modeling by Giordano, Weir &Fox, pub. Brooks/Cole. Today we’re in chapters 5 and 6.
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Aim
To study how random numbers can be generatedTo see how random numbers can be used
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Monte Carlo integration
In the last lecture we talked about Monte Carlo methods ofintegration. This uses the fact that:∫ b
af (x)dx = (b − a) < f (x) >
Often random numbers will come in the range 0 ≤ x < 1 sowe’ll need to rescale our function and integral:∫ b
af (x)dx =
∫ 1
0g(u)du
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Monte Carlo integration
choose a random N-point samplecalculate f (x) at each of the N pointscompute the sample average of fthis is our estimate for the integral!
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Random numbers
How can we get random numbers?
Measure a random processe.g. timing of radioactive decaytabulate resultsevery time you use a random number, cross it off tablee.g. ERNIE
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Random numbers
How can we get random numbers?
Measure a random processPseudo-random number generator
e.g. linear congruence method, xn+1 = (axn + b) mod ce.g. a=16807, b=2836, c=231 − 1 gives 231 numbers beforeit repeatsTo make it 0 ≤ xn < 1 just divide by c before use
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Random processes
We can also use random numbers when simulating randomevents. E.g. tossing a coin:
Choose random number 0 ≤ xi < 1if 0 ≤ xi <
12 −→ heads
if 12 ≤ xi < 1 −→ tails
The range of random numbers we assign to each event is givenby the cumulative frequencyor cumulative probability.
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
A biased die
A slightly more complex example: the score on an unfair die.
score prob. cumulative prob.1 0.1 0.12 0.1 0.23 0.2 0.44 0.3 0.75 0.2 0.96 0.1 1.0
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
General procedure
Calculate or measure the frequency distributionConvert into a cumulative frequency distributionSimulate
This kind of problem often occurs as a submodel of a largerproblem.
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Example – Petrol station
Task is to minimise cost of storing and delivering petrol at apetrol station to meet fluctuating demand.
The daily cost is a function of three variables:
Storage costs −→ assume constant up to some max.capacityDelivery costs −→ assume constant up to some max.capacityDemand −→ fluctuates
−→ need three submodels. We’ll concentrate on the demandmodel.
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Example – Petrol station demand
Measure demand over a period of time, e.g. 1000 daysDemand is continuous, so discretise (e.g. 10 intervals)Compute frequency and hence probabilityCompute cumulative probabilityModel cumulative probability with empirical methods, e.g.linear splines
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Example – Petrol station demand
score freq. (days) prob. cumulative prob.1000-1099 10 0.01 0.011100-1199 20 0.02 0.031200-1299 50 0.05 0.081300-1399 120 0.12 0.201400-1499 200 0.20 0.401500-1599 270 0.27 0.671600-1699 180 0.18 0.851700-1799 80 0.08 0.931800-1899 40 0.04 0.971900-1999 30 0.03 1.00
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Example – Petrol station demand
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Example – Petrol station demand
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Example – Petrol station demand
Model cumulative frequency with empirical methods, e.g.linear splinesInvert empirical model (e.g. splines) to give demand forgiven probabilityRun simulations and use inverse model to map random no.0 ≤ xi < 1 to a daily demand
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Example – Petrol station demand
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Example – Petrol station demand
Model cumulative frequency with empirical methods, e.g.linear splinesInvert empirical model (e.g. splines) to give demand forgiven probabilityRun simulations and use inverse model to map random no.0 ≤ xi < 1 to a daily demandInvestigate different storage/delivery strategies to
Minimise cost (min. excess fuel)Avoid running out of fuel
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Random walks
Brownian motion is a simple example of a random process.How can we model it? One approach is as a random walk.
e.g. toss a coin, heads⇒ move left, tails⇒ move rightAfter N steps, how far RN have we moved?The mean displacement will be zero, < RN >= 0The mean distance is not! < R2
N >6= 0
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
1D Example
First, let’s look at a directed walk (i.e. not random)
Suppose we move distance s per step (s = 1 in ourexample)RN = Ns, so < RN >= Ns – in our example then< RN >= NR2
N = N2s2, so < R2N >= N2s2 – in our example then
< R2N >= N2
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
1D Example
So for a directed walk it’s easy. What about a random walk?Let’s simulate it:
Use random numbers 0 ≤ z < 1R0 = 0If 0 ≤ z < 1
2 , RN+1 = RN − 1
If 12 ≤ z < 1, RN+1 = RN + 1
We run the simulation for different final values of N
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
1D Example
N < R2N >
10 1100 9
1000 22510000 14161
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
1D Example
How can we model this? Let’s suppose < R2N >∼ CNp, i.e.
⇒ ln< R2N > = ln C + p ln N
Should give a straight(-ish) line on log-log plotIn fact least-squares fitting gives c = 0.0009, p = 1.8Is that it? No – random process−→ need to repeat and average
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
1D example
N < R2N >1 < R2
N >10 < R2N >100 < R2
N >100010 1 19.2 11.320 10.872
100 9 108.4 102.320 107.4801000 225 1041.2 946.600 980.944
10000 14161 8579.6 9332.840 9459.512c 9.1× 10−4 1.8 0.99 1.1p 1.8 0.92 0.99 0.98
So it seems as we average over more runs, c → 1 and p → 1.
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
2D example
What about 2D? Square lattice, now can move either up/downor left/right each turn (but not both).
N < R2N >1000
10 9.14100 98.884
1000 985.4610000 10164.2
So again it seems, c → 1 and p → 1.
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Einstein
In 1905 Einstein showed Brownian motion is related todiffusionThus < R2
N >∝ N (i.e. p = 1) is exactSee e.g. Feynmann Vol. 1 for proof
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Onward and upward
This model is very flexible −→ can do lots of interestingphysics with itCan often model things easily that are v. difficult to solvemathematicallye.g. QMC/DMC techniques use this to solve Schrödinger’sequatione.g. non-crossing random walks
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Non-crossing random walks
Random walk, but cannot visit any location more than onceBoring in 1D, interesting in higher dimensionsModel of a polymer −→ excluded volume effectPath now has some kind of memory of where it’s been
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Example – polymer
0 ≤ z < 13 ⇒ turn right
13 ≤ z < 2
3 ⇒ keep going23 ≤ z < 1⇒ turn leftVery difficult mathsVery easy simulation! < R2
N >∼ N1.4
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Extensions
There are lots of other things we could do, e.g.
Can also vary the step lengthModel for electron conduction – resistance due toscattering off defects
However always remember the results have some statisticalerror σ due to the sampling – you need to be careful.
σ ∼ 1√N
Phil Hasnip Mathematical Modelling
IntroductionMonte Carlo integration
Random numbersRandom eventsRandom walks
Summary
Can get random numbers from tables or pseudorandomgeneratorsUsed for Monte carlo integrationUsed for random walks – e.g. brownian motion, polymers,ties etc.
Phil Hasnip Mathematical Modelling