本文整理汇总了Python中hmmlearn.hmm.GaussianHMM.transmat_方法的典型用法代码示例。如果您正苦于以下问题:Python GaussianHMM.transmat_方法的具体用法?Python GaussianHMM.transmat_怎么用?Python GaussianHMM.transmat_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hmmlearn.hmm.GaussianHMM
的用法示例。
在下文中一共展示了GaussianHMM.transmat_方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import transmat_ [as 别名]
def main(args):
x, X = loadDiffRows(args.diffFile)
model = GaussianHMM(n_components=3,
covariance_type="diag",
n_iter=100000000000)
model.transmat_ = numpy.array([[0.5, 0.5, 0.0],
[0.0, 0.5, 0.5],
[0.0, 0.0, 1.0]])
model.fit(X)
print(model.transmat_)
model.transmat_[0][2] = 0.
model.transmat_[1][0] = 0.
model.transmat_[2][0] = 0.
model.transmat_[2][1] = 0.
exp = args.outFile.split('/')[-1].split('_')[0]
with open(args.outFile, 'w') as fout:
print('exp\tbin\treads\tstate', file=fout)
for seq in X:
hiddenStates = model.predict(seq)
for idx,v in enumerate(zip(x,hiddenStates)):
r,h = v
print(exp + '\t' + str(idx) + '\t'
+ str(r) + '\t' + str(h),
file=fout)
示例2: calculate_hmm_g
# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import transmat_ [as 别名]
def calculate_hmm_g(training_set, test_set, taxonomy, cursor, connection, settings):
da_id_taxonomy = find_da_id(taxonomy, cursor)
states, start_probability, transition_probability = start_transition_probability_extraction(training_set, taxonomy)
n_states = len(states)
feature_list = extract_features_training_set_gaus(training_set, taxonomy, settings)
n_features = len(feature_list[states[0]][0])
mean = calculate_means(states, feature_list, n_features)
covariance = calculate_covariance(states, feature_list, n_features)
# covariance = diag_cov(states, feature_list, n_features, mean)
model = GaussianHMM(n_components=n_states, covariance_type='full')
model.startprob_ = start_probability
model.transmat_ = transition_probability
model.means_ = mean
model.covars_ = covariance
test_seq, con_pathes = extract_features_test_set_gaus(test_set, taxonomy, settings)
da_predictions(test_seq, model, con_pathes, states, da_id_taxonomy, taxonomy, cursor, connection)
示例3: GaussianHMM
# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import transmat_ [as 别名]
from hmmlearn.hmm import GaussianHMM
import matplotlib.pyplot as plt
import numpy as np
# Here n_components correspond to number of states in the hidden
# variables.
model_gaussian = GaussianHMM(n_components=3, covariance_type='full')
# Transition probability as specified above
transition_matrix = np.array([[0.2, 0.6, 0.2],
[0.4, 0.3, 0.3],
[0.05, 0.05, 0.9]])
# Setting the transition probability
model_gaussian.transmat_ = transition_matrix
# Initial state probability
initial_state_prob = np.array([0.1, 0.4, 0.5])
# Setting initial state probability
model_gaussian.startprob_ = initial_state_prob
# As we want to have a 2-D gaussian distribution the mean has to
# be in the shape of (n_components, 2)
mean = np.array([[0.0, 0.0],
[0.0, 10.0],
[10.0, 0.0]])
# Setting the mean
model_gaussian.means_ = mean
示例4: main
# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import transmat_ [as 别名]
#.........这里部分代码省略.........
else: # Argument was not passed
for group in group_list:
group.flag_multiple_hmms = False
if(group.dnase_only):
if(bias_correction): group.hmm = hmm_data.get_default_hmm_dnase_bc()
else: group.hmm = hmm_data.get_default_hmm_dnase()
elif(group.histone_only):
group.hmm = hmm_data.get_default_hmm_histone()
else:
if(bias_correction): group.hmm = hmm_data.get_default_hmm_dnase_histone_bc()
else: group.hmm = hmm_data.get_default_hmm_dnase_histone()
# Creating scikit HMM list
for group in group_list:
if(group.flag_multiple_hmms):
hmm_list = []
for hmm_file_name in group.hmm:
try:
hmm_scaffold = HMM()
hmm_scaffold.load_hmm(hmm_file_name)
if(int(hmm_ver.split(".")[0]) <= 0 and int(hmm_ver.split(".")[1]) <= 1):
scikit_hmm = GaussianHMM(n_components=hmm_scaffold.states, covariance_type="full",
transmat=array(hmm_scaffold.A), startprob=array(hmm_scaffold.pi))
scikit_hmm.means_ = array(hmm_scaffold.means)
scikit_hmm.covars_ = array(hmm_scaffold.covs)
else:
scikit_hmm = GaussianHMM(n_components=hmm_scaffold.states, covariance_type="full")
scikit_hmm.startprob_ = array(hmm_scaffold.pi)
scikit_hmm.transmat_ = array(hmm_scaffold.A)
scikit_hmm.means_ = array(hmm_scaffold.means)
scikit_hmm.covars_ = array(hmm_scaffold.covs)
except Exception: error_handler.throw_error("FP_HMM_FILES")
hmm_list.append(scikit_hmm)
group.hmm = hmm_list
else:
scikit_hmm = None
try:
hmm_scaffold = HMM()
hmm_scaffold.load_hmm(group.hmm)
if(int(hmm_ver.split(".")[0]) <= 0 and int(hmm_ver.split(".")[1]) <= 1):
scikit_hmm = GaussianHMM(n_components=hmm_scaffold.states, covariance_type="full",
transmat=array(hmm_scaffold.A), startprob=array(hmm_scaffold.pi))
scikit_hmm.means_ = array(hmm_scaffold.means)
scikit_hmm.covars_ = array(hmm_scaffold.covs)
else:
scikit_hmm = GaussianHMM(n_components=hmm_scaffold.states, covariance_type="full")
scikit_hmm.startprob_ = array(hmm_scaffold.pi)
scikit_hmm.transmat_ = array(hmm_scaffold.A)
scikit_hmm.means_ = array(hmm_scaffold.means)
scikit_hmm.covars_ = array(hmm_scaffold.covs)
except Exception: error_handler.throw_error("FP_HMM_FILES")
group.hmm = scikit_hmm
###################################################################################################
# Main Pipeline
示例5: scale
# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import transmat_ [as 别名]
try:
obs = numpy.array(analysis)
obs = obs.T
obs = obs[1:]
obs = obs.T
obs = scale(obs)
model = GaussianHMM(algorithm='viterbi', covariance_type='diag', covars_prior=0.01,
covars_weight=1, init_params='mc', means_prior=0, means_weight=0,
min_covar=0.001, n_components=3, n_iter=1000, params='mc',
random_state=None, startprob_prior=1.0, tol=0.01, transmat_prior=1.0,
verbose=False)
model.startprob_ = numpy.array([1., 0, 0])
model.startprob_prior = model.startprob_
model.transmat_ = numpy.array([[0.9, 0.1, 0], [0, 0.9, 0.1], [0, 0, 1]])
model.transmat_prior = model.transmat_
model.fit(obs)
pi = model.startprob_
A = model.transmat_
w = numpy.ones((n, m), dtype=numpy.double)
hmm_means = numpy.ones((n, m, d), dtype=numpy.double)
hmm_means[0][0] = model.means_[0]
hmm_means[1][0] = model.means_[1]
hmm_means[2][0] = model.means_[2]
hmm_covars = numpy.array([[ numpy.matrix(numpy.eye(d,d)) for j in xrange(m)] for i in xrange(n)])
hmm_covars[0][0] = model.covars_[0]
hmm_covars[1][0] = model.covars_[1]
hmm_covars[2][0] = model.covars_[2]