You are on page 1of 31

CHAPTER- TWO

Monte Carlo Method

Compiled by: Er. Ashok G.M. 1


Overview
• Monte Carlo Method
• Normally Distributed random numbers
• Monte Carlo method v/s stochastic Simulation

Compiled by: Er. Ashok G.M. 2


Introduction
• Monte Carlo method is a class of computational algorithm that rely
on repeated sampling to compute the results.
• Monte Carlo Methods are often used in simulating physical and
mathematical simulation.
• These methods are most suited for calculation by a computer and
tend to be used when it is impossible to compute an exact result
with deterministic algorithm.
• This method is also used to compliment the theoretical derivations.

Compiled by: Er. Ashok G.M. 3


Applications of Monte Carlo Method
• Specially useful for simulating the systems with many coupled
degree of freedom such as fluids, disordered materials, cellular
structures etc.
• Used to model phenomenon with significant uncertainty in inputs
such as calculations of risk in business.
• Widely used in mathematics to evaluate multi dimensional definite
integral with complicated boundary conditions.
• It is also used in space exploration and oil exploration to predicate
failures, cost over runs, schedule over run etc.

Compiled by: Er. Ashok G.M. 4


Calculation of PI(π) using Monte Carlo Method
• It uses the simple integration of “HITS” and “MISS”.

Fig i Fig ii
Compiled by: Er. Ashok G.M. 5
• Let us take a quadrant of a circle. It is easy to imagine throwing
darts randomly at figure ii.
• It is apparent that the total numbers of darts that hit within the
square and the number of darts that hit the accept zone(quadrant)
is proportional to the area of that part.
• In other words:
1 2
𝑁𝑜 𝑜𝑓 𝑑𝑎𝑟𝑡𝑠 ℎ𝑖𝑡𝑡𝑖𝑛𝑔 𝑡ℎ𝑒 𝑞𝑢𝑎𝑑𝑟𝑎𝑛𝑡 (𝑛) 4
∗ π∗𝑟
= 2
𝑁𝑜 𝑜𝑓 𝑑𝑎𝑟𝑡𝑠 ℎ𝑖𝑡𝑡𝑖𝑛𝑔 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑠𝑞𝑢𝑎𝑟𝑒(𝑁) 𝑟

𝑛
Hence, π = 4*
𝑁

Compiled by: Er. Ashok G.M. 6


Q. Calculate the value of π using Monte Carlo Method where the equation of circle is given
as x2+y2=100. Calculation Table
Solution: Is
2 2
Equation of circle= x +y =100. random x random distance <
No. Itr(N) (x<=r) y (y<=r) distance r? count (n)
Comparing it with the standard form of 1 7.5 7.8 10.82081 F 0
equation, we get: r2=100 i.e; r=10 2 6.7 6.5 9.334881 T 1
3 8.8 4.5 9.883825 T 2
Now, distance= x2+y2 4 9.8 2.5 10.11385 F 2
From table: 5 5.6 1.2 5.727128 T 3
6 1.2 7.3 7.397973 T 4
n=14 7 3.4 5.8 6.723095 T 5
N= 20 8 3.9 9 9.80867 T 6
𝑛 9 5.4 3.7 6.545991 T 7
PI= 4*𝑁 10 7.6 8.9 11.70342 F 7
11 8.2 3.5 8.915716 T 8
= 2.8 12 1.5 8.6 8.729834 T 9
actual value−observed value 13 9 6.7 11.22007 F 9
Error%= ∗ 100%
actual value 14 5.8 4.8 7.528612 T 10
15 8.4 6.4 10.5603 F 10
16 7.7 3.5 8.458132 T 11
=10.9%
17 3.4 8.7 9.340771 T 12
18 5.1 9.8 11.04762 F 12
19 2.8 6.7 7.261543 T 13
20 8 5.5 9.708244 T 14

Compiled by: Er. Ashok G.M. 7


Monte Carlo Method to calculate definite Integral
• The Monte Carlo method is a numerical
computational method which consists of
experimental sampling with random
number.
For example, the integral of a single
variable over a given range corresponds
to finding the area under the graph
representing the function.
• Suppose the function f(x0) is positive and
has lower and upper bound a and b
respectively and the function is bounded
above by the value c.
• The graph of the function is then contained within a rectangle with sides of length (b-c)
and c.

Compiled by: Er. Ashok G.M. 8


• If we are pick points at random within the rectangle and determined whether
they lie beneath the curve or not, it is apparent that, providing the distribution of
selected points is uniformly spread over the rectangle, the fraction of points
falling on or below the curve should be approximately the ratio of the area under
the curve to the area of the rectangle.
• If ‘N’ points are used and ‘n’ of them fall under the curve, then approximately,

• The accuracy improves as the number N increases. When it is decided that


sufficient points have been taken, the value of integral is estimated by multiplying
n with N by the area of rectangle i.e.)c(b-a).

Compiled by: Er. Ashok G.M. 9


Computational Technique
• For each point, a value of ‘x’ is selected at random between a and b,
say x0.
• A second random selection is made between 0 and c to give Y. If Y0 is
<=f(x0), the point is accepted in the count ‘n’, otherwise it is rejected
and the next point is picked.
• This method often based on integral of many variables by using a
random number for each of the variables.
• Monte Carlo application are sometimes classified as being
simulation.
• Simulation and Monte Carlo method are both numerical
computational technique but the difference is that simulation
applies to dynamic model whereas Monte Carlo technique applied
to static model.

Compiled by: Er. Ashok G.M. 10


5 3
• Q. Evaluate I= 2
𝑥 dx using Monte Carlo Method.
Solution: Calculation Table
Y=f(x)= 𝑥 3 a=2 b=5 random x random y Is y < f(x)
No. Itr(N) (2-5) (0-125) f(x) ? count (n)
Determining ‘c’, 1 2.5 110 15.625 F 0
X 2 2.5 3 3.5 4 4.5 5 2 3 90 27 F 0
Y 8 15.625 27 42.875 64 91.125 125 3 2.3 30 12.167 F 0
4 4.9 67 117.649 T 1
Therefore, c=125 5 4.4 118 85.184 F 1
6 3.5 101 42.875 F 1
I= n/N* c*(b-a) 7 4.6 56 97.336 T 2
From table; 8 2.9 49 24.389 F 2
9 2.7 11 19.683 T 3
I=9/20*125*(5-2) 10 3.2 89 32.768 F 3
= 168.75 11 3.1 95 29.791 F 3
Mathematically, 12 4.8 27 110.592 T 4
13 4.1 121 68.921 F 4
I= 152 14 3.6 66 46.656 F 4
actual value−observed value 15 3.7 95 50.653 F 4
Error%= ∗ 100% 16 3.6 35 46.656 T 5
actual value
17 2.9 19 24.389 T 6
18 4.5 89 91.125 T 7
= 11.01% 19 3.1 17 29.791 T 8
20 4.3 69 79.507 T 9

Compiled by: Er. Ashok G.M. 11


Class Work
π
• Q. Evaluate I= 0
𝐶𝑜𝑠𝑥 dx using Monte Carlo Method.

Compiled by: Er. Ashok G.M. 12


Assignment 2
• Write Short Notes on Stochastic Simulation and Deterministic
Simulation.

Compiled by: Er. Ashok G.M. 13


Distributed Lag Model
• Models that have the properties of changing only at a fixed interval of time, and
of basing current values of the variables on other current values and values that
occurred in previous intervals are called distributed lag model.
• They are used extensively in econometric studies where uniform steps
corresponds to a time interval such as a month or year over which economic data
are collected. As a rule these model consist of linear , algebraic equations.
• They represent a continuous system but one in which the data is only available at
fixed points in time.
• Distributed lag model can also be defined as a model which contains both the
current and past(lagged variables) variables of explanatory variables.
• Eg. Yt= a + b0 xt + b1 xt-1 + ……. + bk xt-k
• In a dynamic model the variable of interest may be influenced by the value of
some variable in the previous time period, which is lagged variables.

Compiled by: Er. Ashok G.M. 14


• For Eg. Consider the following simple mathematical model of National Economy.
C=Consumption
C=20 + 0.7 (Y-T)
I= Investment
I= 2 + 0.1 Y
T= Taxes
T= 0.2 Y
G= Government Expenditure
Y= C+I+G
Y= National income
• This is a static mathematical model but it can be made dynamic by picking a fixed time
interval say, 1 year expressing current values of the variables in terms of values at previous
intervals.
• The values in previous intervals is denoted by attaching suffix –n to the variable where n
indicates the interval(1 denoting previous interval, 2 denoting the prior to that and so on)
• The Static model could be made dynamic by lagging all the variables.
I= 2+ 0.1 Y-1 T= 0.2 Y-1 Y= C-1+ I-1 +G-1 C= 20+ 0.7 (Y-1 + T-1)
• It is not necessary to lag all variables. By solving the equations, the model may be made
dependent only on one lagged variable.
• Eg. I= 2+ 0.1 Y-1 Y= 45.45 +2.27(I+G) T= 0.2 Y C=20 + 0.7(Y-T)

Compiled by: Er. Ashok G.M. 15


Normally Distributed random numbers
• Normal distribution: The normal distribution is widely known and used
because it approximate many natural phenomena and it is a reference for
many probability problem.
Characteristics of Normal Distribution:
• Symmetric, bell shaped
• Continuous for all values of X between -∞ and +∞ so that each
conceivable interval of real numbers has a probability other than zero.
• -∞ ≤ X ≤ ∞
• Two parameters, µ and σ. Note that the normal distribution is actually a
family of distributions, since µ and σ determine the shape of the
distribution.
• The rule for a normal density function is:

Compiled by: Er. Ashok G.M. 16


Contd..

• The notation N(µ, σ2) means normally distributed with mean µ and
variance σ2.. If we say X ∼ N(µ, σ2) we mean that X is distributed N(µ,
σ2).
• About 2/3 of all cases fall within one standard deviation of the
mean, that is P(µ - σ ≤ X ≤ µ + σ) = .6826.
• About 95% of cases lie within 2 standard deviations of the mean,
that is P(µ - 2σ ≤ X ≤ µ + 2σ) = .9544

Compiled by: Er. Ashok G.M. 17


Compiled by: Er. Ashok G.M. 18
Why is the normal distribution useful?
• Many things actually are normally distributed, or very close to it. For
example, height and intelligence are approximately normally
distributed; measurement errors also often have a normal
distribution
• The normal distribution is easy to work with mathematically. In
many practical cases, the methods developed using normal theory
work quite well even when the distribution is not normal.
• There is a very strong connection between the size of a sample N
and the extent to which a sampling distribution approaches the
normal form. Many sampling distributions based on large N can be
approximated by the normal distribution even though the
population distribution itself is definitely not normal.

Compiled by: Er. Ashok G.M. 19


Standardized normal distribution.
• General Procedure. As you might suspect from the formula for the normal density
function, it would be difficult and tedious to do the calculus every time we had a
new set of parameters for µ and σ. So instead, we usually work with the
standardized normal distribution, where µ = 0 and σ = 1, i.e. N(0,1).
• That is, rather than directly solve a problem involving a normally distributed
variable X with mean µ and standard deviation σ, an indirect approach is used.
1. We first convert the problem into an equivalent one dealing with a normal
variable measured in standardized deviation units, called a standardized
normal variable. To do this, if X ∼ N(µ, σ2), then,

2. A table of standardized normal values (Table) can then be used to obtain an


answer in terms of the converted problem.
3. If necessary, we can then convert back to the original units of measurement. To
do this, simply note that, if we take the formula for Z, multiply both sides by σ,
and then add µ to both sides, we get X = Z σ + µ

Compiled by: Er. Ashok G.M. 20


4. The interpretation of Z values is straightforward. Since σ = 1, if Z = 2, the
corresponding X value is exactly 2 standard deviations above the mean. If Z
= -1, the corresponding X value is one standard deviation below the mean. If
Z = 0, X = the mean, i.e. µ.
Rules for using the standardized normal distribution.
It is very important to understand how the standardized normal
distribution works, so we will spend some time here going over it.
Recall that, for a random variable X, F(x) = P(X ≤ x)
1. P(Z ≤ a)
= F(a) (use when a is positive)
= 1 - F(-a) (use when a is negative)

Compiled by: Er. Ashok G.M. 21


 Find P(Z ≤ a) for a = 1.65, -1.65, 1.0, -1.0
• P(Z ≤ 1.65) = F(1.65) = .95
• P(Z ≤ -1.65) = F(-1.65) = 1 - F(1.65) = .05
• P(Z ≤ 1.0) = F(1.0) = .84
• P(Z ≤ -1.0) = F(-1.0) = 1 - F(1.0) = .16
 Find a for P(Z ≤ a) = .6026, .9750, .3446
• To solve: for p ≥ .5, find the probability value in Table, and report the
corresponding value for Z. For p < .5, compute 1 - p, find the corresponding Z
value, and report the negative of that value, i.e. -Z.
P(Z ≤ .26) = .6026
P(Z ≤ 1.96) = .9750
P(Z ≤ -.40) = .3446 (since 1 - .3446 = .6554 = F(.40))

Compiled by: Er. Ashok G.M. 22


2. P(Z ≥ a)
= 1 - F(a) (use when a is positive)
= F(-a) (use when a is negative)
Find P(Z ≥ a) for a = 1.5, -1.5
To solve: for a positive, look up F(a), as before, and subtract F(a) from 1. For a
negative, just report F(-a).
P(Z ≥ 1.5) = 1 - F(1.5) = 1 - .9332 = .0668
P(Z ≥ -1.5) = F(1.5) = 0.9332
3. P(a ≤ Z ≤ b) = F(b) - F(a)
Find P(a ≤ Z ≤ b) for a = -1 and b = 1.5
To solve: determine F(b) and F(a), and subtract.
P(-1 ≤ Z ≤ 1.5) = F(1.5) - F(-1) = F(1.5) - (1 - F(1)) = .9332 - 1 + .8413 = .7745

Compiled by: Er. Ashok G.M. 23


4. For a positive, P(-a ≤ Z ≤ a) = 2F(a) – 1
PROOF:
P(-a ≤ Z ≤ a)
= F(a) - F(-a) (by rule 3)
= F(a) - (1 - F(a)) (by rule 1)
= F(a) - 1 + F(a)
= 2F(a) - 1
 find P(-a ≤ Z ≤ a) for a = 1.96, a = 2.58
P(-1.96 ≤ Z ≤ 1.96) = 2F(1.96) - 1 = (2 * .975) - 1 = .95
P(-2.58 ≤ Z ≤ 2.58) = 2F(2.58) - 1 = (2 * .995) - 1 = .99

Compiled by: Er. Ashok G.M. 24


• Q. The top 5% of applicants (as measured by GRE scores) will receive scholarships.
If GRE ~ N(500, 1002), how high does your GRE score have to be to qualify for a
scholarship?
Solutions: Let X = GRE. We want to find x such that P(X ≥ x) = .05
compute ,
Z = (X - 500)/100 (NOTE: Z ~ N(0,1) )
and find z for the problem,
P(Z ≥ z) = .05
= 1 - F(z)
If 1 - F(z) = .05, then F(z) = .95.
Looking at Table , F(z) = .95 for z = 1.65 (approximately).
Hence, z = 1.65. To find the equivalent x, compute
x = (z * 100) + 500
= (1.65 * 100) + 500
= 665.
Thus, your GRE score needs to be 665 or higher to qualify for a scholarship.
Compiled by: Er. Ashok G.M. 25
• Q. Family income ~ N($25000, $100002). If the poverty level is $10,000, what
percentage of the population lives in poverty?
Solution.
Let X = Family income. We want to find P(X ≤ $10,000). This is too hard to
compute directly, so let
Z = (X - $25,000)/$10,000.
If x = $10,000, then z = ($10,000 - $25,000)/$10,000 = -1.5.
So,
P(X ≤ $10,000)
= P(Z ≤ -1.5)
=F(-1.5)
= 1 - F(1.5)
= 1 - .9332
= .0668. Hence, a little under 7% of the population lives in poverty.

Compiled by: Er. Ashok G.M. 26


• Q. A new tax law is expected to benefit “middle income” families, those with
incomes between $20,000 and $30,000. If Family income ~ N($25000, $100002),
what percentage of the population will benefit from the law?
Solution.
Let X = Family income. We want to find P($20,000 X ≤ $30,000). To solve, let
Z = (X - $25,000)/$10,000.
Note that when,
x = $20,000
z = ($20,000 - $25,000)/$10,000
= -0.5
and when x = $30,000,
z = +0.5.
Hence, P($20,000 ≤ X ≤ $30,000) = P(-.5 ≤ Z ≤.5) = 2F(.5) - 1 = 1.383 - 1 = .383. Thus,
about 38% of the taxpayers will benefit from the new law.

Compiled by: Er. Ashok G.M. 27


Monte Carlo method v/s stochastic Simulation
• There is not a single definition of a Monte Carlo method, but they have in
common that they make use of random sampling to compute the result.
• The algorithms typically rely on pseudo random numbers, computer
generated numbers mimicking true random numbers, to generate a
realization, one possible outcome of a process.
• All outcomes do not have to be equally probable, and by repeating the
procedure with different random numbers as input, one gathers data
corresponding to the modeled process.

Compiled by: Er. Ashok G.M. 28


• Stochastic simulation is a tool that allows Monte Carlo analysis of
spatially distributed input variables. It aims at providing joint outcomes of
any set of dependent random variables. These random variables can be
• Discrete (indicating the presence or absence of a character)
• Continuous, such as porosity or permeability values
• Random sets, such as ellipses with a given distribution of size and aspect ratio, or
shapes drawn at random from a frequency table of recorded shapes
• The set of random variables can be any combination of these types. Some
random variables can be functions of the geographic coordinates, in
which case they are called random functions.
• A stochastic simulation is a simulation of a system that has variables that
can change stochastically (randomly) with individual probabilities.
• Realizations of these random variables are generated and inserted into a
model of the system. Outputs of the model are recorded, and then the
process is repeated with a new set of random values.

Compiled by: Er. Ashok G.M. 29


• These steps are repeated until a sufficient amount of data is gathered. In the
end, the distribution of the outputs shows the most probable estimates as
well as a frame of expectations regarding what ranges of values the variables
are more or less likely to fall in.
• Often random variables inserted into the model are created on a computer
with a random number generator (RNG).
• The U(0,1) uniform distribution outputs of the random number generator are
then transformed into random variables with probability distributions that are
used in the system model

Compiled by: Er. Ashok G.M. 30


Any Queries??

Compiled by: Er. Ashok G.M. 31

You might also like