class Experiment03(object): """ Experiment03 class """ def __init__(self, config_): """ Constructor :param config_: :return: """ self.config = config_ self.data_exporter = DataExporter(self.config) self.logger = logging.getLogger("cuda_logger") self.expt_name = "expt_03" self.config['RL_parameters']['experiment'] = self.expt_name @staticmethod def run_rl_training(config): rl_trainer = RunRLTrainingJob(config) data = rl_trainer.run() return data def run(self): """ Run experiment """ num_drivers = np.arange(1000, 6500, 500) objectives = ['pickups', 'revenue'] combinations = list(itertools.product(num_drivers, objectives)) # Create a pool of processes num_processes = mp.cpu_count() pool = ProcessPool(nodes=num_processes) configs = [] count = 0 for comb in combinations: self.config['RL_parameters'][ 'experiment'] = self.expt_name + "_" + str(count) self.config['RL_parameters'][ 'city_states_filename'] = "city_states.dill" self.config['RL_parameters']['num_drivers'] = comb[0] self.config['RL_parameters']['num_strategic_drivers'] = comb[0] self.config['RL_parameters']['objective'] = comb[1] configs.append(deepcopy(self.config)) count += 1 self.logger.info("Starting expt_03") results = pool.amap(self.run_rl_training, configs).get() pool.close() pool.join() pool.clear() self.logger.info("Finished expt_03") # Export best episode self.data_exporter.export_episode(results, self.expt_name + ".dill")
class RunRLTrainingJob(object): """ This class implements a job to run the RL training """ def __init__(self, config_): """ Constructor :param config_: :return: """ self.config = config_ self.logger = logging.getLogger("cuda_logger") self.data_exporter = DataExporter(self.config) def run(self): """ This method executes the job :param: :return: """ self.logger.info("Starting job: RunRLTrainingJob\n") self.logger.info("RL training parameters:") pp = pprint.PrettyPrinter(indent=4) self.logger.info(pp.pprint(self.config['RL_parameters'])) # Create RL trainer rl_trainer = RLTrainer(self.config) # Runs RL episodes result = rl_trainer.run() best_episode = result[0] best_model = result[1] training_tracker = result[2] # Export best_model best_model_filename = self.config['RL_parameters'].get( 'best_model_filename', False) best_episode_filename = self.config['RL_parameters'].get( 'best_episode_filename', False) training_tracker_filename = self.config['RL_parameters'].get( 'training_tracker_filename', False) if best_model_filename: self.data_exporter.export_model(best_model, best_model_filename) if best_episode_filename: self.data_exporter.export_episode(best_episode, best_episode_filename) if training_tracker_filename: self.data_exporter.export_training_tracker( training_tracker, training_tracker_filename) self.logger.info("Finished job: RunRLTrainingJob") return best_episode
class Experiment05(object): """ Experiment05 class """ def __init__(self, config_): """ Constructor :param config_: :return: """ self.config = config_ self.data_exporter = DataExporter(self.config) self.logger = logging.getLogger("cuda_logger") self.expt_name = "expt_05" self.config['RL_parameters']['experiment'] = self.expt_name @staticmethod def run_rl_training(config): rl_trainer = RunRLTrainingJob(config) data = rl_trainer.run() return data def run(self): """ Run experiment """ num_drivers = self.config['RL_parameters']['num_drivers'] percent_strategic_drivers = np.arange(0, 1.1, 0.1) num_strategic_drivers = [int(x * num_drivers) for x in percent_strategic_drivers] # Create a pool of processes num_processes = mp.cpu_count() pool = ProcessPool(nodes=num_processes) configs = [] count = 0 for drivers in num_strategic_drivers: self.config['RL_parameters']['experiment'] = self.expt_name + "_" + str(count) self.config['RL_parameters']['num_strategic_drivers'] = drivers configs.append(deepcopy(self.config)) count += 1 self.logger.info("Starting expt_05") results = pool.amap(self.run_rl_training, configs).get() pool.close() pool.join() pool.clear() self.logger.info("Finished expt_05") # Export best episode self.data_exporter.export_episode(results, self.expt_name + ".dill")
class Experiment01(object): """ Experiment01 class """ def __init__(self, config_): """ Constructor :param config_: :return: """ self.config = config_ self.data_exporter = DataExporter(self.config) self.logger = logging.getLogger("cuda_logger") self.expt_name = "expt_01" self.config['RL_parameters']['experiment'] = self.expt_name @staticmethod def run_rl_training(config): rl_trainer = RunRLTrainingJob(config) data = rl_trainer.run() return data def run(self): """ Run experiment """ ind_percent = np.arange(0., 1.1, 0.1) reb_percent = np.arange(0., 1.1, 0.1) ind_percent[0] = 0.01 reb_percent[0] = 0.01 combinations = list(itertools.product(ind_percent, reb_percent)) num_episodes = self.config['RL_parameters']['num_episodes'] # Create a pool of processes num_processes = mp.cpu_count() pool = ProcessPool(nodes=num_processes) configs = [] count = 0 for comb in combinations: self.config['RL_parameters']['experiment'] = self.expt_name + "_" + str(count) ind_episodes = int(comb[0] * num_episodes) reb_episodes = int(comb[1] * num_episodes) if (ind_episodes + reb_episodes) < num_episodes: self.config['RL_parameters']['ind_episodes'] = ind_episodes self.config['RL_parameters']['reb_episodes'] = reb_episodes configs.append(deepcopy(self.config)) count += 1 self.logger.info("Starting expt_01") results = pool.amap(self.run_rl_training, configs).get() pool.close() pool.join() pool.clear() self.logger.info("Finished expt_01") # Export best episode self.data_exporter.export_episode(results, self.expt_name + ".dill")
class Experiment06(object): """ Experiment06 class """ def __init__(self, config_): """ Constructor :param config_: :return: """ self.config = config_ self.data_exporter = DataExporter(self.config) self.logger = logging.getLogger("cuda_logger") self.expt_name = "expt_06" self.config['RL_parameters']['experiment'] = self.expt_name @staticmethod def run_rl_training(config): rl_trainer = RunRLTrainingJob(config) data = rl_trainer.run() return data def run(self): """ Run experiment """ days = [ 'Sunday_00_', 'Monday_00_', 'Tuesday_00_', 'Wednesday_00_', 'Thursday_00_', 'Friday_00_', 'Saturday_00_', 'Sunday_01_', 'Monday_01_', 'Tuesday_01_', 'Wednesday_01_', 'Thursday_01_', 'Friday_01_', 'Saturday_01_', 'Sunday_02_', 'Monday_02_', 'Tuesday_02_', 'Wednesday_02_', 'Thursday_02_', 'Friday_02_', 'Saturday_02_', 'Sunday_03_', 'Monday_03_', 'Tuesday_03_', 'Wednesday_03_', 'Thursday_03_', 'Friday_03_', 'Saturday_03_' ] # Create a pool of processes num_processes = mp.cpu_count() pool = ProcessPool(nodes=num_processes) configs = [] count = 0 for day in days: self.config['RL_parameters'][ 'experiment'] = self.expt_name + "_" + str(count) self.config['RL_parameters'][ 'city_states_filename'] = day + 'city_states.dill' self.config['RL_parameters'][ 'best_model_filename'] = day + 'model.dill' configs.append(deepcopy(self.config)) count += 1 self.logger.info("Starting expt_06") results = pool.amap(self.run_rl_training, configs).get() pool.close() pool.join() pool.clear() self.logger.info("Finished expt_06") # Export best episode self.data_exporter.export_episode(results, self.expt_name + ".dill")
class Experiment08(object): """ Experiment08 class """ def __init__(self, config_): """ Constructor :param config_: :return: """ self.config = config_ self.data_exporter = DataExporter(self.config) self.logger = logging.getLogger("cuda_logger") self.expt_name = "expt_08" self.config['Model_testing']['experiment'] = self.expt_name @staticmethod def run_rl_testing(config): rl_tester = RunRLTestingJob(config) data = rl_tester.run() return data def run(self): """ Run experiment """ days = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ] weeks_of_month = ['00', '01', '02', '03', '04'] imbalance_thresholds = [2] model_num_drivers = [4000, 5000, 6000, 7000, 8000, 9000, 10000] test_combinations = [] for model_day in days: for model_wom in weeks_of_month: for model_threshold in imbalance_thresholds: for model_drivers in model_num_drivers: model_args = [ model_day, model_wom, str(model_drivers), str(model_threshold) ] model_filename = "_".join(model_args) + "_model.dill" if os.path.isfile(self.config['app']['DATA_DIR'] + 'models/' + model_filename): for test_wom in weeks_of_month: for test_drivers in range( model_drivers - 3000, model_drivers + 4000, 1000): test_file = model_day + '_' + test_wom + '_city_states.dill' if os.path.isfile( self.config['app']['DATA_DIR'] + 'city_states/' + test_file): test_combinations.append({ 'model': model_filename, 'test_dow': model_day, 'test_wom': test_wom, 'test_drivers': test_drivers }) self.logger.info("Total test combinations: {}".format( len(test_combinations))) # Create a pool of processes num_processes = mp.cpu_count() pool = ProcessPool(nodes=num_processes) configs = [] count = 0 for comb in test_combinations: self.config['Model_testing'][ 'experiment'] = self.expt_name + "_" + str(count) self.config['Model_testing']['city_states_filename'] = ( comb['test_dow'] + '_' + comb['test_wom'] + '_city_states.dill') self.config['Model_testing']['model_filename'] = comb['model'] self.config['RL_parameters']['num_drivers'] = comb['test_drivers'] self.config['RL_parameters']['num_strategic_drivers'] = comb[ 'test_drivers'] configs.append(deepcopy(self.config)) count += 1 self.logger.info("Starting expt_08") results = pool.amap(self.run_rl_testing, configs).get() pool.close() pool.join() pool.clear() self.logger.info("Finished expt_08") # Export best episode self.data_exporter.export_episode(results, self.expt_name + ".dill")
class Experiment04(object): """ Experiment04 class """ def __init__(self, config_): """ Constructor :param config_: :return: """ self.config = config_ self.data_exporter = DataExporter(self.config) self.logger = logging.getLogger("cuda_logger") self.expt_name = "expt_04" self.config['RL_parameters']['experiment'] = self.expt_name @staticmethod def run_rl_training(config): rl_trainer = RunRLTrainingJob(config) try: data = rl_trainer.run() except BaseException: print config raise ValueError return data def run(self): """ Run experiment """ num_drivers = np.arange(1000, 6500, 500) thresholds = np.arange(5, 55, 5) thresholds = np.insert(thresholds, 0, 2) combinations = list(itertools.product(num_drivers, thresholds)) # Create a pool of processes num_processes = mp.cpu_count() self.logger.info("Processes: {}".format(num_processes)) pool = ProcessPool(nodes=num_processes) configs = [] count = 0 for comb in combinations: self.config['RL_parameters'][ 'experiment'] = self.expt_name + "_" + str(count) self.config['RL_parameters']['num_drivers'] = comb[0] self.config['RL_parameters']['imbalance_threshold'] = comb[1] configs.append(deepcopy(self.config)) count += 1 self.logger.info("Starting expt_04") results = pool.amap(self.run_rl_training, configs).get() pool.close() pool.join() pool.clear() self.logger.info("Finished expt_04") # Export best episode self.data_exporter.export_episode(results, self.expt_name + ".dill")