You are on page 1of 14

Table of Contents

What.....................................................................................................................................................2
Some examples...........................................................................................................................2
Example 1: estimate using Monte Carlo method............................................................2
Example 2: Finding global minimum of a function using Simulated annealing...............3
Example 3: improve a real product with simulated data...................................................3
Why......................................................................................................................................................4
Why Monte Carlo is used for optimization.................................................................................4
Why Monte Carlo is used for numerical integration...................................................................5
Why Monte Carlo is used for improving real products...............................................................6
How......................................................................................................................................................6
How to measure the Pi number using Monte Carlo....................................................................6
How to find global minimum using Monte Carlo.......................................................................7
How to reduce defects using Monte Carlo..................................................................................7
What do we need to perform Monte Carlo method..............................................................................8
Random number generators........................................................................................................8
Middle-square method.......................................................................................................8
Simple Linear Congruential Generators [7]......................................................................8
Software for Random Number Generation.................................................................................9
Some hand-on examples.......................................................................................................................9
On matlab....................................................................................................................................9
Calculate Pi number...........................................................................................................9
Rolling three dice.............................................................................................................10
Application of Monte Carlo on Geophysics.......................................................................................11
Geostatistical Reservoir Modeling............................................................................................11
Geophysical softwares using Monte Carlo.........................................................................................13
Petrel Platform's uncertainty and optimization.........................................................................13
References..........................................................................................................................................14

What
Monte Carlo simulation is the use of experiments with random numbers to evaluate mathematical
expression [7]. They are often used in physical and mathematical problems and are most
useful when it is difficult or impossible to use other mathematical methods. Monte Carlo
methods are mainly used in three distinct problem classes [1]:
+ optimization.
+ numerical integration.
+ simulating systems with many coupled degrees of freedom, such as fluids, disordered
materials, strongly coupled solids, and cellular structures.
+ modeling phenomena with significant uncertainty in inputs such as the calculation of risk
in business.
+ Inverse problems.
The idea of Monte Carlo calculation is a lot older than the computer. The name Monte Carlo is
relatively recentit was coined by Nicolas Metropolis in 1949but under the older name of
statistical sampling the method has a history stretching back well into the last century,when
numerical calculations were performed by hand using pencil and paper [4]. In the very first
applications, it used to calculate Pi number , calculating integrals.

Some examples
Example 1: estimate using Monte Carlo method
Consider a circle inscribed in a unit square. Given that the circle and the square have a ratio of
areas that is /4, the value of can be approximated using a Monte Carlo method [1]:
1.
2.
3.
4.

Draw a square on the ground, then inscribe a circle within it.


Uniformly scatter some objects of uniform size (grains of rice or sand) over the square.
Count the number of objects inside the circle and the total number of objects.
The ratio of the two counts is an estimate of the ratio of the two areas, which is /4. Multiply
the result by 4 to estimate .

Illustration 1: Estimating Pi
using Monte Carlo method.

Example 2: Finding global minimum of a function using Simulated


annealing
Simulated annealing (SA) is a probabilistic technique for approximating the global optimum of a
given function. At each step, the SA heuristic considers some neighbouring state s' of the current
state s, and probabilistically decides between moving the system to state s' or staying in state s.
These probabilities ultimately lead the system to move to states of lower energy but still give a
chance to move to higher enegry. Typically this step is repeated until the system reaches a state
that is good enough for the application, or until a given computation budget has been exhausted.
[2]

Example 3: improve a real product with simulated data


The Monte Carlo method uses repeated random sampling to generate simulated data to use with a
mathematical model. This model often comes from a statistical analysis, such as a designed
experiment or a regression analysis.
Suppose you study a process and use statistics to model it like this:

With this type of linear model, you can enter the process input values into the equation and predict
the process output. However, in the real world, the input values wont be a single value thanks to
variability. Unfortunately, this input variability causes variability and defects in the output.
To design a better process, you could collect a mountain of data in order to determine how input
variability relates to output variability under a variety of conditions. However, if you understand the
typical distribution of the input values and you have an equation that models the process, you can
easily generate a vast amount of simulated input values and enter them into the process equation
to produce a simulated distribution of the process outputs.
You can also easily change these input distributions to answer "what if" types of questions. That's
what Monte Carlo simulation is all about. In the example we are about to work through, we'll
change both the mean and standard deviation of the simulated data to improve the quality
of a product [5].
Today, simulated data is routinely used in situations where resources are limited or gathering real
data would be too expensive or impractical.
This process can help to:

Simulate product results while accounting for the variability in the inputs

Optimize process settings

Identify critical-to-quality factors

Find a solution to reduce defects

In a nutshell, Monte Carlo methods (or Monte Carlo experiments) are a broad class of
computational algorithms that rely on repeated random sampling to obtain numerical
results. Monte Carlo method is used widely in many fields, above examples are just to name
some.

Why
Why Monte Carlo is used for optimization
Optimization is a process to find a good solution, it is even a maximum or a minimum of a function.
Simulated annealing (SA) is a probabilistic technique for approximating the global optimum of a
given function [2]. If global mininum is less imporant than a local minimum then we can use
Steepest descent, gradient descent. But for a function with many local minimum, Steepest descent
and gradient descent will fail to find a global minimum/maximum and would rather be stuck at a
local instead.
Mathematical approaches like gradient descent or steepest descent are only suitable for
find a local minimum/maximum or global minimum of a very simple function having only
one minimum or maximum.

Illustration 2: Gradient Descent


For some functions in finance, they may look like this:

Illustration 3: Function with many local


minimum.
With this kind of function, a purely mathematical approaches like gradient descent or steepest
descent will get stuck on a local maximum instead of finding the global maximum. They
need a mechanism which somehow allows the optimizer to take risk accepting a worst solution to
find a better solution later rather to get stuck in a local minimum/maximum. Monte Carlo method
gives them a method to randomly take this risk.

Why Monte Carlo is used for numerical integration


For example, we have a function like this.

Illustration 4: Function: sin^2(1/x)

And we need to calculate the integrals below:

The fast fluctuation near the origin makes it very difficult to solve this analytically. Monte Carlo is
used to solve this problem [4].

Why Monte Carlo is used for improving real products


Firstly, the input of any system often variate rather than can be specified exactly. Secondly,
the process of putting input in a system to collect a large number of output can be a very
expensive or impractical process. In this case, Monte Carlo is used to simulate a distribution of
input. Moreover, by adjusting mean and deviation of input you can understand the distribution of
output variable. With these information you can tailor the system to reduce defect percentage at
output.

In a nutshell, Monte Carlo is used when mathematical methods becomes impractical or


impossible.

How
How to measure the Pi number using Monte Carlo
Taking the example as in What section:

Basing on the theory of probability, one can calculate the probability that a random grain falling into
the red section equals to the area of red section over the whole square section: pi/4.
By using the law of large number, when you repeat the action of dropping grains onto this square
and the number of repetition, N, is large enough. The fraction of number of grains fall onto red
section, n, and N will tend to converge to pi/4.

How to find global minimum using Monte Carlo


The probability of making the transition from the current state s to a candidate new state is s'
specified by an acceptance probability function

, that depends on the energies

and
of the two states, and on a global time-varying parameter T called
the temperature. States with a smaller energy are better than those with a greater energy. The
probability function P must be positive even when e' is greater than e. This feature prevents the
method from becoming stuck at a local minimum that is worse than the global one.
When T tends to zero, the probability
must tend to zero if e'>e and to a positive value
otherwise. For sufficiently small values of T, the system will then increasingly favor moves that go
"downhill" (i.e., to lower energy values), and avoid those that go "uphill." With T=0 the procedure
reduces to the greedy algorithm, which makes only the downhill transitions.
In the original description of SA, the probability
was equal to 1 when e'<e i.e., the
procedure always moved downhill when it found a way to do so, irrespective of the temperature.
Many descriptions and implementations of SA still take this condition as part of the method's
definition. However, this condition is not essential for the method to work.
The P function is usually chosen so that the probability of accepting a move decreases when the
difference (e'-e) increasesthat is, small uphill moves are more likely than large ones. However,
this requirement is not strictly necessary, provided that the above requirements are met.
Given these properties, the temperature T plays a crucial role in controlling the evolution of the
state s of the system with regard to its sensitivity to the variations of system energies. To be
precise, for a large T, the evolution of s is sensitive to coarser energy variations, while it is sensitive
to finer energy variations when T is small.
This scheme make Simulated Annealing method get out of local minimum since it still gives a
chance to change to a state having a bigger energy.

How to reduce defects using Monte Carlo


Because mean value of input can be controlled easier by the instrument than the deviation [5], one
have to change the means of inputs to check for the distribution of output values. The output
values output a specified range are called defects and this must be reduced. By variating mean
values of input, one can test at which means of inputs we will get least defects. One can proceed
further to control deviation to check for a point where a further decrement of deviation will not help
to reduce defects. All these process will help to reduce defects in reality.

In a nutshell, Monte Carlo uses Law of large number, table list of random number or pseurandom numbers to mimic the random of nature and to simulate nature.

What do we need to perform Monte Carlo method


That is Random number
Monte Carlo Random numbers Truly random numbers slow Pseudorandom
numbers middle-square method (John Von Neuman, 1949), Linear congruential generator

(Lehmer, 1951), Multiple Recursive Generators, Matrix Congruential Generators, Inversive


Congruential Generators, Feedback Shift Register Generators,

Random number generators


Middle-square method
In mathematics, the middle-square method is a method of generating pseudorandom numbers. In
practice it is not a good method, since its period is usually very short and it has some severe
weaknesses, such as the output sequence almost always converging to zero [6].
The alogrithm:
To generate a sequence of 4-digit pseudorandom numbers, a 4-digit starting value is created and
squared, producing an 8-digit number. If the result is less than 8 digits, leading zeroes are added to
compensate. The middle 4 digits of the result would be the next number in the sequence, and
returned as the result. This process is then repeated to generate more numbers.

Illustration 5: The middle-square


method

Simple Linear Congruential Generators [7]


D. H. Lehmer in 1948 proposed a simple linear congruential generator as a source of random
numbers. In this generator, each single number determines its successor by means of a simple linear
function followed by a modular reduction. Although this generator is limited in its ability to produce
very long streams of numbers that appear to be independent realization of a uniform process.
Understanding its properties is necessary in order to use it to build better generators.
The frm of the linear congruential generator is

a is call the multiplier, c is called the increment, and m is called the modulus of the generator.
Often, c in equation above is taken to be 0, and, in this case, the generator is called a
multiplicative congruential generator:

For c not equal to 0, the generator is sometimes called a mixed congruential generator. The seed
for this generator is just the single starting value in the recursion, x0. A sequence resulting from the
recursion above called a Lehmaer sequence. Each xi is scaled into the unit interval (0,1) by
division by m, that is,

If a and m are properly chosen, the ui will look like they are randomly and uniformly distributed
between 0 and 1.

Software for Random Number Generation


Random number generators have been developed for a long time so we should use existing library
instead of developing all algorithms ourselves. Just in the case of needed, we can develop a new and
better one. Random numbers generators are widely available in a variety of software packages.
Some programming languages such as C/C++, Fortran 95, and Ada 95 provide built-in
uniform random number generators, but the standards for these languages do not specify the
algorithm, and it is often difficult to determine from the documentation what algorithm is
implemented or whether the algorithm is correctly implemented. Except for small studies, these
built-in generators should be avoided [7].
Because the computation of Monte-Carlo is expensive, we should use low level languages like
C/C++, Fortran for library. But after all, a Monte Carlo study involves more than just generating
random numbers. This means that users need some high level language to interpret the results
with plots.
Some statistical library we can use are statlib and netlib, IMSL Numerical Libraries.

Some high-level language can be used: Matlab, R, Sclilab.

Some hand-on examples


On matlab
Calculate Pi number
% Matlab Program to Find Pi using Random Numbers
% Tom Huber, June 15, 1996
Nrand = input('How Many Random Numbers ');

NInside = 0;
for nloops=1:Nrand
Xrand = rand;
% Generate Random XY Point
Yrand = rand;
Rrand = Xrand^2 + Yrand^2; % Find its distance from origin
if (Rrand <= 1)
NInside = NInside + 1;
end
end
disp(['Total Generated: ' num2str(Nrand) ' Inside Pts: ' ...
num2str(NInside)]);
piapprox = 4*NInside/Nrand;
disp([' Approximation to pi = ' num2str(piapprox)]);

For Nrand = 5000; approximated Pi = 3.136


For Nrand = 50000; approximated Pi = 3.1414
For Nrand = 100000; approximated Pi = 3.1356

Rolling three dice


clear all
close all
clc
d1 = floor(rand(10000,1)*6+1);
d2 = floor(rand(10000,1)*6+1);
d3 = floor(rand(10000,1)*6+1);
Y = (d1+d2+d3);
for i = 1:18
f(i) = sum(Y==i);
end
bar(f/10000)
xlabel('Sum of dice value');
ylabel('Probability');

Illustration 6: Distribution of sum of three dice.

Application of Monte Carlo on Geophysics


Geostatistical Reservoir Modeling
Geostatistical reservoir-modeling technologies depart from traditional deterministic modeling
methods through consideration of spatial statistics and uncertainties. Geostatistical models
typically examine closely the numerous solutions that satisfy the constraints imposed by the data.
Using these tools, we can assess the uncertainty in the models, the unknown that inevitably
results from never having enough data.

Data for Reservoir Modeling [12]:


* Core data available from a limited number of wells. Although core data or reliable well logs from
horizontal wells would be valuable to assess horizontal measures of spatial continuity, such data are
still uncommon. Core may be sampled by relatively small core plugs or entire section of core may
be measured for whole core data.
* Well log data provide precise information on stratigraphic surfaces and faults as well as
measurements of petrophysical properties such as facies type, porosity, permeability.
* Seismic-derived attributes provide information on large-scale variations in facies proportions and

porosity.
* Seismic-derive structural interpretation, that is, surface grids and fault locations that define largescale reservoir geometry.
* Well test and production data yield interpreted permeability thickness, channel widths, connected
flow paths and barriers. The use of inversion methods provide coarse scale porosity and
permeability models with and associated measure of uncertainty.

There is uncertainties on all these input values and all uncertainties can be modeled using Monte
Carlo method. Moreover, there are maybe conflicts of information from these inputs. For examples,
Core data maybe conflict with well data on permeability since there are some structures of high
permeability like faults.

Illustration 7: Geostatistical Reservoir Modeling.

Geophysical softwares using Monte Carlo

Petrel Platform's uncertainty and optimization


Used to understand the impact of uncertainty on reserves estimates and production forecasting. This
is essential to making effective field development decisions.

References
[1] Monte Carlo method: https://en.wikipedia.org/wiki/Monte_Carlo_method.
[2] Simulated annealing: https://en.wikipedia.org/wiki/Simulated_annealing.
[3] Gradient descent: https://en.wikipedia.org/wiki/Gradient_descent.
[4] M. E. J. Newman and G.T. Barkema (1999), Monte Carlo Methods in Statistical Physics.
[5] http://blog.minitab.com/blog/adventures-in-statistics/understanding-monte-carlo-simulation-withan-example.
[6] Middle-square method https://en.wikipedia.org/wiki/Middle-square_method.
[7] James E. Gentle (2003), Random number generation and Monte Carlo method.
[8] Guide to Available Mathematical Software (GAMS), http://gams.nist.gov.
[9] Introduction to Monte Carlo
Simulation,http://physics.gac.edu/~huber/envision/instruct/montecar.htm.
[10] Monte Carlo Simulation and Matlab.
[11] Geostatistical reservoir modeling, http://petrowiki.org/Geostatistical_reservoir_modeling.
[12] Clayton V. Deutsch, Geostatistical Reservoir Modeling.
[13] Petrel Reservoir Geo-mechanics documentation.

You might also like