Exemplo n.º 1
0
 def final(self, state):
     "Called at the end of each game."
     # call the super-class final method
     ReinforcementAgent.final(self, state)
     #gc.collect() #por si escaso
     #del gc.garbage[:] # por si escaso
     #print "memory length: ", len(self.memory)
     self.new_episode = True
     if self.training and state.getScore() > self.best_score:
         self.model.save_weights("models/best_model.h5")
         self.double_model.save_weights("models/best_double_model.h5")
         self.best_score = state.getScore()
         print "updated best models for best score: ", self.best_score
     if self.episodesSoFar % 1000 == 0 and self.training:
         #print "starting memory dump"
         # with open('models/memory.dictionary', 'wb') as memory_deque_file:
         #     pickle.dump(self.memory, memory_deque_file)
         # print "finished memory dump"
         self.model.save_weights("models/" + str(self.episodesSoFar) +
                                 "model.h5")
         self.double_model.save_weights("models/" +
                                        str(self.episodesSoFar) +
                                        "double_model.h5")
     # did we finish training?
     if self.episodesSoFar == self.numTraining:
         # you might want to print your weights here for debugging
         "*** YOUR CODE HERE ***"
         self.training = False
         pass
Exemplo n.º 2
0
 def final(self, state):
     ReinforcementAgent.final(self, state)
     print("episode so far: %d" % (self.episodesSoFar))
     self.new_episode = True
     if self.training and state.getScore() > self.best_score:
         self.best_score = state.getScore()
         print("updated best first_models for best score: ",
               self.best_score)
     if self.episodesSoFar == self.numTraining:
         self.training = False
         pass
Exemplo n.º 3
0
    def final(self, state):
        "Called at the end of each game."
        # call the super-class final method
        ReinforcementAgent.final(self, state)

        if self.episodesSoFar <= self.numTraining:
            self.saveQTableToFile('qvalues.pkl')
        # did we finish training?
        if self.episodesSoFar == self.numTraining:
            # you might want to print your weights here for debugging
            "*** YOUR CODE HERE ***"
            pass
Exemplo n.º 4
0
    def final(self, state):
        # print("Score: {}".format(state.getScore()))
        ReinforcementAgent.final(self, state)
        # if self.episodesSoFar == self.numTraining:
        self.outfile.write("{}\n".format(state.getScore()))

        if self.episodesSoFar == self.numTesting:
            msg = "Training Done (turning off epsilon and alpha). Beginning Testing..."
            print("%s\n%s" % (msg, "-" * len(msg)))
            self.epsilon = 0.0  # no exploration
            self.alpha = 0.0  # no learning
            self.outfile.write("\n")

        if self.episodesSoFar == self.numTraining:
            msg = "Testing Done."
            print("%s\n%s" % (msg, "-" * len(msg)))
    def final(self, state):
        """
        Shows episode statistics and call superclass final
        :param state:
        :return:
        """

        self.stats['finalScore'] = state.getScore()

        self.trace('Final Statictics:')
        for stat in enumerate(self.stats):
            self.trace('  ' + str(stat[0]) + "/" + str(stat[1]) + "=" +
                       str(self.stats[stat[1]]))

        return ReinforcementAgent.final(self, state)
Exemplo n.º 6
0
    def final(self, state):

        ReinforcementAgent.final(self, state)

        if self.episodesSoFar <= self.numTraining:
            self.saveTableToFile('featuresqtable.pkl')