Created
January 15, 2020 06:43
-
-
Save pythonlessons/49eeb3fc8af0f6189dfb15f47503a6d8 to your computer and use it in GitHub Desktop.
05_CartPole-reinforcement-learning_PER_D3QN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_leaf(self, v): | |
| parent_index = 0 | |
| while True: | |
| left_child_index = 2 * parent_index + 1 | |
| right_child_index = left_child_index + 1 | |
| # If we reach bottom, end the search | |
| if left_child_index >= len(self.tree): | |
| leaf_index = parent_index | |
| break | |
| else: # downward search, always search for a higher priority node | |
| if v <= self.tree[left_child_index]: | |
| parent_index = left_child_index | |
| else: | |
| v -= self.tree[left_child_index] | |
| parent_index = right_child_index | |
| data_index = leaf_index - self.capacity + 1 | |
| return leaf_index, self.tree[leaf_index], self.data[data_index] | |
| @property | |
| def total_priority(self): | |
| return self.tree[0] # Returns the root node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment