autorl/agents.py
def train(self, n_episodes, max_steps=1000, epsilon=0.01, epsilon_schedule=False, network=None):
        """
        For each episode, play with the epsilon-greedy policy and record
        the states, actions, and rewards. Once the episode is up, use the
        true reward to prep a batch and update the action value network.
        :param n_episodes:
        :param max_steps:
        :param epsilon:
        :param epsilon_schedule:
        :return:
        """

        if self._q_network is None:
            self._q_network = self.configure(network)

        max_reward = 0.0

        for i in range(n_episodes):

            if epsilon_schedule is not None:
                if i % epsilon_schedule == 0:
                    schedule_step = int(i/epsilon_schedule)
                    epsilon = epsilon*pow(0.9, schedule_step)

            obs = self.reset()
            ep_reward = 0.0
            tuple_batch = []

            for j in range(max_steps):
                self.render()
                obs = obs.reshape([1] + self._state_dim)
                action = self.policy(obs, epsilon=epsilon)
                new_obs, reward, done, info = self.observe(action)
                ep_reward += reward
                tuple_batch.append((obs, action, reward))
                if done:
                    max_reward = max(max_reward, ep_reward)
                    print("Current max reward: {}".format(max_reward))
                    break
                else:
                    obs = new_obs

            # after the episode, prep batch for training, take the grads, and apply.
            # because the state space is continuous, essentially "first-visit" MC
            # is all we can really do without bucketing or adding a vector
            # similarity calculation to the processing. possible for future versions
            batch_x, batch_y = self._batch(tuple_batch)
            loss, grads = train.grad(self._q_network, batch_x, batch_y)
            updates = zip(grads, self._q_network.trainable_variables)
            self._q_network.optimizer.apply_gradients(updates)

            print("Current loss: {}".format(loss))

        For each episode, play with the epsilon-greedy policy and record
        the states, actions, and rewards. Once the episode is up, use the
        true reward to prep a batch and update the action value network.
        :param n_episodes:
        :param max_steps:
        :param epsilon:
        :param epsilon_schedule:
        :return:
        
For each episode, play with the epsilon-greedy policy and record
the states, actions, and rewards. Once the episode is up, use the
true reward to prep a batch and update the action value network.
For each episode play with the epsilon - greedy policy and record the states actions and rewards . Once the episode is up use the true reward to prep a batch and update the action value network .
def train(self, n_episodes, max_steps=1000, epsilon=0.01, epsilon_schedule=False, network=None):
        if self._q_network is None:
            self._q_network = self.configure(network)
        max_reward = 0.0
        for i in range(n_episodes):
            if epsilon_schedule is not None:
                if i % epsilon_schedule == 0:
                    schedule_step = int(i/epsilon_schedule)
                    epsilon = epsilon*pow(0.9, schedule_step)
            obs = self.reset()
            ep_reward = 0.0
            tuple_batch = []
            for j in range(max_steps):
                self.render()
                obs = obs.reshape([1] + self._state_dim)
                action = self.policy(obs, epsilon=epsilon)
                new_obs, reward, done, info = self.observe(action)
                ep_reward += reward
                tuple_batch.append((obs, action, reward))
                if done:
                    max_reward = max(max_reward, ep_reward)
                    print("Current max reward: {}".format(max_reward))
                    break
                else:
                    obs = new_obs
            batch_x, batch_y = self._batch(tuple_batch)
            loss, grads = train.grad(self._q_network, batch_x, batch_y)
            updates = zip(grads, self._q_network.trainable_variables)
            self._q_network.optimizer.apply_gradients(updates)
            print("Current loss: {}".format(loss))
def train ( self , n_episodes , max_steps = 1000 , epsilon = 0.01 , epsilon_schedule = False , network = None ) : if self . _q_network is None : self . _q_network = self . configure ( network ) max_reward = 0.0 for i in range ( n_episodes ) : if epsilon_schedule is not None : if i % epsilon_schedule == 0 : schedule_step = int ( i / epsilon_schedule ) epsilon = epsilon * pow ( 0.9 , schedule_step ) obs = self . reset ( ) ep_reward = 0.0 tuple_batch = [ ] for j in range ( max_steps ) : self . render ( ) obs = obs . reshape ( [ 1 ] + self . _state_dim ) action = self . policy ( obs , epsilon = epsilon ) new_obs , reward , done , info = self . observe ( action ) ep_reward += reward tuple_batch . append ( ( obs , action , reward ) ) if done : max_reward = max ( max_reward , ep_reward ) print ( "Current max reward: {}" . format ( max_reward ) ) break else : obs = new_obs batch_x , batch_y = self . _batch ( tuple_batch ) loss , grads = train . grad ( self . _q_network , batch_x , batch_y ) updates = zip ( grads , self . _q_network . trainable_variables ) self . _q_network . optimizer . apply_gradients ( updates ) print ( "Current loss: {}" . format ( loss ) )
For each episode, play with the epsilon-greedy policy and record
the states, actions, and rewards.
For each episode play with the epsilon - greedy policy and record the states actions and rewards .
"""
        For each episode, play with the epsilon-greedy policy and record
        the states, actions, and rewards. Once the episode is up, use the
        true reward to prep a batch and update the action value network.
        :param n_episodes:
        :param max_steps:
        :param epsilon:
        :param epsilon_schedule:
        :return:
        """ # after the episode, prep batch for training, take the grads, and apply. # because the state space is continuous, essentially "first-visit" MC # is all we can really do without bucketing or adding a vector # similarity calculation to the processing. possible for future versions
None
self
n_episodes
None
max_steps
None
epsilon
None
epsilon_schedule
None
network