0

For training a HMM model, I need start probabilities (pi), the transition probabilities, and emission probabilities. Now I want to train a HMM model with 3 states (1,2,3) and 4 outputs (a,b,c, d). The training data is:

[[abcdabcdabcdabcdabcdbacbacd,abababcdcdcdcdababab,badcacdabacdbbacd,dacdbacdbbccaaadacdbabd,cababcacdbacacdbdacdacdbacdbab,acddbaacbdcaabdcbabd,cdbadcbacdbbdacdbcdaaabd,bcadabbacbacdbdacddb]]

I am trying to use pomegranate to do that, but in the example all of the states have probabilities specified like this:

rainy = State( DiscreteDistribution({ 
    'walk': 0.1, 'shop': 0.4, 'clean': 0.5 }),
    name='Rainy' )
sunny = State( DiscreteDistribution({ 
    'walk': 0.6, 'shop': 0.3, 'clean': 0.1 }), 
    name='Sunny' )`

My problem is how to get the probabilities. I am trying to use pomegranate method model.add_transition() , but I don't know which parameter I should give? Is there any example that can teach me how to get the probability in my data?

paisanco
  • 4,098
  • 6
  • 27
  • 33
Shukuang Chen
  • 23
  • 1
  • 8
  • Try [**this link**](https://github.com/jmschrei/pomegranate/issues/485) at Github –  Feb 14 '20 at 13:24
  • Beware pomegranate is still pretty buggy and with skimpy documentation. Brace yourself for a rough ride. –  Feb 19 '20 at 11:38

2 Answers2

3

If you do not know the parameters of the desired model i.e. you want to use model to learn those parameters, then in the unsupervised setting, you can use fit() function from pomegranate. model = HiddenMarkovModel() #create reference model.fit(sequences, algorithm='baum-welch') # let model fit to the data model.bake() #finalize the model (Note: Make sure each of the sequence you are feeding in is a list or numpy array)

Once the model has learned the parameters, you can use below functions to extract results:

  1. To get the transition probability matrix:

    model.dense_transition_matrix()

  2. To get the emission distributions:

    print(model)

  3. Then if you wish to use the model to generate samples:

    model.sample(length=10)

  4. You can further improve the model by adjusting using transition and emission parameters above, as you see fit, and creating new model by:

    custom_model = HiddenMarkovModel.from_matrix(transition_matrix, distributions, start_probs, end_probs)

Pomegranate docs is the best source to get the details of each of these functions.

Jaideep
  • 76
  • 1
  • 6
0

Pomegranate is a tool that can give you the state labels (or probabilities) for the sequence that you model using HMM. Pomegranate can figure out the Start Probabilities, Transition Probabilities, and Emission Probabilities for you given that you give us initial transition probabilities, emission probabilities based on your domain knowledge of the problem. This is a good starting point for HMM using Pomegranate.

peer
  • 4,171
  • 8
  • 42
  • 73
Abhishek Mishra
  • 1,984
  • 1
  • 18
  • 13