Jason Cawley
Wolfram Science Group
Phoenix, AZ USA
Registered: Aug 2003
Posts: 712 |
Markov Machines
While NKS focuses primarily on deterministic rules, the simple programs approach can be readily extended to stochastic processes. If these are kept simple enough, then NKS methods of enumeration and experimentation can be applied in straightforward ways. A particularly simple kind of stochastic rule system that can serve to illustrate this is the Markov machine or MM.
A Markov machine is a non-deterministic finite state machine specified by a state transition probability matrix or STM. The system has n states. In each state there is a set of probabilities, summing to 1, to move to each of the other possible states. A current state read across the top of a matrix gives the column, the state at the next step gives a row. A single number at each matrix location gives the probability of making that transition. Each step is independent of the last, with constant probabilities within the STM (if the probabilities can vary the system is no longer Markovian).
A typical STM might look like -
{{0, 0.333333, 0}, {0, 0.333333, 0.666667}, {1., 0.333333, 0.333333}}
Note that columns must sum to 1 but rows need not. Also notice that deterministic finite state machines are a proper subset of MMs, exactly those with only 1s in their STMs and no fractional values.
One can enumerate MMs by increasing the fineness of the gradations allowed in the probability matrix or by increasing the number of allowed states. In general the number of MMs with n states and k "choices" at each step is -
Length[Compositions[choices,states]]^states
Note that Compositions is a Mathematica function defined in the Combinatorica package, which returns all the possible combinations of n integers summing to a given integer. Thus -
Compositions[3,3] = {{0, 0, 3}, {0, 1, 2}, {0, 2, 1}, {0, 3, 0}, {1, 0, 2}, {1, 1, 1}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}, {3, 0, 0}}
One can specify a random MM of a given size by first defining a function that takes an integer rule number and returns a unique state transition matrix -
stm[rn_Integer, chance_Integer, size_Integer] := With[{big = Compositions[chance, size]}, Transpose[Part[big, 1 + IntegerDigits[rn, Length[big], size]]/(1.chance)]]
Then by assigning down values to a variable you can specify a particular MM in that class, chosen at random, by -
statetran = stm[Random[Integer, 10^3 ], 3, 3]
That sort of space one can simply explore exhaustively. Note that there are 9 possible 2 state MM with 50-50 or automatic transitions, 16 with 1, 2/3, 1/3, 0 chances - each easily enumerated and explored. With 3 states there are already 216 MMs with 50-50 chances, and there are 1000 with 1/3 chances allowed.
Other sizes are trivial to sample, but too large to completely span. Here we want 4 states and transition probabilities specified with 10% fineness; there are 6.7 billion of those -
statetran = stm[Random[Integer, 286^4 ], 10, 4]
And here we look at the much more extensive space possible with larger values in the number of states (Having checked that the length of Compositions[6,6] is 462) -
statetran = stm[Random[Integer, 462^6 ], 6, 6]
Any of the above specifies a STM uniquely. Then we just need to evolve the system so specified, with a pair of functions. One to evaluate a single step, and another to chain a bunch of them together.
next[current_Integer] := With[{a = Random[Real]}, For[j = 1, j =< Length[statetran], j++, If[a < Total[Table[statetran[[i, current]], {i, 1, j}]], Return[j] ]]]
trajectory[start_Integer, steps_Integer] := NestList[next, start, steps]
(I'm sure there is cleaner way to do the step but that suffices).
That is enough to see single trajectories, as lists of states. But obviously one would like to see many examples starting from each of the possible initial states. A single line to do that and sort the results slightly, with each element suitable for plotting as a typical NKS array, is -
evolutions[size_Integer] := Table[ Transpose[Sort[Table[trajectory[i, 20], {10}]]], {i, 1, size} ]
A note about reading these plots. Each column down the page is one run of the Markov machine. The color at each step tells you the state of the machine at that step in that run (lighter is a lower state number). The adjacent columns are independent runs. Sorting them has just put runs that happen to be the same for several steps, in order from left to right across the display. As soon as they differ, the higher valued state at that position goes on the right. The additional arrays are still the same Markov machine, using the same state transition matrix. But they have been started off in a different initial state.
You can regenerate any line containing evolutions to sample additional runs, and regenerate any line containing statetran to try a new probability table, aka a different MM.
One can then readily explore issues of attractors and basins, averages for time spent in each state and the evolution of those averages over time, and the complexity of the internal dynamics. The NKS approach would stress looking at the variety in typical dynamics ("transients") rather than simply calculating long run averages.
I hope this is interesting. A sample notebook with the necessary functions is attached.
Attachment: markovmachines5.nb
This has been downloaded 1882 time(s).
Report this post to a moderator | IP: Logged
|