Mathematical Modelling Lecture 13 – Randomness

Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Mathematical Modelling
Lecture 13 – Randomness
Phil Hasnip
[email protected]
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Overview of Course
Model construction −→ dimensional analysis
Experimental input −→ fitting
Finding a ‘best’ answer −→ optimisation
Tools for constructing and manipulating models −→
networks, differential equations, integration
Tools for constructing and simulating models −→
randomness
Real 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
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Aim
To study how random numbers can be generated
To see how random numbers can be used
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Monte Carlo integration
In the last lecture we talked about Monte Carlo methods of
integration. This uses the fact that:
Z
b
f (x)dx = (b − a) < f (x) >
a
Often random numbers will come in the range 0 ≤ x < 1 so
we’ll need to rescale our function and integral:
Z
b
Z
f (x)dx =
a
1
g(u)du
0
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Monte Carlo integration
choose a random N-point sample
calculate f (x) at each of the N points
compute the sample average of f
this is our estimate for the integral!
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Random numbers
How can we get random numbers?
Measure a random process
e.g. timing of radioactive decay
tabulate results
every time you use a random number, cross it off table
e.g. ERNIE
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Random numbers
How can we get random numbers?
Measure a random process
Pseudo-random number generator
e.g. linear congruence method, xn+1 = (axn + b) mod c
e.g. a=16807, b=2836, c=231 − 1 gives 231 numbers before
it repeats
To make it 0 ≤ xn < 1 just divide by c before use
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Random processes
We can also use random numbers when simulating random
events. E.g. tossing a coin:
Choose random number 0 ≤ xi < 1
if 0 ≤ xi <
if
1
2
1
2
−→ heads
≤ xi < 1 −→ tails
The range of random numbers we assign to each event is given
by the cumulative frequencyor cumulative probability.
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
A biased die
A slightly more complex example: the score on an unfair die.
score
1
2
3
4
5
6
prob.
0.1
0.1
0.2
0.3
0.2
0.1
Phil Hasnip
cumulative prob.
0.1
0.2
0.4
0.7
0.9
1.0
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
General procedure
Calculate or measure the frequency distribution
Convert into a cumulative frequency distribution
Simulate
This kind of problem often occurs as a submodel of a larger
problem.
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Example – Petrol station
Task is to minimise cost of storing and delivering petrol at a
petrol station to meet fluctuating demand.
The daily cost is a function of three variables:
Storage costs −→ assume constant up to some max.
capacity
Delivery costs −→ assume constant up to some max.
capacity
Demand −→ fluctuates
−→ need three submodels. We’ll concentrate on the demand
model.
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Example – Petrol station demand
Measure demand over a period of time, e.g. 1000 days
Demand is continuous, so discretise (e.g. 10 intervals)
Compute frequency and hence probability
Compute cumulative probability
Model cumulative probability with empirical methods, e.g.
linear splines
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Example – Petrol station demand
score
1000-1099
1100-1199
1200-1299
1300-1399
1400-1499
1500-1599
1600-1699
1700-1799
1800-1899
1900-1999
freq. (days)
10
20
50
120
200
270
180
80
40
30
Phil Hasnip
prob.
0.01
0.02
0.05
0.12
0.20
0.27
0.18
0.08
0.04
0.03
cumulative prob.
0.01
0.03
0.08
0.20
0.40
0.67
0.85
0.93
0.97
1.00
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Example – Petrol station demand
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Example – Petrol station demand
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Example – Petrol station demand
Model cumulative frequency with empirical methods, e.g.
linear splines
Invert empirical model (e.g. splines) to give demand for
given probability
Run simulations and use inverse model to map random no.
0 ≤ xi < 1 to a daily demand
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Example – Petrol station demand
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Example – Petrol station demand
Model cumulative frequency with empirical methods, e.g.
linear splines
Invert empirical model (e.g. splines) to give demand for
given probability
Run simulations and use inverse model to map random no.
0 ≤ xi < 1 to a daily demand
Investigate different storage/delivery strategies to
Minimise cost (min. excess fuel)
Avoid running out of fuel
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random 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 right
After N steps, how far RN have we moved?
The mean displacement will be zero, < RN >= 0
The mean distance is not! < RN2 >6= 0
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random 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 our
example)
RN = Ns, so < RN >= Ns – in our example then
< RN >= N
RN2 = N 2 s2 , so < RN2 >= N 2 s2 – in our example then
< RN2 >= N 2
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random 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 < 1
R0 = 0
If 0 ≤ z < 12 , RN+1 = RN − 1
If
1
2
≤ z < 1, RN+1 = RN + 1
We run the simulation for different final values of N
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
1D Example
N
10
100
1000
10000
Phil Hasnip
< RN2 >
1
9
225
14161
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
1D Example
How can we model this? Let’s suppose < RN2 >∼ CN p , i.e.
⇒ ln < RN2 > = ln C + p ln N
Should give a straight(-ish) line on log-log plot
In fact least-squares fitting gives c = 0.0009, p = 1.8
Is that it? No – random process
−→ need to repeat and average
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
1D example
N
10
100
1000
10000
c
p
< RN2 >1
1
9
225
14161
9.1 × 10−4
1.8
< RN2 >10
19.2
108.4
1041.2
8579.6
1.8
0.92
< RN2 >100
11.320
102.320
946.600
9332.840
0.99
0.99
< RN2 >1000
10.872
107.480
980.944
9459.512
1.1
0.98
So it seems as we average over more runs, c → 1 and p → 1.
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
2D example
What about 2D? Square lattice, now can move either up/down
or left/right each turn (but not both).
N
10
100
1000
10000
< RN2 >1000
9.14
98.884
985.46
10164.2
So again it seems, c → 1 and p → 1.
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Einstein
In 1905 Einstein showed Brownian motion is related to
diffusion
Thus < RN2 >∝ N (i.e. p = 1) is exact
See e.g. Feynmann Vol. 1 for proof
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Onward and upward
This model is very flexible −→ can do lots of interesting
physics with it
Can often model things easily that are v. difficult to solve
mathematically
e.g. QMC/DMC techniques use this to solve Schrödinger’s
equation
e.g. non-crossing random walks
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Non-crossing random walks
Random walk, but cannot visit any location more than once
Boring in 1D, interesting in higher dimensions
Model of a polymer −→ excluded volume effect
Path now has some kind of memory of where it’s been
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Example – polymer
0≤z<
1
3
2
3
≤z<
1
3
2
3
⇒ turn right
⇒ keep going
≤ z < 1 ⇒ turn left
Very difficult maths
Very easy simulation! < RN2 >∼ N 1.4
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Extensions
There are lots of other things we could do, e.g.
Can also vary the step length
Model for electron conduction – resistance due to
scattering off defects
However always remember the results have some statistical
error σ due to the sampling – you need to be careful.
1
σ∼√
N
Phil Hasnip
Mathematical Modelling
Introduction
Monte Carlo integration
Random numbers
Random events
Random walks
Summary
Can get random numbers from tables or pseudorandom
generators
Used for Monte carlo integration
Used for random walks – e.g. brownian motion, polymers,
ties etc.
Phil Hasnip
Mathematical Modelling