Skip to content

Instantly share code, notes, and snippets.

@pythonlessons
Last active January 15, 2020 06:44
Show Gist options
  • Select an option

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

Select an option

Save pythonlessons/d5391fe227b6485d39a7288cb202bdfd to your computer and use it in GitHub Desktop.
05_CartPole-reinforcement-learning_PER_D3QN
def add(self, priority, data):
# Look at what index we want to put the experience
tree_index = self.data_pointer + self.capacity - 1
""" tree:
0
/ \
0 0
/ \ / \
tree_index 0 0 0 We fill the leaves from left to right
"""
# Update data frame
self.data[self.data_pointer] = data
# Update the leaf
self.update (tree_index, priority)
# Add 1 to data_pointer
self.data_pointer += 1
if self.data_pointer >= self.capacity: # If we're above the capacity, we go back to first index (we overwrite)
self.data_pointer = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment