class Sep_test(object): def __init__(self,feature_size): ''' self.total_runs: the total times of making prediction self.total_reward: the total reward of prediction B, miu, f are median parameters ''' self.linucb = LinUCB(feature_size) self.lts = LTS(feature_size) self.stat = Statistic(feature_size) self.his_linucb = [] self.his_lts = [] self.his_stat = [] self.valid_linucb = 0 self.valid_lts = 0 self.valid_stat = 0 def LinUCB_predict_and_learn(self,context,articleID,reward,pool): prediction = self.linucb.predict(context,pool) #update records if prediction==articleID: self.his_linucb.append(reward) self.valid_linucb += 1 #train one of the agents self.linucb.learn(context,articleID,reward) def lts_predict_and_learn(self,context,articleID,reward,pool): prediction = self.lts.predict(context,pool) #update records if prediction==articleID: self.his_lts.append(reward) self.valid_lts += 1 #train one of the agents self.lts.learn(context,articleID,reward) def stat_predict_and_learn(self,context,articleID,reward,pool): prediction = self.stat.predict(context,pool) #update records if prediction==articleID: self.his_stat.append(reward) self.valid_stat += 1 #train one of the agents self.stat.learn(context,articleID,reward) def predict_and_learn(self,context,articleID,reward,pool): self.LinUCB_predict_and_learn(context,articleID,reward,pool) self.lts_predict_and_learn(context,articleID,reward,pool) self.stat_predict_and_learn(context,articleID,reward,pool)
class Sep_test(object): def __init__(self, feature_size): ''' self.total_runs: the total times of making prediction self.total_reward: the total reward of prediction B, miu, f are median parameters ''' self.linucb = LinUCB(feature_size) self.lts = LTS(feature_size) self.stat = Statistic(feature_size) self.his_linucb = [] self.his_lts = [] self.his_stat = [] self.his_hybrid = [] self.valid_linucb = 0 self.valid_lts = 0 self.valid_stat = 0 self.valid_hybrid = 0 self.vote = [] def LinUCB_predict_and_learn(self, context, articleID, reward, pool): prediction = self.linucb.predict(context, pool) self.vote.append(prediction) #update records if prediction == articleID: self.his_linucb.append(reward) self.valid_linucb += 1 #train one of the agents self.linucb.learn(context, articleID, reward) def lts_predict_and_learn(self, context, articleID, reward, pool): prediction = self.lts.predict(context, pool) self.vote.append(prediction) #update records if prediction == articleID: self.his_lts.append(reward) self.valid_lts += 1 #train one of the agents self.lts.learn(context, articleID, reward) def stat_predict_and_learn(self, context, articleID, reward, pool): prediction = self.stat.predict(context, pool) self.vote.append(prediction) #update records if prediction == articleID: self.his_stat.append(reward) self.valid_stat += 1 #train one of the agents self.stat.learn(context, articleID, reward) def predict_and_learn(self, context, articleID, reward, pool): self.LinUCB_predict_and_learn(context, articleID, reward, pool) self.lts_predict_and_learn(context, articleID, reward, pool) self.stat_predict_and_learn(context, articleID, reward, pool) def Hybrid_predict_and_learn(self, context, articleID, reward, pool): self.predict_and_learn(context, articleID, reward, pool) counts = np.bincount(self.vote) prediction = choice(np.flatnonzero(counts == counts.max())) #update records if prediction == articleID: self.his_hybrid.append(reward) self.valid_hybrid += 1 self.vote = []