(self, policy_fn, obsfeat_fn, max_traj_len, init_state=None)
return Trajectory(obs_T_Do, obsfeat_T_Df, adist_T_Pa, a_T_Da, r_T)
Simulate a single trajectory
Simulate a single trajectory
Simulate a single trajectory
def sim_single(self, policy_fn, obsfeat_fn, max_traj_len, init_state=None):
        '''Simulate a single trajectory'''
        sim = self.new_sim(init_state=init_state)
        obs, obsfeat, actions, actiondists, rewards = [], [], [], [], []
        for _ in xrange(max_traj_len):
            obs.append(sim.obs[None,...].copy())
            obsfeat.append(obsfeat_fn(obs[-1]))
            a, adist = policy_fn(obsfeat[-1])
            actions.append(a)
            actiondists.append(adist)
            rewards.append(sim.step(a[0,:]))
            if sim.done: break
        obs_T_Do = np.concatenate(obs); assert obs_T_Do.shape == (len(obs), self.obs_space.storage_size)
        obsfeat_T_Df = np.concatenate(obsfeat); assert obsfeat_T_Df.shape[0] == len(obs)
        adist_T_Pa = np.concatenate(actiondists); assert adist_T_Pa.ndim == 2 and adist_T_Pa.shape[0] == len(obs)
        a_T_Da = np.concatenate(actions); assert a_T_Da.shape == (len(obs), self.action_space.storage_size)
        r_T = np.asarray(rewards); assert r_T.shape == (len(obs),)
        return Trajectory(obs_T_Do, obsfeat_T_Df, adist_T_Pa, a_T_Da, r_T)
def sim_single ( self , policy_fn , obsfeat_fn , max_traj_len , init_state = None ) : sim = self . new_sim ( init_state = init_state ) obs , obsfeat , actions , actiondists , rewards = [ ] , [ ] , [ ] , [ ] , [ ] for _ in xrange ( max_traj_len ) : obs . append ( sim . obs [ None , ... ] . copy ( ) ) obsfeat . append ( obsfeat_fn ( obs [ - 1 ] ) ) a , adist = policy_fn ( obsfeat [ - 1 ] ) actions . append ( a ) actiondists . append ( adist ) rewards . append ( sim . step ( a [ 0 , : ] ) ) if sim . done : break obs_T_Do = np . concatenate ( obs ) assert obs_T_Do . shape == ( len ( obs ) , self . obs_space . storage_size ) obsfeat_T_Df = np . concatenate ( obsfeat ) assert obsfeat_T_Df . shape [ 0 ] == len ( obs ) adist_T_Pa = np . concatenate ( actiondists ) assert adist_T_Pa . ndim == 2 and adist_T_Pa . shape [ 0 ] == len ( obs ) a_T_Da = np . concatenate ( actions ) assert a_T_Da . shape == ( len ( obs ) , self . action_space . storage_size ) r_T = np . asarray ( rewards ) assert r_T . shape == ( len ( obs ) , ) return Trajectory ( obs_T_Do , obsfeat_T_Df , adist_T_Pa , a_T_Da , r_T )