def test_prob_item_given_tag(self):
        self.__init_test(test.SMALL_DEL_FILE)
        
        lambda_ = 0.3
        smooth_func = 'Bayes'
        p = SmoothEstimator(smooth_func, lambda_, self.annots, 1)
        
        for tag in [0, 1, 2, 3, 4, 5]:
            pis = []
            pits = []
            
            for item in [0, 1, 2, 3, 4]:
                pi = p.prob_item(item)
                pti = p.prob_tag_given_item(item, tag)
                
                pis.append(pi)
                pits.append(pti * pi)
                
            #Assert
            pis = np.array(pis)
            pis /= pis.sum()
            
            pits = np.array(pits)
            pits /= pits.sum()
            
            gamma_items = np.array([0, 1, 2, 3, 4])
            assert_array_almost_equal(pis, p.prob_items(gamma_items))
            assert_array_almost_equal(pits, p.prob_items_given_tag(tag, 
                                                                gamma_items))

            self.assertAlmostEqual(1, sum(p.prob_items(gamma_items)))
            self.assertAlmostEqual(1, 
                    sum(p.prob_items_given_tag(tag, gamma_items)))             
    def test_prob_item_given_tag(self):
        self.__init_test(test.SMALL_DEL_FILE)

        lambda_ = 0.3
        smooth_func = 'Bayes'
        p = SmoothEstimator(smooth_func, lambda_, self.annots, 1)

        for tag in [0, 1, 2, 3, 4, 5]:
            pis = []
            pits = []

            for item in [0, 1, 2, 3, 4]:
                pi = p.prob_item(item)
                pti = p.prob_tag_given_item(item, tag)

                pis.append(pi)
                pits.append(pti * pi)

            #Assert
            pis = np.array(pis)
            pis /= pis.sum()

            pits = np.array(pits)
            pits /= pits.sum()

            gamma_items = np.array([0, 1, 2, 3, 4])
            assert_array_almost_equal(pis, p.prob_items(gamma_items))
            assert_array_almost_equal(pits,
                                      p.prob_items_given_tag(tag, gamma_items))

            self.assertAlmostEqual(1, sum(p.prob_items(gamma_items)))
            self.assertAlmostEqual(
                1, sum(p.prob_items_given_tag(tag, gamma_items)))
 def test_gamma_items_prob_items(self):
     self.__init_test(test.SMALL_DEL_FILE)
     
     lambda_ = 0.3
     smooth_func = 'Bayes'
     p = SmoothEstimator(smooth_func, lambda_, self.annots, 1)
     
     gamma_items = np.array([1, 2])
     
     pi_1 = p.prob_item(1)
     pi_2 = p.prob_item(2)
     
     gamma_pi = p.prob_items(gamma_items)
     
     self.assertEqual(gamma_pi[0], pi_1 / (pi_1 + pi_2))
     self.assertEqual(gamma_pi[1], pi_2 / (pi_1 + pi_2))
    def test_gamma_items_prob_items(self):
        self.__init_test(test.SMALL_DEL_FILE)

        lambda_ = 0.3
        smooth_func = 'Bayes'
        p = SmoothEstimator(smooth_func, lambda_, self.annots, 1)

        gamma_items = np.array([1, 2])

        pi_1 = p.prob_item(1)
        pi_2 = p.prob_item(2)

        gamma_pi = p.prob_items(gamma_items)

        self.assertEqual(gamma_pi[0], pi_1 / (pi_1 + pi_2))
        self.assertEqual(gamma_pi[1], pi_2 / (pi_1 + pi_2))