Pebble transfer.py
From Werner KRAUTH
(Difference between revisions)
| Revision as of 21:43, 22 September 2015 Werner (Talk | contribs) ← Previous diff |
Current revision Werner (Talk | contribs) |
||
| 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 pebble_transfer.py, a simple linear algebra algorithm for multifplying a probability vector with a transfer matrix. |
| __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 numpy | import numpy | ||
| Line 41: | Line 19: | ||
| print t,' ',["%0.5f" % i for i in position] | print t,' ',["%0.5f" % i for i in position] | ||
| position = numpy.dot(transfer, position) | position = numpy.dot(transfer, position) | ||
| + | |||
| + | =Version= | ||
| + | See history for version information. | ||
| + | |||
| + | [[Category:Python]] [[Category:Honnef_2015]] [[Category:MOOC_SMAC]] | ||
Current revision
This page presents the program pebble_transfer.py, a simple linear algebra algorithm for multifplying a probability vector with a transfer matrix.
Contents |
[edit]
Description
[edit]
Program
import numpy
neighbor = [[1, 3, 0, 0], [2, 4, 0, 1], [2, 5, 1, 2],
[4, 6, 3, 0], [5, 7, 3, 1], [5, 8, 4, 2],
[7, 6, 6, 3], [8, 7, 6, 4], [8, 8, 7, 5]]
transfer = numpy.zeros((9, 9))
for k in range(9):
for neigh in range(4): transfer[neighbor[k][neigh], k] += 0.25
position = numpy.zeros(9)
position[8] = 1.0
for t in range(100):
print t,' ',["%0.5f" % i for i in position]
position = numpy.dot(transfer, position)
[edit]
Version
See history for version information.
