Implementing the Shallow_Q_Learner

We can then modify the Q_Learner class to use this SLP to represent the Q-function. Note that we will have to modify the Q_Learner class learn(...) method as well to calculate the gradients of loss with respect to the weights of the SLP and backpropagate them so as to update and optimize the neural network's weights to improve its Q-value representation to be close to the actual values. We'll also slightly modify the get_action(...) method to get the Q-values with a forward pass through the neural network. The following code for the Shallow_Q_Learner class with the changes from the Q_Learner class implementation are shown in bold to make it easy for you to see the differences at a glance:

import torchfrom ...

Get Hands-On Intelligent Agents with OpenAI Gym now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.