def setup_dqn(self): print_ts("Setup DQN of Move2BeaconAgent") self.DQN = DQN_module(self.batch_size, self.gamma, self.history_length, self.size_replaybuffer, self.optim_learning_rate, self.dim_actions) self.device = self.DQN.device print_ts("DQN module has been initalized")
def setup_dqn(self): # TODO(vloet): what to do with history length? unecessary imho. self.history_length = 1 self.DQN = DQN_module(self.batch_size, self.gamma, self.history_length, self.size_replaybuffer, self.optim_learning_rate, self.dim_actions) self.device = self.DQN.device print_ts("DQN module has been initalized")
def update_target_network(self): """ Transferring the estimator weights to the target weights and resetting the agent. """ if self.episodes % self.target_update_period == 0: print_ts("About to update") self.DQN.update_target_net()
def _setup_torch(self): """ Setting GPU if available. Else, use the CPU. """ # Initalizing device = torch.device("cuda:1" if torch.cuda.is_available() else "cpu") torch.set_printoptions(linewidth=750, profile="full") print_ts("Performing calculations on {}".format(device)) return device
def setup_dqn(self): self.dim_actions = 2 self.smart_actions = SMART_ACTIONS print_ts("Setup DQN of CartPoleAgent") self.DQN = DQN_module(self.batch_size, self.gamma, self.history_length, self.size_replaybuffer, self.optim_learning_rate, self.dim_actions) self.device = self.DQN.device print_ts("DQN module has been initalized")
def save_model(self, exp_path, emergency=False): if emergency: print("KeyboardInterrupt detected, saving last model!") save_path = exp_path + "/model/emergency_model.pt" else: save_path = exp_path + "/model/model.pt" # Path((self.exp_path + "/model")).mkdir(parents=True, exist_ok=True) self.DQN.save(save_path) print_ts("Model has been saved at {}".format(save_path))
def setup_agent(agent_specs): """ Initializing right agent and agent_interface for the environment. """ agent_type = agent_specs["AGENT_TYPE"] if agent_type == 'pendulum': return PendulumAgent(agent_specs) else: print_ts("The agent type {} is not known".format(agent_type)) exit()
def change_cwd(self, change_path): """ Change cwd if directory exists. """ if not path.exists(change_path): print_ts("Directory is unknown") return self.cwd = change_path self.current_test_dir = change_path + "/test_reports" self.current_train_dir = change_path + "/training_reports" print_ts("Changed cwd to {}".format(self.cwd))
def setup_dqn(self): """ Setting up the DQN module with the grid action space. """ self._xy_pairs, self.dim_actions, self.smart_actions = \ self.discretize_xy_grid() self.DQN = DQN_module(self.batch_size, self.gamma, self.history_length, self.size_replaybuffer, self.optim_learning_rate, self.dim_actions) self.device = self.DQN.device print_ts("DQN module has been initalized")
def setup_agent(agent_specs): """ Initializing right agent and agent_interface for the environment. """ agent_type = agent_specs["AGENT_TYPE"] if agent_type == 'defeatroaches': return DefeatRoachesAgent(agent_specs) if agent_type == 'move2beacon': return Move2BeaconAgent(agent_specs) else: print_ts("The agent type {} is not known".format(agent_type)) exit()
def create_experiment(self, exp_name): """ Creates the folder structure which is necessary to save files. """ # Create free path free_exp_path, _ = self.find_free_path(self.exp_dir, exp_name) # print(free_exp_path, exp_name) # Create the experiment folders creation_success = self.create_folders(free_exp_path) if creation_success: print_ts("Created experiment at path {}".format(free_exp_path)) self.change_cwd(free_exp_path) else: pass
def setup_dqn(self): """ Setting up the DQN module with the compass action space. """ self.smart_actions = SMART_ACTIONS self.dim_actions = len(self.smart_actions) self.DQN = DQN_module(self.batch_size, self.gamma, self.history_length, self.size_replaybuffer, self.optim_learning_rate, self.dim_actions) self.device = self.DQN.device print_ts("DQN module has been initalized")
def setup_agent(agent_specs): """ Initializing right agent and agent_interface for the environment. """ agent_type = agent_specs["AGENT_TYPE"] if agent_type == 'compass': return CompassAgent(agent_specs) if agent_type == 'grid': return GridAgent(agent_specs) if agent_type == 'original': raise("This agent type has not been implemeted yet.") exit() else: print_ts("The agent type {} is not known".format(agent_type)) exit()
def print_cwd(self): """ """ print_ts(self.cwd)
def print_architecture(self): print_ts("Network: \n{}".format(self.net)) print_ts("Optimizer: \n{}".format(self.optimizer)) print_ts("Target Network: \n{}".format(self.target_net))