Skip to content

Commit

Permalink
Merge pull request #33 from JdeRobot/fix/f1_env_division
Browse files Browse the repository at this point in the history
Fix/f1 env division
  • Loading branch information
igarag authored Oct 3, 2021
2 parents 661adb8 + 2474a0e commit 55656fb
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 244 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CustomRobots
.vscode
.jekyll-cache
_site
rl_studio/agents/f1/brains/logs/f1_qlearn_gym_experiments
agents/brains/logs/f1_qlearn_gym_experiments
*.manifest.json
*.stats.json
*.pkl
Expand Down
2 changes: 1 addition & 1 deletion rl_studio/agents/f1/brains/train_dqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from keras import backend as K
from settings import my_board

from rl_studio.agents.f1.algorithms.dqn import DeepQ
from algorithms.dqn import DeepQ

# To equal the inputs, we set the channels first and the image next.
K.set_image_data_format("channels_first")
Expand Down
28 changes: 15 additions & 13 deletions rl_studio/agents/f1/brains/train_qlearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import numpy as np

from rl_studio.agents.f1 import liveplot
from rl_studio.agents.f1 import settings
from rl_studio.agents.f1.settings import QLearnConfig
from rl_studio.agents.f1 import utils
from rl_studio.agents.f1.algorithms.qlearn import QLearn
from algorithms.qlearn import QLearn
from rl_studio.visual.ascii.images import JDEROBOT_LOGO
from rl_studio.visual.ascii.text import JDEROBOT, QLEARN_CAMERA, LETS_GO

Expand All @@ -20,7 +20,9 @@ def main():
print(QLEARN_CAMERA)
print(f"\t- Start hour: {datetime.datetime.now()}")

environment = settings.envs_params["simple"]
config = QLearnConfig()

environment = config.envs_params["simple"]
env = gym.make(environment["env"], **environment)

# TODO: Move to settings file
Expand All @@ -43,7 +45,7 @@ def main():

qlearn = QLearn(actions=actions, alpha=0.8, gamma=0.9, epsilon=0.99)

if settings.load_model:
if config.load_model:
# TODO: Folder to models. Maybe from environment variable?
file_name = ""
utils.load_model(qlearn, file_name)
Expand All @@ -61,7 +63,7 @@ def main():
previous = datetime.datetime.now()
checkpoints = [] # "ID" - x, y - time

# START ############################################################################################################
# START
for episode in range(total_episodes):

counter = 0
Expand Down Expand Up @@ -101,7 +103,7 @@ def main():

env._flush(force=True)

if settings.save_positions:
if config.save_positions:
now = datetime.datetime.now()
if now - datetime.timedelta(seconds=3) > previous:
previous = datetime.datetime.now()
Expand Down Expand Up @@ -131,13 +133,13 @@ def main():
states_reward[int(episode)] = cumulated_reward
print(
f"EP: {episode + 1} - epsilon: {round(qlearn.epsilon, 2)} - Reward: {cumulated_reward}"
f"- Time: {start_time_format} - Steps: {step}"
f" - Time: {start_time_format} - Steps: {step}"
)
break

if step > estimate_step_per_lap and not lap_completed:
lap_completed = True
if settings.plotter_graphic:
if config.plotter_graphic:
plotter.plot_steps_vs_epoch(stats, save=True)
utils.save_model(
qlearn, start_time_format, stats, states_counter, states_reward
Expand All @@ -148,7 +150,7 @@ def main():
)

if counter > 1000:
if settings.plotter_graphic:
if config.plotter_graphic:
plotter.plot_steps_vs_epoch(stats, save=True)
qlearn.epsilon *= epsilon_discount
utils.save_model(
Expand All @@ -161,25 +163,25 @@ def main():
counter = 0

if datetime.datetime.now() - datetime.timedelta(hours=2) > start_time:
print(settings.eop)
print(config.eop)
utils.save_model(
qlearn, start_time_format, stats, states_counter, states_reward
)
print(f" - N epoch: {episode}")
print(f" - Model size: {len(qlearn.q)}")
print(f" - Action set: {settings.actions_set}")
print(f" - Action set: {config.actions_set}")
print(f" - Epsilon: {round(qlearn.epsilon, 2)}")
print(f" - Cum. reward: {cumulated_reward}")

env.close()
exit(0)

if episode % 1 == 0 and settings.plotter_graphic:
if episode % 1 == 0 and config.plotter_graphic:
# plotter.plot(env)
plotter.plot_steps_vs_epoch(stats)
# plotter.full_plot(env, stats, 2) # optional parameter = mode (0, 1, 2)

if episode % 250 == 0 and settings.save_model and episode > 1:
if episode % 250 == 0 and config.save_model and episode > 1:
print(f"\nSaving model . . .\n")
utils.save_model(
qlearn, start_time_format, stats, states_counter, states_reward
Expand Down
Loading

0 comments on commit 55656fb

Please sign in to comment.