本文整理汇总了Python中sklearn.hmm.GaussianHMM._decode_viterbi方法的典型用法代码示例。如果您正苦于以下问题:Python GaussianHMM._decode_viterbi方法的具体用法?Python GaussianHMM._decode_viterbi怎么用?Python GaussianHMM._decode_viterbi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.hmm.GaussianHMM
的用法示例。
在下文中一共展示了GaussianHMM._decode_viterbi方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _SklearnGaussianHMMCPUImpl
# 需要导入模块: from sklearn.hmm import GaussianHMM [as 别名]
# 或者: from sklearn.hmm.GaussianHMM import _decode_viterbi [as 别名]
class _SklearnGaussianHMMCPUImpl(object):
def __init__(self, n_states, n_features):
from sklearn.hmm import GaussianHMM
self.impl = GaussianHMM(n_states, params='stmc')
self._sequences = None
self.means_ = None
self.vars_ = None
self.transmat_ = None
self.startprob_ = None
def do_estep(self):
from sklearn.utils.extmath import logsumexp
self.impl.means_ = self.means_.astype(np.double)
self.impl.covars_ = self.vars_.astype(np.double)
self.impl.transmat_ = self.transmat_.astype(np.double)
self.impl.startprob_ = self.startprob_.astype(np.double)
stats = self.impl._initialize_sufficient_statistics()
curr_logprob = 0
for seq in self._sequences:
seq = seq.astype(np.double)
framelogprob = self.impl._compute_log_likelihood(seq)
lpr, fwdlattice = self.impl._do_forward_pass(framelogprob)
bwdlattice = self.impl._do_backward_pass(framelogprob)
gamma = fwdlattice + bwdlattice
posteriors = np.exp(gamma.T - logsumexp(gamma, axis=1)).T
curr_logprob += lpr
self.impl._accumulate_sufficient_statistics(
stats, seq, framelogprob, posteriors, fwdlattice,
bwdlattice, self.impl.params)
return curr_logprob, stats
def do_viterbi(self):
logprob = 0
state_sequences = []
for obs in self._sequences:
lpr, ss = self.impl._decode_viterbi(obs)
logprob += lpr
state_sequences.append(ss)
return logprob, state_sequences