Skip to content

Instantly share code, notes, and snippets.

@pythonlessons
Created January 15, 2020 08:45
Show Gist options
  • Select an option

  • Save pythonlessons/6f52464068f9213578c073ea7905421c to your computer and use it in GitHub Desktop.

Select an option

Save pythonlessons/6f52464068f9213578c073ea7905421c to your computer and use it in GitHub Desktop.
05_CartPole-reinforcement-learning_PER_D3QN
def replay(self):
if self.USE_PER:
# Sample minibatch from the PER memory
tree_idx, minibatch = self.MEMORY.sample(self.batch_size)
else:
# Randomly sample minibatch from the deque memory
minibatch = random.sample(self.memory, min(len(self.memory), self.batch_size))
'''
everything stay the same here as before
'''
target_old = np.array(target)
'''
everything stay the same here as before
'''
if self.USE_PER:
absolute_errors = np.abs(target_old[i]-target[i])
# Update priority
self.MEMORY.batch_update(tree_idx, absolute_errors)
# Train the Neural Network with batches
self.model.fit(state, target, batch_size=self.batch_size, verbose=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment