Created
January 15, 2020 08:45
-
-
Save pythonlessons/6f52464068f9213578c073ea7905421c 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 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