示例#1
0
    def setUp(self):
        base.BaseObject.print_level = base.WARNING

        TDAgent.action_selection = 'epsilon_greedy'
        TDAgent.initial_epsilon = 1.0
        TDAgent.min_epsilon = 0.0

        self.env = gridworld.GridWorld(grid=self.grid)
        self.setUp_agent()
        self.rli = LoggingRLI(name=self.__class__.__name__)
        self.rli.init(self.agent, self.env)
        self.rli.episodes(self.num_episodes, 100)
示例#2
0
    def setUp(self):
        base.BaseObject.print_level = base.WARNING

        TDAgent.action_selection = 'epsilon_greedy'
        TDAgent.initial_epsilon = 1.0
        TDAgent.min_epsilon = 0.0
        
        self.env = gridworld.GridWorld(grid=self.grid)
        self.setUp_agent()
        self.rli = LoggingRLI(name=self.__class__.__name__)
        self.rli.init(self.agent,self.env)
        self.rli.episodes(self.num_episodes,100)
示例#3
0
class TestTDGridWorld(unittest.TestCase):
    '''
    An abstract test class for RL agent classes, assumes subclasses
    will define self.agent to be various kinds of agents.
    '''
    grid = ['S..',
            '...',
            '..G']


    correct_reward = -3
    correct_length = 4
    num_episodes = 300

    def setUp(self):
        base.BaseObject.print_level = base.WARNING

        TDAgent.action_selection = 'epsilon_greedy'
        TDAgent.initial_epsilon = 1.0
        TDAgent.min_epsilon = 0.0
        
        self.env = gridworld.GridWorld(grid=self.grid)
        self.setUp_agent()
        self.rli = LoggingRLI(name=self.__class__.__name__)
        self.rli.init(self.agent,self.env)
        self.rli.episodes(self.num_episodes,100)


    def testMain(self):
        self.myTestAgent()
        self.assertEqual(self.rli.episode_data.variables['length'][-1], self.correct_length)
        self.assertEqual(self.rli.episode_data.variables['reward'][-1], self.correct_reward)

        steps = self.rli.episode_data.variables['length']
        
        self.agent.sim = None
        name = tmpnam()
        pkl.save(self.agent,name)
        new_agent = pkl.load(name)
        new_agent.sim = self.rli
        self.rli.agent = new_agent
        self.rli.episodes(2,100)
        self.assertEqual(steps,self.rli.episode_data.variables['length'][-1])

    def myTestAgent(self): pass
    def tearDown(self):
        self.rli.episode_data.close()
        os.remove(self.rli.episode_filename)
示例#4
0
class TestTDGridWorld(unittest.TestCase):
    '''
    An abstract test class for RL agent classes, assumes subclasses
    will define self.agent to be various kinds of agents.
    '''
    grid = ['S..', '...', '..G']

    correct_reward = -3
    correct_length = 4
    num_episodes = 300

    def setUp(self):
        base.BaseObject.print_level = base.WARNING

        TDAgent.action_selection = 'epsilon_greedy'
        TDAgent.initial_epsilon = 1.0
        TDAgent.min_epsilon = 0.0

        self.env = gridworld.GridWorld(grid=self.grid)
        self.setUp_agent()
        self.rli = LoggingRLI(name=self.__class__.__name__)
        self.rli.init(self.agent, self.env)
        self.rli.episodes(self.num_episodes, 100)

    def testMain(self):
        self.myTestAgent()
        self.assertEqual(self.rli.episode_data.variables['length'][-1],
                         self.correct_length)
        self.assertEqual(self.rli.episode_data.variables['reward'][-1],
                         self.correct_reward)

        steps = self.rli.episode_data.variables['length']

        self.agent.sim = None
        name = tmpnam()
        pkl.save(self.agent, name)
        new_agent = pkl.load(name)
        new_agent.sim = self.rli
        self.rli.agent = new_agent
        self.rli.episodes(2, 100)
        self.assertEqual(steps, self.rli.episode_data.variables['length'][-1])

    def myTestAgent(self):
        pass

    def tearDown(self):
        self.rli.episode_data.close()
        os.remove(self.rli.episode_filename)