Metoda Monte Carlo Katarzyna Sznajd-Weron
Stanisław Ulam i metoda Monte Carlo The idea for what was later called the Monte Carlo method occurred to me when I was laying solitaire during my illness. I noticed that it may be much more ractical to get an idea of the robability of the successful outcome of a solitaire game (like Canfield or some other where the skill of the layer is not imortant) by laying down the cards, or exerimenting with the rocess and merely noticing what roortion comes out successfully, rather than to try to comute all the combinatorial ossibilities 2
Idea metody Canfield (solitaire): What is the chance of winning with a roerly shuffled deck? Hard to comute analytically the outcome deends on many moves What if we lay a few hands and see emirically how many do in fact win? You lose You lose You win You lose Chance of winning = ¼! 3
Historia: ręczne Monte Carlo First documented exeriment erformed by a French scientist and writer in the 18th cent. He tossed a coin 4040 times! The mean value was 0.5069 (heads = 1, tails = 0) In the 20th century the exeriment was reeated by a Russian statistician Romanowski He tossed a coin 80640 times! The mean value was 0.4923 4 hr. Georges-Louis Leclerc Buffon (1707-1788)
Buffon s needle, 1733 What is the chance that a needle randomly tossed will fall across the lines on a arquet floor? We randomly dro a needle of length l < d onto a sheet of aer with arallel lines d aart Probability that a short needle crosses one of the lines: = 2l πd Show it! 5 Source: M. E. Calhoun, P. R. Mouton, Journal of Chemical Neuroanatomy 20 (2000) 61 69
Buffon s needle, 1733 Exeriment for estimating the value of π by tossing a needle onto a ruled surface π can be aroximated as: π = 2nl/md where m is the number of throws crossing a line and n is the total number of throws 6 Source: M. E. Calhoun, P. R. Mouton, Journal of Chemical Neuroanatomy 20 (2000) 61 69
How good is the aroximation? In 1864, catain O.C.Fox erformed this exeriment when recovering from wounds Using a rotating surface imroved the results removed the bias of the random number generator n m l d surface π 500 236 3 4 still 3.1780 530 253 3 4 rotating 3.1423 7
8 Ekseryment komuterowy
Pseudorandom number generator (PRNG) A linear congruential generator Form a sequence U n = X n /m with X n+1 = ax n + c mod m All the `magic' comes from the `modulo' oerator Goal: roducing seudorandom numbers which can ass formal tests for randomness long eriod fast 9 magic numbers : a, c, m are crucial
Linear Congruential Generators Examles of historical choices of a and m (c = 0) X n+1 = ax n + c mod m The first known LCG (1951): a = 23; m = 10 8 + 1 RANDU from IBM (1960s): a = 65539 = 2 16 + 3; m = 2 31 Knuth (1981): this is one of the worst in history 10
Test of IBM's RANDU generator Do you remember the simle solution? 11
Test of IBM's RANDU generator Plot it in 3D! 12
Test of IBM's RANDU generator 13 nmax = 10^6; max = 5*10^3; n = zeros (nmax,1); N = n; a = 2^16+3; m = 2^31; c = 0; N (1) = 10^3; for i=2: nmax N(i) = mod (a*n(i -1) + c, m); end n = N/m; figure (1) lot3 (n (1: max -2,1),n (2: max -1,1),n (3: max,1), '.') xlabel ('U_{k -2} '); ylabel ('U_{k -1} '); zlabel ('U_k ')
The best PRNG for Monte Carlo simulations: The Mersenne Twister 14 Develoed in 1997 by Makoto Matsumoto and Takuji Nishimura The name comes from Mersenne's rime numbers of the form 2 n 1 Based on a matrix linear recurrence Passes numerous tests for statistical randomness, including the Diehard tests A very long eriod of 2 19937 1 Fast Is not crytograhically secure: PRNG
3D lot for the Mersenne Twister Matlab ver. 7.4 and later use the Mersenne Twister 15
Modern history of the MC method Stanisław Ulam during... recovery from an illness lays solitaire (Canfield) Nicolas Metroolis gives the new method a name The name is a reference to the Monte Carlo casino in Monaco where Ulam s uncle would borrow money to gamble In 1949 the first article about the MC method coauthored by Ulam and Metroolis is ublished 16 Stanisław Ulam (1909-1984)
Alications of the MC method 17 Aroximating robabilities Aroximating areas of geometric figures Comuting integrals Solving artial differential equations Weather forecasts Derivatives ricing Comuting thermodynamical variables within microscoic models Comuting aggregated variables within agent-based models
Perkolacja 2014 Katarzyna Sznajd-Weron
Model erkolacji (site lub bond) Model erkolacji : Każdy węzeł (wiązanie) sieci jest zajęty niezależnie z rawdoodobieństwem Jak duże musi być to rawdoodobieństwo aby owstał nieskończony? site site bond
Perkolacja: Pożary lasów
Prawdoodobieństwo rzejścia na drugą stronę Symulacja Monte Carlo Granica termodynamiczna: N, L, = N L 2 = const gęstość zadrzewienia L 21 Source: Introduction to Comutational Physics, Lecture of Prof. H. J. Herrmann
Sowolnienie krytyczne (critical slowing down) =0.5 1 nn =0.6 =0.7 1 nn AND nnn 2 nn OR nnn
Model erkolacji: filtry vs. ożary Inne rzykłady? Filtr Pożar substacja Woda/olej ogień Płynie rzez Puste miejsca Drzewa Miejsca zakazane Ziarna/Skała Puste miejsca P (gęstość/rawd.) Pustych miejsc Drzew <* Faza sucha Faza niesalona >* Faza mokra Faza salona 23
24 The Burning Method Introduction to Comutational Physics, Lecture of Prof. H. J. Herrmann 2 2 1. Label all occuied cells in the to line with the marker t=2. 8 7 6 5 2. Iteration ste t+1: a) Go through all the cells and 8 7 find the cells which have label t. b) For each of the found t-label cells do i. Check if any direct neighbor (North, East, South,West) is occuied and not burning (label is 1). ii. Set the found neighbors to label t+1. 3. Reeat ste 2 (with t=t+1) until either there are no neighbors to burn anymore or the bottom line has been reached - in the latter case the latest label minus 1 defines the shortest ath. 8 7 6 4 5 3 3 4
Perkolacja site Rozważmy sieć dwuwymiarową L na L Każde miejsce sieci jest zajęte niezależnie z rawdoodobieństwem Klaster grua zajętych węzłów znajdujących się wzajemnie w najbliższym sąsiedztwie (rozmiar s)
26 Skalowanie rozmiaru (masy) klastra s s D P L L L L M c c c c d c 2 ln Fraktal!
Jak zliczać klastry? Algorytm Hoshen-Koelman algorithm Lattice = matrix N ij, N i, j = 0 (site is unoccuied) N i, j = 1 (site is occuied) M k mass of cluster k (labels clusters) We comb through the lattice from to-left The algorithm is very efficient since it scales linearly with the number of sites 27
Hoshen-Koelman algorithm Phys. Rev. B14 (1976) 3439 1. k = 2, M k = 1 2. for all i, j of N ij (a) if to and left are emty: k = k + 1, N ij = k, M k = 1 (b) if one is occuied with k 0 then N ij = k 0, M k0 = M k0 + 1 (c) if both are occuied with k 1 and k 2 (k 1 k 2 ) then choose one, e.g. k 1, N ij = k 1, M k1 = M k1 +M k2 +1, M k2 = k 1 (d) If both are occuied with k 1, N ij = k 1, M k1 = M k1 + 1 28
Krytyczność w modelu erkolacji Próg erkolacji - najmniejsza koncentracja zaełnionych węzłów na sieci, rzy której owstaje nieskończony klaster. Parametr orządku Wyniki dla sieci 2D
Krytyczność w modelu erkolacji Próg erkolacji dla roblemu site to najmniejsza koncentracja zaełnionych węzłów na sieci, rzy której owstaje nieskończony klaster. Próg erkolacji dla roblemu bond to najmniejsza koncentracja zaełnionych ołączeń między węzłami sieci, rzy której owstaje nieskończony klaster.
Próg erkolacji nie jest uniwersalny! sieć site bond heksagonalna 0.696 2 0.652 71 kwadratowa 0.592 75 0.500 00 trójkątna 0.500 00 0.347 29 diamond 0.428 0.388 Prosta kubiczna 0.311 7 0.249 2 BCC 0.245 0.178 5 FCC 0.198 0.119
Symulacja Monte Carlo Modelu Isinga dla zadanej temeratury T Przygotuj stan oczątkowy układu Pozwól mu ewoluować jak? Poczekaj aż ustali się magnetyzacja Zanotuj wartość m Powtarzaj to dużo razy Policz średnią magnetyzację Jaka to średnia? N m =< S i > 1 N i=1 S i
Średnia o zesole Średnia o czasie i średnia o zesole Średnia o czasie Układ ergodyczny to średnia o zesole = średnia o czasie
Algorytm Metroolisa
Algorytm Metroolisa 1MCS = N losowań Wylosuj jeden sin S i Oblicz energię E = E(S i ) = S i J σ j nn S j Oblicz energię E = E( S i ) = S i J σ j nn S j Oblicz zmianę energii ΔE = E E Jeżeli ΔE 0 to S i S i Jeżeli ΔE > 0 to wylosuj r z rzedziału [0,1] i akcetuj nową konfigurację jeżeli: r < = ex ΔE k B T, k B = J = 1
Wylosuj sin S i Oblicz ΔE obrotu S i S i Obróć sin TAK NIE ΔE < 0? S i S i Wylosuj x U(0,1) Obróć sin TAK NIE x < ex( ΔE/T)? S i S i iter N? TAK Oblicz magnetyzację NIE
Trajektorie dla T=1.85, L=100 (symulacje Jakub Pawłowski)
Trajektorie dla T=2.26 (symulacje Jakub Pawłowski)
Przejście fazowe w modelu Isinga (symulacje Maciej Tabiszewski)
Prawdoodobieństwo rzejścia dynamika Metroolisa: W M = min[1, ex( βδe)] dynamika Glaubera = termostatu (heat-bath): W G = 1 1 + ex(βδe) W temeraturze T = 0: 0 jeśli ΔE > 0 W(ΔE) = W 0 jeśli ΔE = 0 1 jeśli ΔE < 0
Dynamiki w modelu Isinga
Prawdoodobieństwo rzejścia β = 1 k B T
Ewolucja gęstości rawdoodobieństwa dp r dt = s r dp r dt = s r W s r P s s r W r s P r W s r P s W r s P r = 0 W s r P s = W r s P r Warunek stacjonarności Warunek równowagi szczegółowej P r = Zex βe r Rozkład w równowadze W s r W r s = P r P s = Zex βe r Zex βe S = ex( βδe)
Rozkład magnetyzacji w czasie dla T=1.85 (symulacje Jakub Pawłowski)
Rozkład magnetyzacji w czasie dla T=2.26 (symulacje Jakub Pawłowski)
Relaksacja w T=0 z aktualizacją sekwencyjną
Literatura D. W. Heermann, Podstawy symulacji komuterowych w fizyce, WNT 1997 D. P. Landau, K. Binder, A Guide to Monte Carlo Simulations in Statistical Physics, Cambridge University Press 2005
Trzewo (sieć) Bethego (z=3) Klaster erkolujący rozciąga się w nieskończoność Rozważmy sacer o erkolującym nieskończonym klastrze Kontynuując sacer z węzła i-tego możemy ójść w z 1 kierunkach Tylko (z 1) jest wolnych Czyli musi być rzynajmniej jedna wolna z 1 1 c = 1 z 1
Perkolacja na sieci kwadratowej (bond): dualność sieci Sieć wyjściowa: mogę rzejść q=1- nie mogę rzejść Sieć dualna: nie mogę rzejść q=1- mogę rzejść
Samodualność sieci kwadratowej * q q * q q * * q* 1 *, q* * 0.5 *
Metoda Średniego Pola (MFA) erkolacja wiązań (bond) Pytanie: Jaka jest krytyczna wartość koncentracji wiązań (mostów), rzy której owstanie nieskończony klaster? Oznaczenia: rawdoodobieństwo tego, że dwa dowolne węzły sieci są ołączone (tzn. że istnieje wiązanie): rawdoodobieństwo, że i-ty węzeł należy do nieskończonego klastra: P i
Kiedy należy do nieskończonego klastra? Żeby węzeł i należał do klastra to: musi on mieć rzy najmniej jednego sąsiada j, z którym jest ołączony mostem, j należy do nieskończonego klastra. Prawdoodobieństwo tego, że ma: P j Prawd., że nie należy do klastra
Mean field aroximation (MFA) z 1 P i = j=1 1 P j MFA: i P i = P (układ jednorodny) z 1 P = j=1 1 P = 1 P z 1 P = 1 P z Dla układu jednowymiarowego (1D): z = 2 1 P = 1 P 2
Układ jednowymiarowy, z = 2 1 P = 1 P 2 Pytanie: Czy istnieje takie, żeby P > 0? 1 P = 1 2P + 2 P 2 2 P 2 + 1 2 P = 0 P( 2 P + 1 2 ) = 0 2 P + 1 2 = 0 P = 2 1 2 P = 2 1 2 > 0 2 1 > 0 > 1 2
4 2 3 2 2 4 2 ) (1 4 ) (1 2 ' Grua renormalizacyjna (decymacja): Perkolacja na sieci kwadratowej =0 =0 =0 =1 =1 =1
0 2 1 5 2 1 5 ) (1 0 1 ) (1 0 ) 2 (1 2 ', 2 ' 2 3 4 2 4 2 0 *=0.618 1 Szukamy unktów stałych transformacji
Grua renormalizacyjna (majority rule): Perkolacja na sieci trójkątnej rawdoodobieństwo rawdoodobieństwo = 3 + 3 2 1 = = 3 + 3 2 1 0 c = 1 2 1 2 3 + 3 2 = 0 ( 2 2 + 3 1) = 0 1 1 2 = 0