DQN: Prioritized Experience Replay

Experience replay allows agents to remember and reuse past experiences. It samples the experiences uniformly from the memory. However, some experiences are more important than others and should not be treated equally. With prioritized experience replay (PER), the agents replay important experiences more often and therefore, learn more efficiently.

Why are we using experience replay in the first place? Without experience replay, the samples taken from reinforcement learning are highly correlated and breaking the i.i.d. assumption - a very common assumption in many machine learning algorithms that the samples are independent and identically distributed random variables. In addition, without memory, the agent forgets experiences immediately. Instead of waiting for important but rare experiences to happen again, which might take forever, it seems wiser to remember them.

Greedy TD-Error Prioritization

Prioritized experience replay takes experience replay one step further. Experiences are not only remembered but also replayed according to importance. The more available to learn from an experience, the more important it is, and the more frequent we want to replay it. We use the difference between the target and prediction to determine the level of importance. The greater the difference, the greater the room for improvement, and the greater the importance. This difference is called the TD error.

Greedy TD-error prioritization is an algorithm that stores each experience along with its TD error. It’s called “greedy” because the largest TD error experience always gets to replay. New experiences are assigned with the largest TD error to make sure they are replayed for at least once.

However, this approach has some issues. The system overfits when there are experiences with large initial TD errors. During training, step by step, similar to gradient descent, the TD errors shrink slowly. The system trains with the same experience for many steps, until it finds another experience with a larger error. When a system trains with same experiences for too many times, it overfits. On the other hand, an experience with small initial TD error has a problem too. It has to wait for a long time before gettin replayed, or may even never get replayed when there’s a sliding window.

Note the system is very sensitive to stochastic rewards. For example, when an unimportant experience gets a high initial TD error, because of the randomness in rewards, the agent will waste a lot of time learning from it repeatedly.

Stochastic Prioritization

We want to make sure every experience gets a chance to be picked, and the higher the priority, the greater the probability. Stochastic prioritization is a sampling method created for this purpose. The probability for experience to be picked is defined as

is the priority of experience . The priority can be defined in various ways. Either directly relates to TD error

is a constant to ensure the experience with zero error still stands a chance to be picked.

or indirectly through the ranks

where the is the rank of the experience when the replay memory is sorted by TD errors.

The hyperparameter controls the randomness involved. Set to do uniform random sampling, and to do greedy prioritization.

Importance Sampling

Prioritize sampling introduces a bias toward high-priority experiences. To understand, let’s review how Q-learning update at each step:

In general, the samples and estimations should fall in the same distribution. When they don’t, the solution we find will be wrong. When we assign higher probabilities to high-priority experiences, we are changing the underlying sampling distribution. The high-priority experiences are been picked up more often than they should under the true distribution. To compensate this, we use importance sampling weights:

During Q-learning update, we use instead of to scale the TD error.

The hyperparameter controls the level of compensation. When , the prioritize sampling probabilities are fully compensated. In reinforcement learning, unbiased updates are most important near convergence at the end of the training. We typically set close to zero at the beginning of learning, and anneal it up to one over the training.

References

[1] Schaul, T., Quan, J., Antonoglou, I., & Silver, D. (2015). Prioritized Experience Replay.