示例#1
0
 def ddpg_call_back_emulator(
         self):  #should be called at the end of each episode
     if (msgs.algo == "DDPG"):
         if (msgs.mode == 'train'):
             append_log_file(self.episodeN, "verbose")
             append_log_file(self.episodeN, "")
             if not (msgs.success):
                 return
             weight_file_name = self.check_point.find_file_to_check_point(
                 msgs.cur_zone_number)
             weight_file_name = weight_file_name.replace('_critic', '')
             self.actor.save_weights(weight_file_name + "_actor",
                                     overwrite=True)
             self.critic.save_weights(weight_file_name + "_critic",
                                      overwrite=True)
             with open(weight_file_name + "_meta_data", "w") as file_hndle:
                 json.dump(msgs.meta_data, file_hndle)
         elif (msgs.mode == 'test'):
             append_log_file(self.episodeN, "verbose")
             append_log_file(self.episodeN, "")
             with open(
                     msgs.weight_file_under_test + "_test" +
                     str(msgs.tst_inst_ctr) + "_meta_data",
                     "w") as file_hndle:
                 json.dump(msgs.meta_data, file_hndle)
         else:
             print("this mode " + str(msgs.mode) +
                   "is not defined. only train and test defined")
             exit(0)
     else:
         return
示例#2
0
 def sac_call_back_emulator(self):
     if (msgs.mode == 'train'):
         append_log_file(self.episodeN, "verbose")
         append_log_file(self.episodeN, "")
         if not (msgs.success):
             return
         weight_file_name = self.check_point.find_file_to_check_point(
             msgs.cur_zone_number)
         self.model.save(weight_file_name)
         with open(weight_file_name + "_meta_data", "w") as file_hndle:
             json.dump(msgs.meta_data, file_hndle)
     elif (msgs.mode == 'test'):
         append_log_file(self.episodeN, "verbose")
         append_log_file(self.episodeN, "")
         with open(
                 msgs.weight_file_under_test + "_test" +
                 str(msgs.tst_inst_ctr) + "_meta_data", "w") as file_hndle:
             json.dump(msgs.meta_data, file_hndle)
     else:
         print("this mode " + str(msgs.mode) +
               "is not defined. only train and test defined")
         exit(0)
 def on_episode_end(self, step, logs={}):
     append_log_file(self.episodeN, "verbose")
     append_log_file(self.episodeN, "")
     self.episodeN += 1