我正在尝试创建一个 HMM,我想创建我的转换矩阵,但我不确定如何。我有一本包含转换的字典以及这些转换发生的概率,如下所示(仅更大):
{(1, 2): 0.0035842293906810036, (2, 3): 0.0035842293906810036, (3, 4): 0.0035842293906810036, (4, 5): 0.0035842293906810036, (5, 6): 0.0035842293906810036, (6, 7): 0.0035842293906810036, (7, 8)}
我定义如下:
# create a list of bigrams
bigrams = []
for i in range(len(integer_list)):
if i+1 in range(len(integer_list)):
bigrams.append((integer_list[i], integer_list[i+1]))
# Create a dictionary containing the counts each bigram occurs in the dataset
bigrams_dict = Counter(bigrams)
values = bigrams_dict.values()
# create a dictionary containing the probability of a word occurring. <- initial probs
frequencies = {key:float(value)/sum(counts_dict.values()) for (key,value) in counts_dict.items()}
frequency_list = []
for value in frequencies.values():
frequency_list.append(value)
现在我想从中制作一个转换矩阵,这将是一个多维数组,但我不知道该怎么做。谁能帮帮我。
转换矩阵看起来像这样的示例(当然只有更多状态):
0 1/3 2/3
0 2/3 1/3
1 0 0