Created
August 8, 2018 20:43
-
-
Save llSourcell/5a3070b337c96905075808ee770a0578 to your computer and use it in GitHub Desktop.
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 training_loop(self): | |
| #remember our gradients! | |
| gradients = np.vstack(self.gradients) | |
| rewards = np.vstack(self.rewards) | |
| rewards = self.discount_rewards(rewards) | |
| rewards = rewards / np.std(rewards - np.mean(rewards)) | |
| gradients *= rewards | |
| X = np.squeeze(np.vstack([self.states])) | |
| Y = self.probs + self.learning_rate * np.squeeze(np.vstack([gradients])) | |
| #update our model after a full-episode, did we win or lose? | |
| #Use that as the reward signal | |
| self.model.train_on_batch(X, Y) | |
| self.states, self.probs, self.gradients, self.rewards = [], [], [], [] | |
| if __name__ == "__main__": | |
| env = gym.make("Pong-v0") | |
| agent = PGAgent() | |
| while True: | |
| env.render() | |
| action, prob = agent.act(x) | |
| state, reward, done, info = env.step(action) | |
| score += reward | |
| agent.remember(x, action, prob, reward) | |
| agent.train() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment