本文整理汇总了Python中hmmlearn.hmm.GaussianHMM.covars_方法的典型用法代码示例。如果您正苦于以下问题:Python GaussianHMM.covars_方法的具体用法?Python GaussianHMM.covars_怎么用?Python GaussianHMM.covars_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hmmlearn.hmm.GaussianHMM
的用法示例。
在下文中一共展示了GaussianHMM.covars_方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bench_gaussian_hmm
# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import covars_ [as 别名]
def bench_gaussian_hmm(size):
title = "benchmarking Gaussian HMM on a sample of size {0}".format(size)
print(title.center(36, " "))
ghmm = GaussianHMM()
ghmm.means_ = [[42], [24]]
ghmm.covars_ = [[1], [1]]
with timed_step("generating sample"):
sample, _states = ghmm.sample(size)
with timed_step("fitting"):
fit = GaussianHMM(n_components=2).fit([sample])
with timed_step("estimating states"):
fit.predict(sample)
示例2: calculate_hmm_g
# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import covars_ [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: of
# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import covars_ [as 别名]
# 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
# As emission probability is a 2-D gaussian distribution, thus
# covariance matrix for each state would be a 2-D matrix, thus
# overall the covariance matrix for all the states would be in the
# form of (n_components, 2, 2)
covariance = 0.5 * np.tile(np.identity(2), (3, 1, 1))
model_gaussian.covars_ = covariance
# model.sample returns both observations as well as hidden states
# the first return argument being the observation and the second
# being the hidden states
Z, X = model_gaussian.sample(100)
# Plotting the observations
plt.plot(Z[:, 0], Z[:, 1], "-o", label="observations",
ms=6, mfc="orange", alpha=0.7)
# Indicate the state numbers
for i, m in enumerate(mean):
plt.text(m[0], m[1], 'Component %i' % (i + 1),
size=17, horizontalalignment='center',
bbox=dict(alpha=.7, facecolor='w'))
示例4: main
# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import covars_ [as 别名]
#.........这里部分代码省略.........
group.hmm = group.hmm[0]
elif(len(group.hmm) == len(histone_file_name_list)): flag_multiple_hmms = True
else: error_handler.throw_error("FP_NB_HMMS")
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")
示例5: float
# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import covars_ [as 别名]
else:
stateCovs[i] = covAll * float(i)/args.ploidy;
cnvsToStateIs[i]=i
statePDFMaxima[i]=np.log(multivariate_normal.pdf(x=stateMeans[i],mean=stateMeans[i],cov=stateCovs[i]))
cnvsToStateIs0=cnvsToStateIs;
stateIsToCNVs0 = stateIsToCNVs;
if len(IDs)==1:
stateCovs = np.expand_dims(stateCovs,1)
#model = GaussianHMM(len(states),covariance_type="full",n_iter=1);
model = GaussianHMM(numStates,covariance_type="full", n_iter=1);
###insert my own params
model.means_ = stateMeans;
model.covars_ = stateCovs;
### make transmat
if args.transition <= -100:
transitionMatrix = (1-np.eye(numStates))*args.transition*np.log(10);
model._log_transmat =transitionMatrix;
else:
transitionMatrix = np.add(np.eye(numStates)*(1-(numStates-1)*10**args.transition),(1-np.eye(numStates))*10**args.transition);
model._set_transmat(transitionMatrix);
if args.verbose>0: sys.stderr.write(np.array_str(model._log_transmat)+"\n");
#exit;
meanNormal = meanAll;
normalState = cnvsToStateIs[args.ploidy];
lastClass = {};