compphys-6.pdf
-
Upload
evan-reeves -
Category
Documents
-
view
213 -
download
0
Transcript of compphys-6.pdf
![Page 1: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/1.jpg)
Lecture 6
Monte Carlo Methods
Computa(onal Methods in Condensed Ma2er Physics
![Page 2: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/2.jpg)
Introduc)on
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 2
• Monte Carlo (MC) methods have been used for centuries (sta%s%cal sampling).
• However during World War II, this method was used to simulate the probabilis)c issues with neutron diffusion (first real use).
• modern version of the Monte Carlo method invented in the late 1940s by Stanislaw Ulam, while working on nuclear weapons projects at the Los Alamos Na)onal Laboratory
• named by Nicholas Metropolis, aUer the Monte Carlo Casino, where Ulam’s uncle oUen gambled
![Page 3: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/3.jpg)
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 3
![Page 4: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/4.jpg)
What is a MC method?
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 4
• Non Monte Carlo methods typically involve ODE/PDE equa)ons that describe the system.
• Monte Carlo method refers to any method that makes use of random numbers – Simula)on of natural phenomena – Simula)on of experimental apparatus – Numerical analysis
• Monte Carlo methods are stochas)c techniques. • It is based on the use of random numbers and probability sta)s)cs to simulate problems.
![Page 5: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/5.jpg)
Why is MC used?
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 5
• It allows us to examine complex system. And is usually easy to formulate (independent of the problem).
• For example, solving equa)ons which describe two atoms interac)ons. This would be doable without using Monte Carlo method. But solving the interac)ons for thousands of atoms using the same equa)ons is impossible.
• However, the solu)ons are imprecise and it can be very slow if higher precision is desired.
![Page 6: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/6.jpg)
Simple Example 1: ¼
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 6
Consider a circle inscribed in a unit square: the circle and the square have a ra)o of areas that is π/4 à the value of π can be approximated using a Monte Carlo method: • Draw a square, then inscribe a circle within it
• Uniformly sca:er 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 ra)o of the two counts is an es)mate of the ra)o of the two areas, which is π/4. Mul)ply the result by 4 to es)mate π.
![Page 7: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/7.jpg)
Simple Example 2: dice
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 7
• Problem: What is the probability that 10 dice throws add up exactly to 32?
• Exact Way. Calculate this exactly by coun)ng all possible ways of making 32 from 10 dice.
• Approximate (Lazy) Way. Simulate throwing the dice (say 500 )mes), count the number of )mes the results add up to 32, and divide this by 500.
• Lazy Way can get quite close to the correct answer quite quickly.
![Page 8: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/8.jpg)
Simple Example 3: integra)on
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 8
f(x)
a b x
f(x)
a b
• Method 1: Analy)cal Integra)on • Method 2: Quadrature (cf. lecture 3) • Method 3: MC -‐-‐ random sampling the area enclosed by
a<x<b and 0<y<max (p(x))
f (x)dxa
b∫ ≈max( f (x))(b− a) #
# + #$
%&
'
()
probability{y<f(x)}
![Page 9: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/9.jpg)
…
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 9
General case: integrate funcGon over complicated region G • Pick a simple (e.g. rectangular) region G’ • Sample N’ random points over G’ • Count points in G: N
![Page 10: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/10.jpg)
Other applica)ons
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 10
• Integra)on • System simula)on • Computer graphics -‐ Rendering • Physical phenomena -‐ radia)on transport • Simula)on of Bingo game
![Page 11: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/11.jpg)
Monte Carlo Error
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 11
• From probability theory one can show that the Monte Carlo error decreases with sample size N as
independent of dimension d.
1N
ε ∝
![Page 12: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/12.jpg)
Reminder: Good PRNG
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 12
• Any subsequence of random numbers should not be correlated with any other subsequence of random numbers. For example, when simula)ng the launched par)cles, we should not generate geometrical pa:erns.
• Random number repe))on should occur only aUer a very large genera)on of random numbers.
• The random numbers generated should be uniform. This point and the first one are loosely related.
• The RNG should be efficient. (It should be vectorizable with low overhead. The processors in parallel systems, should not be required to talk between each other.)
![Page 13: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/13.jpg)
Par)cle/molecular simula)on
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 13
• fixed number of molecules N, fixed volume V (volume), fixed temperature T
• The canonical ensemble par))on func)on from sta)s)cal mechanics
• Evalua)on of observable proper)es A
• Random sampling -‐ brute force Monte Carlo
• When es)mate <A> , most of the compu)ng is wasted
Zc = dΓexp[−βH (Γ)]∫ ,β =1/ (kBT )
Γ = {r1,…, rN ; p1,…, pN}
A =dΓA(Γ)exp[−βH (Γ)]∫
Z
![Page 14: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/14.jpg)
Metropolis-‐Has)ngs algorithm
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 14
A =dΓA(Γ)exp[−βH (Γ)]∫
Z
p(Γ) = exp[−βH (Γ)]d !Γexp[−βH ( !Γ)]∫
Probability of finding the system in a configura)on around ¡
Evalua)on of observable proper)es A
A = p(Γi )A(Γi )i=1
L
∑
Randomly generate sampling points according to the probability distribu)on p(¡ )
![Page 15: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/15.jpg)
Simula)on process
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 15
• Ini)alize the system – Put the system in a random state
• Make a trial move – Randomly make a trial move
• Calculate the energy change – Reevaluate the interac)ons of the moved
par)cles with its neighbors and calculate the energy change
• Accept the trial move with the Metropolis scheme
• Keep trying the moves un)l system approach equilibrium – Either monitor the total energy change, or monitor the structure formed in
the simula)on box • Sampling
– Sample a certain property over a certain number of configura)ons
P = exp −ΔEkBT
#
$%
&
'( ΔE > 0
1 ΔE < 0
)
*+
,+
![Page 16: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/16.jpg)
Lab today
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 16
• Get familiar with the systems • Compile and run the random examples • Implement a mid-‐square RNG for 32-‐bit integers • Create a random walk • Get familiar with a ploqng/data analysis soUware and plot the variance of the random walk and make a linear fit
• Run MC calcula)on for ¼ using rand(), rand48(), and the above
• Implement an MC calcula)on for e • Idea:
![Page 17: compphys-6.pdf](https://reader035.fdocuments.us/reader035/viewer/2022062811/5695d0881a28ab9b0292d8b4/html5/thumbnails/17.jpg)
Next week
A. Glatz: Computa)onal Methods in Condensed Ma:er Physics -‐ Monte Carlo Methods 17
Simula)on of the Ising model &
(Interac)ng gas)