2024 · REINFORCEMENT LEARNING

DQN

Configurable Deep Q-Network Experiments可配置 Deep Q-Network 实验

A PyTorch implementation that turns the DQN training loop into comparable experiments across network variants and environments, with configuration, visualization, and saved checkpoints built in.一套 PyTorch 实现:把 DQN 训练循环扩展为可比较的网络结构与环境实验,并内置配置、可视化和 Checkpoint 保存。

LunarLander environment running from a trained Deep Q-Network checkpoint
Role角色
RL implementation · Experiment design强化学习实现 · 实验设计
Stack技术栈
Python · PyTorch · OpenAI Gym
Variants网络变体
DQN · Duelling DQN
01

Learning problem学习问题

Value learning combines bootstrapped targets, correlated experience, and a policy that changes while data is collected—conditions that can destabilize training.价值学习同时面临自举目标、相关经验,以及随数据收集持续变化的策略,训练容易失稳。

02

Engineering response工程处理

Replay memory decorrelates samples, an epsilon-greedy policy manages exploration, and a separate target network slows the moving objective.经验回放降低样本相关性,Epsilon-greedy 管理探索,独立目标网络减缓目标漂移。

03

Experiment surface实验能力

One runner compares single-hidden, two-hidden, and Duelling DQN models across CartPole and LunarLander configurations.同一 Runner 可比较单隐藏层、双隐藏层与 Duelling DQN,并覆盖 CartPole 与 LunarLander 配置。

Training loop训练循环

Separate acting, learning, and target updates.把行动、学习与目标更新拆开。

The implementation makes each stability mechanism explicit, so architecture and hyperparameter changes can be compared without rewriting the training loop.实现把每一种稳定机制显式化,使网络结构与超参数可以直接比较,而无需重写训练循环。

01 · ACT Explore and choose探索并选择动作

Use epsilon-greedy action selection with a configurable decay schedule for each environment.针对每个环境使用带可配置衰减计划的 Epsilon-greedy 动作选择。

02 · STORE Replay experience经验回放

Store transitions in a bounded replay buffer and sample minibatches after the warm-up threshold.把 Transition 存入有界 Replay Buffer,并在预热阈值后抽取 Minibatch。

03 · OPTIMIZE Fit the Q target拟合 Q Target

Compute bootstrapped Bellman targets, backpropagate loss, and optionally clip gradients.计算自举 Bellman Target、反向传播损失,并可选择进行梯度裁剪。

04 · SYNC Update the target更新目标网络

Compare periodic hard copies with soft Polyak updates controlled by tau.比较周期性硬同步与由 Tau 控制的 Polyak 软更新。

Animated LunarLander episode generated by a trained DQN agent
Trained policy训练后策略 A checkpoint should produce behavior you can inspect.Checkpoint 应该产生可检查的实际行为。 The visualizer opens near the solved threshold, connecting reward statistics with the policy’s actual control of the environment.Visualizer 会在接近解决阈值时运行,把奖励统计与策略对环境的实际控制表现对应起来。
CartPole-v1475.920Saved R100 checkpoint已保存 R100 Checkpoint
LunarLander-v3+202.956Saved Duelling DQN checkpoint已保存 Duelling DQN Checkpoint
Network choices网络选择3Single · two-hidden · duelling单层 · 双层 · Duelling

Experiment design实验设计

Move decisions out of the script and into configuration.把实验决策从脚本移到配置中。

Environment-specific YAML controls discounting, replay capacity, exploration decay, hidden sizes, learning rate, synchronization, stopping reward, and frame budget. The command line selects the environment and network variant, so comparable runs share one implementation path.环境级 YAML 统一控制折扣因子、Replay 容量、探索衰减、隐藏层、学习率、同步方式、停止奖励与 Frame 预算;命令行只选择环境和网络变体,让可比较实验复用同一实现路径。

Architecture comparison架构比较

Test capacity and value decomposition separately.分别测试网络容量与价值分解。

The experiment surface separates a deeper plain DQN from Duelling DQN, which estimates state value and action advantage through different streams before combining them. Saved models and reward traces make those comparisons reproducible.实验将更深的普通 DQN 与 Duelling DQN 分开比较;后者分别估计状态价值与动作优势,再合并输出。已保存模型与奖励轨迹让比较结果可以复现。