當前位置: 首頁>>代碼示例>>Python>>正文


Python util.convert_episode_to_batch_major方法代碼示例

本文整理匯總了Python中baselines.her.util.convert_episode_to_batch_major方法的典型用法代碼示例。如果您正苦於以下問題:Python util.convert_episode_to_batch_major方法的具體用法?Python util.convert_episode_to_batch_major怎麽用?Python util.convert_episode_to_batch_major使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在baselines.her.util的用法示例。


在下文中一共展示了util.convert_episode_to_batch_major方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: initDemoBuffer

# 需要導入模塊: from baselines.her import util [as 別名]
# 或者: from baselines.her.util import convert_episode_to_batch_major [as 別名]
def initDemoBuffer(self, demoDataFile, update_stats=True):

        demoData = np.load(demoDataFile)
        info_keys = [key.replace('info_', '') for key in self.input_dims.keys() if key.startswith('info_')]
        info_values = [np.empty((self.T, self.rollout_batch_size, self.input_dims['info_' + key]), np.float32) for key in info_keys]

        for epsd in range(self.num_demo):
            obs, acts, goals, achieved_goals = [], [] ,[] ,[]
            i = 0
            for transition in range(self.T):
                obs.append([demoData['obs'][epsd ][transition].get('observation')])
                acts.append([demoData['acs'][epsd][transition]])
                goals.append([demoData['obs'][epsd][transition].get('desired_goal')])
                achieved_goals.append([demoData['obs'][epsd][transition].get('achieved_goal')])
                for idx, key in enumerate(info_keys):
                    info_values[idx][transition, i] = demoData['info'][epsd][transition][key]

            obs.append([demoData['obs'][epsd][self.T].get('observation')])
            achieved_goals.append([demoData['obs'][epsd][self.T].get('achieved_goal')])

            episode = dict(o=obs,
                           u=acts,
                           g=goals,
                           ag=achieved_goals)
            for key, value in zip(info_keys, info_values):
                episode['info_{}'.format(key)] = value

            episode = convert_episode_to_batch_major(episode)
            global demoBuffer
            demoBuffer.store_episode(episode)

            print("Demo buffer size currently ", demoBuffer.get_current_size())

            if update_stats:
                # add transitions to normalizer to normalize the demo data as well
                episode['o_2'] = episode['o'][:, 1:, :]
                episode['ag_2'] = episode['ag'][:, 1:, :]
                num_normalizing_transitions = transitions_in_episode_batch(episode)
                transitions = self.sample_transitions(episode, num_normalizing_transitions)

                o, o_2, g, ag = transitions['o'], transitions['o_2'], transitions['g'], transitions['ag']
                transitions['o'], transitions['g'] = self._preprocess_og(o, ag, g)
                # No need to preprocess the o_2 and g_2 since this is only used for stats

                self.o_stats.update(transitions['o'])
                self.g_stats.update(transitions['g'])

                self.o_stats.recompute_stats()
                self.g_stats.recompute_stats()
            episode.clear() 
開發者ID:jangirrishabh,項目名稱:Overcoming-exploration-from-demos,代碼行數:52,代碼來源:ddpg.py


注:本文中的baselines.her.util.convert_episode_to_batch_major方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。