A TADS3/adv3 module for implementing discrete Markov chains

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 a List of the state IDs, in this case “foo”, “bar”, and “baz”.
  • @[ probability matrix ]
    The next bit is another List 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 the List above is 0, indicating that the foofoo transition has a probability of 0, the next element is the probability of foobar, which is 75%, then foobaz (25%), then barfoo (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.

4 Likes