780.20 Session 3 (lst revised: Februry 25, 202) 3 3. 780.20 Session 3. Follow-ups to Session 2 Histogrms of Uniform Rndom Number Distributions. Here is typicl figure you might get when histogrmming uniform distributions using gnuplot (using plot... with steps to get the histogrm look): Two sets of numbers hve n verge of 2000 counts per Uniform Rndom Number Distributions 2000 500 # in bin 000 500 uniform uniform 2 uniform 3 uniform 4 0 0 0.2 0.4 0.6 0.8 Thu My 0 :38:2 2008 bin nd two sets hve n verge of 500 per bin. The size of the fluctutions should scle s # of counts in bin, which is evident in the figure. Tht is, the fluctutions of the top sets look roughly twice s lrge s those of the bottom set nd stndrd devition of 40 50 looks bout right. The Length of Rndom Wlks. In Session you explored how the finl distnce R from the origin of rndom wlk scles with the number of steps N. Remember tht there is no reltionship for ny individul wlk, but only sttisticl reltionship tht rises by verging R for given N over mny trils. Here is grph tht you might obtin: It shows good fit to the expected N dependence! x
780.20 Session 3 (lst revised: Februry 25, 202) 3 2 000 rndom wlks best-fit line sqrt(# of steps) Rndom Wlks fit slope = +0.54 finl distnce from origin 00 0 0 00 000 0000 00000 # of steps Thu My 0 0:22:20 2008 b. Recp of Session 2: Monte Crlo Integrtion nd Led-in to Session 3 We explored in Session 2 how we could pproximte n integrl f(x) dx by picking rndom sequence of N vlues of x, which we lbel {x i }, distributed uniformly on [, b]. Tht is, the probbility of choosing number between x nd x + dx is P uniform (x) dx = dx. (3.) b Note tht this PDF (probbility distribution function) is normlized, i.e., P uniform (x) dx = b s you d expect since the totl probbility must be unity. dx =, (3.2) The Monte Crlo expression for the integrl rises by pproximting the verge of f(x) in [, b]: We cn write this s f = b f(x) dx f(x i ). (3.3) N i f(x) P uniform (x) dx f(x i ). (3.4) N i
780.20 Session 3 (lst revised: Februry 25, 202) 3 3 You should hve found tht the ccurcy of the integrl improved sttisticlly with the number of points. Here is grph showing the results of 6 trils for ech vlue of N: Monte Crlo Integrtion monte crlo estimte best-fit line fit slope = -0.47 0. bsolute error 0.0 0.00 0 00 000 0000 00000 Thu My 0 0:2:09 2008 # of integrtion points The expected behvior is reveled by the fit (error improves like / N), but with lrge fluctutions. We should verge over mny more trils if we wnt clener demonstrtion! Now wht if we used different probbility distribution P (x)? Then if our N vlues of x, which we ll lbel { x i }, re distributed ccording to P (x), the verge of the f( x i ) s yields n pproximtion to the integrl over f(x)p (x): N f( x i ) i f(x) P (x) dx. (3.5) This mens tht we cn lwys divide given integrnd into prt tht we tret s probbility distribution (clled P (x) here) nd the rest (which is clled f(x) here). If we choose P (x) so tht f(x) vries only reltively slowly with x, we will get n ccurte estimte of the integrl. This is clled importnce smpling. The generliztion to mny dimensions is immedite: we simply replce one-dimensionl x by multi-dimensionl vector x everywhere. In Session 2 we sw tht GSL cn generte rndom numbers ccording to vrious one-dimensionl PDF s, such s uniform nd gussin distributions. But the multi-dimensionl integrls we ll wnt
780.20 Session 3 (lst revised: Februry 25, 202) 3 4 to do for physicl problems will generlly hve nonstndrd P (x). We will use the Metropolis lgorithm to generte n pproprite distribution of x i s. c. Thermodynmic Properties of the Ising Model If we wnt to clculte the thermodynmic properties of system t temperture T (tht is, in equilibrium) tht hs Hmiltonin H(x), we hve the problem of clculting high dimensionl integrl with rpidly vrying integrnd. Here H(x) is the energy of the system for given configurtion x. A configurtion is specifiction of the stte of the system in some relevnt vribles. For quntum mechnicl system of N spinless prticles, configurtion could be the N position vectors. For system of spins on lttice, configurtion could be specifiction of the spin projection t ech lttice point. We ll use the Ising model in one nd two dimensions s our first exmple. The system consists of set of lttice sites with spins, which tke on only two possible vlues, + or. The spins re rrnged in chin (one-dimensionl Ising model) or squre lttice (two-dimensionl Ising model). The interction between spins is short-rnged, which is represented in our model by interctions only between nerest neighbors. Tht is, there is potentil energy only from djcent spins. Ech spin hs two nerest neighbors in one dimension nd four nerest neighbors in two dimensions (digonls don t count here!). We hve to specify wht hppens t the edge of the system. E.g., do the ends of the onedimensionl chin hve only one nerest neighbor, or do we imgine the chin wrpped into continuous bnd? In the ltter cse, we hve periodic boundry conditions, becuse it is equivlent to imgining n infinite chin tht repets itself periodiclly. We lso llow for n externl constnt mgnetic field, H, which intercts with ech of the spins individully to contribute Zeemn energy. (Note: the nottion H for the mgnetic field is somewht unfortunte becuse of the confusion with the Hmiltonin. In other references such s Lndu nd Pez, H µb is used insted.) We choose units so tht the Hmiltonin tkes the simple form: H(x) = J i,j S i S j i HS i, (3.6) where S i = ± is the spin. Here x is just shorthnd for specifiction of the spin S i on ech site. For one-dimensionl Ising model with N sites, you could store this s n rry of length N with ech element either + or.
780.20 Session 3 (lst revised: Februry 25, 202) 3 5 The nottion i, j stnds for nerest neighbor pirs of spins. Obviously the product S i S j cn be either + or. In mny pplictions we ll set the externl field H to zero. The constnt J (clled the exchnge energy ) specifies the strength of the spin-spin interction. For ferromgnetic interction, J > 0, while for n nti-feromgnetic interction J < 0. Wht do you think is the physicl origin of J for ferromgnetic interction? The mgnetiztion of the system is the verge vlue of the spin, S i, where the verge is tken over the entire lttice. If the spins re eqully likely to be up (+) s down ( ), then the net mgnetiztion is zero. In n externl mgnetic field, up or down will be fvored energeticlly (if H > 0 in H(x) bove, which is fvored?), nd there will generlly be net mgnetiztion. In ferromgnet t sufficiently low temperture, there will be spontneous mgnetiztion even in the bsence of n externl field. This my occur over regions ( domins ) or over the entire lttice. A configurtion in the Ising model is microstte of the system. If we hve N sites in onedimensionl Ising model, how mny possible configurtions (or microsttes) re there? How mny different vlues of the energy (with H = 0)? The therml verge of quntity A tht depends on the configurtion x (exmples of A re the energy per degree of freedom E = H T /N or the mgnetiztion per degree of freedom M = i S i T /N) is given by the cnonicl ensemble (the denomintor is the prtition function Z) dx A(x) e H(x)/kT A(x) T = dx = dx A(x) P e H(x )/kt eq (H(x)), (3.7) where we hve pulled out the Boltzmnn fctors to identify the probbility distribution function P eq (H(x)): e H(x)/kT P eq (H(x)) = dx e H(x )/kt. (3.8) (Is this PDF normlized?) In the Ising model exmple, the integrtion over x is just sum over the spin configurtions. If our configurtions re chosen s eigensttes of energy (which they re in the Ising model exmple), then we cn just sum over energies rther thn every configurtion: A T = (# of sttes with energy E) A(E) e E/kT E E (# of sttes with energy E ) e E /kt = E A(E) P (E). (3.9) If we cn construct set of N configurtions { x i } ( sttisticl smple) tht re distributed ccording to P, then we cn pply our Monte Crlo method (i.e., we will be doing importnce smpling) nd A T = (/N) i A( x i). This is wht the Metropolis lgorithm does for us!
780.20 Session 3 (lst revised: Februry 25, 202) 3 6 d. Metropolis Algorithm The first thing to get stright is tht the Metropolis lgorithm hs nothing to do with Supermn or Fritz Lng :). It is nmed for the first uthor on the pper tht described the lgorithm. (A bit of trivi: nother uthor on the pper is Edwrd Teller.) The Metropolis lgorithm genertes Mrkov chin; this is sequence of configurtions x i tht will be distributed ccording to the cnonicl distribution (i.e., the Boltzmnn fctor will tell us the reltive probbility of ny configurtion). The Mrkov process constructs stte x l+ from the previous stte x l ccording to trnsition probbility W (x l x l+ ). The ide is to construct W such tht in the limit of lrge number of configurtions, the distribution of sttes x i pproches the equilibrium Boltzmn distribution P eq from Eq. (3.8). A sufficient condition for this to hppen is tht the principle of detiled blnce should hold. In equilibrium, the rte of x x should equl the rte of x x, or else it is not equilibrium! In clculting these rtes, there re two terms to multiply: ( ) ( ) probbility probbility of x x (# of x s) = of x x (# of x s) (3.0) time time or which is detiled blnce. This mens tht W (x x ) N P eq (x) = W (x x) N P eq (x ), (3.) W (x x ) W (x x) = P eq(x) P eq (x ). (3.2) But we know tht P eq (x) = Z e H(x)/kT. (3.3) Any choice of W stisfying Eq. (3.2) should work, in principle. For exmple, we cn tke W (x x ) = { e δe/kt if δe > 0 if δe 0 (3.4) with rbitrry for now (set it equl to unity for convenience) nd where δe E x E x. (3.5) We cn check tht it works by considering ll possible outcomes, s shown in this chrt: δe W (x x ) e E/kT δe W (x x) e E/kT E x > E x > 0 e (E x Ex)/kT e Ex/kT < 0 E x < E x < 0 e Ex/kT > 0 e (Ex E x )/kt e E x /kt e E x /kt
780.20 Session 3 (lst revised: Februry 25, 202) 3 7 If you do the multiplictions, you ll see tht detiled blnce is stisfied in every cse. Section 2.2 of the Binder/Heermn excerpt describes n implementtion of Metropolis for the Ising model. The bsic ide is tht from strting configurtion, one genertes cndidte for new configurtion somehow (for exmple, by flipping one rndomly selected spin). After clculting the energy chnge between new nd old, one hs the trnsition probbility W from Eq. (3.4). Generte rndom number between 0 nd ; if the number is less thn W keep the new configurtion but otherwise flip the spin bck nd keep this s the new configurtion. We ll go over vrious implementtion issues in this Session nd the next. These include: Equilibrtion. If we re going to use configurtions generted by Metropolis to clculte therml verges, we wnt to mke sure we hve reched equilibrium. How long does this tke nd wht is the signture? Efficiency. The initil two-dimensionl Ising model code hs severl inefficiencies tht re generic to mny types of Monte Crlo simultions. In Session 4 we ll look t how to optimize to gin fctor of six in speed. Autocorreltion. When evluting n verge over Monte Crlo configurtions, we wnt to skip the first n steps nd then use dt tken every n 0 Monte Crlo steps. How do we determine how lrge to tke n 0 nd n? The utocorreltion function cn be used to determine resonble choice for n 0. e. References [] R.H. Lndu nd M.J. Pez, Computtionl Physics: Problem Solving with Computers (Wiley- Interscience, 997). [See the 780.20 info webpge for detils on new version.] [2] M. Hjorth-Jensen, Lecture Notes on Computtionl Physics (2009). These re notes from course offered t the University of Oslo. See the 780.20 webpge for links to excerpts. [3] W. Press et l., Numericl Recipes in C++, 3rd ed. (Cmbridge, 2007). Chpters from the 2nd edition re vilble online from http://www.nrbook.com//. There re lso Fortrn versions.