def learn_concept(self, word, percept_data): """ learn a concept (word + percept) """ # if word is already know, update perceptual data if self.lex.check_word(word): cs_tag = self.cs_lex.get_h_tag(word) self.cs.get_concept(cs_tag).add_data(percept_data) # if word is not known, create new concept else: self.lex.add_word(word) # create word in lexicon self.lex_lex.create_node(word) # create lex node in lex_lex self.lex_lex.add_link(word, word) # add link between lex and lex node cs_list = [] # create list of percept tags for i in percept_data: cs_tag = "no_tag" while ((cs_tag == "no_tag") or (cs_tag in self.cs.concept_tags)): # make sure the cs_tag is unique cs_tag = auks.generateRandomTag(6) cs_list.append(cs_tag) self.cs.create_pconcept(cs_tag, [i]) # create pconcept in CS self.cs_cs.create_node(cs_tag) # create cs node in cs_cs self.cs_cs.add_link(cs_tag, cs_tag) # add link between cs and cs node self.cs_lex.add_link(cs_tag, word) # add link between lex and cs matrix self.n_percepts = len(self.cs.concepts) # update numbers self.n_words = len(self.lex.words) if len(cs_list) > 1 and cfg.associative_object_learning: while len(cs_list) > 1: self.cs_cs.add_link(cs_list[0], cs_list[1]) self.cs_cs.add_link(cs_list[1], cs_list[0]) cs_list = cs_list[1:]
def discrimination_game(agent, 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. context = sets of data [ [[ "domain", [ [d1, value], [d2, value], ..., [dn, value] ]], ..., ]] [ [["c", [ ["r",1.0], ["g",0.0], ["b",0.0]]]]] """ # if agent knowledge is empty, create new percept and concept if agent.cs.concepts == []: cs_tag = auks.generateRandomTag(6) agent.cs.create_pconcept(cs_tag, context[topic_index]) agent.cs_cs.create_node(cs_tag) # create cs node in cs_cs matrix agent.cs_cs.add_link(cs_tag, cs_tag) # add link between cs and cs nod answer = cs_tag else: best_matching_percepts = [] for i in context: best_matching_percepts.append(agent.cs.get_closest_concept_tag(i)) # determine the outcome of the discrimination game if best_matching_percepts.count(best_matching_percepts[topic_index]) == 1: success = True agent.n_success_dg += 1.0 answer = best_matching_percepts[topic_index] agent.cs.set_concept_disc_use(best_matching_percepts[topic_index], 1) else: agent.cs.set_concept_disc_use(best_matching_percepts[topic_index], 0) # if agent discrimination success is below threshold a new percept is created if agent.discrimination_success < cfg.adapt_threshold: cs_tag = auks.generateRandomTag(6) agent.cs.create_pconcept(cs_tag, context[topic_index]) agent.cs_cs.create_node(cs_tag) # create cs node in cs_cs matrix agent.cs_cs.add_link(cs_tag, cs_tag) # add link between cs and cs nod answer = cs_tag # else, the best matching percept is shifted towards the topic else: cs_tag = best_matching_percepts[topic_index] agent.cs.get_concept(cs_tag).add_data(context[topic_index]) #agent.cs.get_concept(cs_tag).move_to(context[topic_index]) answer = cs_tag agent.n_discrimination_games += 1 agent.discrimination_success = agent.n_success_dg/agent.n_discrimination_games return answer
def load_initial_knowledge(self, dat): """ load of initial knowledge """ for i in dat: cs_tag = auks.generateRandomTag(6) self.cs.create_pconcept(cs_tag, i[1]) # create pconcept in CS self.cs_cs.create_node(cs_tag) # create cs node in cs_cs self.cs_cs.add_link(cs_tag, cs_tag) # add link between cs and cs node self.lex.add_word(i[0]) # create word in lexicon self.lex_lex.create_node(i[0]) # create lex node in lex_lex self.lex_lex.add_link(i[0], i[0]) # add link between lex and lex node self.cs_lex.add_link(cs_tag, i[0]) # add link between lex and cs matrix