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


Python GaussianHMM._compute_log_likelihood方法代码示例

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


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

示例1: test_backward_with_hmmlearn

# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import _compute_log_likelihood [as 别名]
    def test_backward_with_hmmlearn(self):
        r = np.random.randn
        obs = [np.array([[-600 + r(), 100 + r()], [-300 + r(), 200 + r()], [0 + r(), 300 + r()]]) for _ in xrange(10)]
        hmm = GaussianHMM(n_components=3)
        hmm.fit(obs)

        # Calculcate bwdlattice using hmmlearn algorithm
        framelogprob = hmm._compute_log_likelihood(obs[0])
        start = timeit.default_timer()
        bwdlattice1 = hmm._do_backward_pass(framelogprob)
        print('hmmlearn took %fs' % (timeit.default_timer() - start))

        # Calculate bwdlattice using fhmm algorithm with #chains = 1. This should yield the exact same results
        start = timeit.default_timer()
        bwdlattice2 = np.zeros(bwdlattice1.shape)
        fhmmc._backward(obs[0].shape[0], 1, hmm.n_components, [(x,) for x in xrange(hmm.n_components)],
                        hmm._log_startprob.reshape(1, 3), hmm._log_transmat.reshape(1, 3, 3), framelogprob, bwdlattice2)
        print('fhmm took %fs' % (timeit.default_timer() - start))
        self.assertTrue(np.allclose(bwdlattice1, bwdlattice2))
开发者ID:caomw,项目名称:motion-classification,代码行数:21,代码来源:test_fhmm.py

示例2: range

# 需要导入模块: from hmmlearn.hmm import GaussianHMM [as 别名]
# 或者: from hmmlearn.hmm.GaussianHMM import _compute_log_likelihood [as 别名]
for chr in chrOrder:
	lastClass[chr] = np.tile(args.ploidy,allData[chr].shape[0]);


for i in range(0,args.iterations):
	warned=False;
	if args.verbose>1: sys.stderr.write("  Iteration %i.\n"%(i));
	viterbi = {}
	noChange=0;
	viterbiCat =np.zeros(allDataCat.shape[0]);
	curTot=0;
	curNumCNVs=0;
	for chr in chrOrder:
		#3. Calculate Viterbi path given data
		if args.verbose>2: sys.stderr.write("    i=%i; Calculating Viterbi path for %s.\n"%(i,chr));
		framelogprob = model._compute_log_likelihood(allData[chr])
		#sys.stderr.write("framelogprob dim: "+str(framelogprob.shape)+"\n");
		framelogprob[:,cnvsToStateIs[args.ploidy]] = np.subtract(framelogprob[:,cnvsToStateIs[args.ploidy]], args.standardPrior); #add log(prior)
		if args.scalePDF>0:
			framelogprob = np.subtract(framelogprob,statePDFMaxima) #### This requires some explanation.  See Note 1 below. 
		logprob, viterbi[chr] = model._do_viterbi_pass(framelogprob);
		curLen = len(viterbi[chr]);
		#4. For each non-standard state, calculate the mean in that state and add a state with a mean representing that ploidy
		changeStart=-1
		viterbi[chr] = np.insert(viterbi[chr],[0,curLen],[normalState,normalState]); # add initial and terminal normalStates so that telomeres in CNV will be detected.
		for j in range(1,len(viterbi[chr])):
			if viterbi[chr][j]!=viterbi[chr][j-1]:#there was a change
				if changeStart==-1:
					if viterbi[chr][j]==normalState:
						raise Exception("new state is normal ploidy state");
					changeStart=j;
开发者ID:Carldeboer,项目名称:BigWig-Tools,代码行数:33,代码来源:findCopyNumber.py


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