Code Monkey home page Code Monkey logo

rl-book's Introduction

Reinforcement Learning: Theory and Python Implementation

The First Reinforcement Learning Tutorial Book with one-on-one mapping TensorFlow 2 and PyTorch 1&2 Implementation

English Edition 中文版 中文2019版
Book Book Book

Please email me if you are interested in publishing this book in other languages.

Features

This is a tutorial book on reinforcement learning, with explanation of theory and Python implementation.

  • Theory: Starting from a uniform mathematical framework, this book derives the theory and algorithms of reinforcement learning, including all major algorithms such as eligibility traces and soft actor-critic algorithms.
  • Practice: Every chapter is accompanied by high quality implementation based on Python 3, Gym 0.26, and TensorFlow 2 / PyTorch 1&2. All codes are compatible with Windows, Linux, and macOS, can be run in a laptop.

Supporting contents for English version

Check here for codes, exercise answers, etc.

Table of Codes

All codes have been saved as a .ipynb file and a .html file in the same directory.

Chapter Environment & Closed-Form Policy Agent
2 CliffWalking-v0 Bellman
3 FrozenLake-v1 DP
4 Blackjack-v1 MC
5 Taxi-v3 SARSA, ExpectedSARSA, QL, DoubleQL, SARSA(λ)
6 MountainCar-v0 SARSA, SARSA(λ), DQN tf torch, DoubleDQN tf torch, DuelDQN tf torch
7 CartPole-0 VPG tf torch, VPGwBaseline tf torch, OffPolicyVPG tf torch, OffPolicyVPGwBaseline tf torch
8 Acrobot-v1 QAC tf torch, AdvantageAC tf torch, EligibilityTraceAC tf torch, PPO tf torch, NPG tf torch, TRPO tf torch, OffPAC tf torch
9 Pendulum-v1 DDPG tf torch, TD3 tf torch
10 LunarLander-v2 SQL tf torch, SAC tf torch, SACwA tf torch
10 LunarLanderContinuous-v2 SACwA tf torch
11 BipedalWalker-v3 ES, ARS
12 PongNoFrameskip-v4 CategoricalDQN tf torch, QR-DQN tf torch, IQN tf torch
13 BernoulliMAB-v0 UCB
13 GaussianMAB-v0 UCB
14 TicTacToe-v0 AlphaZero tf torch
15 Tiger-v0 VI
16 HumanoidBulletEnv-v0 BehaviorClone tf torch, GAIL tf torch

强化学习:原理与Python实战

全球第一本配套 TensorFlow 2 和 PyTorch 1/2 对照代码的强化学习教程书

中文版书籍支持内容

  • 代码、习题答案、勘误更新等配套资源见这里

本书内容

  • 第一部分(第 1 章):从零开始介绍强化学习的背景知识,介绍环境库 Gym 的使用。
  • 第二部分(第 2~15 章):基于折扣奖励离散时间 Markov 决策过程模型,介绍强化学习的主干理论和常见算法。采用数学语言推导强化学习的基础理论,进而在理论的基础上讲解算法,并为算法提供配套代码实现。基础理论的讲解突出主干部分,算法讲解全面覆盖主流的强化学习算法,包括经典的非深度强化学习算法和近年流行的强化学习算法。 Python 实现和算法讲解一一对应,还给出了深度强化学习算法的 TensorFlow 和 PyTorch 对照实现。
  • 第三部分(第 16 章):介绍其他强化学习模型,包括平均奖励模型、连续时间模型、非齐次模型、半 Markov 模型、部分可观测模型等,以便更好了解强化学习研究的全貌。

本书特色

本书完整地介绍了主流强化学习理论。

  • 选用现代强化学习理论体系,突出主干,主要定理均给出证明过程。基于理论讲解强化学习算法,全面覆盖主流强化学习算法,包括了资格迹等经典算法和 MuZero 等深度强化学习算法。
  • 全书采用完整的数学体系,各章内容循序渐进。全书采用一致的数学符号,并兼容主流强化学习教程。
  • 每章都配有知识点总结,并搭配习题。

本书各章均提供Python代码,实战性强。

  • 简洁易懂:全书代码统一规范、简约完备,与算法讲解直接对应。
  • 查阅方便:所有代码及运行结果均在 GitHub 上展示,既可以在浏览器上查阅,也可以下载到本地运行。各算法实现放在单独的文件里,可单独查阅和运行。
  • 环境全面:既有 Gym 的内置环境,也有在 Gym 基础上进一步扩展的第三方环境,还带领读者一起实现自定义的环境。
  • 兼容性好:所有代码在三大操作系统(Windows、macOS、Linux)上均可运行,书中给出了环境的安装和配置方法。深度强化学习代码还提供了 TensorFlow 和 PyTorch 对照代码。读者可任选其一。
  • 硬件要求低:所有代码均可在没有 GPU 的个人计算机上运行。

强化学习:原理与Python实现 (2019)

全球第一本配套 TensorFlow 2 代码的强化学习教程书

**第一本配套 TensorFlow 2 代码的纸质算法书

中文版书籍支持内容

  • 代码、勘误更新等见这里

本书特色

本书介绍强化学习理论及其 Python 实现。

  • 理论完备:全书用一套完整的数学体系,严谨地讲授强化学习的理论基础,主要定理均给出证明过程。各章内容循序渐进,覆盖了所有主流强化学习算法,包括资格迹等非深度强化学习算法和柔性执行者/评论者等深度强化学习算法。
  • 案例丰富:在您最爱的操作系统(包括 Windows、macOS、Linux)上,基于 Python 3、Gym 0.26 和 TensorFlow 2 + PyTorch 1/2,实现强化学习算法。全书实现统一规范,体积小、重量轻。第 1~9 章给出了算法的配套实现,环境部分只依赖于 Gym 的最小安装,在没有 GPU 的计算机上也可运行;第 10~12 章介绍了多个热门综合案例,涵盖 Gym 的完整安装和自定义扩展,在有普通 GPU 的计算机上即可运行。

QQ群

  • QQ群:722846914(勘误报错可发此群,其他问题提问前请先Google,群主和管理员不提供免费咨询服务)
  • 多任务群:696984257(非小白群,多任务强化学习+强化元学习+终身强化学习+迁移强化学习,勘误报错勿发此群,提问前请先Google)
  • 关于入群验证问题:由于QQ的bug,即使正确输入答案,也可能会验证失败。这时更换设备重试、更换输入法重试、改日重试均可能解决问题。如果答案中有英文字母,清注意大小写。
  • 中文版书前言中给出的QQ群(935702193、243613392和948110103)已满,不再新增群成员,谢谢理解。

rl-book's People

Contributors

zhiqingxiao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rl-book's Issues

ValueError: too many values to unpack (expected 2)

I'm getting the following error when running the Advantage Actor-Critic to Play Acrobot-V1

ValueError Traceback (most recent call last)
in <cell line: 21>()
20 episode_rewards = []
21 for episode in itertools.count():
---> 22 episode_reward, elapsed_steps = play_episode(env, agent, seed=episode,
23 mode='train')
24 episode_rewards.append(episode_reward)

in play_episode(env, agent, seed, mode, render)
1 def play_episode(env, agent, seed=None, mode=None, render=False):
----> 2 observation, _ = env.reset(seed=seed)
3 reward, terminated, truncated = 0., False, False
4 agent.reset(mode=mode)
5 episode_reward, elapsed_steps = 0., 0

ValueError: too many values to unpack (expected 2)

第6章 小车上山

请教

  1. 代码清单6-4中,智能体的get_q方法的return,动作价值不是应该权重乘上特征向量吗,但是为什么这里是self.w[features]?

  2. 代码清单6.3 砖瓦编码
    为什么这么第一层是64个砖瓦,剩下7层是81个砖瓦呢?8+1是怎么来的?我的理解是如果选用8层,那么每层是大网格/砖瓦 相当于8*8的小格。可一层覆盖最终有网格/瓦片是怎么决定的呢?

第六章MoutainCar-v0 砖瓦编码计算的问题

在 class TileCoder 里的__call__()
def call(self, floats=(), ints=()):
dim = len(floats)
scaled_floats = tuple(f * self.layers * self.layers for f in floats)
features = []
for layer in range(self.layers):
codeword = (layer,) + tuple(int((f + (1 + dim * i) * layer) /
self.layers) for i, f in enumerate(scaled_floats)) + ints
feature = self.get_feature(codeword)
features.append(feature)
return features
这里使用了 (f + (1 + dim * i) * layer) 来计算不同layer的位置
但是实际计算, 当i=1时 会把1-7层的的坐标映射到1-9或2-10
实测表明 使用(f + layer) 效果会更好 而且会严格的把1-7层的数据映射到0-8

SARSA 算法<<<<<<<<<<<<<<<<<<<<<
平均回合奖励 = -12649.0 / 100 = -126.49
SARSA(λ) 算法<<<<<<<<<<<<<<<<<<<<<
平均回合奖励 = -10181.0 / 100 = -101.81
我们为什么要采用(f + (1 + dim * i) * layer) 来计算呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.