DQN is All You Need

 

Rainbow is a method to combine all six improvements in Deep Q-Network(DQN). Since the emergence of DQN, scholars have proposed various improvements to it. This post will focus on six of the major improvements, which are eventually integrated into the Rainbow model.

Deep Q-Network

As I introduced in my previous post, the Dynamic Programming, Monte Carlo, and Temporal Difference approach only work on discrete finite sets of states. For complicated and continuous states, we need to use neural networks to approximate the state value function.

Unlike the basic DQN, we adopt the improved version of DQN(Mnih, Volodymyr, et al.) which uses two neural networks in practice. In the ordinary DQN, we use a Q-network as the policy network. Whereas in the improved DQN, in addition to the policy network, we also need a target network to calculate the target Q value.

Double DQN

Double DQN(DDQN) separates action selections and value estimation to avoid overestimation of the value, since DQN uses a greedy policy to estimate the target Q value, this case will always overestimate the Q value. DDQN is basically similar to the above DQN, the only difference is the method of calculating the target Q value.

Instead of finding the maximum Q value in each action with the target Q network, DDQN first finds the optimal action corresponding to the maximum Q value in the current policy Q network:

\[a^{\max}(S'_j, \theta) = \arg\max_{a'}Q(\phi(S'_j),a,\theta)\]

Then use this selected action $a^{\max}(S_j’,\theta)$ to calculate the target Q value in the target Q network:

\[y_j = r_j + \gamma Q'(\phi(S'_j),\arg\max_{a'}Q(\phi(S'_j),a,w),w')\]

Dueling Networks

Dueling DQN decomposes Q value into state value and advantage function to get more useful information.

In order to optimize the network structure, Dueling DQN considers dividing the Q-network into two parts: the first part is only related to the state $s$ and not to the specific action $a$ to be executed, this part is called the value function, denoted as $V(s;\theta,\alpha)$; the second part is related to both the state $s$ and the action $a$, which is called the Advantage Function, denoted as $A(s,a;\theta,\beta)$. Then our value function can be defined as:

Regular deep Q-network structure (top) and the dueling Q-network (bottom) [Source: Wang et al., [Dueling Network Architectures for Deep Reinforcement Learning]

\[Q(s,a;\theta, \alpha, \beta) = V(s;\theta,\alpha) + A(s,a;\theta,\beta)\]

where $\theta$ is the shared parameter, $\alpha$ is the parameter of the value function, and $\beta$ is the parameter of the advantage function.

To distinguish the value of $V$ and $A$ in $Q$, the actual formulation chosen for identifiability is defined as:

\[Q\left(s, a; \theta, \alpha, \beta\right) =V\left(s; \theta, \beta\right) + \left(A\left(s, a; \theta, \alpha\right) - \frac{1}{|\mathcal{A}|}\sum_{a'}A\left(s, a'; \theta, \alpha\right)\right)\]

In this case, the advantage function estimator has zero advantage at the chosen action. Instead of calculating the maximum, it uses an average operator to increase the stability of the optimization.

Prioritized Experience Replay

All types of DQN are sampled by experience replay, and then do the calculation of the target Q value. In general, DQN collects experiences by random sampling, so all samples have the same probability of being sampled.

However, different samples in the Experience Replay pool have different TD errors $\vert\delta_t\vert$ , in this case, they have different effects on the backpropagation process. In Q-networks, the TD error represents the difference between the target Q value(value of TD target) and the current Q value(estimation of Q). The larger the TD error, the greater the effect on the backpropagation. While with a small TD error, the samples will have little effect on the backpropagation. If samples with larger TD error are more likely to be sampled, it is easier to converge the deep Q-learning algorithm.

Prioritizing with TD-error

In addition to the Experience Replay in the regular DQN, the Prioritized Experience Replay(PER) not only stores state, action, reward, and other data, and also add priority to making the order for sampling. In this case, we use TD-error to indicate the priority of each transition. One approach is to use a greedy TD-error prioritization to rank the new transitions with the unknown TD-error in the highest priority. However, this can also have some issues at the same time:

  1. samples with low TD-error may never be replayed.
  2. sensitive to noise.
  3. samples with large TD-error can easily make the neural network overfit (because transitions with large TD-error can be replayed frequently).

Stochastic Prioritization

To solved the above problems, Stochastic Prioritization is introduced. Concretely, define the probability of sampling transition $i$ as:

\[P(i) = \frac{p_i^{\alpha}}{\sum_k p_k^{\alpha}}\]

where $p_i$ is the priority of transition $i$. $\alpha$ indicates how much prioritization is used. $\alpha=0$ is equivalent to the general uniform sampling.

For the above $P(i)$, there are two variants:

  1. Proportional prioritization:

    Define $p_i=\vert\delta_i\vert+\epsilon$, where $\delta_i$ is the TD-error and $\epsilon$ denotes a very small positive number. The purpose of this is to make sure that the transitions with a TD-error of 0 will also be sampled. In practice, we use a ‘sum-tree’ data structure as the experience buffer pool for this variant.

  2. Rank-based prioritization:

    Define $p_i = \frac{1}{\text{rank}(i)}$, where $\text{rank}(i)$ is the ranking according to $|\delta_i|$. In this case, $P$  becomes a power-law distribution with exponent $\alpha$.

However, the PER also introduces bias since the distribution of the samples is changed. This may cause our model to converge to a different value. Thus, we introduce importance sampling(IS) to correct the bias:

\[ w_{i} = \left(\frac{1}{N}\cdot\frac{1}{P\left(i\right)}\right)^{\beta} \]

Multi-Step Learning

Similar to the TD($\lambda$) method instead of using a single step approach in regular DQN, Multi-step learning considers $n$-step of the rewards:

\[R_t^{(n)}=\sum_{k=0}^{n-1}\gamma_t^{(k)}R_{t+k+1}\]

By estimating the target value through the rewards of $n$ steps, the loss function of the DQN becomes:

\[(R_t^{(n)}+\gamma_t^{(n)}\max_{a'}q_{\theta'}(S_{t+n},a')-q_\theta(S_t,A_t))^2\]

This approach can help us speed up the training of DQN agents.

Distributional RL

Bellman Operator

In previous post, we define Bellman equations as:

\[v_{\pi}(s) = \sum\limits_{a \in A} \pi(a\vert s)(r(s,a) + \gamma \sum\limits_{s' \in S}P(s'\vert s,a)v_{\pi}(s'))\] \[q_{\pi}(s,a) = r(s, a) + \gamma \sum\limits_{s' \in S}P(s'\vert s,a)\sum\limits_{a' \in A} \pi(a'\vert s')q_{\pi}(s',a')\]

When $\pi$ is deterministic, the equations can be reduced to:

\[v_{\pi}(s) = r(s,\pi(s)) + \gamma \sum\limits_{s' \in S}P(s'\vert s,a)v_{\pi}(s')\] \[q_{\pi}(s,a) = r(s, a) + \gamma \sum\limits_{s' \in S}P(s'\vert s,a)q_{\pi}(s',\pi(s'))\]

Define the Bellman operator $T^\pi : (S \rightarrow \mathbb{R}) \rightarrow (S \rightarrow \mathbb{R})$ for $S$ via any $v : S \rightarrow \mathbb{R}$ in the following way:

\[(T^\pi v)(s) = r(s,\pi(s)) + \gamma \sum\limits_{s' \in S}P(s'\vert s,a)v_{\pi}(s')\]

Similarly, define the Bellman operator for functions of $S \times A$ as $T^\pi : (S \times A \rightarrow \mathbb{R}) \rightarrow (S \times A \rightarrow \mathbb{R})$:

\[(T^\pi q)(s,a) = r(s, a) + \gamma \sum\limits_{s' \in S}P(s'\vert s,a)q_{\pi}(s',\pi(s'))\]

Thus, we can rewrite the Bellman equations as:

\[T^\pi v_\pi=v_\pi,T^\pi Q_\pi=Q_\pi\]

Then, the Bellman optimality operators can be defined as:

\[(T v)(s) = \max_a (r(s,a) + \gamma \sum\limits_{s' \in S}P(s'\vert s,a)v(s'))\] \[(Tq)(s,a) = r(s, a) + \gamma \sum\limits_{s' \in S}P(s'\vert s,a)\max_{a'\in A}q(s',a')\]

The Bellman operator $\mathcal{T}^{\pi}$ is a $\gamma$-contraction, meaning that for any $q_1,q_2$ we have:

\[\mathrm{dist}\left(\mathcal{T}Q_{1},\mathcal{T}Q_{2}\right)\leq\gamma\mathrm{dist}\left(Q_{1},Q_{2}\right)\]

Thus according to the Contraction Mapping Theorem, $\mathcal{T}^{\pi}$ has a unique fixed point, and then we have:

\[\mathcal{T}^{\infty}Q=Q^{\pi}\]

KL Divergence

For the distribution $p,q$, the KL Divergence is defined as:

\[\mathrm{KL}(p\|q)=\int p(x)\log\frac{p(x)}{q(x)}dx\]

As for the discrete case:

\[\mathrm{KL}(p\|q)=\sum_{i=1}^{N}p(x_{i})\log\frac{p(x_{i})}{q(x_{i})}=\sum_{i=1}^{N}p(x_{i})[\log p(x_{i})-\log q(x_{i})]\]

Distributional DQN replaces the value function in a regular DQN with a value distribution. Therefore, the value function $q(s,a)$ becomes a value distribution in Distributional DQN. It receives $s,a$ and outputs a distribution that describes all values of the state action pair $(s,a)$.

In Distributional DQN, we no longer use $Q(s,a)$ for “value”, we no longer use the expectation to estimate the value, but use its distribution directly, $Q(s,a)$ and $Z(x,a)$ satisfy

\[Q(s,a)=\mathbb{E}[Z(s,a)]=\sum_{i=1}^{N}p_{i}x_{i}\]

Our purpose is to move $Z(s,a)$ towards $r+\gamma Z(s’,a^{*})$, where $r+\gamma Z(s’,a^{\ast})$ is a collection of samples of the real target distribution.

Noisy Nets

The exploration capability of the Agent can be effectively enhanced by using Noisy Net. This approach increases the exploration capability of the model by adding noise to the parameters. In this case, the linear layer in the model becomes a noisy linear layer:

\[y=(b+Wx)+(b_{noisy}\odot\epsilon^b+(W_{noisy}\odot\epsilon^w)x)\]

where $\epsilon$ is a random noise which is following the standard normal distribution $N(0,1)$.

References

  1. Hessel, Matteo, et al. “Rainbow: Combining improvements in deep reinforcement learning.” Thirty-second AAAI conference on artificial intelligence. 2018.
  2. Mnih, Volodymyr, et al. “Human-level control through deep reinforcement learning.” nature  518.7540 (2015): 529-533.
  3. Van Hasselt, Hado, Arthur Guez, and David Silver. “Deep reinforcement learning with double q-learning.” Proceedings of the AAAI conference on artificial intelligence . Vol. 30. No. 1. 2016.
  4. Wang, Ziyu, et al. “Dueling network architectures for deep reinforcement learning.” International conference on machine learning . PMLR, 2016.
  5. Fortunato, Meire, et al. “Noisy networks for exploration.” arXiv preprint arXiv:1706.10295  (2017).
  6. Schaul, Tom, et al. “Prioritized experience replay.” arXiv preprint arXiv:1511.05952  (2015).
  7. Bellemare, Marc G., Will Dabney, and Rémi Munos. “A distributional perspective on reinforcement learning.” International Conference on Machine Learning . PMLR, 2017.
  8. Hernandez-Garcia, J. Fernando, and Richard S. Sutton. “Understanding multi-step deep reinforcement learning: a systematic study of the DQN target.” arXiv preprint arXiv:1901.07510  (2019).