L E C T U R E 6 : M o n t e C a r l o M e t h o d s a n d S S A
M o d e l i n g a n d S i m u l a t i o n 2 D a n i e l G e o r g i e v
O U T L I N E
• Introduction computation of pi multidimensional integrals
• Monte Carlo Simulation algorithm convergence sensitivity
• Random number generation uniform distribution inverse method
• Stochastic simulation algorithm first reaction Gillespie method
E S T I M AT I N G π
• Area of a circle: • Area of a square: • Areas expressed as expectation values:
where is the volume of the domain and are the indicator functions for the circle and square.
• Random approximation of expectation values: generate points uniformly distributed in evaluate and at each point compute the sample averages of
estimate pi
AC = ⇡r2
AS = 4r2
V (⌦) IS |IC
AC = V (⌦)R⌦ IC(x)
1V (⌦)dx,AS = V (⌦)
R⌦ IS(x)
1V (⌦)dx
⌦xi, i = 1, ..., N
IS(xi) IC(xi)
IC = 1N
PNi=1 IC(xi), IS = 1
N
PNi=1 IS(xi)
⇡
4 = ACAS
=R⌦ IC(x) 1
V (⌦)dxR⌦ IS(x) 1
V (⌦)dx= IC
IS
E S T I M AT I N G π - R A N D O M S I M U L AT I O N
N U M E R I C A L I N T E G R AT I O N
Numerical integration can be performed using deterministic and random methods.
• Simpson’s rule for numerical integration uses quadratic approx.
• Error of Simpson’s rule for an n-dimensional system: • Number of points required to achieve error epsilon: • Random approximation of integral:
where are uniformly distributed in • Expected error of random method is independent of the dimension d:
✏ / N�4/d
N / 1✏d/4
R⌦ g(x)dx ⇡ V (⌦)
PNi=1 g(xi)
xi, i = 1, ..., N ⌦
✏ / N�1/2
G E N E R A L M O N T E C A R L O M E T H O D
Monte Carlo Simulation is a method for approximating expectation values of a general function g(X), where X is a random variable with a known distribution F(x) = P(X<x).
The basic steps of Monte Carlo Simulation 1. Distributions (F) - description of the underlying random variables, these
can be cumulative distributions derived from analytical models or empirical distributions measured from experiments
2. Sampling (xi) - generation of independently distributed samples based on given distributions.
3. Deterministic execution (g(xi)) - use deterministic methods to compute the function for the given samples.
4. Aggregation of results ( ) - compute the final estimate of the expectation value using the sampled calculations of f.
5. Error approximation ( ) - approximate the error of the aggregated results.
|ENg(X)� Eg(X)|
ENg(X)
C E N T R A L L I M I T T H E O R E MCentral limit theorem: Consider N identical and independently distributed random variables Xi with probability distribution F and finite standard deviations, i.e., and . Define the sample mean (itself a random variable) as The distribution of the difference between the sample mean and the mean of Xi approaches the standard normal distribution as N goes to infinity, i.e.,
NOTE: the central limit theorem applies for any distribution F.
P (Xi > x) = F (x)
ENX = 1N
PNi=1 Xi
�2 = EX2i � (EXi)2 < 1
ENX�EXi
�/pN
! N(0, 1) as N ! 1
C O N V E R G E N C EFor Monte Carlo methods, the accuracy requirements are specified as follows. Let the error be defined as
Want an approximate solution that satisfies
According to the central limit theorem Hence is the quantile function, i.e., zx satisfies P(Z<zx) = x, where Setting
Caveat: The above formula is a recipe for calculating the number of points needed to meet the accuracy requirements. However, if we don’t know the mean, we also don’t know σ. This problem is circumvented by approximating σ from a fixed number of pilot runs (approx. 100) and setting σ to be the sample standard deviation
r = |ENX � EXi|
P (r ✏) = 1� ↵
ENX � EXi ⇡ N(0,�/pN)
P (r z1�↵/2�/pN) = 1� ↵, where z1�↵/2
Z ⇠ N(0, 1)
✏ = z1�↵/2�/pN , yields N =
�2z21�↵/2
✏2
�2N =
PNi=1(Xi�ENXi)
2
N�1
R A N D O M N U M B E R G E N E R AT I O N
The number of needed samples N is also affected by the sampling efficiency. If we know the density function f, we can always sample from the uniform distribution
where Y is uniformly distributed on Ω.
Remark: There are no true random number generators, not even for the uniform distribution. MATLAB and other sw tools generate pseudorandom numbers as that are uniformly distributed as follows 1. pick a seed x0 >0
2. generate an integer sequence xk+1 = modm (a xk + c) 3. The numbers xk+1/m are uniformly distributed on on the interval [0,1]
Eg(X) =R⌦ g(x)f(x)dx = V (⌦)
R⌦ g(x)f(x) 1
V (⌦)dx = V (⌦)Eg(Y )f(Y )
I N V E R S E M E T H O DSampling from uniform distributions, however, is not efficient. One may end up performing deterministic computations of the function g(x)f(x) for values of x with 0 probability, i.e., xk for which f(xk) = 0.
It is more efficient to sample from the actual cumulative distribution F.
The majority of 1 dimensional random variables can be sampled using the inverse method and a uniform random number generator.
Let U be uniformly distributed on [0,1]. Let Hence, we can sample any 1 dimensional random variable, even if F is an empirically measured distribution.
Then P (U x) = x, x 2 [0, 1].
X = F
�1(U), then P (X x) = P (F�1(U) x) = P (U F (x)) = F (x)
E X A M P L E S O F T H E I N V E R S E M E T H O D
General uniform RVs
Exponential RVs
Univariate Normal RVs
X ⇠ Uniform(a, b), F (x) = x�a
b�a
, F
�1(y) = (b� a)y + a
X = (b� a)U + a
X ⇠ Exp(�), F (x) = 1� e
��x
, F
�1(y) = � 1�
log(1� y)X = � 1
� log(1� U) = � 1� log(U)
X ⇠ N(0, 1), X
2+ Y
2= �2 log(U), X =
p�2 log(U)cos(2⇡V ),
U ⇠ Uniform(0, 1), V ⇠ Uniform(0, 2⇡)
M O N T E C A R L O S I M U L AT I O N M E T H O D S
S T O C H A S T I C S I M U L AT I O N A L G O R I T H M ( S S A ) D . T. G i l l e s p i e , J . P h y s . C h e m . A 8 1 , 2 3 4 0 ( 1 9 7 7 ) M . G i b s o n a n d J . B r u c k , J . P h y s . C h e m . 1 0 4 , 1 8 7 6 ( 2 0 0 0 )
G E N E R A L S T R AT E G Y
F I R S T R E A C T I O N M E T H O D ( n a i v e m e t h o d )
f i r s t r e a c t i o n m e t h o d r e q u i r e s M R V s
F I R S T R E A C T I O N M E T H O D ( M AT L A B i m p l e m e n t a t i o n )
T H E N E X T R E A C T I O N M E T H O D ( u s e f u l i n c o m p a r t m e n t a l i s e d s y s t e m s )
K E Y P R O P E R T Y O F E X P R V s
T H E D I R E C T M E T H O D ( G i l l e s p i e a l g o r i t h m )
f i r s t r e a c t i o n m e t h o d r e q u i r e s M R V s
T H E D I R E C T M E T H O D ( M AT L A B i m p l e m e n t a t i o n )
TA U L E A P I N G ( s p e e d i n g u p t h e s i m u l a t i o n )m a n y s y s t e m i n c l u d e t h o u s a n d s o f m o l e c u l e s t o g e n e r a t e t h e s e n u m b e r n e e d t h o u s a n d s o f s t e p s t h i s m a k e s m a n y s t o c h a s t i c s i m u l a t i o n v e r y t i m e c o n s u m i n g
D I S C R E T E A N D C O N T I N U O U S ( s p e e d i n g u p t h e s i m u l a t i o n )
w (P ) =
V Pn
Pn+Kn , activation
H I L L f u n c t i o n m o d e l s o f g e n e a c t i v a t i o n a n d i n h i b i t i o n
w (P ) =
V1+Pn/Kn , inhibition