Specifying a transition matrix

The Python library numpy allows its users to create a matrix from a string representation. So I can enter a transition matrix for a Markov chain like this:

".95 .05 0 0; 0 0 1 0; 0 0 .95 .05; 0 0 0 1"

OK, that's not bad, but I would like to allow my users to just specify the actual transitions, and not have to fill in all of those zeroes. So I'd like to have something like:

0 -> 0 = .95
0 -> 1 = .05
1 -> 2 = 1.0
2 -> 2 = .95
2 -> 3 = .05

And so on. But of course I don't want to do string parsing to interpret a table like the one I just presented. Maybe I want tuples like:

[0, 0, .95]
[0, 1, .05]
[1, 2, 1.0]

In any case, I'm just mulling this over at present, and looking for ideas.

Comments

  1. I've been using python to create calculation programs at work, & I found it useful to just pack all my calculations in a module and make a gui with tkinter that the user interacts with to trigger the calculations & pass info to them. Also, you can use the gui to basically "manage" the user -- they think "ooh! I get to use this easy, spiffy ui!" when actually you are guiding and constraining their choices so they don't break your program.

    I made a window ('main menu') that called a bunch of other windows with fields & radio buttons etc. But then between pushing a 'calculate' button and the execution of the calculation, there is a block of "try" if-then statements to kick them back to data entry if their numbers aren't reasonable, with little messages put up in message boxes to help them fix their data when it isn't right.

    Took a long time to learn the tkinter, but it has worked pretty well so far. There is a helpful video here with a link to a stackoverflow page that has code you can use for the basic architecture of the gui.

    https://youtu.be/jBUpjijYtCk

    ReplyDelete
  2. give the user buttons that are labelled with the transition, whose function is to barf up strings as they are pressed. the strings get compiled into the matrix (the function of which you could attach to a button labelled "done".)

    you could let them see the compiled matrix, and then choose "go back" or "continue". or something like that.

    ReplyDelete
  3. I'd consider a dictionary of dictionaries, with the outer dimension holding the current node, the inner dimension holding the next node, and the inner value the transition probability. The uniqueness of dictionary keys helps protect against typos and transcription errors, and you could easily validate that the probabilities sum to 1 before evaluating the chain.

    You can also subclass dictionary to get the terse dict user interface while adding additional semantics (such as "must sum to 1") behind the scenes.

    ReplyDelete
  4. OK, Matt's way is awesome...never would have thought of that. and you could have a really organized & usable ui even without any tkinter...

    the only thing is, after you do your "matrix = np.array (stuff)" I think you are pretty much going to obliterate the really cool dictionary structure...oh well, I guess it will have served it's purpose at that point...

    ReplyDelete

Post a Comment

Popular posts from this blog

Libertarians, My Libertarians!

"Pre-Galilean" Foolishness