Vous êtes sur la page 1sur 39

Introduction to Monte Carlo Methods

Introduction to
Monte Carlo Methods

V. Sundararajan
Evolutionary Computing Team
Scientific and Engineering Computing Group
C-DAC, Pune 411 007
vsundar@cdac.in
vijayraghavan.sundararajan@gmail.com
Introduction to Monte Carlo Methods

Contents
1. What is Optimisation?
2. Methods of optimisation and simulations
3. Introduction to Monte Carlo methods
4. Random Walk
5. Simple Monte Carlo
6. Metropolis Monte Carlo
7. Simulated Anealing
8. Applications:
a) Structure Optimisation
b) Protein polymer Simulations
Introduction to Monte Carlo Methods

Optimisation
• What is optimisation?
– Finding minimum or maximum of a function
• Categories:
– Unimodal

– Multimodal

– Combinatorial
Introduction to Monte Carlo Methods

Class of Methods
• Enumerative – not for complex multimodal or combinatorial
– Calculating function for all possible states
– In a way, Random walk
• Calculus based – works well for unimodal problems
– Steepest descent
– Conjugate Gradient
– Newton Raphson (Variable Metric)
• Stochastic – Widely usable for all types of problems
– Monte Carlo
– Simulated Annealing
– Nature inspired (Evolutionary Strategies, Genetic Algorithms, Ant
colony, Artificial immune systems, genetic programming, gene
expression programming, etc.)
Introduction to Monte Carlo Methods

Efficiency Comparison
Maximum efficiency
1.0
Calculus

Stochastic
Efficiency

Enumerative

Taken from
Goldberg’s book, Chap 1
Introduction to Monte Carlo Methods

Introduction to
Monte Carlo Methods
Introduction to Monte Carlo Methods

Hit or Miss: Area of pond by throw of pebbles

a/A = n/N
A – Area of the land;
a – area of the pond;
N – Total no of pebbles;
n – no of pebbles falling in to the pond
Introduction to Monte Carlo Methods

 Area of a circle circumscribed by a square


π /4 (π r2/4r2 = π /4 ) can be used to find the
value of π
Introduction to Monte Carlo Methods

Tossing the coin

 Toss the coin and check whether ‘H’ or ‘T’


 Count the no of ‘H’ and no of ‘T’
 Find the ratio of n(H)/N where N is total no
of trials

N n(H) n(H)/N
100 52 0.52
1000 485 0.485
10000 5105 0.5105
0.50
100000 50893 0.50893
Introduction to Monte Carlo Methods

HISTORY

In 1777 Comte de Buffon described following expt:


- A needle of length L is thrown at random onto a horizontal
plane ruled with straight lines at a distance of d (d<L) apart.
what is the probability that the needle will intersect one of
these lines? He did the experiment by throwing the needle
many times and arrived at
P = 2L /(π d)
Laplace (1886) suggested this idea to evaluate the value of
π .

L d
Introduction to Monte Carlo Methods

HISTORY
• Lord Kelvin (1901) used random sampling to aid in
evaluation of integrals of the K.E that appears in kinetic
theory of gases.
• Courant, Fredricks & Lewy (1928) showed the
equivalence of the behaviour of random walks to solutions
of certain PDE.
• In 1930s Enrico Fermi made certain numerical
experiments that would now be called MC calculations.
• During Second World War (late 1940s) people like Von
Neumann, Fermi, Uram and Metropolis and advent of
digital computers gave a strong inputs to the advancement
of Monte Carlo.
• Most of the computations to start with were pilot studies,
as the computation power increased, more ambitious
calculations were made and lessons learnt
Introduction to Monte Carlo Methods

Definitions & Observations

 Monte Carlo Methods involve the deliberate use of


random numbers
 Stochastic process: A sequence of states whose
evaluation is determined by random events.
 Answers obtained are statistical in nature and
subject to the laws of chance, more the experiments
more the accuracy
First used for the development of nuclear weapons in
Los Alamos in 1940s.
MC yield both powerful and expressive simulation
and efficient numerical methods for a wide class of
problems.
Introduction to Monte Carlo Methods

MC methods are computationally effective


compared with deterministic methods especially
while handling many dimensional problems
Computer games, generation of synthetic data for
testing
Invention of games of chance whose behavior and
outcome can be used to study some interesting
phenomena.
Simulation of “Solitaire” and estimate the
chance of success, MC is the easiest way of
making such an estimate
Introduction to Monte Carlo Methods

Structure Optimisation

Energy

0.0

r
Introduction to Monte Carlo Methods

Hierarchy of methods

• Random walk
• Monte Carlo
• Metropolis Monte Carlo
• Simulated Annealing
• Population Monte Carlo
Introduction to Monte Carlo Methods

Random Walk
• Start from a random point
• Calculate the energy
• Start a loop over no of RW steps (nrws)
– Start a loop over no of variables
• Propose a random step
• Calculate the energy
– End of loop over no of variables
• End of loop over nrws
Introduction to Monte Carlo Methods

Structure Optimisation

1. Choose a random value for distance between


the atoms R (between 0.8 and 2.0)
• Calculate energy A/R12 – B/R6
1. Choose a random change in R (between –0.05
and +0.05)
2. Calculate energy
3. Repeat the steps 3 and 4 for about 100 times
4. Plot the R in each step vs energy as points
Introduction to Monte Carlo Methods

Random Walk

Initiate

Propose Change
Evaluate Obj. Fun.
Iterate over Statistics
Particles &
No of steps
Termination
Condition

Stop
Introduction to Monte Carlo Methods

Random Walk

Accept any random step


Introduction to Monte Carlo Methods

Computer Exercise
Simulations and Optimisation

Consider a diatomic molecule. You have to find


the equilibrium distance between the atoms. (for
this exercise consider A=B=1.0 ) Start with a
random R value and move to different random
points to explore which is the best R value that
gives minimum energy.
Introduction to Monte Carlo Methods

Simple Monte Carlo


• Start from a random point
• Calculate the energy
• Start a loop over no of MC steps (nmcs)
• Start a loop over no of variables
• Propose a random step
• Calculate the eneergy
• Accept the step if it favourable otherwise, reject it (if
change in energy ‘deltaE’ is negative for minimization
problems, accept)
• End of loop over no of variables
• End of loop over nmcs
Introduction to Monte Carlo Methods

Monte Carlo
Initiate

Propose Change
Evaluate Obj. Fun.

Iterate over DeltaE < 0


Favourable?
Particles & Accept
No of MC steps
Reject Statistics

Termination
Condition

For minimization
Stop DeltaE = Final-Initial
Introduction to Monte Carlo Methods

Random Walk

Accept any random step


Introduction to Monte Carlo Methods

Monte Carlo

Accept any random step


Only if it is favourable
Introduction to Monte Carlo Methods

Computer Exercise:
Monte Carlo simulations

Repeat the exercise with Monte Carlo method and


comment on your results compared to the
random walk process.
Introduction to Monte Carlo Methods

Measuring process in macro-systems


• Macroscopic measuring processes take finite time.
• During this process the system goes through a succession of a
very large number of microstates.
• Any measured property is, hence, its time average of over the
trajectory in the appropriate state variable space (phase space
for physicists).
• In thermal equilibrium, this time average is equal to (under the
so-called ergodic conditions) an equivalent average over a
suitably constructed (Boltzmann) ensemble of systems.
• Monte Carlo simulations are concerned with estimating
averages of different physical properties over such equilibrium
ensembles.

courtesy: Prof. Shastry, UoH


Introduction to Monte Carlo Methods

Metropolis Monte Carlo


• Start from a random point
• Calculate the energy
• Start a loop over no of MMC steps (nmcs)
• Start a loop over no of variables
• Propose a random step
• Calculate the eneergy
• Accept the step if r < exp(-deltaE) accept otherwise,
reject it (r is a random number in the range [0,1])
• End of loop over no of variables
• End of loop over nmcs
Introduction to Monte Carlo Methods

Metropolis Monte Carlo


Initiate

Propose Change
Evaluate Obj. Fun.

r < exp(-deltaE)
Favourable?
Iterate over Accept
Particles &
No of MMC steps Reject Statistics

Termination
Condition

For minimization
Stop
Delta = Final-Initial
Introduction to Monte Carlo Methods

Metropolis Monte Carlo


exp(-deltaE)

1.0
Accept any random step
Only if it is probabilistically
Favourable
0.0
r < exp(-deltaE)
deltaE
Introduction to Monte Carlo Methods

Central Issue in Monte Carlo Application


• Curiously, a system in thermal equilibrium (fixed temperature,
Boltzmann ensemble) moves overwhelmingly only in a limited
volume of phase space.

• Averages of variables computed based on simple Monte Carlo


integration methods, on the other hand, span the entire phase
space. This is very cumbersome and prohibitively expensive.

• Importance sampling techniques focus on guiding Monte


Carlo steps so as to limit them only in the preponderant region
of phase space (region of importance). This improves
significantly the efficiency of making the estimates.

courtesy: Prof. Shastry, UoH


Introduction to Monte Carlo Methods

Use of Metropolis algorithm


• Metropolis algorithm makes the system hop from one
microstate to another (random walk in phase space), but with a
preference to stay in the region of importance.

• It is based on conservation laws of the probability flow in


phase space (microscopic detailed balance).

• Observable features are extracted by averaging them over


microstates collected in the regions of importance.

courtesy: Prof. Shastry, UoH


Introduction to Monte Carlo Methods

Computer Exercise:
Monte Carlo simulations
Repeat the exercise with Metropolis Monte Carlo
method and comment on your results compared
to the random walk process as well as Monte
Carlo method.
Introduction to Monte Carlo Methods

Computer Exercise
Simulation using Monte Carlo

• Simulate a system of particles using MC steps and


collect statistical data on the simulation. For
instance, take 10 particles, track their coordinates
every MC step. Using one of the graphics tools like
MovieMol, make an animation.
Introduction to Monte Carlo Methods

Simulated Annealing
• Start from a random point
• Calculate the energy
• Start a loop over Temperature T
• Start a loop over no of MMC steps (nmcs)
• Start a loop over no of variables
• Propose a random step
• Calculate the eneergy
• Accept the step if r < exp(-deltaE/T) accept otherwise,
reject it (r is a random number in the range [0,1])
• End of loop over no of variables
• End of loop over nmcs
• End of loop over Temperature (decrease temp)
Introduction to Monte Carlo Methods

Simulated Annealing
Initiate

Propose Change
Evaluate Obj. Fun.

r < exp(-deltaE/T)
Iterate over Favourable?
Particles, Accept
Temp T &
No of MC steps Reject Statistics

Termination
Condition

For minimization
Stop
deltaE = Final-Initial
Introduction to Monte Carlo Methods

Simulated Annealing
exp(-deltaE/T)

1.0
Accept any random step
Only if it is probabilistically
Favourable
0.0
r < exp(-deltaE/T)
deltaE/T
Introduction to Monte Carlo Methods

Schedule in Simulated Annealing


Schedule in SA is crucial
• Start from an initial high temperature T (roughly 10 to
100 times change in objective function) depending on the
problem at hand
• Make some initial runs at that temperature to observe
the equilibration through RMSD of the variables and
decide a suitable NMCS.
• Decrease T by a suitable deltaT (roughly by 10%) and
repeat NMCS iterations at each T
• Terminate when T=1 or any suitable nonzero value of T

After this RMSD is


RMSD

hovering around an
average value

NMCS
iterations
Introduction to Monte Carlo Methods

Computer Exercise:
Monte Carlo simulations
Consider molecules like water, carbon-di-oxide, and
benzene and obtain their equilibrium structure
using simulated annealing. Collect required
information like values of A,B, etc from web and
use them.
A 13-atom cluster using Lennard-Jones potential be
simulated.
Introduction to Monte Carlo Methods

Possible Applications of MC

• Multi-dimensional integration
• Volume enclosed by irregular surfaces
• Optimisation
• Molecular Modeling
• Simulations (percolation, ideal gas, ising model)
• Molecules
• Nuclear reactor – prediction of criticality
• Games

Vous aimerez peut-être aussi