def update_output(self, t, out_ind): # Figure out what the motor output is and write it to file if out_ind >= 0 and out_ind < len(self.num_out_list): out_str = self.num_out_list[out_ind] else: out_str = self.null_output logger.write(out_str) logger.flush() if self.in_learning_phase(t): # Denote learning phase reward logger.write('|') logger.flush() # In learning phase. Evaluate output and choose reward if out_ind >= 0 and out_ind < (len(self.num_out_list) - 1): t_ind = min(self.get_t_ind(t), len(self.task_phase_seq_list) - 1) rewards = self.task_phase_seq_list[t_ind][1] if out_ind >= 0 and out_ind < self.num_learn_actions: reward_chance = rewards[out_ind] else: reward_chance = 0 rewarded = str(int(np.random.random() < reward_chance)) self.stim_seq_list[self.get_t_ind(t) + 1] = \ self.num_map[rewarded] elif (self.get_t_ind(t) + 1) < len(self.stim_seq_list): self.stim_seq_list[self.get_t_ind(t) + 1] = self.num_map['0'] else: pass
def update_output(self, t, out_ind): # Figure out what the motor output is and write it to file if out_ind >= 0 and out_ind < len(self.num_out_list): out_str = self.num_out_list[out_ind] else: out_str = self.null_output logger.write(out_str) logger.flush() if self.in_learning_phase(t): # Denote learning phase reward logger.write('|') logger.flush() # In learning phase. Evaluate output and choose reward if out_ind >= 0 and out_ind < (len(self.num_out_list) - 1): t_ind = min(self.get_t_ind(t), len(self.task_phase_seq_list) - 1) rewards = self.task_phase_seq_list[t_ind][1] if out_ind >= 0 and out_ind < self.num_learn_actions: reward_chance = rewards[out_ind] else: reward_chance = 0 rewarded = str(int(np.random.random() < reward_chance)) self.stim_seq_list[self.get_t_ind(t) + 1] = \ self.num_map[rewarded] elif (self.get_t_ind(t) + 1) < len(self.stim_seq_list): self.stim_seq_list[self.get_t_ind(t) + 1] = self.num_map['0'] else: pass
def write_header(self): # Write spaun configurator options logger.write('# Spaun Configuration Options:\n') logger.write('# ----------------------------\n') for param_name in sorted(self.__dict__.keys()): param_value = getattr(self, param_name) if not callable(param_value): logger.write('# - %s = %s\n' % (param_name, param_value)) logger.write('#\n')
def write_header(self): # Write spaun configurator options logger.write('# Spaun Configuration Options:\n') logger.write('# ----------------------------\n') for param_name in sorted(self.__dict__.keys()): param_value = getattr(self, param_name) if not callable(param_value): logger.write('# - %s = %s\n' % (param_name, param_value)) logger.write('#\n')
def write_header(self): logger.write('# Spaun Vocabulary Options:\n') logger.write('# -------------------------\n') for param_name in sorted(self.__dict__.keys()): param_value = getattr(self, param_name) if not callable(param_value) and not isinstance(param_value, list)\ and not isinstance(param_value, Vocabulary) \ and not isinstance(param_value, SemanticPointer) \ and not isinstance(param_value, np.ndarray): logger.write('# - %s = %s\n' % (param_name, param_value)) logger.write('\n')
def get_stimulus(self, t): t_ind = self.get_t_ind(t) t_ind_float = self.get_t_ind_float(t) if t <= 0: return None if t_ind != self.prev_t_ind: # Write the stimulus to file if t_ind < len(self.stim_seq_list): stim_char = self.stim_seq_list[t_ind] if (stim_char == '.'): # logger.write('_') logger.write('') # Ignore the . blank character elif stim_char == 'A' and self.prev_t_ind >= 0: logger.write('\nA') elif isinstance(stim_char, int): logger.write('<%s>' % stim_char) elif stim_char in self.num_rev_map: logger.write('%s' % self.num_rev_map[stim_char]) elif stim_char in self.sym_rev_map: logger.write('%s' % self.sym_rev_map[stim_char]) elif stim_char is not None: logger.write('%s' % str(stim_char)) # Done all the stuff needed for new t_ind. Store new t_ind self.prev_t_ind = t_ind if (self.present_blanks and t_ind != int(round(t_ind_float))) or \ t_ind >= len(self.stim_seq_list) or \ self.stim_seq_list[t_ind] == '.': return None else: return self.stim_seq_list[t_ind]
def write_header(self): logger.write('# Spaun Experiment Options:\n') logger.write('# -------------------------\n') for param_name in sorted(self.__dict__.keys()): param_value = getattr(self, param_name) if not callable(param_value): if (isinstance(param_value, list) and len(param_value) > 20) \ or (isinstance(param_value, np.ndarray) and param_value.shape[0] > 20): param_value = str(param_value[:20])[:-1] + '...' logger.write('# - %s = %s\n' % (param_name, param_value)) logger.write('# ------\n') logger.write('# Simulation time: %0.2fs' % self.get_est_simtime()) logger.write('#\n')
def write_header(self): logger.write('# Spaun Experiment Options:\n') logger.write('# -------------------------\n') for param_name in sorted(self.__dict__.keys()): param_value = getattr(self, param_name) if not callable(param_value): if (isinstance(param_value, list) and len(param_value) > 20) \ or (isinstance(param_value, np.ndarray) and param_value.shape[0] > 20): param_value = str(param_value[:20])[:-1] + '...' logger.write('# - %s = %s\n' % (param_name, param_value)) logger.write('# ------\n') logger.write('# Simulation time: %0.2fs' % self.get_est_simtime()) logger.write('#\n')
def get_stimulus(self, t): t_ind = self.get_t_ind(t) t_ind_float = self.get_t_ind_float(t) if t <= 0: return None if t_ind != self.prev_t_ind: # Write the stimulus to file if t_ind < len(self.stim_seq_list): stim_char = self.stim_seq_list[t_ind] if (stim_char == '.'): # logger.write('_') logger.write('') # Ignore the . blank character elif stim_char == 'A' and self.prev_t_ind >= 0: logger.write('\nA') elif isinstance(stim_char, int): logger.write('<%s>' % stim_char) elif stim_char in self.num_rev_map: logger.write('%s' % self.num_rev_map[stim_char]) elif stim_char in self.sym_rev_map: logger.write('%s' % self.sym_rev_map[stim_char]) elif stim_char is not None: logger.write('%s' % str(stim_char)) # Done all the stuff needed for new t_ind. Store new t_ind self.prev_t_ind = t_ind if (self.present_blanks and t_ind != int(round(t_ind_float))) or \ t_ind >= len(self.stim_seq_list) or \ self.stim_seq_list[t_ind] == '.': return None else: return self.stim_seq_list[t_ind]