''' From Algorithms and Computations by Werner Krauth code the following algorithms in python Markov discrete-pebble procedure markov-discrete-pebble input k (position of pebble) n ← Nran (1, 4) if (Nbr(n, k) 6 = 0) then (see Table 1.3) k ← Nbr(n, k) output k (next position) —— Algorithm 1.6 markov-discrete-pebble. Discrete Markov-chain Monte Carlo algorithm for the pebble game. procedure transfer-matrix input {p(a → b)} (matrix in eqn (1.14)) input {i(1), . . . , i(9)} for a = 1, . . . , 9 do i+1(a) ← 0 for b = 1, . . . , 9 do i+1(a) ← i+1(a) + p(b → a)i(b) output {i+1(1), . . . , i+1(9)} —— Algorithm 1.7 transfer-matrix. Computing pebble-game probabilities at iteration i + 1 from the probabilities at iteration i. procedure markov-two-site input k (either 0 or 1) if (k = 0) l ← 1 if (k = 1) l ← 0 ← (l)/(k) if (ran (0, 1) < ) k ← l output k (next site) —— Algorithm 1.8 markov-two-site. Sampling sites 0 and 1 with station- ary probabilities (0) and (1) by the Metropolis algorithm. '''
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question