Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
test_HMMGeneral.AbstractTrainerTest Class Reference

List of all members.

Public Member Functions

def setUp
def test_ml_estimator
def test_log_likelihood

Public Attributes

 test_trainer

Detailed Description

Definition at line 380 of file test_HMMGeneral.py.


Member Function Documentation

Definition at line 381 of file test_HMMGeneral.py.

00381 
00382     def setUp(self):
00383         # set up a bogus HMM and our trainer
00384         hmm = MarkovModel.HiddenMarkovModel({}, {}, {}, {}, {})
00385         self.test_trainer = Trainer.AbstractTrainer(hmm)
    
Calculate log likelihood.

Definition at line 414 of file test_HMMGeneral.py.

00414 
00415     def test_log_likelihood(self):
00416         """Calculate log likelihood.
00417         """
00418         probs = [.25, .13, .12, .17]
00419 
00420         log_prob = self.test_trainer.log_likelihood(probs)
00421         expected_log_prob = -7.31873556778
00422         assert abs(expected_log_prob - log_prob) < 0.1, \
00423           "Bad probability calculated: %s" % log_prob
00424 
# run the tests
Test the maximum likelihood estimator for simple cases.

Definition at line 386 of file test_HMMGeneral.py.

00386 
00387     def test_ml_estimator(self):
00388         """Test the maximum likelihood estimator for simple cases.
00389         """
00390         # set up a simple dictionary
00391         counts = {('A', 'A') : 10,
00392                   ('A', 'B') : 20,
00393                   ('A', 'C') : 15,
00394                   ('B', 'B') : 5,
00395                   ('C', 'A') : 15,
00396                   ('C', 'C') : 10}
00397 
00398         results = self.test_trainer.ml_estimator(counts)
00399 
00400         # now make sure we are getting back the right thing
00401         result_tests = []
00402         result_tests.append([('A', 'A'), float(10) / float(45)])
00403         result_tests.append([('A', 'B'), float(20) / float(45)])
00404         result_tests.append([('A', 'C'), float(15) / float(45)])
00405         result_tests.append([('B', 'B'), float(5) / float(5)])
00406         result_tests.append([('C', 'A'), float(15) / float(25)])
00407         result_tests.append([('C', 'C'), float(10) / float(25)])
00408 
00409         for test_result in result_tests:
00410             assert results[test_result[0]] == test_result[1], \
00411                    "Got %f, expected %f for %s" % (results[test_result[0]],
00412                                                    test_result[1],
00413                                                    test_result[0])


Member Data Documentation

Definition at line 384 of file test_HMMGeneral.py.


The documentation for this class was generated from the following file: