当前位置: 首页>>代码示例>>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;未经允许,请勿转载。