def step(self, action, goal): ''' Action to discover a node. If action is -1, we stop discovery and return reward as influence maximization output else reward is 0 ''' if action == -1: self.done = True self.reward_ = parallel_influence(self.graph, full_graph=self.fullGraph, influence=self.influence_algo, times=self.times_mean) if self.normalize: self.reward = self.reward_ / self.opt_reward else: self.reward = self.reward_ - self.opt_reward if self.clip_max is not None or self.clip_min is not None: self.reward = np.clip(self.reward, self.clip_min, self.clip_max) if self.reward_ < int(goal): self.reward = -1 else: self.reward = self.reward_ / int(goal) return self.graph, self.reward, self.done, None, self.reward_ if action in self.possible_actions: self.enlarge_graph(action) self.reward = self.no_reward self.T += 1 # self.reward_ = parallel_influence(self.graph, full_graph=self.fullGraph, # influence=self.influence_algo, times=self.times_mean) if self.T > self.max_T: self.done = True # if self.reward_ < int(goal): # self.reward = -1 # else: # self.reward = self.reward_/int(goal) self.reward_ = -1 return self.graph, self.reward, self.done, None, self.reward_ if action in self.active: self.reward = self.bad_reward0 self.reward = -100 self.T += 1 if self.T > self.max_T: self.done = True self.reward_ = parallel_influence(self.graph, full_graph=self.fullGraph, influence=self.influence_algo, times=self.times_mean) if self.normalize: self.reward = self.reward_ / self.opt_reward else: self.reward = self.reward_ - self.opt_reward if self.clip_max is not None or self.clip_min is not None: self.reward = np.clip(self.reward, self.clip_min, self.clip_max) return self.graph, self.reward, self.done, None, self.reward_ else: raise Exception("Wrong Action:" + str(action) + "\nPossible Actions:" + str(self.possible_actions))
def goal_setting(self, budget): for i in range(budget): query_node = list(self.possible_actions) for j in query_node: self.enlarge_graph(j) self.goal = parallel_influence(self.graph, full_graph=self.fullGraph, influence=self.influence_algo, times=self.times_mean) return self.goal
def goal_setting3(self, budget, num_query, times): self.goal = 0 for i in range(times): for i in range(budget): query_node = list(self.possible_actions) query_node = random.sample(query_node, num_query) for j in query_node: self.enlarge_graph(j) tmp_goal = parallel_influence(self.graph, full_graph=self.fullGraph, influence=self.influence_algo, times=self.times_mean) if tmp_goal > self.goal: self.goal = tmp_goal return self.goal
def num_infl(self): self.num_infl = parallel_influence(self.graph, full_graph=self.fullGraph, influence=self.influence_algo, times=self.times_mean) return self.num_infl