concept overestimation in category reinforcement learning

This is an excerpt from Manning's book Grokking Deep Reinforcement Learning.
We all know someone with a positive-bias personality that has let something gone wrong in their lives. Someone that is blinded by shiny things, that are not as shiny. To me, this is one of the reasons why many people advise against feeding the AI hype; because overestimation is often your enemy, and certainly something to mitigate for an improved performance.
Know that there is such a thing as “reward clipping,” which is different than “gradient clipping.” These are two very different things, so beware. One works on the rewards and the other on the errors (the loss). Now, above all is not to confuse either of these with “Q-value clipping,” which is undoubtedly a mistake.
Remember, the goal in our case is to prevent gradients from becoming too large. For this, we either make the loss linear outside a given absolute TD error threshold or make the gradient constant outside a max gradient magnitude threshold.
In the cart-pole environment experiments that you find in the Notebook, I implemented the Huber loss function by using the “gradient clipping” technique: That is, I calculate MSE and then clip the gradients. However, as I mentioned before, I set the hyperparameter setting the maximum gradient values to infinity. Therefore, it is effectively using good-old MSE. But, please, experiment, play around, explore! The Notebooks I created should help you learn almost as much as the book. So, set yourself free over there.
It's In The Details
The full Double Deep Q-Network (DDQN) algorithm
DDQN is almost identical to DQN, but there are still some differences. We still:
· Approximate the action-value function Q(s,a; θ).
· Use a state-in-values-out architecture (nodes: 4, 512,128, 2).
· Optimize the action-value function to approximate the optimal action- value function q*(s,a).
· Use off-policy TD targets (r + gamma*max_a’Q(s’,a’; θ)) to evaluate policies.
Notice that we now:
· Use an adjustable Huber loss, which since we set the ‘max_gradient_norm’ variable to ‘float(‘inf’)’, we are effectively just using mean squared error (MSE) for our loss function.
· Use RMSprop as our optimizer with a learning rate of 0.0007. Note that before we used 0.0005 because without double learning (vanilla DQN) some seeds fail if we train with a learning rate of 0.0007. Perhaps stability? In DDQN, on the other hand, training with a higher learning rate works best.
In DDQN we are still using:
· An exponentially decaying epsilon-greedy strategy (from 1.0 to 0.3 in roughly 20,000 steps) to improve policies.
· A replay buffer with 320 samples min, 50,000 max, and a batch of 64.
· A target network that freezes for 15 steps and then updates fully.
DDQN, just like DQN has the same 3 main steps:
1. Collect experience: (St, At, Rt+1, St+1, Dt+1), and insert it into the replay buffer.
2. Randomly sample a mini-batch from the buffer and calculate the off-policy TD targets for the whole batch: r + gamma*max_a’Q(s’,a’; θ).
3. Fit the action-value function Q(s,a; θ): Using MSE and RMSprop.
The bottom line is the DDQN implementation and hyperparameters are identical to those of DQN, except that we now use double learning and therefore train with a slightly higher learning rate. The addition of the Huber loss does not change anything because we are “clipping” gradients to a max value of infinite, which is equivalent to using MSE. However, for many other environments you will find it useful, so tune this hyperparameter.
Tally It Up
DDQN is more stable than NFQ or DQN
DQN and DDQN have very similar performance in the cart-pole environment. However, this is a simple environment with a very smooth reward function. In reality, DDQN should always give better performance.
Figure 9.24
9.2.6 Things we can still improve on
Surely our current value-based deep reinforcement learning method is not perfect, but it is pretty solid. DDQN can reach super-human performance in many of the ATARI games. To replicate those results, you would have to change the network to take images as input (a stack of 4 images to be able to infer things such as direction and velocity from the images), and, of course, tune the hyperparameters.
Yet, we can still go a little further. There are at least a couple of other improvements to consider that are easy to implement and impact performance in a very positive way.
The first improvement requires us to reconsider the current network architecture. As of right now, we have a very naive representation of the Q-function on our neural network architecture.
Refresh My Memory
Current neural network architecture
We are literately “making reinforcement learning look like supervised learning”. But, we can, and should, break free from this constraint, and think out of the box.
Figure 9.25 State-in-values-out architecture
Is there any better way of representing the Q-function? Think about this for a second while you look at the images on the next page.
The images on the right are bar plots representing the estimated action-value function Q, state-value function V, and action-advantage function A for the cart-pole environment with a state in which the pole is near vertical.
Figure 9.26
Notice the different functions and values and start thinking about how to better architect the neural network so that data is used more efficiently. As a hint, let me remind you that the Q-values of a state are related through the V-function. That is, the action-value function Q has an essential relationship with the state-value function V, because of both actions in Q(s) and indexed by the same state s (in the example to the right s=[0.02, -0.01, -0.02, -0.04]).
Figure 9.27
The question is, would you be able to learn anything about Q(s, 0) if you are using a Q(s, 1) sample? Look at the plot showing the action-advantage function A(s) and notice how much easier it is for you to eyeball the greedy action with respect to these estimates than when using the plot with the action-value function Q(s). What can you do about this? In the next chapter, we look at a network architecture called the Dueling network that helps us exploit these relationships.
Figure 9.28
The other thing to consider improving is the way we sample experiences from the replay buffer. As of now, we pull samples from the buffer uniformly at random, and I’m sure your intuition questions this approach and suggests we can do better, and we can.
Humans don’t go around the world, just remembering random things to learn from at random times. There is a more systematic way in which intelligent agents “replay memories.” I’m pretty sure my dog chases rabbits in her sleep. Some experiences are more important than others to our goals. Humans often replay experiences that caused them unexpected joy or pain. And it makes sense, and you need to learn from these experiences to generate more or less of them. In the next chapter, we look at ways of prioritizing the sampling of experiences to get the most out of each sample, when we learn about the Prioritized Experience Replay (PER) method.
9.3 Summary
In this chapter, you learned about the widespread issues with value-based deep reinforcement learning methods. The fact that online data is not stationary, and it is also not independent and identically distributed as most optimization methods expect, creates an enormous amount of problems value-based methods are susceptible to.
You learn to stabilize value-based deep reinforcement learning methods by using a variety of techniques that have empirical results in several benchmarks, and you dug deep on these components that make value-based methods more stable. Namely, you learned about the advantages of using target networks and replay buffers in an algorithm known as DQN (‘Nature’ DQN, or ‘Vanilla’ DQN). You learned that by using target networks, we make the targets appear stationary to the optimizer, which is good for stability, although by sacrificing convergence speed. You also learn that by using replay buffers, the online data looks more IID, which you also learned, is a source of significant issues in value-based bootstrapping methods. These two techniques combined make the algorithm sufficiently stable for performing well in several deep reinforcement learning tasks.
However, there are many more potential improvements to value-based methods. You implemented a straightforward change that has a significant impact on performance, in general. You added a double learning strategy to the baseline DQN agent that, when using function approximation, is known as the DDQN agent, and it mitigates the issues of overestimation in off-policy value-based methods.
In addition to these new algorithms, you learned about different exploration strategies to use with value-based methods. You learned about linearly and exponentially decaying epsilon-greedy and SoftMax exploration strategies, this time, in the context of function approximation. Also, you learned about different loss functions and which ones make more sense for reinforcement learning and why. You learned that the Huber loss function allows you to tune between MSE and MAE with a single hyperparameter, and it is, therefore, one of the preferred loss functions used in value-based deep reinforcement learning methods.
By now you:
· Understand why using online data for training neural network with optimizers that expect stationary and IID data is a problem in value-based DRL methods.
· Can solve reinforcement learning problems with continuous state-spaces with algo-rithms that are more stable and therefore give more consistent results.
· Have an understanding of state-of-the-art value-based deep reinforcement learning methods and are able to solve complex problems.
Tweetable Tweet
Do some work on your own and share your findings
Every chapter, I’ll give some ideas on how to take what you have learned to the next level. If you’d like, share your results with the rest of the world and make sure to check out what others have done, too. It’s a win-win situation, and hopefully, you take advantage of it.
For this chapter, here are some ideas to explore:
· #gdrl-ch09-tf01: In this and next chapter, we test the algorithms only in the Cart- Pole environment. Find a couple other environments and test the agents in those. For instance, the LunarLander environment here: https://gym.openai.com/envs/#box2d, and the MountainCar environment here: https://gym.openai.com/envs/#classic_con- trol. Did you have to make any changes to the agents, excluding hyperparamters, to make the agents work in these environments? Now, make sure to find a single set of hyperparameters that solve all environments. To clarify, I mean you use a single set of hyperparameters, and train an agents from scratch in each environment, not a single trained agents that does well in all environments.
· #gdrl-ch09-tf02: In this and next chapter, we test the algorithms in environ- ments that are continuous, but low dimensional. You know what a high-dimensional environment is? ATARI environments. Look them up here (the non ‘ram’): https://gym. openai.com/envs/#atari. Now, modify the networks, replay buffer, and agent code in this chapter so that the agent can solve image-based environments. Beware that this is not a trivial task, and training will take while, from many hours to several days.
· #gdrl-ch09-tf03: I mentioned that value-based methods are very sensitive to hyperparameters. In reality, there is something called the “Deadly Triad,” that basically tells us using neural networks, with bootstrapping and off-policy is bad. Investigate!
· #gdrl-ch09-tf04: In every chapter, I’m using the final hashtag as a ‘catch-all’ hashtag. Feel free to use this one to discuss anything else that you worked on relevant to this chapter. There is no more exciting homework that the one you create for your- self. Make sure to share what you set yourself to investigate and your results.
Write a tweet with your findings, tag me @mimoralea (I’ll retweet,) and use the particular hashtag from the list above to help folks interested find your results. There are no right or wrong results; you share your findings and check others’ findings. Take advantage of this to socialize, contribute, and get yourself out there! We’re waiting for you!
Here is a tweet example:
“Hey, @mimoralea. I created a blog post with a list of resources to study deep reinforcement learning. Check it out at <link>. #gdrl-ch01-tf01”
I’ll make sure to retweet and help others find your work.




