0

While i was making model in HMM is stuck in problem AssertionError but couldnt figure out what the problem is?

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from helpers import show_model
from pomegranate import State, HiddenMarkovModel, DiscreteDistribution



model = HiddenMarkovModel(name='Example Model')

#Emission probabiliy of distributions, p(umbrella|weather)
sunny_emission = DiscreteDistribution({'yes':0.1, 'no':0.8})
sunny_state = State(sunny_emission, name='Sunny')

rainy_emission = DiscreteDistribution({'yes':0.8, 'no':0.2})
rainy_state = State(rainy_emission, name='rainy')


model.add_states(sunny_state, rainy_state)

assert rainy_emission.probability('yes') == 0.8, "The director brings his umbrella with probability 0.8 on rainy days"
print("looks good so far")

model.add_transition(model.start, sunny_state, 0.5)
model.add_transition(model.start, rainy_state, 0.5)


model.add_transition(sunny_state, sunny_state, 0.8) # 80%sunny days
model.add_transition(rainy_state, rainy_state, 0.2) # 20% rainy days


model.add_transition(rainy_state, rainy_state, 0.6)
model.add_transition(rainy_state, sunny_state, 0.4)

model.bake()


assert model.edge_count() == 6, "There should be two edges from model.start, two from Rainy, and two from Sunny"
assert model.node_count() == 4, "The states should include model.start, model.end, Rainy, and Sunny"

AssertionError: There should be two edges from model.start, two from Rainy, and two from Sunny

desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

0

the reason that you are getting that error is because , there are only 5 edges from the hidden state ('SUNNY') in your code but assert statement is checking for 6 edges .

**model.add_transition(rainy_state, rainy_state, 0.2) # 20% rainy days**

this is line where the error is , here the transition is from "rainy to rainy" instead of "sunny to rainy" .