Diffusion forward.py

From Werner KRAUTH

(Difference between revisions)
Jump to: navigation, search
Revision as of 13:31, 6 June 2024
Werner (Talk | contribs)

← Previous diff
Current revision
Werner (Talk | contribs)
(Context)
Line 1: Line 1:
 +==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).
 +
 +We consider a particle diffusing on a path graph with five sites, but we start, at time t=0, at all possible positions. As in [[Diffusion.py| the naive program Diffusion.py]], arrows go "down", "straight" and "up" with equal probability. In application of the Metropolis algorithm, an arrow that goes outside the range [0, N - 1] is rejected, that is, replaced by a straight arrow. The stationary distribution of this reversible Markov chain is uniform on the N sites, because the probability to move from site i to site j equals the probability to move from site j to site i.
 +
 +==Python program==
import random import random
import matplotlib.pyplot as plt import matplotlib.pyplot as plt

Current revision

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).

We consider a particle diffusing on a path graph with five sites, but we start, at time t=0, at all possible positions. As in the naive program Diffusion.py, arrows go "down", "straight" and "up" with equal probability. In application of the Metropolis algorithm, an arrow that goes outside the range [0, N - 1] is rejected, that is, replaced by a straight arrow. The stationary distribution of this reversible Markov chain is uniform on the N sites, because the probability to move from site i to site j equals the probability to move from site j to site i.

Python program

import random
import matplotlib.pyplot as plt

N = 5
pos = []
for stat in range(10000):
   posit = set(range(N))
   t = 0
   while True:
      t += 1
      posit = set([min(max(b + random.choice([-1, 0, 1]), 0), N - 1) for b in posit])
      if len(posit) == 1: break
   pos.append(posit.pop())
plt.title('Forward coupling: 1-d with walls: position of the coupled config.')
plt.hist(pos,bins=N,range=(-0.5, N - 0.5), density=True)
plt.savefig('ForwardCoupling.png')
plt.show()
Personal tools