def load(self, output_dir): if not exists(output_dir): return self.c_s = np.load(join(output_dir, C_S_TABLE_FILE_NAME) + BIN_EXT)['a'] if \ exists(join(output_dir, C_S_TABLE_FILE_NAME) + BIN_EXT) else \ read_table_csv(join(output_dir, C_S_TABLE_FILE_NAME) + TEXT_EXT, dtype=np.uint32, has_header=True) self.c_sa = np.load(join(output_dir, C_SA_TABLE_FILE_NAME) + BIN_EXT)['a'] if \ exists(join(output_dir, C_SA_TABLE_FILE_NAME) + BIN_EXT) else \ read_table_csv(join(output_dir, C_SA_TABLE_FILE_NAME) + TEXT_EXT, dtype=np.uint32, has_header=True) if exists(join(output_dir, C_SAS_TABLE_FILE_NAME) + BIN_EXT): self.c_sas = np.load( join(output_dir, C_SAS_TABLE_FILE_NAME) + BIN_EXT)['a'] else: read_3d_table_csv(self.c_sas, join(output_dir, C_SAS_TABLE_FILE_NAME) + TEXT_EXT, dtype=np.uint32, has_header=True) self.r_sa = np.load(join(output_dir, R_SA_TABLE_FILE_NAME) + BIN_EXT)['a'] if \ exists(join(output_dir, R_SA_TABLE_FILE_NAME) + BIN_EXT) else \ read_table_csv(join(output_dir, R_SA_TABLE_FILE_NAME) + TEXT_EXT, dtype=np.float, has_header=True) self.t_s = np.load(join(output_dir, T_S_TABLE_FILE_NAME) + BIN_EXT)['a'] if \ exists(join(output_dir, T_S_TABLE_FILE_NAME) + BIN_EXT) else \ read_table_csv(join(output_dir, T_S_TABLE_FILE_NAME) + TEXT_EXT, dtype=np.int32, has_header=True) self.t_sa = np.load(join(output_dir, T_SA_TABLE_FILE_NAME) + BIN_EXT)['a'] if \ exists(join(output_dir, T_SA_TABLE_FILE_NAME) + BIN_EXT) else \ read_table_csv(join(output_dir, T_SA_TABLE_FILE_NAME) + TEXT_EXT, dtype=np.int32, has_header=True) self.t = np.max(self.t_s)
def load(self, output_dir): if not exists(output_dir): return super().load(output_dir) self.q = np.load(join(output_dir, Q_TABLE_FILE_NAME) + BIN_EXT)['a'] if \ exists(join(output_dir, Q_TABLE_FILE_NAME) + BIN_EXT) else \ read_table_csv(join(output_dir, Q_TABLE_FILE_NAME), has_header=True) self.dq = np.load(join(output_dir, DQ_TABLE_FILE_NAME) + BIN_EXT)['a'] if \ exists(join(output_dir, DQ_TABLE_FILE_NAME) + BIN_EXT) else \ read_table_csv(join(output_dir, DQ_TABLE_FILE_NAME), has_header=True)
def load(self, name, file_path, stat_t=StatType.mean, binary=False, delimiter=','): """ Loads the data regarding a variable previously-saved by a stats collector from a file. Adds the variable sample data per trial to the collection of variables in this collector. :param str name: the name of the variable that we want to load. :param str file_path: the path to the file. :param int stat_t: the type of statistic of the variable to be loaded. :param bool binary: whether to load a binary file. If False, a CSV text file will be loaded. :param str delimiter: the delimiter for the fields in the CSV file, if binary is False. :rtype: bool :return: whether the data was successfully loaded. """ # tries to load files in different formats data = None if binary: if exists('{}.npz'.format(file_path)): data = np.load('{}.npz'.format(file_path))['a'] elif exists('{}.npy'.format(file_path)): data = np.load('{}.npy'.format(file_path)) elif exists('{}.csv'.format(file_path)): data = read_table_csv('{}.csv'.format(file_path), delimiter, has_header=True).T if data is None: return False # sets variable data if loaded correctly self._vars[name] = data self._counts[name] = np.count_nonzero(~np.isnan(data), axis=1) self._stat_types[name] = stat_t return True
raise ValueError('Full analysis not found: {}'.format(file_name)) full_analysis.set_helper(helper) # creates and load the agent's tables agent, exploration_strategy = create_agent(helper, DEF_AGENT_TYPE, None) agent.load(agent_dir) # loads the agent's behavior behavior_tracker = BehaviorTracker(0) behavior_tracker.load(agent_dir) # tries to load recorded episodes from results dir rec_episodes_file = join(agent_dir, 'rec_episodes.csv') if not exists(rec_episodes_file): raise ValueError('Recorded episodes file not found: {}'.format(rec_episodes_file)) recorded_episodes = read_table_csv(rec_episodes_file, dtype=int) # creates output dir if needed output_dir = sys.argv[5] if len(sys.argv) > 5 else get_explanation_output_dir(agent_dir, explanation_t) if not exists(output_dir): makedirs(output_dir) elif CLEAN_DIR: rmtree(output_dir) makedirs(output_dir) # saves / copies configs to file config.save_json(join(output_dir, 'config.json')) # register environment in Gym according to env config helper.register_gym_environment(False, 0, False)