Skip to content

Units on Q matrix for CtHMM #7

@cmaclell

Description

@cmaclell

I'm trying to do a form of HMM clustering where I fit an HMM to each group of data points, then construct a big HMM that handles the cluster assignment for me. I've done this with regular HMMs in the past and am trying to port the idea over to work with your continuous time HMMs, but I'm a bit unclear on the units of the Q matrix that is passed into the CtHMM constructor.

Your ipython notebooks says # Q is the matrix of transition rates from state [row] to state [column]. Digging into your code, it looks like if I run scipy.linalg.expm(chmm.q) I can get something akin to transition probabilities that should sum to 1, and I can translate probabilities into transition rates by doing the opposite, scipy.linalg.logm(Q_prob) does this sound right to you?

What I'm trying to do is to construct an HMM where there are groups of state that are connected to within group, but not between group and there is a start probability that specifies the probability that a sequence is in any one group. So my parameters might look something like this:

Initial probabilities (π) :
          0
0  0.633333
1  0.000000
2  0.000000
3  0.066667
4  0.300000
5  0.000000
Transition rate matrix (Q):
          0          1          2          3          4         5
0 -0.391591   0.313380   0.078211   0.000000   0.000000  0.000000
1  0.949768  -0.960014   0.010246   0.000000   0.000000  0.000000
2  5.652769  21.046363 -26.699132   0.000000   0.000000  0.000000
3  0.000000   0.000000   0.000000  -0.282953   0.006097  0.276856
4  0.000000   0.000000   0.000000  13.135779 -14.030817  0.895038
5  0.000000   0.000000   0.000000   0.661941   0.003459 -0.665400
Transition probabilities for one time unit :
          0         1         2         3         4         5
0  0.790908  0.206685  0.002406  0.000000  0.000000  0.000000
1  0.526236  0.472067  0.001697  0.000000  0.000000  0.000000
2  0.575279  0.422892  0.001829  0.000000  0.000000  0.000000
3  0.000000  0.000000  0.000000  0.820134  0.000402  0.179464
4  0.000000  0.000000  0.000000  0.801739  0.000399  0.197862
5  0.000000  0.000000  0.000000  0.430510  0.000324  0.569167
Emission probabilities matrix (B):
          0         1         2
0  0.359413  0.000000  0.640587
1  0.000000  1.000000  0.000000
2  0.333333  0.333333  0.333333
3  0.000000  0.583333  0.416667
4  0.000000  1.000000  0.000000
5  1.000000  0.000000  0.000000

I ask about the units of Q because when I try and fit this CtHMM to the data I get the following error:

  File "hmms/cthmm.pyx", line 907, in hmms.cthmm.CtHMM.baum_welch
  File "hmms/cthmm.pyx", line 1060, in hmms.cthmm.CtHMM._baum_welch
ValueError: Parameter error! Matrix Q can't contain unreachable states.

I'm not sure if it is because I specified the units wrong, or if maybe your formulation doesn't like the somewhat strange Q matrix I provided.

I'm curious to hear your thoughts and, if possible, to get a brief description of the units for Q.

Thanks!

Chris

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions