Just pushed an update that adds an alternate syntax for declaring Markov chains. Example:
myChain: MarkovChain
@[ 'foo', 'bar', 'baz' ]
@[
0, 0.75, 0.25,
0.67, 0, 0.33,
0.5, 0.5, 0
]
->[ 0.34, 0.34, 0.32 ]
;
That’s
- @[ state list ]
The first bit is just aList
of the state IDs, in this case “foo”, “bar”, and “baz”. - @[ probability matrix ]
The next bit is anotherList
formatted like a 2d matrix. In that view, the row indicates the state being transitioned from and the column the state being transitioned to, with the value being a decimal probability for that transition. So the first element in theList
above is0
, indicating that thefoo
→foo
transition has a probability of0
, the next element is the probability offoo
→bar
, which is 75%, thenfoo
→baz
(25%), thenbar
→foo
(67%), and so on. - ->[ initialization vector]
The last bit is the probability of each state being the initial state. If no IV is declared the first state in the state list (above) will always be used
This is mostly equivalent to the syntax described in the OP. This might be easier for some people to work with/visualize. And it might be more convenient for important data from a CSV or whatever.
I also added some linter checks for MarkovChain
declarations. They’re disabled by default. To use them, compile with -D LINTER
. If you do that you’ll also need the linter module.