当前位置: 首页>>代码示例>>Python>>正文


Python HMM.to_file方法代码示例

本文整理汇总了Python中hmm.HMM.to_file方法的典型用法代码示例。如果您正苦于以下问题:Python HMM.to_file方法的具体用法?Python HMM.to_file怎么用?Python HMM.to_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hmm.HMM的用法示例。


在下文中一共展示了HMM.to_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate

# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import to_file [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)    
开发者ID:DucQuang1,项目名称:Spectral-learning,代码行数:34,代码来源:generator.py

示例2: setUp

# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import to_file [as 别名]
 def setUp(self):
     self._model_filename = "hmm_m4n4.pkl"
     self._train_filename = "m4n4.train.data"
     self._num_hidden = 4
     self._num_observ = 4
     transition_matrix = np.random.rand(4, 4)
     observation_matrix = np.random.rand(4, 4)
     hmm = HMM(self._num_hidden, self._num_observ, transition_matrix=transition_matrix,
               observation_matrix=observation_matrix)
     sequences = hmm.generate_data(10000, 4, 51)
     io.save_sequences(self._train_filename, sequences)
     HMM.to_file(self._model_filename, hmm)
开发者ID:DucQuang1,项目名称:Spectral-learning,代码行数:14,代码来源:testHMM.py


注:本文中的hmm.HMM.to_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。