Event chain.py
From Werner KRAUTH
(Difference between revisions)
| Revision as of 21:42, 22 September 2015 Werner (Talk | contribs) ← Previous diff |
Revision as of 22:04, 22 September 2015 Werner (Talk | contribs) Next diff → |
||
| Line 1: | Line 1: | ||
| - | This page presents the program markov_disks_box.py, a Markov-chain algorithm for four disks in a square box of sides 1. | + | This page presents the program event_chain.py, a Markov-chain algorithm for four disks in a square box of sides 1 with periodic boundary conditions. |
| __FORCETOC__ | __FORCETOC__ | ||
| Line 5: | Line 5: | ||
| =Program= | =Program= | ||
| - | |||
| - | import random | ||
| - | |||
| - | L = [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]] | ||
| - | sigma = 0.15 | ||
| - | sigma_sq = sigma ** 2 | ||
| - | delta = 0.1 | ||
| - | n_steps = 1000 | ||
| - | for steps in range(n_steps): | ||
| - | a = random.choice(L) | ||
| - | b = [a[0] + random.uniform(-delta, delta), a[1] + random.uniform(-delta, delta)] | ||
| - | min_dist = min((b[0] - c[0]) ** 2 + (b[1] - c[1]) ** 2 for c in L if c != a) | ||
| - | box_cond = min(b[0], b[1]) < sigma or max(b[0], b[1]) > 1.0 - sigma | ||
| - | if not (box_cond or min_dist < 4.0 * sigma ** 2): | ||
| - | a[:] = b | ||
| - | print L | ||
| - | |||
| - | =Version= | ||
| - | See history for version information. | ||
| - | |||
| - | [[Category:Python]] | ||
| import random, math | import random, math | ||
| Line 55: | Line 34: | ||
| a[dirc] = (a[dirc] + event_min) % 1.0 | a[dirc] = (a[dirc] + event_min) % 1.0 | ||
| distance_to_go -= event_min | distance_to_go -= event_min | ||
| + | |||
| + | =Version= | ||
| + | See history for version information. | ||
| + | |||
| + | [[Category:Python]] [[Category:Honnef_2015]] | ||
Revision as of 22:04, 22 September 2015
This page presents the program event_chain.py, a Markov-chain algorithm for four disks in a square box of sides 1 with periodic boundary conditions.
Contents |
Description
Program
import random, math
def event(a, b, dirc, sigma):
d_perp = abs(b[not dirc] - a[not dirc]) % 1.0
d_perp = min(d_perp, 1.0 - d_perp)
if d_perp > 2.0 * sigma:
return float("inf")
else:
d_para = math.sqrt(4.0 * sigma ** 2 - d_perp ** 2)
return (b[dirc] - a[dirc] - d_para + 1.0) % 1.0
L = [[0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]]
ltilde = 0.819284; sigma = 0.15
for iter in xrange(20000):
dirc = random.randint(0, 1)
print iter, dirc, L
distance_to_go = ltilde
next_a = random.choice(L)
while distance_to_go > 0.0:
a = next_a
event_min = distance_to_go
for b in [x for x in L if x != a]:
event_b = event(a, b, dirc, sigma)
if event_b < event_min:
next_a = b
event_min = event_b
a[dirc] = (a[dirc] + event_min) % 1.0
distance_to_go -= event_min
Version
See history for version information.
