惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
The Hacker News
The Hacker News
O
OpenAI News
TaoSecurity Blog
TaoSecurity Blog
Google DeepMind News
Google DeepMind News
Forbes - Security
Forbes - Security
Spread Privacy
Spread Privacy
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
Latest news
Latest news
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Schneier on Security
Cloudbric
Cloudbric
Webroot Blog
Webroot Blog
G
Google Developers Blog
M
MIT News - Artificial intelligence
Cisco Talos Blog
Cisco Talos Blog
Blog — PlanetScale
Blog — PlanetScale
Attack and Defense Labs
Attack and Defense Labs
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
Simon Willison's Weblog
Simon Willison's Weblog
N
News and Events Feed by Topic
L
LINUX DO - 热门话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
美团技术团队
C
Cyber Attacks, Cyber Crime and Cyber Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
有赞技术团队
有赞技术团队
N
Netflix TechBlog - Medium
H
Heimdal Security Blog
L
Lohrmann on Cybersecurity
The Last Watchdog
The Last Watchdog
MyScale Blog
MyScale Blog
C
CERT Recently Published Vulnerability Notes
Hugging Face - Blog
Hugging Face - Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Exploit Database - CXSecurity.com
A
About on SuperTechFans
博客园 - 叶小钗
博客园_首页
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Fortinet All Blogs
博客园 - 聂微东

FrWalker Blog

代码开发与环境管理工具汇总 求职-LeetCode热题100刷题记录 新机迁移-hexo\vscode\便携git\miniconda\i卡环境配置 通用印刷电路板全自动布线算法 基于元器件手册的智能建库算法 博客语法记录 柔性电路板FPC自动布线 拓竹P1S初体验 cdn加速hexo博客_2次开发hexo-cdn-jsdelivr 不更换插件解决Hexo博客Latex公式的渲染问题 修改博客加密插件hexo-blog-encrypt 3.1.9,适配移动端 强化学习-1-多臂老虎机 强化学习-2-马尔可夫决策过程 强化学习-3-动态规划 强化学习-4-时序差分 强化学习-6-DQN算法 2024华为软件精英挑战赛-智慧港口 3.liunx shell及其脚本理解 2.linux文件系统及用户管理
强化学习-5-Dyna-Q算法
FrWalker · 2024-08-15 · via FrWalker Blog

发表于更新于

字数总计:433阅读时长:1分钟 新加坡

AI学习强化学习Q-learningDyna-Q

强化学习-5-Dyna-Q算法

强化学习的笔记、理解、感悟及代码实现,仅按个人思维进行精华总结和记录,使用的教程:动手学强化学习

相比Q-learning,Dyna-Q算法引入了一个环境模型,与环境进行交互时不仅更新Q值,也会记录交互数据到环境模型中,然后与环境模型进行n次的模拟交互更新Q值(这个步骤称为Q-planning),使用真实数据和和模拟数据一起改进策略。

Dyna-Q算法的主要步骤如下:
alt text

随着 Q-planning 步数的增多,Dyna-Q 算法的收敛速度也随之变快,但也受限于环境是否是确定的和环境模型的准确性。

实验

class CliffWalkingEnv:
    ...
    def q_learning(self, s0, a0, r, s1):#s0表示当前状态s,s1表示下一个状态s'
        """计算时序差分误差td_error,更新动作价值函数Q(s,a)"""
        td_error = r + self.gamma * self.Q_table[s1].max() - self.Q_table[s0, a0]
        self.Q_table[s0, a0] += self.alpha * td_error
    def run(self, episodes_num=1000,n_planning=2):
        for episode in tqdm(range(episodes_num)):
            s = self.env.reset()  # 初始化
            while True:
                # 真实环境交互,q_learning
                a = self.take_action(s)  # 选取动作
                r,s1,done = self.env.step(a)# 环境反馈
                self.q_learning(s, a, r, s1)  # 更新Q
                self.model[(s,a)] = r,s1  # 记录采集的数据

                # 模拟环境交互,q_palnning步长为n_planning
                for i in range(n_planning):
                    (s0,a0),(r_,s_) = random.choice(list(self.model.items()))  # 随机曾经遇到过的一个数据
                    self.q_learning(s0, a0, r_, s_)
                    
                if done:  # 终止状态
                    break
                s = s1  # 更新状态

当n_planning=0时,即不进行Q-planning,算法退化为Q-learning。

头像头像

FrWalker

a blog for sharing my thoughts and experiences

本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 FrWalker Blog