def test_hmmgraph(self): """Checking graphing process for HMM.""" obs_seq = 'AGACTGCATATATAAGGGGCAGGCTG' sts_seq = '00000000111111100000000000' a = hmm.HiddenMarkovModel().from_seq(obs_seq, sts_seq) graph = a.graph_make() self.assertTrue(isinstance(graph, Digraph))
def test_epm(self): """Checking emission probability matrix.""" result = np.array([[0.21052632, 0.21052632, 0.47368421, 0.10526316], [0.57142857, 0., 0., 0.42857143]]) obs_seq = 'AGACTGCATATATAAGGGGCAGGCTG' sts_seq = '00000000111111100000000000' a = hmm.HiddenMarkovModel().from_seq(obs_seq, sts_seq) self.assertTrue(np.allclose(a.ep, result))
def test_vit(self): """Checking Viterbi.""" obs_seq = 'AGACTGCATATATAAGGGGCAGGCTG' sts_seq = '00000000111111100000000000' a = hmm.HiddenMarkovModel().from_seq(obs_seq, sts_seq) b = a.viterbi(obs_seq) self.assertTrue( isinstance(b[0], np.ndarray) and isinstance(b[1], np.ndarray))
def test_bw(self): '''Checking Baum-Welch''' obs_seq = 'AGACTGCATATATAAGGGGCAGGCTG' sts_seq = '00000000111111100000000000' a = hmm.HiddenMarkovModel().from_seq(obs_seq, sts_seq) b = a.baum_welch(obs_seq, iters=3) self.assertTrue( isinstance(b[0], np.ndarray) and isinstance(b[1], np.ndarray))
def test_bw(self): """Checking Baum-Welch.""" obs_seq = 'AGACTGCATATATAAGGGGCAGGCTG' a = hmm.HiddenMarkovModel().from_baum_welch(obs_seq, states=['0', '1']) self.assertTrue(isinstance(a, hmm.HiddenMarkovModel))