A method that trains the neural network with experiences in the memory is called replay():
- First, we take some experiences from the memory and call them minibatch:
minibatch = random.sample(self.memory, batch_size)
- The preceding code will make minibatch: randomly sampled elements of the memories of the size, batch_size. The batch size is 32 for this example.
- To make the agent perform well in the long-term, we need to take into account not only the immediate rewards but also the future rewards that we are going to get. In order to do this, we have a discount rate or gamma. This way, the agent will learn to maximize the discounted future reward based on the given state:
def replay(self, batch_size): minibatch = random.sample( ...