当我在 HMM 中制作模型时遇到问题 AssertionError 但无法弄清楚问题是什么?
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: model.start 应该有两条边,Rainy 有两条,Sunny 有两条