pythonhidden-markov-modelshmmlearnleft-to-right

HMMlearn library -ergodic and left-to-right topology


I have used the HMMlearn library to perform gesture recognition and in some gestures I would like to use the ergodic topology, and in other the left-to-right one. Is the topology inside the architecture of the HMM defined by the 'covariance' parameters set to either 'full' or 'diag' or there is something else that I need to define?


Solution

  • I don't know if my answer is late or not but may help.

    As stated in their documentation

    The transition probability matrix need not to be ergodic. For instance, a left-right HMM can be defined as follows:

    lr = hmm.GaussianHMM(n_components=3, covariance_type="diag",
                      init_params="cm", params="cmt")
    lr.startprob_ = np.array([1.0, 0.0, 0.0])
    lr.transmat_ = np.array([[0.5, 0.5, 0.0],
                              [0.0, 0.5, 0.5],
                            [0.0, 0.0, 1.0]])
    

    Here you forced the model to learn params 'cmt' stands for co-variance, mean and transition matrix, so startprob will never change. but you inform (by passing init_params) it just to initialize by himself the co-variance and mean values, so your values you make in startprob and transmat_ will be latched. the hack here is any 0 here will not be trained and will always be 0 in updates, so you force the topology to be ltr.

    covariance full or diag is not related to the topology at all. it related to the knowledge of your features. in diag for exampl, you say that all features is totally independent so they have 0 co-variance