Monte Carlo and cold gases Lode Pollet lpollet@physics.harvard.edu 1
Outline Classical Monte Carlo The Monte Carlo trick Markov chains Metropolis algorithm Ising model critical slowing down Quantum Monte Carlo diffusion Monte Carlo worm algorithm sign problem Applications 2
What I will not do high performing computing parallelization programming language (C++) other numerical methods Required knowledge statistical mechanics quantum mechanics some knowledge about many-body physics 3
Integration h = b a N f(x) discrete sum: I = b a f(x)dx = h N f(a + ih)+o(1/n ) i=1 a b higher order integrators trapezoidal I = h N 1 1 2 f(a)+ i=1 f(a + ih)+ 1 2 f(b) +O(1/N 2 ) Simpson I = h 3 f(a)+ (3 ( 1) i )f(a + ih)+f(b) N 1 i=1 +O(1/N 4 ) (N even) 4
Integration Simpson rule with M points per dimension The error in one dimension is O(M 4 ) In d dimensions we need N = M d points the error is O(M 4 )=O(N 4/d ) Integration becomes inefficient in higher dimensions In statistical mechanics the integrals are 6N-dimensional (3N positions, 3N momenta) 5
The Monte Carlo trick I = D g(x)dx identical and independent random samples uniformly drawn from D Î m = 1 m ( ) g(x (1) )+ + g(x (m) ) g(x) D P law of the large numbers [ ] lim m Îm I =0 =1 6
The Monte Carlo trick lim m Cdf m central limit theorem (Îm I) convergence is O(m 1/2 ) = CdfN(0,σ 2 ) regardless of the dimensionality of D 7
random numbers Pseudo random numbers not random at all, but generated by an algorithm probably good enough reproducible Linear congruential generators x n+1 = f(x n ) GGL x n+1 =(ax + c) modm a = 16807,c=0,m=2 31 1 problem is periodicity with 500 million random numbers per second : 4s should not be used any more 8
Lagged Fibonacci generator x n = x n p x n q mod m 0 <p<q, =+,,, XOR Initialization using linear congruential generator very long period (large block of seeds) very fast complex mathematics see: http://beta.boost.org/doc/libs/1_42_0/libs/random/random-generators.html 9
Independent sampling Known geometry converges to π/4 10
demonstration Segmentation fault 10 1./sqrt(x) 1 0.1! - <MC> 0.01 0.001 0.0001 1e-05 1 10 100 1000 10000 100000 1e+06 1e+07 1e+08 Nsteps 11
Importance sampling I = 0 g(x)e x dx draw random numbers that are exponentially distributed, then Î m = 1 m ( ) g(x (1) )+ + g(x (m) ) how? u [0, 1[ p = lnu p [0, [ inverse transformation is needed standard random number generator 12
Importance sampling f(x) N f(x i ) f = 1 V f(x)dx = 1 V p(x) p(x)dx 1 N Varf/p i=1 p(x i ) = N imagine function f is sharply peaked then the variance can be reduced by finding p(x) such that p(x) is close to f(x) and that it is easy to generate random numbers according to p(x) 13
change of variables y = F (y) = y 0 x = F 1 (y) general f(u)du f(x) =x exponential y = F (x) = x =2 y x 0 x dx = x2 2 p = ln(u) Box-Mueller (gaussian) p 1 = R cos(θ) = 2ln(u 1 ) cos(2πu 2 ) p 2 = R sin(θ) = 2ln(u 1 )sin(2πu 2 ) 14
Statistical mechanics : Q = 1 Z Tr [ Qe βh] = Tr[Qe βh ] unnormalized weights W (x) =e βe(x) Tr[e βh ] how do we get random variables that are distributed according to W(x)? 15
Markov chains and rejections Small steps random walk through configuration space at each time : measure transition function? Rejection : stay at same configuration, update clock and measure 16
Markov chains A Markov chain is a sequence of random variables X1, X2, X3,... with the property that the future state depends only on the past via the present state. P [X n+1 = x X n = x n,...,x 1 = x 1,X 0 = x 0 ]=P [X n+1 = x X n = x n ] transition function y T (x, y) T (x, y) =1 conservation of probability irreducible : it must be possible to reach any configuration x from any other configuration y in a finite number of steps. 17
Markov chain irreducible aperiodic } convergence to the stationary distribution W transition kernel has one eigenvalue 1, while all other eigenvalues satisfy λ j < 1,j =2,...N The second largest eigenvalue determines the correlations in the Markov process 18
Detailed balance A transition rule T(x,y) leaves the target distribution W(x) invariant if x W (x)t (x, y) W (y) This will certainly be the case if detailed balance is fulfilled, W (x)t (x, y) =W (y)t (y, x) 19
Metropolis algorithm we cannot construct a transition kernel T that fulfills detailed balance. proposal function P(x,y) q = min acceptance factor [ 1, W (y)p (y, x) W (x)p (x, y) go to the proposed configuration y with prob q, otherwise stay in x ] 20
thermalization energy landscape Initial configuration λ2 λ2 τint Discard the first 20% of the Markov steps! Markov Chain should be sufficiently long 21
recapitulation δ W (X) =e βe(x) P (X Y )= 1 1 N W (Y )=e βe(y ) P (Y X) = 1 N δ 2 1 δ 2 N particles interacting via Lennard-Jones interactions q X Y = min 1,e β(e(y ) E(X)) 22
autocorrelations Markov chains trivially correlate measurements autocorrelations decay exponentially integrated autocorrelation time number of independent measurements is reduced, but central limit theorem still holds 23
Binning analysis How to get correct error bars? Markov chain correlates measurements if chain is long enough, then the configuration is independent of the initial one 1 2 m identically and independent τ int (l) = lσ2 (l) 2σ 2 http://arxiv.org/abs/cond-mat/9707221 appendix 24
Jackknife analysis R (0) R (j), j = 1, k Bias = (k-1)(r av - R (0) ) δr = k 1 1 k k (R (j) ) 2 (R av ) 2 j R = R (0) - Bias 1/2 25
2d Ising model H = J σ i σ j <i,j> Select random spin W (x)t (x, y) =W (y)t (y, x) q = min [ 1, ] W (y)p (y, x) W (x)p (x, y) P (x, y) =P (y, x) = 1 L 2 W (y) W (x) = exp q = min 2βJσ i [ 1,e 2βJσ i <i,j> σ j <i,j> σ j ] 26
Critical slowing down 0.1 0.01 0.001 error(m) T c = ln(1 + 2) 2 0.0001 1e-05 1e-06 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1/T Magnetization m = ±2 divergence of correlation length, critical fluctuations 27
improved estimator m 2 = 1 L 2 σ i σ j = 1 L S(cluster) i,j domain size ~ susceptibility There exist more formal ways and also other ways to solve the problem of critical slowing down 28
cluster algorithm select like spins with probability p p =1 exp[ 2β] then update always accepted (exercise : show that this is true) (why is this not the same as flipping many spins at the same time?) 29
e β(c 1 c 2 ) (1 p) c 2 q X Y = e β(c 2 c 1 ) (1 p) c 1 min 1, e β(c 2 c 1 ) (1 p) c 1 e β(c 1 c 2) (1 p) c 2 30
phase transitions and critical phenomena 0.1 0.01 0.001 0.0001 1e-05 Error on magnetization 1e-06 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1/T local Wolff 1 cluster size in Wolff 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1/T 31
phase transitions and critical phenomena critical exponents have to be calculated numerically P.S. you need to know about finite size scaling 32
Wang-Landau sampling Cluster algorithms do not help near first order transitions 33
Wang-Landau sampling Z = E ρ(e)e E/kT Density of states is however unknown. probability minimum disappears however if we choose - start with ρ(e) = 1 and f =1 - repeat - reset histogram H(E) = 0 p(e) 1/ρ(E) - perform simulations by picking random site and Metropolis updates p(e) 1/ρ(E) H(E) H(E)+1 ρ(e) ρ(e) f - when histogram is flat, reduce f f - stop when f 1 + 10 8 34
References J. S. Liu, Monte Carlo strategies in scientific computing, Springer Verlag W. Krauth, Statistical Mechanics : algorithms and computations, Oxford University Press ETH Zurich professor scripts : http:// www.ifb.ethz.ch/education/introductioncomphys ( and references therein) 35
Homework calculate (mean value, no error analysis) : I = 6 0 exp( x/2)dx by : 1. direct integration (analytical/monte Carlo by exponentially distributed random numbers) 2. Markov chain Monte Carlo : choose a step size d (wisely), and update the current position according to the Metropolis algorithm by choosing a random step of. Don t forget that in every step you can move to larger or smaller x values. Show that you satisfy detailed balance. 3. modification (advanced). Suppose the following. Suppose you start with moving to the right. If you accept the move, then always choose moving to the right in the next step. If you reject the move, then start moving to the left. So, you keep moving in one direction until you have a rejection (bounce), and then you change the direction and keep moving in this direction until there is another bounce after which you change the direction again. Does this Monte Carlo Markov chain produce the right answer? 36