本文整理汇总了Python中hmm.HMM.generate方法的典型用法代码示例。如果您正苦于以下问题:Python HMM.generate方法的具体用法?Python HMM.generate怎么用?Python HMM.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hmm.HMM
的用法示例。
在下文中一共展示了HMM.generate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import generate [as 别名]
def main(job_id, params):
num_runs = 20
obs_length = 100
num_states = 2
num_obs = 2
# readin hmm indx
t = 0
try:
with open(os.path.join('.', 'hmm_index.txt')) as hmm_index_file:
t = int(hmm_index_file.read())
sys.stderr.write("!!!!!!!!!!!!!!!!!!HMM INDEX: " + str(t) + " !!!!!!!!!!!!!!!\n")
except IOError:
t = 0
# generate HMM observations
np.random.seed(0x6b6c26b2)
seeds = np.random.randint(0x0fffffff, size=num_runs)
np.random.seed(seeds[t])
# random hmm
z_mat, t_mat = random_hmm(num_states, num_obs)
pi_vec = np.array([1.0 / num_states] * num_states)
hmm_test = HMM(z_mat, t_mat, pi_vec)
# random obs trajectory
obs = hmm_test.generate(obs_length)[np.newaxis,:]
# calculate log likelihood for input HMM parameters
z_mat_p_input = np.array([[params['z_mat_p_0'][0], params['z_mat_p_1'][0]]])
t_mat_p_input = np.array([[params['t_mat_p_0'][0], params['t_mat_p_1'][0]]])
# pi_vec_input = np.array([params['pi_0'], 1 - params['pi_0']])
hmm_estimate = make_parameterized_HMM(z_mat_p_input, t_mat_p_input, pi_vec)
hmm_loglikelihood = hmm_estimate.loglikelihood(obs[0])
return -hmm_loglikelihood
示例2: main
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import generate [as 别名]
def main(job_id, params):
num_runs = 20
obs_length = 100
num_states = 2
num_obs = 2
# readin hmm indx
t = 0
try:
with open(os.path.join('.', 'hmm_index.txt')) as hmm_index_file:
t = int(hmm_index_file.read())
sys.stderr.write("!!!!!!!!!!!!!!!!!!HMM INDEX: " + str(t) + " !!!!!!!!!!!!!!!\n")
except IOError:
t = 0
# generate HMM observations
np.random.seed(0x6b6c26b2)
seeds = np.random.randint(0x0fffffff, size=num_runs)
np.random.seed(seeds[t])
# random hmm
z_mat, t_mat = random_hmm(num_states, num_obs)
pi_vec = np.array([1.0 / num_states] * num_states)
hmm_test = HMM(z_mat, t_mat, pi_vec)
# random obs trajectory
obs = hmm_test.generate(obs_length)[np.newaxis, :]
# calculate log likelihood for input HMM parameters
z_mat_p_input = np.array([[params['z_mat_p_0'][0], params['z_mat_p_1'][0]]])
t_mat_p_input = np.array([[params['t_mat_p_0'][0], params['t_mat_p_1'][0]]])
# pi_vec_input = np.array([params['pi_0'], 1 - params['pi_0']])
hmm_estimate = make_parameterized_HMM(z_mat_p_input, t_mat_p_input, pi_vec)
hmm_loglikelihood = hmm_estimate.loglikelihood(obs[0])
# use the current suggest point and run EM to get a new point
hmm_em_est, _, _ = em.em(hmm_estimate, hmm_estimate.z_mat, hmm_estimate.t_mat, obs, 30, 0.1)
em_est_z_mat, em_est_t_mat = retrieve_parameterized_HMM(hmm_em_est)
em_est_ll = -hmm_em_est.loglikelihood(obs[0])
em_est_z_mat.reshape((em_est_z_mat.size,))
em_est_t_mat.reshape((em_est_t_mat.size,))
print em_est_t_mat
print em_est_z_mat
historical_points = [{'params': {}}]
# write z_mat
for i, v in enumerate(em_est_z_mat[0]):
historical_points[0]['params']['z_mat_p_' + str(i)] = {'values': np.array([v]), 'type': 'float'}
# write t_mat
for i, v in enumerate(em_est_t_mat[0]):
historical_points[0]['params']['t_mat_p_' + str(i)] = {'values': np.array([v]), 'type': 'float'}
historical_points[0]['value'] = em_est_ll
dump_new_history('.', historical_points)
return -hmm_loglikelihood
示例3: range
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import generate [as 别名]
# for i in range(len(obs)):
# print str(obs[i])+' '+path[i]
# Learning Test
hmmLearn = HMM(a2, b2, pi2)
#Defines the influence that new observations have on previous probabilities
hmmLearn.influence = (3, 14)
# hmmLearn.generateMatrix(states, alphabet)
##Supervised Learning
# for x in range(50):
# hmmLearn.supertrain(hmm.generate(2000))
# print "-----"
# print hmmLearn.pi
# print hmmLearn.a
# print hmmLearn.b
##Unsupervised Learning (EM/Baum-Welch)
for x in range(100):
hmmLearn.baum_welch(hmm.generate(100, True))
print pi
print a
print b
print "---"
print hmmLearn.pi
print hmmLearn.a
print hmmLearn.b