Last active
January 15, 2020 06:44
-
-
Save pythonlessons/d5391fe227b6485d39a7288cb202bdfd 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 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