示例#1
0
def separateVowels(model,characters,alphabet):
	alpha,beta,logProb = hmm.betaPass(model,hmm.transformObservations(alphabet,characters))
	gam = hmm.gamma(alpha,beta)
	stateProbs = sp.sum(gam,0)/gam.shape[0]
	bools = model[1][0,:]*stateProbs[0] > model[1][1,:]*stateProbs[1]
	state_1_chars = sp.array(alphabet)[bools].tolist()
	state_2_chars = sp.array(alphabet)[-bools].tolist()
	return state_1_chars, state_2_chars
示例#2
0
def russianHMM(n_trials,characters,alphabet):
	model = hmm.hmmTrain(characters,2,tol=.1,maxiter=100)
	obs = hmm.transformObservations(alphabet,characters)
	logProb = hmm.score(model,obs)
	for i in xrange(n_trials-1):
		print(i)
		temp_model = hmm.hmmTrain(characters,2,tol=.1,maxiter=100)
		temp_logProb = hmm.score(temp_model,obs)
		if temp_logProb > logProb:
			model = temp_model
			logProb = temp_logProb
	return model