Back to index

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

List of all members.

Public Member Functions

def setUp
def test_test_initialize
def test_allow_all_transitions
def test_set_initial_probabilities
def test_set_equal_probabilities
def test_set_random_probabilities

Public Attributes

 mm_builder

Detailed Description

Definition at line 38 of file test_HMMGeneral.py.


Member Function Documentation

Definition at line 39 of file test_HMMGeneral.py.

00039 
00040     def setUp(self):
00041         self.mm_builder = MarkovModel.MarkovModelBuilder(NumberAlphabet(),
00042                                                          LetterAlphabet())

Testing allow_all_transitions.

Definition at line 66 of file test_HMMGeneral.py.

00066 
00067     def test_allow_all_transitions(self):
00068         """Testing allow_all_transitions.
00069         """
00070         self.mm_builder.allow_all_transitions()
00071 
00072         expected_prob = {('2', '1'): 0, ('1', '1'): 0,
00073                          ('1', '2'): 0, ('2', '2'): 0}
00074 
00075         expected_pseudo = {('2', '1'): 1, ('1', '1'): 1,
00076                            ('1', '2'): 1, ('2', '2'): 1}
00077 
00078         test_assertion("Probabilities", self.mm_builder.transition_prob,
00079                        expected_prob)
00080         
00081         test_assertion("Pseudo counts",  self.mm_builder.transition_pseudo,
00082                        expected_pseudo)
00083 

Here is the call graph for this function:

Definition at line 109 of file test_HMMGeneral.py.

00109 
00110     def test_set_equal_probabilities(self):
00111         self.mm_builder.allow_transition('1', '2', 0.05)
00112         self.mm_builder.allow_transition('2', '1', 0.95)
00113         self.mm_builder.set_equal_probabilities()
00114 
00115         test_assertion("Equal initial probabilities",
00116                        self.mm_builder.initial_prob,
00117                        {'1': 0.5, '2': 0.5})
00118         test_assertion("Equal transition probabilities",
00119                        self.mm_builder.transition_prob,
00120                        {('1', '2'): 0.5, ('2', '1'): 0.5})
00121         test_assertion("Equal emission probabilities",
00122                        self.mm_builder.emission_prob,
00123                        {('2', 'A'): 0.25, ('1', 'B'): 0.25,
00124                         ('1', 'A'): 0.25, ('2', 'B'): 0.25})

Here is the call graph for this function:

Definition at line 84 of file test_HMMGeneral.py.

00084 
00085     def test_set_initial_probabilities(self):
00086         self.mm_builder.set_initial_probabilities({})
00087         test_assertion("Equal initial probabilities by default",
00088                        self.mm_builder.initial_prob, {'1': 0.5, '2': 0.5})
00089 
00090         # initial probability sum > 1, should raise an exception
00091         self.assertRaises(
00092             Exception,
00093             self.mm_builder.set_initial_probabilities,
00094             {'1': 0.6, '2': 0.5})
00095 
00096         # referencing invalid states should raise an exception
00097         self.assertRaises(
00098             Exception,
00099             self.mm_builder.set_initial_probabilities,
00100             {'666': 0.1})
00101 
00102         self.mm_builder.set_initial_probabilities({'1': 0.2})
00103         test_assertion("One default initial probability",
00104                        self.mm_builder.initial_prob, {'1': 0.2, '2': 0.8})
00105 
00106         self.mm_builder.set_initial_probabilities({'1': 0.9, '2': 0.1})
00107         test_assertion("Set initial probabilities",
00108                        self.mm_builder.initial_prob, {'1': 0.9, '2': 0.1})

Here is the call graph for this function:

Definition at line 125 of file test_HMMGeneral.py.

00125 
00126     def test_set_random_probabilities(self):
00127         self.mm_builder.allow_transition('1', '2', 0.05)
00128         self.mm_builder.allow_transition('2', '1', 0.95)
00129         self.mm_builder.set_random_probabilities()
00130 
00131         test_assertion("Number of initial probabilities",
00132                        len(self.mm_builder.initial_prob),
00133                        len(self.mm_builder._state_alphabet.letters))
00134         # To test this more thoroughly, perhaps mock random.random() and
00135         # verify that it's being called as expected?

Here is the call graph for this function:

Making sure MarkovModelBuilder is initialized correctly.

Definition at line 43 of file test_HMMGeneral.py.

00043 
00044     def test_test_initialize(self):
00045         """Making sure MarkovModelBuilder is initialized correctly.
00046         """
00047         expected_transition_prob = {}
00048         expected_transition_pseudo = {}
00049 
00050         expected_emission_prob = {('2', 'A'): 0, ('1', 'A'): 0,
00051                                   ('1', 'B'): 0, ('2', 'B'): 0}
00052         expected_emission_pseudo = {('2', 'A'): 1, ('1', 'A'): 1,
00053                                     ('1', 'B'): 1, ('2', 'B'): 1}
00054 
00055         assertions = []
00056         test_assertion("Transition prob", self.mm_builder.transition_prob,
00057                           expected_transition_prob)
00058         test_assertion("Transition pseudo",
00059                           self.mm_builder.transition_pseudo,
00060                           expected_transition_pseudo)
00061         test_assertion("Emission prob", self.mm_builder.emission_prob,
00062                            expected_emission_prob)
00063         test_assertion("Emission pseudo", self.mm_builder.emission_pseudo,
00064                            expected_emission_pseudo)
00065 

Here is the call graph for this function:


Member Data Documentation

Definition at line 40 of file test_HMMGeneral.py.


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