-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
38 additions
and
40 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,51 +1,33 @@ | ||
from env import Env | ||
from agent import ChaserAgent | ||
from agent import Agent | ||
import numpy as np | ||
|
||
# flake8: noqa | ||
|
||
env = Env() | ||
agent = ChaserAgent(gamma=0.99, epsilon=1.0, lr=0.003, dim_input=13, batch_size=64, dim_action=4, | ||
memory_max=10000, epsilon_min=0.03, epsilon_down=2e-5) | ||
agent = Agent(gamma=0.99, epsilon=1.0, lr=0.003, dim_input=13, batch_size=64, actions=8, | ||
memory_max=10000, epsilon_min=0.05, epsilon_down=2e-3) | ||
scores = [] | ||
eps_history = [] | ||
n_games = 500 | ||
n_games = 50 | ||
|
||
for i in range(n_games): | ||
done = False | ||
score = 0 | ||
observation = env.reset()[0] | ||
while not done: | ||
action = agent.choose_action(observation) | ||
observation_, reward, done = env.step(action) | ||
observation_, reward, done = env.step(env.action_space[action]) | ||
score += reward | ||
agent.store_transition(observation, action, reward, observation_, done) | ||
agent.learn() | ||
observation = observation_ | ||
agent.step += 1 | ||
scores.append(score) | ||
eps_history.append(agent.epsilon) | ||
|
||
avg_score = np.mean(scores[-20:]) | ||
print('episode', i, 'score %.2f' % score, 'average score %.2f' % avg_score, 'epsilon %.2f' % agent.epsilon) | ||
if i+1 % 25 == 0: | ||
print('episode', i, 'score %.2f' % score, 'average score %.2f' % avg_score, 'epsilon %.2f' % agent.epsilon) | ||
print(env.state) | ||
|
||
|
||
# test the rl algo and display the results of the agent | ||
env = Env() | ||
avg_score = 0 | ||
for i in range(100): | ||
state = env.reset() | ||
done = False | ||
score = 0 | ||
observation = env.reset()[0] | ||
while not done: | ||
action = agent.choose_action(observation) | ||
observation_, reward, done = env.step(action) | ||
observation = observation_ | ||
score += reward | ||
if score > 200: | ||
avg_score += 1 | ||
print('Episode:{} Score:{}'.format(i, score)) | ||
print('Average score:', avg_score/100) | ||
env.close() |
This file contains 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