def test07_topk_pool(self): set_log_level(2) data_opt = self.get_ml100k_mm_opt() opt = BPRMFOption().get_default_option() opt.d = 20 opt.num_workers = 1 model = BPRMF(opt, data_opt=data_opt) model.initialize() model.train() par = ParBPRMF(model) pool = np.array([i for i in range(5)], dtype=np.int32) model.build_userid_map() all_keys = model._idmanager.userids[::][:10] naive = model.topk_recommendation(all_keys, topk=10, pool=pool) qkeys1, topks1, scores1 = par.topk_recommendation(all_keys, topk=10, pool=pool, repr=True) for q, t in zip(qkeys1, topks1): self.assertEqual(naive[q], t)
def test03_most_similar(self): set_log_level(1) data_opt = self.get_ml100k_mm_opt() opt = BPRMFOption().get_default_option() opt.d = 20 opt.num_workers = 1 bpr = BPRMF(opt, data_opt=data_opt) bpr.initialize() bpr.train() bpr.build_itemid_map() parbpr = ParBPRMF(bpr) all_keys = bpr._idmanager.itemids[::] start_t = time.time() [bpr.most_similar(k, topk=10) for k in all_keys] naive_elapsed = time.time() - start_t parbpr.num_workers = 4 start_t = time.time() parbpr.most_similar(all_keys, topk=10, repr=True) parbpr_elapsed = time.time() - start_t self.assertTrue(naive_elapsed > parbpr_elapsed * 3.0)