Title: Stochastic Methods
1Stochastic Methods
Using random numbers to solve problems in physics
2General areas of use
- Monte-Carlo integration (Metropolis algorithm)
- Optimisation problems (simulated annealing)
- Modelling processes which depend on probability
- (Brownian motion, Ising model)
- Modelling complex real-life systems
3Plan of next two lectures
Generating random numbers Modelling
stochastic systems Sampling variance
Monte-carlo integration Metropolis algorithm
Simulated annealing
4Generating random numbers
Uniform distribution Non-uniform
distributions Transform method Gaussian
distribution Rejection method
5Pseudo-random numbers
A pre-determined algorithm cannot produce
random numbers. But we can generate a sequence
of numbers for which the numbers are
statistically uncorrelated and repeat only over
a very large set of values. If you run the
algorithm again, it will produce the same set
of numbers. Usually change the seed each
time, so the sequences are different
6Uniform random number generators
7Linear congruential generators
- This is one of the commonest algorithms, and
uses a sequence generated by the recurrence
relation - Ij1 (aIj c) mod(m)
- m, a and c are constants
- A common choice is m232-1, a75, c0
- This repeats after about 2109 values
- A particular good RNG is the Mersenne Twister
(period 219937-1, see workshop) - NB some random number generators are not very
random. be careful
8rand
In C you call the system function rand
i rand()n This sets i to a random integer
between 0 and n-1 It must start from some
initial value, the seed set this using
srand(number) If you run the algorithm
again, it will produce the same set of random
numbers If you want to change the seed each
time, so the sequence is different use the C
function date_time_seed() To use this you
need to include the dbos library include
ltdbos\lib.hgt/
9(No Transcript)
10Non-uniform distributions
Transform from the uniform distribution to
another distribution p( y)dy using the
equality So In general to get p(y)f(y)
from uniform p(x) you need to solve the equation
dx/dy f(y)
11The exponential distribution
We want where x is drawn from a uniform
distribution so which has
the solution
So the probability distribution in terms of y is
exponential
12Gaussian variables
- To generate random numbers following
- Generate two uniform random numbers x1 and x2,
and use the Box-Muller transform
It can be shown that
13Rejection method
Sometimes it is difficult or impossible to
solve for y(x) Suppose we want random numbers
following a function f(y) over a range y1,y2
Generate two random numbers Scale the first to
match the range y1,y2 Use the second to set
the shape of the distribution function
14Rejection example
F(y) exp(sin(y) for x 0 to 3p
15Modelling stochastic systems
In general any system which follows
probabilistic laws Simplest case 1-D random
walk A particle moving in 1D taking a step of
length z to the left or right with equal
probability, so P(z) P(-z) 0.5 Write
the nth step as zn, and the position after n
steps as xn
16 After n steps the position is xn xn-1 zn
z1z2zn What is the probability of having j
steps to the left out of n steps? Number of
ways to choose j out of n steps is
n!/j!(n-j)! Total number of possibilities
is 2n So the probability of that xnn-2j
is P(xnn-2j) n!2-n/j!(n-j)!
17If zn-1, what is the mean square displacement
after n steps?
Since and
So the expected rms displacement varies as
18In general zn can vary eg may be a random
variable following a fixed probability
distribution If the probability at step n
depends on xn, and nothing else, the process is
called a Markov chain
19Can use a simple random walk to model the
diffusion equation Also use random numbers to
model radiation scattering perturbations of
comet orbiting the sun random noise in
experimental measurement power-spectrum in
cosmological simulations ....