def get_new_topic_list(topic_list, board_url): sorted_topic_list = sorted(topic_list, key=itemgetter('post_id')) new_topic_list = [] for topic_index in range(0, len(sorted_topic_list)): topic_id = sorted_topic_list[topic_index]['post_id'] if topic_id > settings.CONFIG['latest_topic_id'][board_url]: new_topic_list.append(sorted_topic_list[topic_index]) settings.CONFIG['latest_topic_id'][board_url] = topic_id save_config(config=settings.CONFIG) return new_topic_list
def main(_): utility.set_up_logging() if not FLAGS.config: raise KeyError('You must specify a configuration.') if FLAGS.load_from: logdir = FLAGS.logdir = FLAGS.load_from else: if FLAGS.logdir and os.path.exists(FLAGS.logdir): run_number = [ int(f.split("-")[0]) for f in os.listdir(FLAGS.logdir) if os.path.isdir(os.path.join(FLAGS.logdir, f)) and FLAGS.config in f ] run_number = max(run_number) + 1 if len(run_number) > 0 else 0 else: run_number = 0 logdir = FLAGS.logdir and os.path.expanduser( os.path.join(FLAGS.logdir, '{}-{}'.format(run_number, FLAGS.config))) try: config = utility.load_config(logdir) except IOError: config = tools.AttrDict(getattr(configs, FLAGS.config)()) config = utility.save_config(config, logdir) train(config, logdir)
def __init__(self, max_iters, eval_n_episodes, eval_every_n_iters, population_size, target_reward, n_repeats, solver, logdir, config, stubs, warm_start_from=None): """Initialization.""" utility.save_config(logdir, config) self.logger = utility.create_logger(logdir) self.logdir = logdir self.env = utility.load_env() self.workers = stubs self.num_workers = len(self.workers) self.max_iters = max_iters self.population_size = population_size self.eval_n_episodes = eval_n_episodes self.eval_every_n_iters = eval_every_n_iters self.target_reward = target_reward self.n_repeats = n_repeats self.policy = utility.create_policy(self.env) if warm_start_from is not None: try: self.policy.load_model(warm_start_from) self.logger.info( 'Model loaded, continue training from {}.'.format( warm_start_from)) except IOError as e: self.logger.error('Failed to load model from {}: {}'.format( warm_start_from, e)) self.w_policy = self.policy.get_params() self.solver = solver(policy=self.policy, population_size=self.population_size) self.best_score = -float('Inf') self.logger.info("Initialization of ESLearner complete")
def main(_): """Create or load configuration and launch the trainer.""" utility.set_up_logging() if not FLAGS.config: raise KeyError('You must specify a configuration.') logdir = FLAGS.logdir and os.path.expanduser( os.path.join(FLAGS.logdir, '{}-{}'.format(FLAGS.timestamp, FLAGS.config))) try: config = utility.load_config(logdir) except IOError: config = tools.AttrDict(getattr(configs, FLAGS.config)()) config = utility.save_config(config, logdir) for score in train(config, FLAGS.env_processes): tf.logging.info('Score {}.'.format(score))
def __init__(self, env_callback, policy_params=None, num_workers=32, num_deltas=320, deltas_used=320, delta_std=0.02, logdir=None, rollout_length=1000, step_size=0.01, shift='constant zero', params=None, seed=123): logz.configure_output_dir(logdir) # params_to_save = copy.deepcopy(params) # params_to_save['env'] = None # logz.save_params(params_to_save) utility.save_config(params, logdir) env = env_callback() self.timesteps = 0 self.action_size = env.action_space.shape[0] self.ob_size = env.observation_space.shape[0] self.num_deltas = num_deltas self.deltas_used = deltas_used self.rollout_length = rollout_length self.step_size = step_size self.delta_std = delta_std self.logdir = logdir self.shift = shift self.params = params self.max_past_avg_reward = float('-inf') self.num_episodes_used = float('inf') # create shared table for storing noise print('Creating deltas table.') deltas = shared_noise.create_shared_noise() self.deltas = shared_noise.SharedNoiseTable(deltas, seed=seed + 3) print('Created deltas table.') # initialize workers with different random seeds print('Initializing workers.') self.num_workers = num_workers self.workers = [ Worker(seed + 7 * i, env_callback=env_callback, policy_params=policy_params, deltas=deltas, rollout_length=rollout_length, delta_std=delta_std) for i in range(num_workers) ] # initialize policy if policy_params['type'] == 'linear': self.policy = policies.LinearPolicy(policy_params) self.w_policy = self.policy.get_weights() else: raise NotImplementedError # initialize optimization algorithm self.optimizer = optimizers.SGD(self.w_policy, self.step_size) print('Initialization of ARS complete.')