Download Random Numbers-Stochastic Process-Lecture Slides and more Slides Stochastic Processes in PDF only on Docsity!
Monte Carlo Methods Lecture Two: Random Numbers
Monte Carlo Methods
Classification of random numbers^ Random numbers for use in computer programs can be classified into 3different categories:^ Truly random numbers: Obviously cannot be produced by computer programs,They must be supplied by an external source like radioactive decay. Suchsequences are available (e.g. on magnetic tape), but clumsy to use and oftennot sufficient in terms of speed and number.^ Pseudorandom numbers: A sequence of numbers is generated to look^ statistically independent
and^ uniformly distributed
. This is the prevailing method
used in random number generators. Quasi-random numbers: These are generated by algorithms tuned to optimizethe sequences
uniform distribution
, which can improve the accuracy of MC
integration. These numbers are not
independent.
^ A function called a
generator
is defined that, when applied to a
number, yields the next number in the sequence. For example, the
linear congruential
generators considered in this
Famous Generator for Random Numbers lecture have the general form:^ One Typical Generator is
X= ( a Xk+^
+ c ) mod mk
Where X
is the kth element, and Xk^
, a, c & m define the generatoro
For numbers in the range [0,1] we divide by m. Such a sequence will however repeat, the length of the repeated cyclebeing referred to as the period.^ ^
A good generator has a long period & No correlation between elements of the sequence.
-^ The parameters are : K
,^ a^ ,^ c o
, and
m
-^ The values are chosen to make the sequence look as random aspossible. Common choices are^ ^
K= Any positive integero^ a = 16807 m = 2
^ c = 0 • Which has a period of m - 1 (that is 2
Random Numbers
Uniform distribution Number
Bins
Random Distributions: Uniform •^ The sequence ofrandom numbers isequally spaced alongthe x-axis. •^ It illustrates the factthat random numbersare distinct, non-repeating and uniformlydistributed in theinterval. This distribution has been drawn using 20 different intervals inthe range (0, 1) range and shown here.
MATLAB provides randn function for Gaussian distribution based randomnumbers and arrays. Its general synopsis is Y = randn(m,n) and it willreturn m
×^ n matix of random entries with average zero and variance
equal to one.^ The^ randn
by itself
returns a scalarvalue when called.Its state can be set by randn(‘state’,j) command.
-3^ -
-^
0 1
2
3
0.6 0.5 0.4 0.3 0.2 0.1 0.
DeviationMean Value
h(z)
The value of z
Random Distributions: Normal
Random Distributions: Normal Let us demonstrate use of uniform distribution of random numbers,to generate a Gaussian or a Normal distribution. The algorithm togenerate a Gaussian distribution of N random numbers is givennext.% Program name; gaussian.m^ % Program to generate 20 bins of a normal distributed^ mbin = 20;^ randn('state', 0) % initialize the generator to state zero^ y = randn(90000,1);^ n = hist(y, mbin) % converts the data from y into 20 bins^ axis([1 mbin 0 9000])^ hold on^ bar(n) % plots the data as a bar graph
-3^ -^
-1^0
1 2
3
0.6 0.5 0.4 0.3 0.2 0.1 0.
DeviationMean Value
h(z)
The value of z
Normal distribution Number
Bin
The distribution from the program is shown here.
Program in Matlab for distributions^ % Program name; monte_normal_dist.m^ % random numbers from rand function in interval [0, 1]^ N = 10;^ NN = 2000;^ xlow_limit = -5.0;^ delta = 0.1;^ Max_bins = 21;^ for i=1:NN^ xx(i) =0.0;^ end^ rand('state', 0) % initialize the generator to state zero^ axis([-5 5 -5 5])^ hold on^ for k = 1: NN^ x1 = 0; x2 = 0;^ u1 = rand;^ u2 = rand;^ x1 = cos(6.32u2)(sqrt(-2log(u1)));^ x2 = sin(6.32u2)(sqrt(-2log(u1)));^ xx(k) = x1;^ k^ plot(x1, x2, 'r:.')^ hold on^ m(k)= getframe;^ end^ %^
movie(m, 30) % play movie 30 times. % plot a histogram to show probability density % hist(xx, 1000) %
Comparison of Two distributions Uniform Distribution
Normal Distribution
Using Random Numbers the event A has occurred if the value of
η^ is
p < ≤η 0
and the event A will occur if
(^1) ≤ ≤η p
The rule for playing the game is to generate a random number andcompare it with p.^ ^
If the value is between zero and
p , we say the event A has
occurred. However, when the value of random number is between
p^ and
1, we will claim that the event B occurred.
p^
1 −^ p
p^
Simulation of Radioactivity •^ A radioactive nucleus is in unstable state capable ofemitting an alpha, beta or a gamma ray at random. •^ Let us consider the radioactive sample of
N atoms at o^
the start of an experiment. • Assume that the probability of a radioactive decay incertain time-period is
p.
-^ For every nucleus in
N nuclei, we give a random o^
number
x^ which belong to the domain
[0, 1]
.
Program in MATLAB: Radioactivity^ N_parent = 1000;
N_daughter = 0;
tmax = 200;
probability_of_decay = 0.01; rand('state', 0) % initialize the generator to state zero t = 0; for i = 1: tmax^ xt(i) = t; xx(i) = N_parent; yy(i) = N_daughter;^ M = N_parent;^ for k = 1: M^ x = rand;^ if x < probability_of_decay^ N_parent = N_parent - 1;^ N_daughter = N_daughter + 1;^ end^ end^ t = t + 1 end plot(xt, xx, 'LineWidth',2) hold on plot(xt, yy, 'LineWidth',2) axis([0 tmax 0 1200]) xlabel('time, t') ylabel('Number of atoms') Grid
Simulation of Radioactivity
te) o(N )t(N
λ−
where,
λ^ is a constant This graph for the decayis similar to anexponential function’sbehavior and we mayattempt to fit thefollowing: related to theprobability of decayper second for theparent nucleus.