def end_epoch(self, nnet, loss): self.epoch_duration = time.time() - self.epoch_start_time self.epoch_total_count += 1 self.epoch_count += 1 self.epochs_duration += self.epoch_duration self.total_duration += self.epoch_duration if self.epoch_count == 1: self.first_loss = loss # Save of the run_manager and the nnet. if self.epoch_count % self.c.epochs_save_interval == 0 and self.epoch_count > 0: jsonManager.save(self, self.c.run_manager_file_name) torch.save(nnet.state_dict(), self.number_file_name(self.c.nnet_file_name)) str_epochs_duration = str( datetime.timedelta(seconds=round(self.epochs_duration))) str_epoch_duration = str( datetime.timedelta(seconds=round(self.epoch_duration))) if self.epoch_count % self.c.epochs_per_iter == 0: print( "_" * 100 + "\n\n" + self.str_general_progression() + f"\n\nepoch: {self.epoch_count} / {self.c.epochs_per_iter} | " f"duration: {str_epochs_duration} | " f"last epoch duration: {str_epoch_duration}" f"\n\nfirst loss: {round(self.first_loss, 3)} | " f"loss: {round(loss, 3)}")
def end_iter(self, nnet): # Reset self.game_count = 0 self.games_duration = 0 self.total_v_max = 0 self.total_proba_max = 0 self.total_noise_max = 0 self.total_v_illegal_max = 0 self.total_v_dictate = 0 self.total_proba_dictate = 0 self.move_count = 0 self.draw_count = 0 self.epoch_count = 0 self.epochs_duration = 0 self.iter_count += 1 # Save of the run_manager and the nnet. jsonManager.save(self, self.c.run_manager_file_name) torch.save(nnet.state_dict(), self.number_file_name(self.c.nnet_file_name)) print("_" * 100 + "\n\n" + self.str_general_progression())
def end_game(self, buffer, num_moves, num_dist_games): self.game_tick_duration = time.time() - self.game_tick_start_time self.game_total_count += 1 self.game_count += 1 self.games_duration += self.game_tick_duration self.total_duration += self.game_tick_duration # Save of the run_manager and the buffer. if self.game_count % self.c.games_save_interval == 0 and self.game_count > 0: jsonManager.save(self, self.c.run_manager_file_name) buffer.save() str_games_duration = str( datetime.timedelta(seconds=round(self.games_duration))) str_tick_duration = str( datetime.timedelta(seconds=round(self.game_tick_duration))) identic_games_perc = round(100 * (1 - num_dist_games / self.game_count)) move_count = max(self.move_count, 1) v_max_mean = round(self.total_v_max / move_count, 2) proba_max_mean = round(self.total_proba_max / move_count, 2) noise_max_mean = round(self.total_noise_max / move_count, 2) p_max_mean = round( (self.total_proba_max - self.total_noise_max) / move_count, 2) v_illegal_max_mean = round(self.total_v_illegal_max / move_count, 3) v_dictate_perc = round(100 * self.total_v_dictate / move_count) proba_dictate_perc = round(100 * self.total_proba_dictate / move_count) print( "_" * 100 + "\n\n" + self.str_general_progression() + f"\n\ngame: {self.game_count} / {self.c.games_per_iter} | " f"moves: {num_moves} | " f"duration: {str_games_duration} | " f"tick duration: {str_tick_duration}" f"\n\nidentical games: {identic_games_perc} % | " f"v illegal max mean: {v_illegal_max_mean} | " f"v dictates: {v_dictate_perc} % | " f"proba dictates: {proba_dictate_perc} %" f"\nv max mean: {v_max_mean} | " f"proba max mean: {proba_max_mean} = {p_max_mean} + {noise_max_mean}" )
def end_game(self, buffer, num_moves): self.game_tick_duration = time.time() - self.game_tick_start_time self.game_total_count += 1 self.game_count += 1 self.games_duration += self.game_tick_duration self.total_duration += self.game_tick_duration # Save of the run_manager and the buffer. if self.game_count % self.c.games_save_interval == 0 and self.game_count > 0: jsonManager.save(self, self.c.run_manager_file_name) jsonManager.save(buffer, self.c.buffer_file_name) str_games_duration = str( datetime.timedelta(seconds=round(self.games_duration))) str_tick_duration = str( datetime.timedelta(seconds=round(self.game_tick_duration))) proba_max_mean = round(self.total_proba_max / self.move_count, 2) noise_max_mean = round(self.total_noise_max / self.move_count, 2) P_max_mean2 = round( (self.total_proba_max - self.total_noise_max) / self.move_count, 2) proba_dictate_perc = round(100 * self.total_proba_dictate / self.move_count) if self.game_count % self.c.games_per_iter == 0: print( "_" * 100 + "\n\n" + self.str_general_progression() + f"\n\ngame: {self.game_count} / {self.c.games_per_iter} | " f"moves: {num_moves} | " f"duration: {str_games_duration} | " f"tick duration: {str_tick_duration}" f"\n\nproba dictates: {proba_dictate_perc} % | " f"proba max mean: {proba_max_mean} = {P_max_mean2} + {noise_max_mean}" )
def save(self): jsonManager.save(self.buffer, self.c.buffer_file_name) with open(self.c.histories_file_name, 'wb') as f: np.save(f, self.histories) with open(self.c.state_checkpoints_file_name, 'wb') as f: np.save(f, self.ls_checks)
def end_games(self, buffer): # Save of the run_manager and the buffer. jsonManager.save(self, self.c.run_manager_file_name) jsonManager.save(buffer, self.c.buffer_file_name)