This repository was archived by the owner on Aug 11, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 506
Update OpenAI Lander example #252
Merged
CodeReclaimers
merged 1 commit into
CodeReclaimers:master
from
Warosaurus:update_openai_lander_example
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!Uh oh!
There was an error while loading. Please reload this page.
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