O'Reilly logo

Python Reinforcement Learning Projects by Rajalingappaa Shanmugamani, Yang Wenzhuo, Sean Saito

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Agent script

In this section, we will train an agent that will perform reinforcement learning based on the actor and critic networks. We will perform the following steps to achieve this:

  1. Create an agent class whose initial function takes in the batch size, state size, and an evaluation Boolean function, to check whether the training is ongoing.
  2. In the agent class, create the following methods:
  3. Import the actor and critic scripts:
from actor import Actorfrom critic import Critic
  1. Import numpy, randomnamedtuple, and deque from the collections package:
import numpy as npfrom numpy.random import choiceimport randomfrom collections import namedtuple, deque
  1. Create a ReplayBuffer class that adds, samples, and evaluates a buffer:
class ReplayBuffer: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required