def test_prob_user_given_item(self):
     self.__init_test(test.SMALL_DEL_FILE)
     smooth_func = 'JM'
     lamb = 0.5
     p = SmoothEstimator(smooth_func, lamb, self.annots, 1)
     
     prob = p.prob_user_given_item(0, 0)
     self.assertTrue(prob > 0)
    def test_prob_user_given_item(self):
        self.__init_test(test.SMALL_DEL_FILE)
        smooth_func = 'JM'
        lamb = 0.5
        p = SmoothEstimator(smooth_func, lamb, self.annots, 1)

        prob = p.prob_user_given_item(0, 0)
        self.assertTrue(prob > 0)
 def test_prob_user_given_item_profsize(self):
     self.__init_test(test.SMALL_DEL_FILE)
     smooth_func = 'JM'
     lamb = 0.5
     p = SmoothEstimator(smooth_func, lamb, self.annots, 
             user_profile_fract_size = 0)
     
     prob = p.prob_user_given_item(0, 0)
     self.assertEquals(prob, 0.0)
    def test_prob_user_given_item_profsize(self):
        self.__init_test(test.SMALL_DEL_FILE)
        smooth_func = 'JM'
        lamb = 0.5
        p = SmoothEstimator(smooth_func,
                            lamb,
                            self.annots,
                            user_profile_fract_size=0)

        prob = p.prob_user_given_item(0, 0)
        self.assertEquals(prob, 0.0)
    def test_prob_items_given_user_and_tag(self):
        self.__init_test(test.SMALL_DEL_FILE)
        
        lambda_ = 0.3
        smooth_func = 'Bayes'
        p = SmoothEstimator(smooth_func, lambda_, self.annots, 1)
        
        for user in [0, 1, 2]:
            for tag in [0, 1, 2, 3, 4, 5]:
                pitus = []
                pius = []
                for item in [0, 1, 2, 3, 4]:
                    pi = p.prob_item(item)
                    pti = p.prob_tag_given_item(item, tag)
                    pui = p.prob_user_given_item(item, user)
                    
                    piu = pui * pi
                    pitu = pti * pui * pi
                    
                    pitus.append(pitu)
                    pius.append(piu)
                
                sum_pitus = sum(pitus)
                sum_pius = sum(pius)
                for item in [0, 1, 2, 3, 4]:
                    pitus[item] = pitus[item] / sum_pitus
                    pius[item] = pius[item] / sum_pius
                    
                #Assert
                gamma_items = np.array([0, 1, 2, 3, 4])
                assert_array_almost_equal(pius, 
                        p.prob_items_given_user(user, gamma_items))
                assert_array_almost_equal(pitus, 
                        p.prob_items_given_user_tag(user, tag, gamma_items))
                
                self.assertAlmostEqual(1, sum(p.prob_items_given_user(user, 
                                                            gamma_items)))

                self.assertAlmostEqual(1, 
                        sum(p.prob_items_given_user_tag(user, tag, 
                                                            gamma_items)))             
    def test_prob_items_given_user_and_tag(self):
        self.__init_test(test.SMALL_DEL_FILE)

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

        for user in [0, 1, 2]:
            for tag in [0, 1, 2, 3, 4, 5]:
                pitus = []
                pius = []
                for item in [0, 1, 2, 3, 4]:
                    pi = p.prob_item(item)
                    pti = p.prob_tag_given_item(item, tag)
                    pui = p.prob_user_given_item(item, user)

                    piu = pui * pi
                    pitu = pti * pui * pi

                    pitus.append(pitu)
                    pius.append(piu)

                sum_pitus = sum(pitus)
                sum_pius = sum(pius)
                for item in [0, 1, 2, 3, 4]:
                    pitus[item] = pitus[item] / sum_pitus
                    pius[item] = pius[item] / sum_pius

                #Assert
                gamma_items = np.array([0, 1, 2, 3, 4])
                assert_array_almost_equal(
                    pius, p.prob_items_given_user(user, gamma_items))
                assert_array_almost_equal(
                    pitus, p.prob_items_given_user_tag(user, tag, gamma_items))

                self.assertAlmostEqual(
                    1, sum(p.prob_items_given_user(user, gamma_items)))

                self.assertAlmostEqual(
                    1, sum(p.prob_items_given_user_tag(user, tag,
                                                       gamma_items)))