def answer_gg(self, label, context): """ Guessing game answer. Agent uses the incoming label and the associated concept to identify the topic from the context, the presumed topic index is communicated to the other agent. """ tag = self.get_tag(label) if tag == "no_tag": return tag else: context_distances = [] for i in context: distance = self.cp.calculate_distance(i, self.cp.get_concept_coordinates(tag)) context_distances.append(distance) return [aux.posMin(context_distances), tag]
def discrimination_game(self, context, topic_index): """ Discrimination game in which an agent has to distinguish the topic from the context. The game succeeds if the agent has a concept which uniquely matches the topic and no other stimuli from the context. If this is not the case, a new concept is build, or the existing concepts are shifted. The return is either the concept tag, or a string description of the action taken by the agent context = sets of data [ [ [d1, value], [d2, value], ..., [dn, value] ], ....] """ context_new = copy.deepcopy(context) # make a copy # get the coordinates of the current known concepts known_concept_coors = self.cp.get_all_concept_coordinates() if len(known_concept_coors) == 0: label = aux.generateRandomLabel(5) self.add_concept(context[topic_index], label) answer = "concept_added" else: # select the best matching concept for every stimulus from the context (including the topic) best_matching_concepts = [] for i in context: distances = [] for j in known_concept_coors: distances.append(self.cp.calculate_distance(i, j)) best_matching_concept = self.cp.get_concepts_tags()[aux.posMin(distances)] best_matching_concepts.append(best_matching_concept) if best_matching_concepts.count(best_matching_concepts[topic_index]) == 1: self.n_succes_games += 1.0 answer = best_matching_concepts[topic_index] else: # if agent discrimination success is below threshold a new concept is created if self.discrimination_succes < cfg.adapt_threshold: label = aux.generateRandomLabel(5) self.add_concept(context[topic_index], label) answer = "concept_added" # if agent discrimination success is above threshold, # topic is added as exemplar for the best matching concept, # i.e. the best matching concept is shifted towards the topic else: self.lex.get_label(best_matching_concepts[topic_index]) self.add_exemplar(context[topic_index], label) answer = "concept_shifted" # calculate statistics self.n_discrimination_games += 1.0 self.discrimination_succes = self.n_succes_games/self.n_discrimination_games return answer