Esempio n. 1
0
 def get_sequence(self, goal, env):
     goal_indices = get_goal_indices(goal)
     symbols = [None] * len(goal_indices)
     positions = []
     for index in goal_indices:
         pos_found = False
         search_index = 0
         column = self.language_matrix[:, index, :]
         sorted_column = column.flatten().argsort()[::-1]
         while not pos_found:
             sym_index, pos = unravel_index(sorted_column[search_index],
                                            column.shape)
             if pos not in positions:
                 positions.append(pos)
                 position = pos if pos < len(goal_indices) else 0
                 symbols[position] = sym_index
                 pos_found = True
             else:
                 contained_sym = symbols[pos]
                 contained_value = column[contained_sym, pos]
                 new_value = column[sym_index, pos]
                 if new_value > contained_value:
                     symbols[pos] = sym_index
                 search_index += 1
     symbs = [env.symbols[symbol] for symbol in symbols]
     return Sequence(symbs)
Esempio n. 2
0
	def negative_align(architecture, status, env):
		symbol_indices = get_symbol_indices(status.sequence, env.symbols)
		goal_indices = get_goal_indices(status.goals_performed[-1])
		index = choice(symbol_indices)
		row = architecture.language_matrix[index, :]
		row[choice(goal_indices)] *= architecture.neg_beta
		row[row < architecture.minimal] = architecture.minimal
		row /= row.sum()
Esempio n. 3
0
	def negative_align(architecture, status, env):
		symbol_indices = get_symbol_indices(status.sequence, env.symbols)
		goal_indices = get_goal_indices(status.goals_performed[-1])
		test = architecture.language_matrix[symbol_indices, goal_indices]
		# for symbol in symbol_indices:
		min_ = test.argmin()
		row = architecture.language_matrix[min_,:]
		row[min_] *= architecture.neg_beta
		row[row < architecture.minimal] = architecture.minimal
		row /= row.sum()
Esempio n. 4
0
 def react_to_success(self, status, env):
     symbol_indices = get_symbol_indices(status.sequence)
     meaning_indices = get_goal_indices(status.goal)
     for position, symbol_index in enumerate(symbol_indices):
         row = self.language_matrix[symbol_index, :, position]
         mask = zeros(row.shape, dtype=bool)
         mask[meaning_indices] = True
         row[~mask] -= 1
         row[mask] += 1
         row[row < 0] = 0
Esempio n. 5
0
 def get_sequence(self, goal, env):
     goal_indices = get_goal_indices(goal)
     symbols = []
     for index in goal_indices:
         column = self.language_matrix[:, index]
         if any(column != column[0]):
             symbol_index = column.argmax()
         else:
             symbol_index = self.choose_new_symbol()
         symbols.append(AgentKnowledge.symbols[symbol_index])
     return Sequence(symbols)
Esempio n. 6
0
 def react_to_success(self, status, env):
     symbol_indices = get_symbol_indices(status.sequence, env.symbols)
     meaning_indices = get_goal_indices(status.goal)
     for position, symbol_index in enumerate(symbol_indices):
         row = self.language_matrix[symbol_index, :, position]
         mask = zeros(row.shape, dtype=bool)
         mask[meaning_indices] = True
         row[~mask] *= self.neg_alpha
         row[mask] *= self.pos_alpha
         row[row < self.threshold] = 0
         self.language_matrix[symbol_index, :, position] = row / row.sum()
Esempio n. 7
0
 def react_to_failure(self, status, env):
     if self.align_strat:
         self.align_strat(self, status, env)
     else:
         symbol_indices = get_symbol_indices(status.sequence, env.symbols)
         goal_indices = get_goal_indices(status.goals_performed[-1])
         for position, symbol in enumerate(symbol_indices):
             # column = self.interaction_memory.columns[position]
             for goal_index in goal_indices:
                 column = self.language_matrix[symbol, goal_index, :]
                 column[position] *= self.neg_beta
                 column /= column.sum()
Esempio n. 8
0
 def react_to_success(self, status, env):
     symbol_indices = get_symbol_indices(status.sequence, env.symbols)
     goal_indices = get_goal_indices(status.goal)
     for position, symbol in enumerate(symbol_indices):
         for goal_index in goal_indices:
             column = self.language_matrix[symbol, goal_index, :]
             mask = ones(column.shape[0], dtype=bool)
             mask[position] = 0
             column[mask] *= self.neg_alpha
             column[position] *= self.pos_alpha
             column[column < self.minimal] = self.minimal
             column[column > self.maximal] = self.maximal
             column /= column.sum()
Esempio n. 9
0
	def negative_align(architecture, status, env):
		symbol_indices = get_symbol_indices(status.sequence, env.symbols)
		# symbol_indices = architecture.interaction_memory.symbols
		goal_indices = get_goal_indices(status.goals_performed[-1])
		mask = ones(architecture.language_matrix.shape[1], dtype=bool)
		mask[symbol_indices] = 0
		for goal in goal_indices:
			colum = architecture.language_matrix[:, goal]
			colum[~mask] *= architecture.neg_beta
		for symbol in symbol_indices:
			row = architecture.language_matrix[symbol, :]
			# row[~mask] *= architecture.neg_beta
			row[row < architecture.minimal] = architecture.minimal
			row /= row.sum()
Esempio n. 10
0
 def react_to_success(self, status, env):
     symbol_indices = get_symbol_indices(status.sequence, env.symbols)
     goal_indices = get_goal_indices(status.goal)
     mask = ones(self.language_matrix.shape[1], dtype=bool)
     mask[symbol_indices] = 0
     for goal in goal_indices:
         colum = self.language_matrix[:, goal]
         colum[mask] *= self.neg_alpha
         colum[~mask] *= self.pos_alpha
     for symbol in symbol_indices:
         row = self.language_matrix[symbol, :]
         row[row < self.minimal] = self.minimal
         row[row > self.maximal] = self.maximal
         row /= row.sum()
Esempio n. 11
0
 def get_sequence(self, goal):
     goal_indices = get_goal_indices(goal)
     shuffle(
         goal_indices
     )  # this is to make sure that the order is not determined by categories
     symbols = [0] * len(goal_indices)
     indices_without_meaning = []
     for index in goal_indices:
         column = self.language_matrix[:, index]
         symbol_indices = list(nonzero(column)[0])
         if symbol_indices:
             symbol_was_positioned = False
             while symbol_indices:
                 chosen = choice(
                     symbol_indices
                 )  # if there is some symbol associated to this meaning we choose one (if there is only one symbol then it will always be chosen)
                 symbol_indices.remove(chosen)
                 position = column[
                     chosen]  # the matrix stores the position of this symbol (starting with 1, so we don't confuse it with no value)
                 if symbols[position - 1] == 0:
                     symbols[position -
                             1] = (AgentKnowledge.symbols[chosen],
                                   meanings[index])
                     symbol_was_positioned = True
                     break
             if not symbol_was_positioned:
                 indices_without_meaning.append(
                     (AgentKnowledge.symbols[chosen], index))
         else:
             indices_without_meaning.append(
                 (choice(AgentKnowledge.symbols), index))
     non_occupied_indices = [
         idx for idx in range(len(symbols)) if symbols[idx] == 0
     ]
     assert len(non_occupied_indices) == len(
         indices_without_meaning), "THIS SHOULD NOT HAPPEN"
     for i, index in enumerate(non_occupied_indices):
         symbols[index] = (indices_without_meaning[i][0],
                           meanings[indices_without_meaning[i][1]])
     return symbols