コード例 #1
0
    def test_viterbi_phrase2(self, part_2_a, multidimensional_viterbi):
        """
        Extracted from BOSTON ASL dataset: video 47, frame 12-30
        Actual words: BUY CAR
        """
        right_y = [42, 40, 41, 43, 52, 55, 59, 60, 55, 47, 39, 32,
                    34, 36, 42, 42, 42, 34, 25]
        left_y = [138, 133, 123, 115, 104, 91, 76, 70, 67, 67, 62,
                    56, 48, 43, 43, 44, 46, 52, 65]
        evidence = list(zip(right_y, left_y))

        prob_ans = 8.3138718215932126e-71

        states, prior, trans, emiss = self.setup(part_2_a)

        seq_ans = ['B1', 'B1', 'B1', 'B1', 'B1', 'B1', 'B2',
                    'B3','B3', 'B3', 'C1', 'C1', 'C1', 'C1',
                    'C1', 'C1', 'C1', 'C1', 'C1']
        seq, prob = multidimensional_viterbi(evidence,
                                            states,
                                            prior,
                                            trans,
                                            emiss)
        self.assertAlmostEqual(prob_ans, prob, places=71)
        self.assertEqual(seq_ans, seq)

        print_success_message("test_viterbi_phrase2")
コード例 #2
0
    def test_viterbi_phrase1(self, part_2_a, multidimensional_viterbi):
        """
        Extracted from BOSTON ASL dataset: video 45, frame 36-56
        Actual words: BUY HOUSE
        """
        right_y = [48, 53, 54, 53, 48, 48, 48, 53, 48, 48, 46, 46,
                    53, 58, 66, 72, 71, 76, 76, 76, 76]
        left_y = [85, 74, 70, 66, 64, 64, 64, 60, 60, 60, 50, 50,
                    57, 67, 74, 85, 84, 89, 93, 93, 94]
        evidence = list(zip(right_y, left_y))

        prob_ans = 3.838599461219723e-75

        states, prior, trans, emiss = self.setup(part_2_a)

        seq_ans = ['B1', 'B2', 'B3', 'B3', 'B3', 'B3', 'B3',
                    'B3', 'H1', 'H1','H1', 'H1', 'H2', 'H3',
                    'H3', 'H3', 'H3', 'H3', 'H3', 'H3', 'H3']
        seq, prob = multidimensional_viterbi(evidence,
                                            states,
                                            prior,
                                            trans,
                                            emiss)
        self.assertAlmostEqual(prob_ans, prob, places=77)
        self.assertEqual(seq_ans, seq)

        print_success_message("test_viterbi_phrase1")
コード例 #3
0
    def test_viterbi_case3(self, part_2_a, multidimensional_viterbi):
        evidence = [(40, 40)]
        prob_ans = 0.000213189518752
        seq_ans = ['C1']

        states, prior, trans, emiss = self.setup(part_2_a)

        seq, prob = multidimensional_viterbi(evidence,
                                            states,
                                            prior,
                                            trans,
                                            emiss)
        self.assertAlmostEqual(prob_ans, prob, places=15)
        self.assertEqual(seq_ans, seq)

        print_success_message("test_viterbi_case3")
コード例 #4
0
    def test_viterbi_case1(self, part_2_a, multidimensional_viterbi):
        evidence = []
        states, prior, trans, emiss = self.setup(part_2_a)
        seq, prob = multidimensional_viterbi(evidence,
                            states,
                            prior,
                            trans,
                            emiss)
        msg = ('when evidence is an empty list, return "None" or [], '
                'get {}').format(seq)
        self.assertTrue(seq in [None, []], msg)
        msg = ('when evidence is an empty list, return prob=0.0, '
                'get {}').format(prob)
        self.assertTrue(prob == 0., msg)

        print_success_message("test_viterbi_case1")
コード例 #5
0
    def test_viterbi_case2(self, part_2_a, multidimensional_viterbi):

        evidence = [(50, 100)]
        prob_ans = 1.18078362571e-05
        seq_ans = ['B1']

        states, prior, trans, emiss = self.setup(part_2_a)

        seq, prob = multidimensional_viterbi(evidence,
                                            states,
                                            prior,
                                            trans,
                                            emiss)
        self.assertAlmostEqual(prob_ans, prob, places=9)
        self.assertEqual(seq_ans, seq)

        print_success_message("test_viterbi_case2")
コード例 #6
0
    def test_viterbi_realsample3(self, part_2_a, multidimensional_viterbi):
        """
        Extracted from BOSTON ASL dataset: video 47, frame 21-30
        Actual words: CAR
        """
        right_y = [47, 39, 32, 34, 36, 42, 42, 42, 34, 25]
        left_y = [67, 62, 56, 48, 43, 43, 44, 46, 52, 65]
        evidence = list(zip(right_y, left_y))

        prob_ans = 1.17739941205e-34
        seq_ans = ['C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1']

        states, prior, trans, emiss = self.setup(part_2_a)

        seq, prob = multidimensional_viterbi(evidence,
                                            states,
                                            prior,
                                            trans,
                                            emiss)
        self.assertAlmostEqual(prob_ans, prob, places=38)
        self.assertEqual(seq_ans, seq)

        print_success_message("test_viterbi_realsample3")
コード例 #7
0
    def test_viterbi_realsample2(self, part_2_a, multidimensional_viterbi):
        """
        Extracted from BOSTON ASL dataset: video 48, frame 27-35
        Actual words: CAR
        """
        right_y = [45, 45, 46, 48, 51, 51, 49, 45, 42]
        left_y = [47, 45, 43, 45, 48, 48, 54, 61, 67]
        evidence = list(zip(right_y, left_y))

        prob_ans = 5.80105906918e-28
        seq_ans = ['H1', 'H1', 'H1', 'H1', 'H1', 'H1', 'H1', 'H1', 'H1']

        states, prior, trans, emiss = self.setup(part_2_a)

        seq, prob = multidimensional_viterbi(evidence,
                                            states,
                                            prior,
                                            trans,
                                            emiss)
        self.assertAlmostEqual(prob_ans, prob, places=32)
        self.assertEqual(seq_ans, seq)

        print_success_message("test_viterbi_realsample2")
コード例 #8
0
    def test_viterbi_realsample1(self, part_2_a, multidimensional_viterbi):
        """
        Extracted from BOSTON ASL dataset: video 51, frame 17-23
        Actual words: BUY
        """
        right_y = [44, 51, 57, 63, 61, 60, 59]
        left_y = [101, 95, 84, 77, 73, 68, 66]
        evidence = list(zip(right_y, left_y))

        prob_ans = 4.1704852628957851e-27
        seq_ans = ['B1', 'B1', 'B2', 'B2', 'B3', 'B3', 'B3']

        states, prior, trans, emiss = self.setup(part_2_a)

        seq, prob = multidimensional_viterbi(evidence,
                                            states,
                                            prior,
                                            trans,
                                            emiss)
        self.assertAlmostEqual(prob_ans, prob, places=32)
        self.assertEqual(seq_ans, seq)

        print_success_message("test_viterbi_realsample1")