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/054832aeeae62606aced2dd82b7817ff to your computer and use it in GitHub Desktop.

Select an option

Save pythonlessons/054832aeeae62606aced2dd82b7817ff to your computer and use it in GitHub Desktop.
05_CartPole-reinforcement-learning_PER_D3QN
class SumTree(object):
data_pointer = 0
# Here we initialize the tree with all nodes = 0, and initialize the data with all values = 0
def __init__(self, capacity):
# Number of leaf nodes (final nodes) that contains experiences
self.capacity = capacity
# Generate the tree with all nodes values = 0
# To understand this calculation (2 * capacity - 1) look at the schema below
# Remember we are in a binary node (each node has max 2 children) so 2x size of leaf (capacity) - 1 (root node)
# Parent nodes = capacity - 1
# Leaf nodes = capacity
self.tree = np.zeros(2 * capacity - 1)
# Contains the experiences (so the size of data is capacity)
self.data = np.zeros(capacity, dtype=object)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment