def test_partial_arguments(self, items=1, users=5): if items is None: items = 1 if users is None: users = np.random.randint(1, 100) # init with partially given arguments s = BassModel(num_users=users) test_utils.assert_correct_num_users(users, s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(users, s, s.user_profiles.shape[1]) test_utils.assert_correct_num_items(s.num_items, s, s.item_attributes.shape[1]) test_utils.assert_not_none(s.predicted_scores) s = BassModel(num_items=items) test_utils.assert_correct_num_users(s.num_users, s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(s.num_users, s, s.user_profiles.shape[1]) test_utils.assert_correct_num_items(items, s, s.item_attributes.shape[1]) test_utils.assert_not_none(s.predicted_scores) # did not set seed, show random behavior s1 = BassModel(num_users=users) with pytest.raises(AssertionError): test_utils.assert_equal_arrays(s.user_profiles, s1.user_profiles) s1 = BassModel(num_items=items) with pytest.raises(AssertionError): test_utils.assert_equal_arrays(s.user_profiles, s1.user_profiles)
def test_default(self): c = PopularityRecommender() test_utils.assert_correct_num_users(c.num_users, c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(c.num_items, c, c.item_attributes.shape[1]) test_utils.assert_not_none(c.predicted_scores)
def test_arguments(self, items=None, attr=None, users=None): if items is None: items = np.random.randint(1, 1000) if users is None: users = np.random.randint(1, 100) if attr is None: attr = np.random.randint(1, 100) # init with given arguments c = ContentFiltering(num_users=users, num_items=items, num_attributes=attr) test_utils.assert_correct_num_users(users, c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(items, c, c.item_attributes.shape[1]) test_utils.assert_correct_size_generic(attr, c.num_attributes, c.item_attributes.shape[0]) test_utils.assert_correct_size_generic(attr, c.num_attributes, c.user_profiles.shape[1]) test_utils.assert_not_none(c.predicted_scores) # did not set seed, show random behavior c1 = ContentFiltering(num_users=users, num_items=items, num_attributes=attr) with pytest.raises(AssertionError): test_utils.assert_equal_arrays(c.item_attributes, c1.item_attributes)
def test_arguments(self, items=None, users=None): if items is None: items = np.random.randint(1, 1000) if users is None: users = np.random.randint(1, 100) # init with given arguments c = PopularityRecommender(num_users=users, num_items=items) test_utils.assert_correct_num_users(users, c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(items, c, c.item_attributes.shape[1]) test_utils.assert_not_none(c.predicted_scores)
def test_additional_params(self, num_items_per_iter=None): if num_items_per_iter is None: num_items_per_iter = np.random.randint(5, 100) c = PopularityRecommender(verbose=False, num_items_per_iter=num_items_per_iter) assert (num_items_per_iter == c.num_items_per_iter) # also check other params test_utils.assert_correct_num_users(c.num_users, c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(c.num_items, c, c.item_attributes.shape[1]) test_utils.assert_not_none(c.predicted_scores)
def test_default(self): s = BassModel() test_utils.assert_correct_num_users(s.num_users, s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(s.num_users, s, s.user_profiles.shape[1]) test_utils.assert_correct_num_items(s.num_items, s, s.item_attributes.shape[1]) test_utils.assert_not_none(s.predicted_scores) # did not set seed, show random behavior s1 = BassModel() with pytest.raises(AssertionError): test_utils.assert_equal_arrays(s.user_profiles, s1.user_profiles)
def test_additional_params(self, num_items_per_iter=None): # these are currently meaningless but at least it should not break if num_items_per_iter is None: # TODO vary parameter num_items_per_iter = 1 #np.random.randint(5, 100) s = BassModel(verbose=False, num_items_per_iter=num_items_per_iter) assert (num_items_per_iter == s.num_items_per_iter) # also check other params test_utils.assert_not_none(s.predicted_scores) test_utils.assert_correct_num_users(s.num_users, s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(s.num_users, s, s.user_profiles.shape[1]) test_utils.assert_correct_num_items(s.num_items, s, s.item_attributes.shape[1])
def test_arguments(self, items=10, users=5): if items is None: items = np.random.randint(10, 1000) if users is None: users = np.random.randint(10, 100) s = SocialFiltering(num_users=users, num_items=items) test_utils.assert_correct_num_users(users, s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(users, s, s.user_profiles.shape[1]) test_utils.assert_correct_num_items(items, s, s.item_attributes.shape[1]) test_utils.assert_not_none(s.predicted_scores) # did not set seed, show random behavior s1 = SocialFiltering(num_users=users, num_items=items) with pytest.raises(AssertionError): test_utils.assert_equal_arrays(s.user_profiles, s1.user_profiles)
def test_default(self): c = ContentFiltering() test_utils.assert_correct_num_users(c.num_users, c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(c.num_items, c, c.item_attributes.shape[1]) test_utils.assert_correct_size_generic(c.num_attributes, c.num_attributes, c.user_profiles.shape[1]) test_utils.assert_correct_size_generic(c.num_attributes, c.num_attributes, c.item_attributes.shape[0]) test_utils.assert_not_none(c.predicted_scores) # did not set seed, show random behavior c1 = ContentFiltering() with pytest.raises(AssertionError): test_utils.assert_equal_arrays(c.item_attributes, c1.item_attributes)
def test_additional_params(self, num_items_per_iter=None): if num_items_per_iter is None: num_items_per_iter = np.random.randint(5, 100) s = SocialFiltering(verbose=False, num_items_per_iter=num_items_per_iter) assert (num_items_per_iter == s.num_items_per_iter) # also check other params test_utils.assert_correct_num_users(s.num_users, s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(s.num_users, s, s.user_profiles.shape[1]) test_utils.assert_correct_num_items(s.num_items, s, s.item_attributes.shape[1]) test_utils.assert_not_none(s.predicted_scores) # did not set seed, show random behavior s1 = SocialFiltering(verbose=False, num_items_per_iter=num_items_per_iter) with pytest.raises(AssertionError): test_utils.assert_equal_arrays(s.user_profiles, s1.user_profiles)
def test_representations(self, item_repr=None, user_repr=None): if item_repr is None: items = np.random.randint(5, 1000) item_repr = np.random.random(size=(1, items)) if user_repr is None or user_repr.shape[1] != item_repr.shape[0]: users = np.random.randint(5, 100) user_repr = np.random.randint(10, size=(users, 1)) c = PopularityRecommender(item_representation=item_repr) test_utils.assert_correct_num_users(c.num_users, c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(item_repr.shape[1], c, c.item_attributes.shape[1]) test_utils.assert_equal_arrays(item_repr, c.item_attributes) test_utils.assert_not_none(c.predicted_scores) c = PopularityRecommender(user_representation=user_repr) test_utils.assert_correct_num_users(user_repr.shape[0], c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(c.num_items, c, c.item_attributes.shape[1]) test_utils.assert_equal_arrays(user_repr, c.user_profiles) test_utils.assert_not_none(c.predicted_scores) c = PopularityRecommender(user_representation=user_repr, item_representation=item_repr) test_utils.assert_correct_num_users(user_repr.shape[0], c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(item_repr.shape[1], c, c.item_attributes.shape[1]) test_utils.assert_equal_arrays(user_repr, c.user_profiles) test_utils.assert_equal_arrays(item_repr, c.item_attributes) test_utils.assert_not_none(c.predicted_scores)
def test_representations(self, item_repr=None, user_repr=None): if item_repr is None: items = np.random.randint(20, 1000) users = (user_repr.shape[0] if user_repr is not None else np.random.randint(20, 100)) item_repr = np.random.random(size=(users, items)) if user_repr is None or user_repr.shape[0] != user_repr.shape[1]: users = item_repr.shape[0] user_repr = np.random.randint(2, size=(users, users)) # test item representation s = SocialFiltering(item_representation=item_repr) test_utils.assert_correct_num_users(s.num_users, s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(s.num_users, s, s.user_profiles.shape[1]) test_utils.assert_correct_num_items(item_repr.shape[1], s, s.item_attributes.shape[1]) test_utils.assert_equal_arrays(item_repr, s.item_attributes) test_utils.assert_not_none(s.predicted_scores) # did not set seed, show random behavior s1 = SocialFiltering(item_representation=item_repr) with pytest.raises(AssertionError): test_utils.assert_equal_arrays(s.user_profiles, s1.user_profiles) # test user representation s = SocialFiltering(user_representation=user_repr) test_utils.assert_correct_num_users(user_repr.shape[0], s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(user_repr.shape[0], s, s.user_profiles.shape[1]) test_utils.assert_correct_num_users(user_repr.shape[1], s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(user_repr.shape[1], s, s.user_profiles.shape[1]) test_utils.assert_correct_num_items(s.num_items, s, s.item_attributes.shape[1]) test_utils.assert_equal_arrays(user_repr, s.user_profiles) test_utils.assert_not_none(s.predicted_scores) # test item and user representations s = SocialFiltering(user_representation=user_repr, item_representation=item_repr) test_utils.assert_correct_num_users(user_repr.shape[0], s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(user_repr.shape[0], s, s.user_profiles.shape[1]) test_utils.assert_correct_num_users(user_repr.shape[1], s, s.user_profiles.shape[0]) test_utils.assert_correct_num_users(user_repr.shape[1], s, s.user_profiles.shape[1]) test_utils.assert_correct_num_items(item_repr.shape[1], s, s.item_attributes.shape[1]) test_utils.assert_equal_arrays(user_repr, s.user_profiles) test_utils.assert_equal_arrays(item_repr, s.item_attributes) test_utils.assert_not_none(s.predicted_scores)
def test_representations(self, item_repr=None, user_repr=None, bad_user_repr=None): if item_repr is None: items = np.random.randint(5, 1000) attr = np.random.randint(5, 100) item_repr = np.random.random(size=(attr, items)) if user_repr is None or user_repr.shape[1] != item_repr.shape[0]: users = np.random.randint(5, 100) user_repr = np.random.randint(10, size=(users, item_repr.shape[0])) c = ContentFiltering(item_representation=item_repr) test_utils.assert_correct_num_users(c.num_users, c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(item_repr.shape[1], c, c.item_attributes.shape[1]) test_utils.assert_correct_size_generic(item_repr.shape[0], c.num_attributes, c.item_attributes.shape[0]) test_utils.assert_correct_size_generic(item_repr.shape[0], c.num_attributes, c.user_profiles.shape[1]) test_utils.assert_equal_arrays(item_repr, c.item_attributes) test_utils.assert_not_none(c.predicted_scores) c = ContentFiltering(user_representation=user_repr) test_utils.assert_correct_num_users(user_repr.shape[0], c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(c.num_items, c, c.item_attributes.shape[1]) test_utils.assert_correct_size_generic(user_repr.shape[1], c.num_attributes, c.item_attributes.shape[0]) test_utils.assert_correct_size_generic(user_repr.shape[1], c.num_attributes, c.user_profiles.shape[1]) test_utils.assert_equal_arrays(user_repr, c.user_profiles) test_utils.assert_not_none(c.predicted_scores) # did not set seed, show random behavior c1 = ContentFiltering(user_representation=user_repr) #with pytest.raises(AssertionError): # test_utils.assert_equal_arrays(c.user_profiles, c1.user_profiles) with pytest.raises(AssertionError): # FIXME this fails from time to time because # it might happen that these two are in fact equal test_utils.assert_equal_arrays(c.item_attributes, c1.item_attributes) #with pytest.raises(AssertionError): # test_utils.assert_equal_arrays(c.num_attributes, c1.num_attributes) c = ContentFiltering(user_representation=user_repr, item_representation=item_repr) test_utils.assert_correct_num_users(user_repr.shape[0], c, c.user_profiles.shape[0]) test_utils.assert_correct_num_items(item_repr.shape[1], c, c.item_attributes.shape[1]) test_utils.assert_correct_size_generic(user_repr.shape[1], c.num_attributes, c.item_attributes.shape[0]) test_utils.assert_correct_size_generic(user_repr.shape[1], c.num_attributes, c.user_profiles.shape[1]) test_utils.assert_correct_size_generic(item_repr.shape[0], c.num_attributes, c.item_attributes.shape[0]) test_utils.assert_correct_size_generic(item_repr.shape[0], c.num_attributes, c.user_profiles.shape[1]) test_utils.assert_equal_arrays(user_repr, c.user_profiles) test_utils.assert_equal_arrays(item_repr, c.item_attributes) test_utils.assert_not_none(c.predicted_scores)