本文整理汇总了Python中hmm.HMM.generate_train_data方法的典型用法代码示例。如果您正苦于以下问题:Python HMM.generate_train_data方法的具体用法?Python HMM.generate_train_data怎么用?Python HMM.generate_train_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hmm.HMM
的用法示例。
在下文中一共展示了HMM.generate_train_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import generate_train_data [as 别名]
def generate(m, n, dsizes, tsize, file_tager):
start_time = time.time()
# Create Hidden Markov Model randomly.
# m --- The number of hidden states
# n --- The number of observation states
model = HMM(m, n)
# Generate training set
for dsize in dsizes:
training_seq = model.generate_train_data(dsize)
training_filename = "train_" + file_tager + ("_%d.data" % dsize)
np.savetxt(training_filename, [training_seq], delimiter=",", fmt="%d")
# Generate test set
test_seqs_F = model.generate_test_data(tsize, min_seq_len=4, max_seq_len=5)
test_seqs_V = model.generate_test_data(tsize, min_seq_len=3, max_seq_len=50)
test_seqs_F_filename = "test_" + file_tager + "_F.data"
test_seqs_V_filename = "test_" + file_tager + "_V.data"
with file(test_seqs_F_filename, "wb") as fout:
writer = csv.writer(fout)
for seq in test_seqs_F:
writer.writerow(seq)
with file(test_seqs_V_filename, "wb") as fout:
writer = csv.writer(fout)
for seq in test_seqs_V:
writer.writerow(seq)
end_time = time.time()
pprint("Time used: %f seconds" % (end_time-start_time))
# Save model to file
model_filename = "model_" + file_tager + ".npy"
HMM.to_file(model_filename, model)