Introduction
In the previous part, we introduced the concept of function approximation in reinforcement learning (RL), which is essential for handling large or continuous state and action spaces. We discussed different types of function approximators, including linear and non-linear methods, and how they can be integrated into RL algorithms. Finally, we provided an introduction to Deep Reinforcement Learning (Deep RL), which combines deep learning techniques with RL to tackle complex problems.
In this part, we will continue our discussion on Deep RL and explore how to use function approximation for control tasks in RL. We will cover key algorithms such as semi-gradient SARSA then continue with Deep Q-Networks (DQN) and its variants.
Control with Function Approximation
Recall (Setup for Control with Function Approximation)
We consider the control problem with a parametric approximation of the action-value function , where is a finite-dimensional weight vector.
Further, instead of using training examples of the form , we now use examples of the form . The update target can be any approximation of , including the usual update values such as the full MC return or any of the -step Sarsa retuns .
Episodic Semi-Gradient SARSA
Definition 1 (Episodic Semi-Gradient SARSA)
The general gradient-descent update for action-value prediction is,
Thus, the update for the one-step SARSA method is,
To form (general) control methods, we need to couple action-value prediction with policy improvement and action selection.
For each possible action available in the next state , we need to compute , and then find the greedy action,
Thus, policy improvement is can be done by changing the estimation policy to a soft approximation of the greedy policy, i.e., -greedy policy.
Algorithm (Semi-Gradient SARSA for estimating )
Input: a differentiable action-value function parameterization
Algorithm parameters: step-size , small
Loop for each episode:
- initial state and action of episode (e.g., -greedy)
- Loop for each step of episode:
- Take action , observe
- If is terminal:
- Go to next episode
- Choose as a function of (e.g., -greedy)
Definition 2 (Semi-Gradient -step SARSA)
We can generalize and obtain an -step version of the episodic semi-gradient SARSA algorithm by using the -step SARSA target instead of the one-step SARSA target .
The -step update equation is,
where,
Deep RL & Deep Q-Networks (DQN)
As we discussed last time, many ideas that we have seen so far, can easily be transferred when using deep neural networks as function approximators.
Definition 3 (Deep Q-Networks (DQN))
Deep Q-Networks (DQN) is a value-based method that combines Q-learning with deep neural networks, developed by DeepMind (Mnih et al., 2015) [^1].
They let the DQN learn to play 49 different Atari 2600 games by interacting with the game environment, using only the raw pixel inputs and the game score as rewards. The innovations of DQN are threefold.
Intuition (Experience Replay)
Experience replay is a technique where the agent’s experiences (state, action, reward, next state) are stored in a replay buffer (memory). After the game emulator executes action in state and yields reward and next state , the experience tuple is stored in the replay buffer.
At each time step in the training phase, a mini-batch of experiences is randomly sampled from the replay buffer and used to update the DQN. Instead of becoming the next for the next update, as it would in the usual form of Q-learning, a new unconnected experience is drawn from the replay buffer.
Note
Since Q-learning is an off-policy method, it can learn from data generated by a different policy than the one currently being learned. Thus, experience replay can be used to break the correlation between consecutive experiences and improve data efficiency.
Intuition (Duplicate Network)
We have previously discussed that Q-learning can suffers from an inherent overestimation bias. To mitigate this issue, DQN uses a duplicate network (also called target network) to generate the target values for the Q-learning updates. The duplicate network has the same architecture as the main DQN but with frozen weights that are periodically updated to match the main network. This helps to stabilize the learning process by providing a more consistent target for the Q-learning updates.
Letting denote the output of this duplicate network, the DQN update equation is,
where are the weights of the duplicate network at time step .
Intuition (Reward Clipping)
To handle the varying reward scales across different Atari games, DQN employs reward clipping. All positive rewards are clipped to +1, all negative rewards are clipped to -1, and zero rewards remain unchanged. This normalization helps to stabilize the learning process and allows the same hyperparameters to be used across different games.
Algorithm (Deep Q-Network (DQN))
Initialize network
Initialize target network
Initialize replay buffer
Initialize the Agent to interact with the Environment
while not converged do
-
setting new epsilon with -decay
-
Choose an action from state using policy -greedy(
-
Agent takes action , observe reward , and next state
-
Store transition in the experience replay memory
-
If enough experiences in then
- Sample random mini-batch of transitions from
- for every transition in the mini-batch do
- if then
- else
- end
- if then
- end
- Calculate the loss
- Update using the SGD algorithm by minimizing the loss
- Every steps, copy weights from to
-
end
end