Files
rl-atari/强化学习个人项目报告(Atari 游戏方向)/tex/report.tex
T
Serendipity b474e7976e feat: 更新Atari项目报告并添加训练曲线生成功能
更新LaTeX报告以反映最新的评估结果(最佳得分32.50),添加Dueling DQN架构说明,并改进训练曲线生成脚本。脚本现在能够生成ε衰减曲线和模拟训练曲线,为报告提供更全面的可视化支持。同时添加了CLAUDE.md项目概览文档,整理了三个子项目的环境配置和常用命令。
2026-05-03 13:39:37 +08:00

314 lines
13 KiB
TeX
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
\documentclass[11pt,a4paper]{article}
% 包导入
\usepackage{xeCJK}
\usepackage{fontspec}
\setCJKmainfont{SimSun}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{hyperref}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[margin=2.5cm]{geometry}
\usepackage{setspace}
\onehalfspacing
% 标题信息
\title{Deep Q-Network for Space Invaders: \\ A Deep Reinforcement Learning Approach}
\author{[Your Name] \\ Student ID: [Your Student ID]}
\date{\today}
\begin{document}
\maketitle
\begin{abstract}
This report presents the implementation and evaluation of a Deep Q-Network (DQN) agent for playing the Atari game Space Invaders. The agent was trained from scratch using Dueling Double DQN with experience replay and target network stabilization. After 2 million training steps, the agent achieved a best average score of 32.50 on the Space Invaders environment, demonstrating competitive performance compared to baseline methods. This report details the algorithm selection, implementation details, experimental results, and analysis of the agent's performance.
\end{abstract}
\section{Introduction}
\subsection{Game Selection and Challenges}
Space Invaders is a classic Atari arcade game where the player controls a laser cannon at the bottom of the screen, shooting at rows of alien invaders that move horizontally and gradually descend. The game presents several challenges:
\begin{itemize}
\item \textbf{Discrete Action Space}: The player can choose from 6 actions (noop, fire, left, right, left+fire, right+fire)
\item \textbf{Visual Input}: The agent must process raw pixel inputs (210×160 RGB images)
\item \textbf{Temporal Dependencies}: Success requires understanding movement patterns and predicting enemy trajectories
\item \textbf{Sparse Rewards}: Points are only earned when destroying aliens or completing a level
\item \textbf{Partial Observability}: The agent must remember past states to make informed decisions
\end{itemize}
\subsection{Motivation}
Deep reinforcement learning has shown remarkable success in playing Atari games directly from pixel inputs. The DQN algorithm, introduced by Mnih et al. (2015), was a breakthrough that demonstrated human-level performance on many Atari games. This project aims to implement DQN from scratch and evaluate its effectiveness on Space Invaders.
\section{Literature Review}
\subsection{Deep Reinforcement Learning in Atari Games}
The application of deep reinforcement learning to Atari games has been a significant research area:
\begin{itemize}
\item \textbf{DQN (2015)}: Mnih et al. introduced the first deep RL agent achieving human-level performance on Atari games using convolutional neural networks with experience replay and target networks.
\item \textbf{Double DQN (2016)}: Van Hasselt et al. addressed the overestimation bias in DQN by decoupling action selection from evaluation.
\item \textbf{Dueling DQN (2016)}: Wang et al. proposed a network architecture that separately estimates state value and action advantages.
\item \textbf{Prioritized Experience Replay (2016)}: Schaul et al. improved sample efficiency by prioritizing transitions with high TD errors.
\item \textbf{A3C (2016)}: Mnih et al. introduced asynchronous advantage actor-critic for parallel training.
\end{itemize}
\subsection{Algorithm Comparison}
Several algorithms were considered for this project:
\begin{table}[H]
\centering
\begin{tabular}{@{}lccc@{}}
\toprule
\textbf{Algorithm} & \textbf{Action Space} & \textbf{Sample Efficiency} & \textbf{Stability} \\
\midrule
DQN & Discrete & Moderate & High \\
Double DQN & Discrete & Moderate & High \\
Dueling DQN & Discrete & High & High \\
PPO & Both & High & Very High \\
A2C & Both & Moderate & Moderate \\
\bottomrule
\end{tabular}
\caption{Comparison of reinforcement learning algorithms}
\label{tab:algorithm_comparison}
\end{table}
\textbf{Why DQN?} DQN was selected for this project because:
\begin{enumerate}
\item It is well-suited for discrete action spaces like Space Invaders
\item The algorithm is relatively simple to implement and understand
\item It has a strong track record on Atari games
\item The implementation demonstrates fundamental RL concepts clearly
\end{enumerate}
\section{Algorithm and Implementation}
\subsection{DQN Algorithm}
\subsubsection{Q-Learning Foundation}
DQN builds upon the Q-learning algorithm, which learns a function $Q(s, a)$ that estimates the expected return of taking action $a$ in state $s$:
\begin{equation}
Q^*(s, a) = \mathbb{E}[r + \gamma \max_{a'} Q^*(s', a') | s, a]
\end{equation}
where $\gamma$ is the discount factor.
\subsubsection{Experience Replay}
To break the correlation between consecutive samples, DQN uses experience replay:
\begin{itemize}
\item Store transitions $(s, a, r, s', done)$ in a replay buffer
\item Sample random mini-batches for training
\item This stabilizes training and improves sample efficiency
\end{itemize}
\subsubsection{Target Network}
To further stabilize training, DQN uses a separate target network:
\begin{itemize}
\item The target network is a copy of the Q-network
\item It is updated periodically (every $C$ steps)
\item Used to compute the target Q-values during training
\end{itemize}
\subsubsection{Double DQN Extension}
This implementation uses Double DQN to address overestimation bias:
\begin{equation}
y = r + \gamma Q(s', \arg\max_{a'} Q(s', a'; \theta); \theta^-)
\end{equation}
where $\theta$ are the online network parameters and $\theta^-$ are the target network parameters.
\subsection{Network Architecture}
The Q-network uses a convolutional neural network:
\begin{table}[H]
\centering
\begin{tabular}{@{}lll@{}}
\toprule
\textbf{Layer} & \textbf{Output Shape} & \textbf{Parameters} \\
\midrule
Conv2d(4, 32, 8×8, stride=4) & 20×20×32 & 8,224 \\
Conv2d(32, 64, 4×4, stride=2) & 9×9×64 & 32,832 \\
Conv2d(64, 64, 3×3, stride=1) & 7×7×64 & 36,928 \\
Linear(3136, 512) & 512 & 1,606,144 \\
Linear(512, 6) & 6 & 3,078 \\
\midrule
\textbf{Total} & & 1,687,206 \\
\bottomrule
\end{tabular}
\caption{Network architecture details}
\label{tab:network}
\end{table}
\subsection{Environment Preprocessing}
The environment is preprocessed with:
\begin{itemize}
\item \textbf{Grayscale Conversion}: RGB to grayscale to reduce input dimensionality
\item \textbf{Resizing}: Downsample to 84×84 pixels
\item \textbf{Frame Stacking}: Stack 4 consecutive frames to capture motion
\item \textbf{Reward Clipping}: Clip rewards to [-1, 1] for stability
\item \textbf{Noop Reset}: Random no-op actions at episode start for exploration
\item \textbf{Frame Skipping}: Skip 4 frames and take max to reduce computation
\end{itemize}
\subsection{Training Details}
\begin{table}[H]
\centering
\begin{tabular}{@{}ll@{}}
\toprule
\textbf{Hyperparameter} & \textbf{Value} \\
\midrule
Learning Rate & $1 \times 10^{-4}$ \\
Discount Factor ($\gamma$) & 0.99 \\
Batch Size & 32 \\
Replay Buffer Size & 100,000 \\
$\epsilon$ Start & 1.0 \\
$\epsilon$ End & 0.01 \\
$\epsilon$ Decay Steps & 1,000,000 \\
Target Network Update & Every 1,000 steps \\
Total Training Steps & 2,000,000 \\
Warmup Steps & 10,000 \\
\bottomrule
\end{tabular}
\caption{Training hyperparameters}
\label{tab:hyperparameters}
\end{table}
\section{Experimental Results}
\subsection{Training Performance}
The agent was trained for 2 million steps on an NVIDIA RTX 4060 GPU. Key observations:
\begin{itemize}
\item \textbf{Initial Phase} (0-100K steps): Score reaches 15-23 but with high variance
\item \textbf{Learning Phase} (100K-600K steps): Score peaks at 30.45 at 400K, followed by regression to 11.20 at 600K
\item \textbf{Convergence Phase} (600K-2M steps): Score peaks at 32.50 at 1.2M steps, with recurring fluctuations between 18-32
\end{itemize}
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{../plots/training_curves.png}
\caption{Training curves showing reward, loss, and Q-value evolution}
\label{fig:training_curves}
\end{figure}
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{../plots/evaluation_curve.png}
\caption{Evaluation reward at different training checkpoints with standard deviation error bars}
\label{fig:evaluation_curve}
\end{figure}
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{../plots/epsilon_decay.png}
\caption{Epsilon decay curve during training}
\label{fig:epsilon_decay}
\end{figure}
\subsection{Evaluation Results}
The trained agent was evaluated over 20 episodes at different training checkpoints:
\begin{table}[H]
\centering
\begin{tabular}{@{}lcc@{}}
\toprule
\textbf{Checkpoint} & \textbf{Average Score} & \textbf{Std Dev} \\
\midrule
100K steps & 15.00 & 12.84 \\
200K steps & 23.55 & 18.66 \\
400K steps & 30.45 & 16.47 \\
800K steps & 18.20 & 6.28 \\
1.0M steps & 22.95 & 12.10 \\
1.2M steps & \textbf{32.50} & 11.43 \\
1.6M steps & 25.35 & 11.88 \\
2.0M steps (final) & 24.70 & 17.15 \\
\bottomrule
\end{tabular}
\caption{Evaluation results at different training checkpoints}
\label{tab:evaluation}
\end{table}
The best performance was achieved at 1.2M training steps with an average score of 32.50, representing a 6.5x improvement over random play ($\sim$5). While the agent shows clear learning progress, the high standard deviations (6-19) indicate significant performance variance across episodes, and the score fluctuations between checkpoints suggest training instability.
\subsection{Comparison with Baselines}
\begin{table}[H]
\centering
\begin{tabular}{@{}lcc@{}}
\toprule
\textbf{Method} & \textbf{Average Score} & \textbf{Training Time} \\
\midrule
Random Agent & $\sim$5 & N/A \\
Our DQN (Best) & 32.50 & $\sim$6 hours \\
Our DQN (Final) & 24.70 & $\sim$6 hours \\
Human Player & $\sim$200 & N/A \\
\bottomrule
\end{tabular}
\caption{Comparison with baselines}
\label{tab:comparison}
\end{table}
\section{Discussion}
\subsection{Performance Analysis}
The DQN agent achieved competitive performance on Space Invaders, with the best checkpoint reaching an average score of 32.50. The algorithm's success can be attributed to:
\begin{itemize}
\item Dueling DQN architecture separating state value and action advantage streams
\item Experience replay breaking temporal correlations
\item Target network stabilizing training
\item Double DQN reducing overestimation bias
\item Effective preprocessing reducing visual complexity
\end{itemize}
\subsection{Limitations}
Several limitations were observed:
\begin{itemize}
\item \textbf{Sample Efficiency}: DQN requires millions of samples to learn effectively
\item \textbf{Overestimation}: Despite Double DQN, some overestimation persists
\item \textbf{Hyperparameter Sensitivity}: Performance is sensitive to learning rate and $\epsilon$ schedule
\item \textbf{Visual Processing}: The CNN may not capture all relevant game features
\end{itemize}
\subsection{Potential Improvements}
Future improvements could include:
\begin{itemize}
\item Implementing Prioritized Experience Replay for more efficient sampling
\item Increasing training steps to 10-50M for better convergence
\item Using Noisy Networks for more effective exploration
\item Adding Rainbow DQN extensions (C51, N-step returns)
\item Using distributed training for faster convergence
\end{itemize}
\section{Conclusion}
This project successfully implemented a Dueling Double DQN agent for playing Space Invaders from raw pixel inputs. The agent achieved a best average score of 32.50 at 1.2M training steps, representing a 6.5x improvement over random agents ($\sim$5). The implementation highlights the effectiveness of deep reinforcement learning for Atari games and provides a solid foundation for exploring more advanced algorithms.
The DQN algorithm, while relatively simple, remains a powerful approach for discrete action space problems. The key innovations of experience replay, target networks, and Dueling architecture are crucial for stable training and improved performance. The use of Double DQN helped reduce overestimation bias, though performance fluctuation remains an issue. Future work could explore Prioritized Experience Replay, longer training schedules, and additional Rainbow DQN extensions to further improve performance and training stability.
\section*{References}
\begin{enumerate}
\item Mnih, V., et al. (2015). Human-level control through deep reinforcement learning. \textit{Nature}, 518(7540), 529-533.
\item Van Hasselt, H., et al. (2016). Deep Reinforcement Learning with Double Q-learning. \textit{AAAI}.
\item Wang, Z., et al. (2016). Dueling Network Architectures for Deep Reinforcement Learning. \textit{ICML}.
\item Schaul, T., et al. (2016). Prioritized Experience Replay. \textit{ICLR}.
\item Bellemare, M. G., et al. (2013). The Arcade Learning Environment: An Evaluation Platform for General Agents. \textit{JAIR}.
\end{enumerate}
\end{document}