Пример #1
0
def TrainLargeAgent(NrGames, writeOn, savePath, show=False):
    from LargeAgent import LargeAgent as Agent

    #make the enviroment
    env = Enviroment(enhancedReward=True, autoFire=True)
    #because of the influence of tensorflow draw the enviroment once before making any call to tensorflow of don't draw at all
    if (show):
        env.reset()
        env.render()

    #make the agent
    agent = Agent()

    #see how many times to save the agent
    NrBatches = int(NrGames / float(writeOn)) + 1

    totalNrFrames = 0
    #Train some games then save the results keep repeating until all number of games have been played
    for i in range(NrBatches):
        print "batch", i, "of", NrBatches
        #train the agent
        reward, steps = trainAgent(env, agent, writeOn, show=show)

        totalNrFrames += np.sum(steps)
        #save the itermediate agent
        agent.save(savePath + "_" + str(i * writeOn))

        #save the stats
        f = open(savePath, 'a')
        for r, s in zip(reward, steps):
            f.write(str(r) + "," + str(s) + '\n')
        f.close()

        env.makeVideo(savePath + "_" + str(i * writeOn) + ".gif")
Пример #2
0
def TrainSmallAgent(NrGames, writeOn, savePath, show=False):
    from SmallAgent import SmallAgent as Agent

    #make the enviroment
    env = Enviroment(fullImage=False, enhancedReward=True, autoFire=True)
    if (show):
        env.reset()
        env.render()

    agent = Agent()

    #see how many times to save the agent
    NrBatches = int(NrGames / float(writeOn)) + 1

    #Train some games then save the results keep repeating until all number of games have been played
    for i in range(NrBatches):
        print "batch", i, "of", NrBatches
        #train the agent
        reward, steps = trainAgent(env, agent, writeOn, show=show)

        #save the itermediate agent
        agent.save(savePath + "_" + str(i * writeOn))

        #save the stats
        f = open(savePath, 'a')
        for r, s in zip(reward, steps):
            f.write(str(r) + "," + str(s) + '\n')
        f.close()

        env.makeVideo(savePath + "_" + str(i * writeOn) + ".gif")
Пример #3
0
  write = 0
  
  rweards = []
  for i in range(500):
    S = env.reset()
    done = False
    while not done:
      action = agent.getAction(S)
      Snew,reward,done,info = env.step(action)
      agent.update(S,action,Snew,reward,done)
      S = Snew
      if(show):
	env.render()
    if(write == 0):
      write = 1
      env.makeVideo('./randomMovement.gif')
    if(i == 250 and write == 1):
      write = 2
      env.makeVideo('./halfRandomMovement.gif')
    rweards.append(env.reward)
    print "End Game",env.reward
  
  env.makeVideo('./minimalRandomMovement.gif')
  
  first = np.mean(rweards)
  second = np.std(rweards)
  
  rweards = []
  for _ in range(30):
    S = env.reset()
    done = False
Пример #4
0
    def load(filename):
        return randomAgent()

    """
  nothing to save so do nothing
  """

    def save(self, filename):
        pass


if (__name__ == "__main__"):
    from Eviroment import Enviroment

    env = Enviroment(Breakout=True,
                     enhancedReward=True,
                     fullImage=False,
                     autoFire=True)

    agent = designedAgent()

    done = False
    S = env.reset()
    while not done:
        action = agent.getAction(S)
        S, r, done, info = env.step(action)

        env.render()

    env.makeVideo('designedAgent.gif')