Running the task loop
The full code for this problem is available on GitHub (https://github.com/PacktPublishing/Hands-On-Q-Learning-with-Python/tree/master/ch6), but we'll go through key sections of it in this chapter.
In the task loop, we create a DQN and run it over a series of episodes. Each episode lasts a maximum of 200 episodes, or until the task is lost. This happens when the pole falls more than 15 degrees from vertical or the cart moves more than 2.4 units from the center of the screen.
We set next_state, reward, done, and info as we did in our previous Q-learning models. (Again, we are not making use of the info variable here.) These variables are set with env.step(action) as before.
We initialize the state and fit it as a state ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access