1 ce 530 molecular simulation lecture 7 david a. kofke department of chemical engineering suny...
TRANSCRIPT
![Page 1: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/1.jpg)
1
CE 530 Molecular Simulation
Lecture 7
David A. Kofke
Department of Chemical Engineering
SUNY Buffalo
![Page 2: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/2.jpg)
2
Monte Carlo Simulation Gives properties via ensemble averaging
• No time integration• Cannot measure dynamical properties
Employs stochastic methods to generate a (large) sample of members of an ensemble• “random numbers” guide the selection of new samples
Permits great flexibility • members of ensemble can be generated according to any convenient probability
distribution…• …and any given probability distribution can be sampled in many ways• strategies developed to optimize quality of results
ergodicity — better sampling of all relevant regions of configuration space
variance minimization — better precision of results
MC “simulation” is the evaluation of statistical-mechanics integrals
31
!NN N E
h NQ dp dr e ( )1 1
!( )
N
N
N N U rZ N
U dr U r e still too hard!
![Page 3: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/3.jpg)
3
One-Dimensional Integrals
Methodical approaches• rectangle rule, trapezoid rule, Simpson’s rule
Quadrature formula
n uniformly separated points
Sum areas of shapes approximating shape of curve ( )
b
a
I f x dxEvaluating the general integral
1 1
( ) ( )n n
i ii i
b aI x f x f x
n
( )f x
x
![Page 4: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/4.jpg)
4
Monte Carlo Integration
Stochastic approach Same quadrature formula, different selection of points
Click here for an applet demonstrating MC integration
1
( )n
ii
b aI f x
n
n points selected from uniform distribution (x)
( )x
x
![Page 5: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/5.jpg)
5
Random Number Generation Random number generators
• subroutines that provide a new random deviate with each call
• basic generators give value on (0,1) with uniform probability
• uses a deterministic algorithm (of course)usually involves multiplication and truncation of leading bits of a number
Returns set of numbers that meet many statistical measures of randomness• histogram is uniform
• no systematic correlation of deviatesno idea what next value will be from knowledge of
present value (without knowing generation algorithm)
but eventually, the series must end up repeating
Some famous failures• be careful to use a good quality generator
1 ( )modn nX aX c m linear congruential sequence
Plot of successive deviates (Xn,Xn+1)
Not so random!
![Page 6: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/6.jpg)
6
Errors in Random vs. Methodical Sampling
Comparison of errors• methodical approach
• Monte Carlo integration
MC error vanishes much more slowly for increasing n For one-dimensional integrals, MC offers no advantage This conclusion changes as the dimension d of the integral increases
• methodical approach
• MC integration
MC “wins” at about d = 4
2 2( )I x n 1/ 2I n
2 2 /( ) dI x n 1// dx L n 1/ 2I n
independent of dimension!
for example (Simpson’s rule)
d = 236 points, 361/2 = 6 in each row
![Page 7: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/7.jpg)
7
Shape of High-Dimensional Regions
Two (and higher) dimensional shapes can be complex
How to construct and weight points in a grid that covers the region R?
2 2
2
( )R
R
x y dxdy
rdxdy
Example: mean-square distance from origin
![Page 8: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/8.jpg)
8
Shape of High-Dimensional Regions
Two (and higher) dimensional shapes can be complex
How to construct and weight points in a grid that covers the region R?• hard to formulate a methodical algorithm in a
complex boundary
• usually do not have analytic expression for position of boundary
• complexity of shape can increase unimaginably as dimension of integral grows
We need to deal with 100+ dimensional integrals
2 2
2
( )R
R
x y dxdy
rdxdy
Example: mean-square distance from origin
( )1 1!
( )N
N
N N U rZ N
U dr U r e
?iw
![Page 9: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/9.jpg)
9
Integrate Over a Simple Shape? 1. Modify integrand to cast integral into a simple
shaped region• define a function indicating if inside or outside R
Difficult problems remain• grid must be fine enough to resolve shape
• many points lie outside region of interest
• too many quadrature points for our high-dimensional integrals (see applet again)
Click here for an applet demonstrating 2D quadrature
0.5 0.5 2 22 0.5 0.5
0.5 0.5
0.5 0.5
( ) ( , )
( , )
dx dy x y s x yr
dx dys x y
1 inside R
0 outside Rs
![Page 10: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/10.jpg)
10
Integrate Over a Simple Shape? 2.
Statistical-mechanics integrals typically have significant contributions from miniscule regions of the integration space•
• contributions come only when no spheres overlap
• e.g., 100 spheres at freezing the fraction is 10-260
Evaluation of integral is possible only if restricted to region important to integral• must contend with complex shape of region
• MC methods highly suited to “importance sampling”
( )1 1!
( )N
N
N N U rZ N
U dr U r e 0Ue
![Page 11: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/11.jpg)
11
Importance Sampling
Put more quadrature points in regions where integral receives its greatest contributions
Return to 1-dimensional example
Most contribution from region near x = 1
Choose quadrature pointsnot uniformly, but accordingto distribution (x)• linear form is one possibility
How to revise the integral to remove the bias?
12
0
3I x dx2( ) 3f x x
( ) 2x x
![Page 12: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/12.jpg)
12
The Importance-Sampled Integral
Consider a rectangle-rule quadrature with unevenly spaced abscissas
Spacing between points• reciprocal of local number of points per unit length
Importance-sampled rectangle rule• Same formula for MC sampling
1
( )n
i ii
I f x x
1x 2x 3x nx…1
( )ii
b ax
n x
Greater more points smaller spacing
1( )
( )
( )
ni
iix
b a f xI
n x
choose x points according to
![Page 13: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/13.jpg)
13
Generating Nonuniform Random Deviates Probability theory says...
• ...given a probability distribution u(z)
• if x is a function x(z),
• then the distribution of (x) obeys
Prescription for (x)• solve this equation for x(z)
• generate z from the uniform random generator
• compute x(z)
Example• we want on x = (0,1)
• then
• so x = z1/2
• taking square root of uniform deviate gives linearly distributed values
Generating (x) requires knowledge of
( ) ( )dz
x u zdx
( )x ax 2 21
2z ax c x a and c from “boundary conditions”
( )x dx
![Page 14: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/14.jpg)
14
Choosing a Good Weighting Function
MC importance-sampling quadrature formula
Do not want (x) to be too much smaller or too much larger than f(x)• too small leads to significant contribution from poorly sampled region
• too large means that too much sampling is done in region that is not (now) contributing much
1( )
1 ( )
( )
ni
iix
f xI
n x
2x 23x 43x
( )x
( )( )
f xx
![Page 15: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/15.jpg)
15
Variance in Importance Sampling Integration
Choose to minimize variance in average
Smallest variance in average corresponds to (x) = c f(x)• not a viable choice
• the constant here is selected to normalize • if we can normalize we can evaluate
• this is equivalent to solving the desired integral of f(x)
Click here for an applet demonstrating importance sampling
( )x dx
222 1 ( ) ( )
( ) ( )( ) ( )I
f x f xx dx x dx
n x x
( )x I n = 100 n = 1000
12
5n 0.09 0.03
2x1
8n 0.04 0.01
23x 0 0 0
34x1
8n 0.04 0.01
2( ) 3f x x
![Page 16: 1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu](https://reader038.vdocument.in/reader038/viewer/2022110212/56649e105503460f94afb3e0/html5/thumbnails/16.jpg)
16
Summary Monte Carlo methods use stochastic process to answer a non-stochastic question
• generate a random sample from an ensemble
• compute properties as ensemble average
• permits more flexibility to design sampling algorithm
Monte Carlo integration• good for high-dimensional integrals
better error properties
better suited for integrating in complex shape
Importance Sampling• focuses selection of points to region contributing most to integral
• selecting of weighting function is important
• choosing perfect weight function is same as solving integral
Next up: • Markov processes: generating points in a complex region