Trieste Lectures 2015
From Werner KRAUTH
(Difference between revisions)
| Revision as of 11:48, 15 September 2015 Werner (Talk | contribs) ← Previous diff |
Revision as of 11:49, 15 September 2015 Werner (Talk | contribs) Next diff → |
||
| Line 3: | Line 3: | ||
| !Lecture 2: Programs | !Lecture 2: Programs | ||
| + | This is lift-two-disks.py | ||
| + | import math, random | ||
| + | |||
| + | def dist(x, y): | ||
| + | d_x = abs(x[0] - y[0]) % 1.0 | ||
| + | d_x = min(d_x, 1.0 - d_x) | ||
| + | d_y = abs(x[1] - y[1]) % 1.0 | ||
| + | d_y = min(d_y, 1.0 - d_y) | ||
| + | return d_x**2 + d_y**2 | ||
| + | |||
| + | L = [[0.25, 0.25], [0.75, 0.75]] | ||
| + | sigma = 0.18 | ||
| + | for steps in range(10000): | ||
| + | delta = random.uniform(0.0, 0.04) | ||
| + | lift = random.choice([0, 1]) | ||
| + | a = L[lift] | ||
| + | dirc = random.choice([0, 1]) | ||
| + | for inner_steps in range(100): | ||
| + | b = a[:] | ||
| + | b[dirc] += delta | ||
| + | distance = dist(b, L[int( not lift)]) | ||
| + | if distance > 4.0 * sigma ** 2: | ||
| + | a[:] = [b[0] % 1.0, b[1] % 1.0] | ||
| + | else: | ||
| + | lift = int(not lift) | ||
| + | a = L[lift] | ||
| + | |||
| + | This is event-chain.py | ||
| import random, math | import random, math | ||
Revision as of 11:49, 15 September 2015
!Lecture 1: Programs
!Lecture 2: Programs
This is lift-two-disks.py
import math, random
def dist(x, y):
d_x = abs(x[0] - y[0]) % 1.0
d_x = min(d_x, 1.0 - d_x)
d_y = abs(x[1] - y[1]) % 1.0
d_y = min(d_y, 1.0 - d_y)
return d_x**2 + d_y**2
L = [[0.25, 0.25], [0.75, 0.75]]
sigma = 0.18
for steps in range(10000):
delta = random.uniform(0.0, 0.04)
lift = random.choice([0, 1])
a = L[lift]
dirc = random.choice([0, 1])
for inner_steps in range(100):
b = a[:]
b[dirc] += delta
distance = dist(b, L[int( not lift)])
if distance > 4.0 * sigma ** 2:
a[:] = [b[0] % 1.0, b[1] % 1.0]
else:
lift = int(not lift)
a = L[lift]
This is event-chain.py
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
