Beispiel #1
0
        def helper(y1, y2):
            alphabet = ('A', 'B', '')
            toy_alphabet = OrderedDict([('A', 0), ('B', 1)])
            profile1 = poreover_profile(y1, alphabet)
            profile2 = poreover_profile(y2, alphabet)
            joint_prof = joint_profile(profile1, profile2)

            gamma = prefix_search.pair_gamma_log(np.log(y1), np.log(y2))
            print('log(Z):', gamma[0, 0], np.log(joint_prof.prob_agree))
            self.assertTrue(
                np.isclose(gamma[0, 0], np.log(joint_prof.prob_agree)))
Beispiel #2
0
 def test_full_envelope(self):
     y1 = np.array([[0.8, 0.1, 0.1], [0.1, 0.3, 0.6], [0.7, 0.2, 0.1],
                    [0.1, 0.1, 0.8]])
     y2 = np.array([[0.7, 0.2, 0.1], [0.2, 0.3, 0.5], [0.7, 0.2, 0.1],
                    [0.05, 0.05, 0.9]])
     full_seq = decoding.decoding_cpp.cpp_beam_search_2d(np.log(y1),
                                                         np.log(y2),
                                                         alphabet_="AB")
     prof1 = poreover_profile(y1, ('A', 'B', ''))
     prof2 = poreover_profile(y2, ('A', 'B', ''))
     joint_prof = joint_profile(prof1, prof2)
     self.assertTrue(full_seq == joint_prof.top_label()[0])
Beispiel #3
0
 def test2(self):
     y = np.array([[0.4, 0.5, 0.1], [0.4, 0.2, 0.4], [0.3, 0.5, 0.2]])
     prof = poreover_profile(y, ('A', 'B', ''))
     result = decoding.decoding_cpp.cpp_beam_search(np.log(y),
                                                    alphabet_="AB")
     print(prof.top_label()[0], "------", result)
     self.assertTrue(result == prof.top_label()[0])
Beispiel #4
0
 def test(self):
     y = np.array([[0.8, 0.1, 0.1], [0.1, 0.3, 0.6], [0.7, 0.2, 0.1],
                   [0.1, 0.1, 0.8]])
     prof = poreover_profile(y, ('A', 'B', ''))
     result = decoding.decoding_cpp.cpp_beam_search(np.log(y),
                                                    alphabet_="AB")
     self.assertTrue(result == prof.top_label()[0])
Beispiel #5
0
        def helper(y1, y2):
            alphabet = ('A', 'B', '')
            toy_alphabet = OrderedDict([('A', 0), ('B', 1)])

            profile1 = poreover_profile(y1, alphabet)
            profile2 = poreover_profile(y2, alphabet)
            joint_prof = joint_profile(profile1, profile2)

            top_label = joint_prof.top_label()
            search_top_label = prefix_search.pair_prefix_search_log_cy(
                np.log(y1), np.log(y2), alphabet=toy_alphabet)

            print(top_label[0], np.log(top_label[1] / joint_prof.prob_agree),
                  search_top_label[0], search_top_label[1])
            return ((top_label[0] == search_top_label[0]) and np.isclose(
                np.log(top_label[1] / joint_prof.prob_agree),
                search_top_label[1]))
Beispiel #6
0
 def helper(y, l):
     label_int = [alphabet_dict[i] for i in label]
     prof = poreover_profile(y, alphabet)
     alpha = prefix_search.forward(label_int, np.log(y))
     prefix_prob = logsumexp(
         prefix_search.forward_vec_no_gap_log(label_int, np.log(y),
                                              alpha[-2]))
     print(prefix_prob, prof.prefix_prob(label))
     self.assertTrue(
         np.isclose(prefix_prob, np.log(prof.prefix_prob(label))))
Beispiel #7
0
 def helper(y):
     alphabet = ('A', 'B', '')
     toy_alphabet = OrderedDict([('A', 0), ('B', 1)])
     prof = poreover_profile(y, alphabet)
     top_label = prof.top_label()
     search_top_label = prefix_search.prefix_search_log(
         np.log(y), alphabet=toy_alphabet)
     print(top_label[0], np.log(top_label[1]), search_top_label[0],
           search_top_label[1])
     return ((top_label[0] == search_top_label[0])
             and np.isclose(np.log(top_label[1]), search_top_label[1]))
Beispiel #8
0
    def test_fw_poreover(self):
        alphabet_tuple = ('A','B','')
        alphabet = "AB"

        y = np.array([[0.8,0.1,0.1],[0.1,0.3,0.6],[0.7,0.2,0.1],[0.1,0.1,0.8]], dtype=np.float32)
        examples = ['AAAA','ABBA','ABA','AAA','BBB', 'AA','BB','A','B']
        prof=poreover_profile(y, alphabet_tuple)

        for label in examples:
            fw_prob_actual =  np.log(prof.label_prob(label))
            fw_prob  = decoding.decoding_cpp.cpp_forward(np.log(y), label, alphabet)
            print(label, fw_prob_actual, fw_prob)
            self.assertTrue(np.isclose(fw_prob_actual, fw_prob))
Beispiel #9
0
    def test_label_prob_log(self):
        alphabet = ('A', 'B', '')
        alphabet_dict = {'A': 0, 'B': 1, '': 2}

        y = np.array([[0.8, 0.1, 0.1], [0.1, 0.3, 0.6], [0.7, 0.2, 0.1],
                      [0.1, 0.1, 0.8]])
        examples = ['AAAA', 'ABBA', 'ABA', 'AA', 'BB', 'A', 'B']
        prof = poreover_profile(y, alphabet)

        for label in examples:
            label_int = [alphabet_dict[i] for i in label]
            alpha = prefix_search.forward(label_int, np.log(y))
            self.assertTrue(
                np.isclose(alpha[-1, -1], np.log(prof.label_prob(label))))