mattjj / pyhsmm

MIT License
547 stars 173 forks source link

Fixing HMM log likelihood #2

Closed interfect closed 11 years ago

interfect commented 11 years ago

I'm trying to use this library to build and run a normal boring no-frills HMM, for which I have a specific topology with specific transition probabilities that I already know. The first step of this is making HMM log likelihood not crash. Later steps will probably have to include adding something like Viterbi to get a self-consistent state path out, and documenting pyhsmm.internals.transitions.HDPHMMTransitions.init so I can tell where to put in the transition probabilities.

Where can I find the reference you used to name all the constructor arguments? What are e.g. the required alpha and gamma arguments to HDPHMMTransitions?

Is there a more appropriate transition distribution class to use when I already know exactly what state transition probabilities will be nonzero?

mattjj commented 11 years ago

Thanks! I renamed that member and neglected to update that function. In fact, I may not have ever used that function...

This document explains the parameter names: http://arxiv.org/pdf/1203.1365v2.pdf. It's linked in the README file.

Viterbi is an easy addition: given the backwards messages, you just need to maximize forward instead of sampling forward. Tropical semiring and all that :)

If you want a fixed transition distribution, just make something like a FixedTransitions class however you want. I think the only thing that gets accessed is a member named A (which is just the transition matrix) in states.py. It'd probably also be easiest to add a resample() method that just contains a pass; otherwise you'll need to add a model that doesn't call resample() on the transition distribution.

mattjj commented 11 years ago

Hm, I should probably clarify that for Viterbi you use the same messages algorithm but you change sums of probabilities to maxes of probabilities. In other words, sum-product and max-product are the same message algorithm but with different "addition" operations. That means the backwards-message-passing code needs to be edited (or abstracted) but only to swap the "addition" operation.

mattjj commented 11 years ago

Actually, if you just want a no-frills HMM, you probably won't find most of the code in this repository useful. Maybe there will be a few lines you can pull out, and maybe you'll want to use some of the distributions in pybasicbayes (as this code does), but I think it would be much easier just to write a simple HMM from scratch.