Exemplo n.º 1
0
class BaumWelchIterate(unittest.TestCase):
	""" Tester la reussite des reestimations """
	def setUp(self):
		self.listState = ['A', 'B']
		self.listObservables = ["je", "ne", "suis", "pas", "un", "hero"]
		self.hmm = HMM_BW(self.listObservables, self.listState, 5)

	def test_setAlpha(self):
		''' Test de l'instanciation des alpha '''
		alpha_0 = self.hmm.alpha[1]['A']
		self.hmm.setAlpha()
		alpha_1 = self.hmm.alpha[1]['A']

		assert(not alpha_0 == alpha_1)

	def test_setBeta(self):
		''' Test de l'instanciation des beta '''
		beta_0 = self.hmm.beta[0]['A']
		self.hmm.setBeta()
		beta_1 = self.hmm.beta[0]['A']

		assert(not beta_0 == beta_1)

	def test_setGamma(self):
		''' Test de l'instanciation des gamma '''
		gamma_0 = self.hmm.gamma[0]['A']
		self.hmm.setGamma()
		gamma_1 = self.hmm.gamma[0]['A']
		
		assert(not gamma_0 == gamma_1)


	def test_iterations(self):
		''' Test du bon fonctionnement d'une iteration '''
		E_0 = self.hmm.emissions[self.listObservables[0]][self.listState[0]]
		self.hmm.iterate()
		E_1 = self.hmm.emissions[self.listObservables[0]][self.listState[0]]
		assert(not E_0 == E_1)
Exemplo n.º 2
0
class BaumWelchIterate(unittest.TestCase):
	""" Tester la reussite des reestimations """
	def setUp(self):
		listObservables = ["je", "ne", "suis", "pas", "un", "hero"]
		self.hmm = HMM_BW(listObservables, 5)

	def test_setAlpha(self):
		alpha_0 = self.hmm.alpha[1]['A']
		self.hmm.setAlpha()
		alpha_1 = self.hmm.alpha[1]['A']

		assert(not alpha_0 == alpha_1)

	def test_setBeta(self):
		beta_0 = self.hmm.beta[0]['A']
		self.hmm.setBeta()
		beta_1 = self.hmm.beta[0]['A']

		assert(not beta_0 == beta_1)

	def test_iterations(self):
		self.hmm.iterate()
		assert(1==2)
Exemplo n.º 3
0
    hmm.emissions[""][state] = 0.0


def get_precision(table):
    conteur = 0
    for index in range(len(table)):
        if table[index][1] == table[index][2]:
            conteur += 1
    precision = float(conteur)/(len(table))
    return precision

table = viterbi.determinerClassesAvecDonneeExternes(test_table, hmm.transitions[""], hmm.transitions, hmm.emissions)

print str(viterbi.get_precision(table)*100)[0:4]+"% correct"
print "on lance les reestimations:"

hmm.iterate()
table = viterbi.determinerClassesAvecDonneeExternes(test_table, hmm.transitions[""], hmm.transitions, hmm.emissions)
print str(get_precision(table)*100)[0:5]+"% correct"

hmm.iterate()
table = viterbi.determinerClassesAvecDonneeExternes(test_table, hmm.transitions[""], hmm.transitions, hmm.emissions)
print str(get_precision(table)*100)[0:5]+"% correct"

print "on applique une perturbation sur la matrice d'emission:"
hmm.perturbation(0.00001)
print str(viterbi.get_precision(table)*100)[0:4]+"% correct"
print "on itere a nouveau:"
hmm.iterate()
table = viterbi.determinerClassesAvecDonneeExternes(test_table, hmm.transitions[""], hmm.transitions, hmm.emissions)
print str(get_precision(table)*100)[0:5]+"% correct"