-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
Update OpenAI Lander example #252
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
import neat | ||
import visualize | ||
|
||
NUM_CORES = 8 | ||
NUM_CORES = multiprocessing.cpu_count() | ||
|
||
env = gym.make('LunarLander-v2') | ||
|
||
|
@@ -86,21 +86,22 @@ def __init__(self, num_workers): | |
def simulate(self, nets): | ||
scores = [] | ||
for genome, net in nets: | ||
observation = env.reset() | ||
observation_init_vals, observation_init_info = env.reset() | ||
step = 0 | ||
data = [] | ||
while 1: | ||
step += 1 | ||
if step < 200 and random.random() < 0.2: | ||
action = env.action_space.sample() | ||
else: | ||
output = net.activate(observation) | ||
output = net.activate(observation_init_vals) | ||
action = np.argmax(output) | ||
|
||
observation, reward, done, info = env.step(action) | ||
# Note: done has been deprecated. | ||
observation, reward, terminated, done, info = env.step(action) | ||
data.append(np.hstack((observation, action, reward))) | ||
|
||
if done: | ||
if terminated: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment for line 223 -> same topic |
||
break | ||
|
||
data = np.array(data) | ||
|
@@ -202,7 +203,7 @@ def run(): | |
solved = True | ||
best_scores = [] | ||
for k in range(100): | ||
observation = env.reset() | ||
observation_init_vals, observation_init_info = env.reset() | ||
score = 0 | ||
step = 0 | ||
while 1: | ||
|
@@ -211,14 +212,15 @@ def run(): | |
# determine the best action given the current state. | ||
votes = np.zeros((4,)) | ||
for n in best_networks: | ||
output = n.activate(observation) | ||
output = n.activate(observation_init_vals) | ||
votes[np.argmax(output)] += 1 | ||
|
||
best_action = np.argmax(votes) | ||
observation, reward, done, info = env.step(best_action) | ||
# Note: done has been deprecated. | ||
observation, reward, terminated, done, info = env.step(best_action) | ||
score += reward | ||
env.render() | ||
if done: | ||
if terminated: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use the truncated state since it seems more to behave like the old "done".
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the correct action here would have been |
||
break | ||
|
||
ec.episode_score.append(score) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this wrong? Shouldn't you have named this
observation
? Now it just feeds the initial observation every time through the loop, and the observation never changes. Same issue below!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you are right. I created another PR ... maybe have a look at it and feel free to comment if u find something
#274