#### Overview of this book

Deep Reinforcement Learning Hands-On is a comprehensive guide to the very latest DL tools and their limitations. You will evaluate methods including Cross-entropy and policy gradients, before applying them to real-world environments. Take on both the Atari set of virtual games and family favorites such as Connect4. The book provides an introduction to the basics of RL, giving you the know-how to code intelligent learning agents to take on a formidable array of practical tasks. Discover how to implement Q-learning on 'grid world' environments, teach your agent to buy and trade stocks, and find out how natural language models are driving the boom in chatbots.
Deep Reinforcement Learning Hands-On
Contributors
Preface
Other Books You May Enjoy
Free Chapter
What is Reinforcement Learning?
OpenAI Gym
Deep Learning with PyTorch
The Cross-Entropy Method
Tabular Learning and the Bellman Equation
Deep Q-Networks
DQN Extensions
The Actor-Critic Method
Chatbots Training with RL
Continuous Action Space
Trust Regions – TRPO, PPO, and ACKTR
Black-Box Optimization in RL
Beyond Model-Free – Imagination
AlphaGo Zero
Index

## The value iteration method

In the simplistic example we just saw, to calculate the values of states and actions, we have exploited the structure of the environment: we had no loops in transitions, so we could start from terminal states, calculate their values and then proceed to the central state. However, just one loop in the environment builds an obstacle in our approach. Let's consider such an environment with two states:

Figure 7: A sample environment with a loop in the transition diagram

We start from state , and the only action we can take leads us to state . We get reward r=1,and the only transition from is an action, which brings us back to the . So, the life of our agent is an infinite sequence of states []. To deal with this infinity loop, we can use a discount factor . Now, the question is, what are the values for both the states?

The answer is not very complicated, though. Every transition from to gives us a reward of 1 and every back transition gives us 2. So, our sequence of...