如题:

class EpisodicLifeEnv(gym.Wrapper):
def __init__(self, env):
"""Make end-of-life == end-of-episode, but only reset on true game over.
Done by DeepMind for the DQN and co. since it helps value estimation.
"""
gym.Wrapper.__init__(self, env)
self.lives = 0
self.was_real_done = True def step(self, action):
obs, reward, done, info = self.env.step(action)
self.was_real_done = done
# check current lives, make loss of life terminal,
# then update lives to handle bonus lives
lives = self.env.unwrapped.ale.lives()
if lives < self.lives and lives > 0:
# for Qbert sometimes we stay in lives == 0 condition for a few frames
# so it's important to keep lives > 0, so that we only reset once
# the environment advertises done.
done = True
self.lives = lives
return obs, reward, done, info def reset(self, **kwargs):
"""Reset only when lives are exhausted.
This way all states are still reachable even though lives are episodic,
and the learner need not know about any of this behind-the-scenes.
"""
if self.was_real_done:
obs = self.env.reset(**kwargs)
else:
# no-op step to advance from terminal/lost life state
obs, _, _, _ = self.env.step(0)
self.lives = self.env.unwrapped.ale.lives()
return obs

EpisodicLifeEnv包装器是针对环境中有多条lives的,游戏中所剩的lives通过: lives = self.env.unwrapped.ale.lives()获得。

主要需要说明的代码为:

        if lives < self.lives and lives > 0:
# for Qbert sometimes we stay in lives == 0 condition for a few frames
# so it's important to keep lives > 0, so that we only reset once
# the environment advertises done.
done = True

根据注释可以知道,对于游戏Qbert来说当所剩lives为0的时候这时返回的done为false,也就是说还需要几帧画面后才会获得done=True的反馈,如果我们将判断条件:

        if lives < self.lives and lives > 0:

改为:

        if lives < self.lives and lives >=0:

这样,step返回的 return obs, reward, done, info 将作为一个episode的最后一帧数据来处理,并调用reset函数中的:

        else:
# no-op step to advance from terminal/lost life state
obs, _, _, _ = self.env.step(0)

这样,在随后的几帧数据中由于 self.was_real_done = False,而  lives = self.env.unwrapped.ale.lives()=0,会不断的循环调用reset操作。

当然针对Qbert游戏中的这种问题我们还可以使用其他的修改方式:

class EpisodicLifeEnv(gym.Wrapper):
def __init__(self, env):
"""Make end-of-life == end-of-episode, but only reset on true game over.
Done by DeepMind for the DQN and co. since it helps value estimation.
"""
gym.Wrapper.__init__(self, env)
self.lives = 0
self.was_real_done = True def step(self, action):
obs, reward, done, info = self.env.step(action)
# self.was_real_done = done
# check current lives, make loss of life terminal,
# then update lives to handle bonus lives
lives = self.env.unwrapped.ale.lives()
if lives < self.lives:
# for Qbert sometimes we stay in lives == 0 condition for a few frames
# so it's important to keep lives > 0, so that we only reset once
# the environment advertises done.
done = True
self.lives = lives
return obs, reward, done, info def reset(self, **kwargs):
"""Reset only when lives are exhausted.
This way all states are still reachable even though lives are episodic,
and the learner need not know about any of this behind-the-scenes.
"""
# if self.was_real_done:
if self.lives == 0:
obs = self.env.reset(**kwargs)
else:
# no-op step to advance from terminal/lost life state
obs, _, _, _ = self.env.step(0)
self.lives = self.env.unwrapped.ale.lives()
return obs

==================================================

baselines中环境包装器EpisodicLifeEnv的分析的更多相关文章

  1. Oracle中CBO优化器简介

    Oracle中CBO优化器简介 Oracle数据库中的优化器是SQL分析和执行的优化工具.它负责制定SQL的执行计划,也就是它负责保证SQL的执行计划的效率最高,比如优化器决定Oracle以什么样的方 ...

  2. SwiftUI 中一些和响应式状态有关的属性包装器的用途

    SwiftUI 借鉴了 React 等 UI 框架的概念,通过 state 的变化,对 View 进行响应式的渲染.主要通过 @State, @StateObject, @ObservedObject ...

  3. Java中基本数据类型和包装器类型的关系

    在程序设计中经常用到一系列的数据类型,在Java中也一样包含八中数据类型,这八种数据类型又各自对应一种包装器类型.如下表: 基本类型 包装器类型 boolean Boolean char Charac ...

  4. javaweb 中的过滤器 包装器

    过滤器要做的事情: 请求过滤器:完毕安全检查,又一次格式化请求首部或体.建立请求审计或日志 响应过滤器:     压缩响应流,追加或改动响应流创建一个全然不同的响应. 过滤器和servlet三个相似地 ...

  5. Java中的类加载器以及Tomcat的类加载机制

    在加载阶段,虚拟机需要完成以下三件事情: 1.通过一个类的全限定名来获取其定义的二进制字节流. 2.将这个字节流所代表的静态存储结构转化为方法区的运行时数据结构. 3.在Java堆中生成一个代表这个类 ...

  6. 【Keras案例学习】 sklearn包装器使用示范(mnist_sklearn_wrapper)

    import numpy as np from keras.datasets import mnist from keras.models import Sequential from keras.l ...

  7. Netty中NioEventLoopGroup的创建源码分析

    NioEventLoopGroup的无参构造: public NioEventLoopGroup() { this(0); } 调用了单参的构造: public NioEventLoopGroup(i ...

  8. global对象,数据存储方式和检测,包装器对象等

    1.理解global对象 global对象是作为 window 对象的一部分实现的,我们无法通过代码访问到 global 对象. 我们平时在全局环境下定义的内容(变量,函数,常量等等)都是作为 glo ...

  9. Linux 内核调度器源码分析 - 初始化

    导语 上篇系列文 混部之殇-论云原生资源隔离技术之CPU隔离(一) 介绍了云原生混部场景中CPU资源隔离核心技术:内核调度器,本系列文章<Linux内核调度器源码分析>将从源码的角度剖析内 ...

  10. SwiftUI 简明教程之属性包装器

    本文为 Eul 样章,如果您喜欢,请移步 AppStore/Eul 查看更多内容. Eul 是一款 SwiftUI & Combine 教程 App(iOS.macOS),以文章(文字.图片. ...

随机推荐

  1. 随机二次元图片API上线

    Tips:当你看到这个提示的时候,说明当前的文章是由原emlog博客系统搬迁至此的,文章发布时间已过于久远,编排和内容不一定完整,还请谅解` 随机二次元图片API上线 日期:2017-12-6 阿珏 ...

  2. QMS质量管理系统:打造企业质量控制的新纪元

    在当今竞争激烈的市场环境下,产品质量是决定企业生存与发展的关键因素之一.为了确保从设计到交付的每一步都符合最高标准,一套高效.全面的质量管理系统(Quality Management System, ...

  3. 一份快速入门的 Makefile 教程

    目录 一份快速入门的 Makefile 教程 关于 Makefile,你应该知道的一些事情 什么是 Makefile? Makefile 能做什么? Makefile 怎么写? Makefile 与 ...

  4. python实现推送消息到微信公众号

    使用到库: Requests 实现方式: 微信已开放了对应的接口,直接通过python的requests库,发起请求,实现推送消息到公众号 微信公众号准备: 1.没有注册微信公众号,可以使用微信提供的 ...

  5. 使用 GPU 进行 Lightmap 烘焙 - 简单 demo

    作者:i_dovelemon 日期:2024-06-16 主题:Lightmap, PathTracer, Compute Shader 引言 一直以来,我都对离线 bake lightmap 操作很 ...

  6. TI AM64x工业核心板硬件说明书(双核ARM Cortex-A53 + 单/四核Cortex-R5F + 单核Cortex-M4F,主频1GHz)

    1          硬件资源 创龙科技SOM-TL64x是一款基于TI Sitara系列AM64x双核ARM Cortex-A53 + 单/四核Cortex-R5F + 单核Cortex-M4F设计 ...

  7. HiAI Foundation开发平台,加速端侧AI应用的智能革命

    如果您是一名开发者,正在寻找一种高效.灵活且易于使用的端侧AI开发框架,那么HarmonyOS SDKHiAI Foundation服务(HiAI Foundation Kit)就是您的理想选择. 作 ...

  8. Python入门学习介绍

    什么是Python? Python它是一种直译式,面向对象,解释式的脚本语言.它和Java,C/C++,Go语言一样都是高级语言,但由于它是解释式语言,所以运行速度会比Java,C/C++等语言慢(虽 ...

  9. Java 、C# Excel模板,数据一对多,主从表关系,导入到数据库

    思路 单表导入的比较容易,但是有的时候,可能会出现,一对多数据导入的,这个情况怎么办呢?先理解上面的图,后台获取数据的时候,除了"风险防控措施"外,其他字段先分组,"黄色 ...

  10. Solo 开发者周刊 (第2期):一站式解决各类办公绘图问题

    这里会整合 Solo 社区每周推广内容.产品模块或活动投稿,每周五发布.在这期周刊中,我们将深入探讨开源软件产品的开发旅程,分享来自一线独立开发者的经验和见解.本杂志开源,欢迎投稿. 好文推荐 重新思 ...