def add_new_article(self, line): article_id = int(line.split(" ")[0]) if article_id in self.bad_articles: return -1 if article_id not in self.articles: try: article = to_vector(line) except IndexError: print("Skipping line, weird formatting.." + str(article_id)) self.bad_articles.add(article_id) return -1 self.k_articles[article_id] = dict() for a in self.articles.keys(): value = self.exponential_kernel(article, self.articles[a]) self.k_articles[a][article_id] = value self.k_articles[article_id][a] = value self.articles[article_id] = article self.k_articles[article_id][article_id] = 1 return article_id
def add_new_article(self, line): article_id = int(line.split(" ")[0]) if article_id in self.bad_articles: return -1 if article_id not in self.articles: try: article = to_vector(line) except IndexError: print("Skipping line, weird formatting.." + str(article_id)) self.bad_articles.add(article_id) return -1 self.articles[article_id] = article.reshape([1, 6]) return article_id
def add_new_article(self, line): article_id = int(line.split(" ")[0]) if article_id in self.bad_articles: return -1 if article_id not in self.article_ids: try: article = to_vector(line) except IndexError: self.bad_articles.add(article_id) return -1 self.article_ids[article_id] = len(self.article_ids) self.articles_1_d = np.append(self.articles_1_d, article).reshape( [len(self.article_ids), self.d]) return article_id
def warmup(self, file): self.warmup_impressions = 0 for line in file: if self.warmup_impressions > self.training_size: break self.warmup_impressions += 1 line = line.split("|") no_space_line = line[0].split(" ") pre_selected_article = int(no_space_line[1]) click = int(no_space_line[2]) user = to_vector(line[1]) for article_line in line[2:]: self.add_new_article(article_line) # If preselected article is the one with bad format skip if pre_selected_article in self.bad_articles: continue self.update(user, pre_selected_article, click)
def add_new_article(self, line): article_id = int(line.split(" ")[0]) if article_id in self.bad_articles: return -1 if article_id not in self.A: try: article = to_vector(line) except IndexError: print("Skipping line, weird formatting.." + str(article_id)) self.bad_articles.add(article_id) return -1 self.articles[article_id] = article self.A[article_id] = np.identity(self.d) self.A_i[article_id] = np.identity(self.d) self.B[article_id] = np.zeros(self.d * self.k).reshape( [self.d, self.k]) self.b[article_id] = np.zeros(self.d) return article_id
for rep in range(0, repetitions): fo = open("..//..//R6//ydata-fp-td-clicks-v1_0.20090501", "r") algo.warmup(fo) print("Starting repetition {0}".format(rep)) total_impressions = 0.0 click_count = 0.0 impression_count = 0.0 local_clicks = 0.0 for line in fo: total_impressions += 1 line = line.split("|") no_space_line = line[0].split(" ") pre_selected_article = int(no_space_line[1]) click = int(no_space_line[2]) user = to_vector(line[1]) selected_article, warmup = algo.select(user, pre_selected_article, line[2:], total_impressions, click) # print(selected_article) if selected_article == pre_selected_article and not warmup: # print('.', end='', flush=True) algo.update(user, pre_selected_article, click) click_count += click impression_count += 1 batch_size = 1000.0