Ising coupling.py
From Werner KRAUTH
(Difference between revisions)
Revision as of 22:13, 12 June 2024 Werner (Talk | contribs) ← Previous diff |
Revision as of 20:41, 18 July 2024 Werner (Talk | contribs) Next diff → |
||
Line 1: | Line 1: | ||
==Context== | ==Context== | ||
This page is part of my [[BegRohu_Lectures_2024|2024 Beg Rohu Lectures]] on "The second Markov chain revolution" at the [https://www.ipht.fr/Meetings/BegRohu2024/index.html Summer School] "Concepts and Methods of Statistical Physics" (3 - 15 June 2024). | This page is part of my [[BegRohu_Lectures_2024|2024 Beg Rohu Lectures]] on "The second Markov chain revolution" at the [https://www.ipht.fr/Meetings/BegRohu2024/index.html Summer School] "Concepts and Methods of Statistical Physics" (3 - 15 June 2024). | ||
+ | |||
+ | The present program illustrates the coupling and the phenomenon of monotone coupling in Markov-chain sampling in the example of the two-dimensional Ising model on an LxL square lattice with periodic boundary conditions. We start, at time t=0 with two configurations, one called SLow (all spins equal to -1) and another one, called SHigh (all spins equal to +1), and runs the same Markov chain on both of them until they resulting configurations coincide. | ||
==Python program== | ==Python program== |
Revision as of 20:41, 18 July 2024
Context
This page is part of my 2024 Beg Rohu Lectures on "The second Markov chain revolution" at the Summer School "Concepts and Methods of Statistical Physics" (3 - 15 June 2024).
The present program illustrates the coupling and the phenomenon of monotone coupling in Markov-chain sampling in the example of the two-dimensional Ising model on an LxL square lattice with periodic boundary conditions. We start, at time t=0 with two configurations, one called SLow (all spins equal to -1) and another one, called SHigh (all spins equal to +1), and runs the same Markov chain on both of them until they resulting configurations coincide.
Python program
import math import random L = 64; N = L * L nbr = {i : ((i // L) * L + (i + 1) % L, (i + L) % N, (i // L) * L + (i - 1) % L, (i - L) % N) \ for i in range(N)} beta = 0.4 # beta = 0.4407 is critical temperature SLow = [-1 for site in range(N)] SHigh = [1 for site in range(N)] iter = 0 while True: iter += 1 k = random.randint(0, N - 1) Upsilon = random.uniform(0.0, 1.0) hLow = sum(SLow[nn] for nn in nbr[k]) hHigh = sum(SHigh[nn] for nn in nbr[k]) SLow[k] = -1 if Upsilon < 1.0 / (1.0 + math.exp(-2.0 * beta * hLow)): SLow[k] = 1 SHigh[k] = -1 if Upsilon < 1.0 / (1.0 + math.exp(-2.0 * beta * hHigh)): SHigh[k] = 1 if SHigh == SLow: print(iter / N) print(SLow, SHigh) break