Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean way to stop training #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions 2-cartpole/1-dqn/cartpole_dqn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import gym
import pylab
import random
Expand Down Expand Up @@ -121,13 +120,16 @@ def train_model(self):
agent = DQNAgent(state_size, action_size)

scores, episodes = [], []
complete = False

for e in range(EPISODES):
done = False
score = 0
state = env.reset()
state = np.reshape(state, [1, state_size])

if complete: break

while not done:
if agent.render:
env.render()
Expand Down Expand Up @@ -162,7 +164,7 @@ def train_model(self):
# if the mean of scores of last 10 episode is bigger than 490
# stop training
if np.mean(scores[-min(10, len(scores)):]) > 490:
sys.exit()
complete = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we just break here? and not use complete flag?


# save the model
if e % 50 == 0:
Expand Down