- #1
jbowers9
- 89
- 1
Homework Statement
I'm taking an online course in Stat. Mech. and we're working on Markov chain Monte Carlo methods. One of the programs supplied uses the following:
Mentor note: Added code tags
Python:
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(10):
print(t,' ',["%0.5f" % abs(i- 1.0 / 9.0) for i in position])
* position = numpy.dot(transfer, position)
I was able to de-construct most of the code by using print statements, but I'm lost on the above statement. I know how to do a dot product but I'm clueless as to how the values in position are being computed after successive iterations of t. I'm a little fuzzy about what the transfer matrix is too - mathematically I think it's the probability matrix for the random walk - but how its datatype, which seems to me to be an array string when I print it, can be used in a dot product gets me head scratching. The [ ] bracket in the print statement also isn't so obvious as i isn't declared/initialized anywhere before its use. I'm new to python, if you haven't guessed, but I have done some C++ programming before. Any help would be greatly appreciated.
2. Homework Equations
πa(p(a→b)+p(a→c)) = πb(p(b→a)) + πc(p(c→a))
The global balance condition is just right.
The Attempt at a Solution
Inserted print statements in the code.
Last edited by a moderator: